@now-ims/slugify
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

slugify

A simple package to create slugs from strings while keeping it DRY. 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:

Readme

Keywords

Package Sidebar

Install

npm i @now-ims/slugify

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.41 kB

Total Files

7

Last publish

Collaborators

  • puchesjr