slugger
Dead simple slugification for node and browser.
What it does:
Converts any string into a url friendly version:
; // returns 'hello-you-crazy-swede' // optionally maintain case; // returns 'Hello-yOu-CRAZY-Swede' // optionally use a different replacement character; // returns 'hello_you_crazy_swede' // optionally trim to max length while not breaking any words; // returns 'hello-you' // optionally allow additional characters// just pass string of characters that would normally be removed// that you want to allow.; // returns 'hello-you-crazy-swede!' // decodes URI components by default, so {decode: true} is not required // returns 'boo-boo';// now without decode // returns boo20boo;
That's all there is to it!
Installing
npm install slugger
Or just grab the slugger.js file and drop it into your project.
It also plays nicely with: https://github.com/henrikjoreteg/clientmodules
https://github.com/dodo/node-slug ?
Why did I write this when there's alreadyBecause I wanted something simpler that didn't try to do anything with special characters or unicode and I wanted something that worked well in the browser or node.
Tests?
Just run npm test
Changelog
- 0.1.0 - Adding option to allow other characters
Dig it?
Then you should probably follow @HenrikJoreteg on twitter.
License
MIT