So here is the deal, I wrote this really Stupid Sling URL Parser:
A Really stupid Apache Sling URL Parser
I built this for fun. It only supports Modern browsers (Sorry not sorry IE) and NodeJs 10+. Also, it is EXTREMELY small! ~0.8KB minified. Sluri is 6.5 KB minified but has a lot more functionality.
Get the minified version in
const slingUrl = new SlingUrl('/a/b.s1.html/c/d'); console.log(slingUrl.resourcePath) // returns: "/a/b" console.log(slingUrl.selectors) // returns ["s1"] console.log(slingUrl.extension) // returns "html" console.log(slingUrl.suffix) // returns "/c/d" // if any of the properties above does not exist, null is returned.
The whole source is in this file: https://github.com/ahmed-musallam/stupid-sling-url-parser/blob/master/src/SlingUrl.js
I'm setting a pretty low bar here, since I wrote this very quickly for the SOLE purpose of saving bytes.
Now, I'd like to see you try to write something better! It would be a good exercise if you're up for it. Plus you'd show some random person on the internet how wrong they are.
All you need to know to rebuild this is in the URL Decomposition Doc of Apache Sling
The doc has examples and I have written tests for my parser