@kchungradio/slugify

0.3.0 • Public • Published

slugify Build Status

Slugify a string

Useful for URLs, filenames, and IDs.

Install

$ npm install @sindresorhus/slugify

Usage

const slugify = require('@sindresorhus/slugify');

slugify('I ♥ Dogs');
//=> 'i-love-dogs'

slugify('  Déjà Vu!  ');
//=> 'deja-vu'

slugify('fooBar 123 $#%');
//=> 'foo-bar-123'

slugify('BAR and baz', {separator: '_'});
//=> 'bar_and_baz'

slugify('I ♥ 🦄 & 🐶', {
  customReplacements: [
    ['🐶', 'dog']
  ]
});
//=> 'i-love-unicorn-and-dog'

API

slugify(input, [options])

input

Type: string

options

Type: Object

separator

Type: string
Default: -

customReplacements

Type: Array
Default: [ ['&', 'and'], ['🦄', 'unicorn'], ['♥', 'love'] ]

Specifying this only replaces the default if you set an item with the same key, like &.

Related

License

MIT © Sindre Sorhus

Package Sidebar

Install

npm i @kchungradio/slugify

Weekly Downloads

0

Version

0.3.0

License

MIT

Unpacked Size

4.55 kB

Total Files

4

Last publish

Collaborators

  • tim-phillips