A simple package to create slugs from strings while keeping it DRY.
npm install @now-ims/slugify -S
string
- is required the string you want to slugifyseparator
- (Default:'-'
) optional character to use as separator+
is another good option
const slugify = require('@now-ims/slugify');
const assert = require('assert'); // not needed to work
let txt = 'This is a test ---';
let slug = slugify(txt);
assert.strictEqual(slug, 'this-is-a-test');
txt = "C'est déjà l'été.";
slug = slugify(txt);
assert.strictEqual(slug, 'c-est-deja-l-ete');
txt = 'Nín hǎo. Wǒ shì zhōng guó rén';
slug = slugify(txt);
assert.strictEqual(slug, 'nin-hao-wo-shi-zhong-guo-ren');
txt = 'jaja---lol-méméméoo--a';
r = slugify(txt);
assert.strictEqual(slug, 'jaja-lol-mememeoo-a');
txt = 'Ford F150 King Ranch';
slug = slugify(txt, '+');
assert.strictEqual(slug, 'ford+f150+king+ranch');
txt = 'Ford F-150 King Ranch';
slug = slugify(txt, '+');
assert.strictEqual(slug, 'ford+f-150+king+ranch');
Licensed under MIT
This project is sponsored and maintained by: