slug
    Overview
    Dependencies
    Versions
    Playground
    Code
    Documentation
    Issues
    Find an Expert
    Career Opportunities
    Alternatives
    Insights & Analysis

slug

slugifies even utf-8 chars!

1.1.0  •  Published 5 months ago  •  by dodo  •  Unknown License

slug

slugifies every string, even when it contains unicode!

Make strings url-safe.

  • respecting RFC 3986
  • 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

var slug = require('slug')
var print = console.log.bind(console, '>')

print(slug('i ♥ unicode'))
// > i-love-unicode

print(slug('unicode ♥ is ☢')) // yes!
// > unicode-love-is-radioactive

print(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
print(slug('I ♥ UNICODE'))
// > I-freaking-love-UNICODE

print(slug('☏-Number', {lower: true})) // If you prefer lower case
// > telephone-number

print(slug('i <3 unicode'))
// > i-love-unicode

options

// options is either object or replacement (sets options.replacement)
slug('string', [{options} || 'replacement']);
slug.defaults.mode ='pretty';
slug.defaults.modes['rfc3986'] = {
    replacement: '-',      // replace spaces with replacement
    symbols: true,         // replace unicode symbols or not
    remove: null,          // (optional) regex to remove characters
    lower: true,           // result in lower case
    charmap: slug.charmap, // replace special characters
    multicharmap: slug.multicharmap // replace multi-characters
};
slug.defaults.modes['pretty'] = {
    replacement: '-',
    symbols: true,
    remove: /[.]/g,
    lower: false,
    charmap: slug.charmap,
    multicharmap: slug.multicharmap
};

browser

When using browserify you might want to remove the symbols table from your bundle by using --ignore similar to this:

# generates a standalone slug browser bundle:
browserify slug.js --ignore unicode/category/So -s slug > slug-browser.js

Build Status

Dependencies

unicode  ·  coffee-script  ·  mocha  ·  should

Tags

slugify
slug
string
utf8
utf-8
unicode
url
Keep your dependencies fresh!
Upgrade your packages safely and continuously.
We run your CI tests and compatability tests on new versions of your packages - to determine which upgrades are safe
Just $9/month per developer

Popularity

Weekly Downloads
129.0K
Stars
46

Issues and PRs

Activity

Last ver 5 months ago
Created 8 years ago
Last commit 5 months ago
20 days between commits

Sustainability

19 contributors

Technology

Node version: 11.13.0
26.6K unpacked

Legal and Compliance

License Unknown
Not OSI Approved
0 vulnerabilities

Top Experts

dodo
108 commits
Rich Trott
Maintainer, 9 commits
Veselin Todorov
7 commits
Works at angellist
Do Minh Hai
3 commits
Works at Freelancer
Zertz-Lenovo
3 commits
Nick Baugh
2 commits
Works at ladjs koajs expressjs