Jeremy Selier

Uslug.js - A unicode slug generator

My very first node module!

Slug generators are a common thing of the web but it's like finding a script to remove accents, everyone has his own solution and it never fits your need! The same applied to me while working on the new Jolicloud. That's why I created uslug (as in unicode slug).

We need to produce slug for obvious reasons, one is clarity in the navigation of our app. I tried first looking for some lib/script that could already do the job. But all I could find were scripts that would keep only [a-zA-Z0-9_-] characters.

It's 2012! I want Chinese people to be able to slug just like English or French people! Punycode is largely supported in browser so it's fine to provide this kind of functionality.

So here's uslug.js, just give it your string and it will slug the hell of it! Here's some example:

  uslug('Быстрее и лучше!') // 'быстрее-и-лучше'
  uslug('汉语/漢語') // '汉语漢語'

Installation is as easy as npm install uslug. I open-sourced the whole thing on github, feel free to report issues and all!

One last thing, I would like to thanks Dave Dash for the kick start and unorm for the JavaScript Unicode Normalization lib.

This post has been cross-posted on the Jolicloud Engineering blog.

All posts >