slug

v0.6.0(not latest)
License
MIT
Install Size
-
Vulns
1
Published

Get started

$npm install slug@0.6.0
$pnpm add slug@0.6.0
$yarn add slug@0.6.0
$bun add slug@0.6.0
$deno add npm:slug@0.6.0
$vlt install slug@0.6.0
$npm install -D @types/slugView @types/slug
$pnpm add -D @types/slugView @types/slug
$yarn add -D @types/slugView @types/slug
$bun add -d @types/slugView @types/slug
$deno add -D npm:@types/slugView @types/slug
$vlt install -D @types/slugView @types/slug
# Run locally
$npx slug
$pnpm exec slug
$npx slug
$bunx slug
$deno run npm:slug
$vlx slug

Readme

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').toLowerCase()) // If you prefer lower case
// > i-freaking-love-unicode

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

Weekly DownloadsAcross all versions

Node.js
>= 0.4.x

Versions

11.0.1
latest