When running devops scripts (among other things), we often need to get a url-safe representation of an arbitrary string. This is commonly known as “url slug” by the average netizens.
npx is more universally available than my capability to master both Windows and Linux shell scripts, I decided to publish a tiny command-line interface that takes in an arbitrary string and outputs a url-safe representation of it.
I intend to mainly use this for my personal projects (in other words: I’m not offering “warranty” of any kind 😅), so I published the script behind my own namespace. Anyhow, it can be used like this (if you have Node.js installed):
npx khang util urlize <your URL-unsafe string here>
(don’t forget to escape your input string properly esp. if you’re using this straight from the command line 😉)
npx khang util urlize haH\#\!woa-\%20_351\$ npx: installed 1 in 2.936s haH--woa--20_351-
As seen from the above example, the url-unsafe string
haH#!woa-\%20_351\$ was turned to a less hostile representation:
I have lots of use for this util. I hope you’ll find a good use for it, too!