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

0.1.9 • Public • Published

npm versionvulnerabilitiesminzipped size   buildcoverage   Platform   Sponsordonatelicense   Follow

slugify

Turns strings into user-friendly and search engine-friendly URL slugs.

Slugify uses a dictionary to translate certain glyphs to the alphabet a-z A-Z 0-9. Beside whitespace, the characters !#$%&()*+,-./:;=?@[\]_|~ are considered as space. All other characters are removed, especially single ' and double " quotes. Finally, the words are joined, by default with hyphen '-'.

A highlight of this solution is the readability of slugs. Only words and a single separator type are used.

Installation

npm i @danieldietrich/slugify

Usage

The module supports ES6 import and CommonJS require style.

import slugify from '@danieldietrich/slugify';

// I-love-it
slugify('I ♥ it!');

// I_love_it
slugify('I ♥ it!', '_');

// cafebab3-gmail-com
slugify('cafebab3@gmail.com');

// dos-and-donts
slugify("Do's and Don'ts").toLowerCase();

Copyright © 2020 by Daniel Dietrich. Released under the MIT license.

Package Sidebar

Install

npm i @danieldietrich/slugify

Weekly Downloads

1

Version

0.1.9

License

MIT

Unpacked Size

17.5 kB

Total Files

6

Last publish

Collaborators

  • danieldietrich