1.0.0 • Published 3 years ago

@now-ims/slugify v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

slugify

A simple package to create slugs from strings while keeping it DRY. npm.io npm (scoped)

How to install

npm install @now-ims/slugify -S

API

  • string - is required the string you want to slugify
  • separator - (Default: '-') optional character to use as separator + is another good option

How to use

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');

License

Licensed under MIT

Acknowledgements

This project is sponsored and maintained by: