Skip to content

jbraithwaite/node-slug

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slugifies every string, even when it contains unicode!

Make strings url-safe.

  • Comprehensive tests
  • No dependencies (except the unicode table)
  • Not in coffee-script (except the tests lol)
  • Coerces foreign symbols to their english equivalent
  • Works in browser (window.slug) and AMD/CommonJS-flavoured module loaders (except the unicode symbols unless you use browserify but who wants to download a ~2mb js file, right?)
npm install slug

example

master//node-slug » node
> slug = require ('./slug')
> slug('i ♥ unicode')
 'i-love-unicode'
> slug('i ♥ unicode', '_') # If you prefer something else then `-` as seperator
 'i_love_unicode'
> slug.charmap[''] = 'freaking love' # change default charmap or use option {charmap:{…}} as 2. argument
> slug('I ♥ UNICODE').toLowerCase() # If you prefer lower case
 'i-freaking-love-unicode'
> slug('unicode ♥ is ☢') # yes!
 'unicode-love-is-radioactive'

options

// options is either object or replacement (sets options.replacement)
slug('string', [{options} || 'replacement']);
slug.defaults = {
    replacement: '-',      // replace spaces with replacement
    symbols: true,         // replace unicode symbols or not
    charmap: slug.charmap, // replace special characters
};

Build Status

Bitdeli Badge

About

slugifies even utf-8 chars!

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 56.7%
  • JavaScript 43.3%