@tlouverse/slugs
v0.1.3
Published
Small dependency-free slugification utilities for frontend and Node.js apps.
Maintainers
Readme
@tlouverse/slugs
Dependency-free slugification utilities for frontend and Node.js apps.
Links
- GitHub: https://github.com/Tlouverse/slugify
- Live demo: https://tools.tlouverse.com/slugifier
- npm: https://www.npmjs.com/package/@tlouverse/slugs
Install
npm install @tlouverse/slugsUsage
import { slugify, slugifyLines } from '@tlouverse/slugs';
slugify("John's cafe & bakery");
// "johns-cafe-and-bakery"
slugify('cafe 中文 Привет', { preserveUnicode: true });
// "cafe-中文-привет"
slugify('café 中文 Привет', { transliterate: false, preserveUnicode: true });
// "café-中文-привет"
slugifyLines('First title\nSecond title');
// ["first-title", "second-title"]
slugifyLines(['First title', 'Second title']);
// ["first-title", "second-title"]API
slugify(input, options?)
Returns a single slug string.
Options:
| Option | Default | Description |
| ------------------- | ------- | --------------------------------------------------------------------------------------------- |
| separator | '-' | Separator inserted between slug parts. Supports '-', '_', and '.'. |
| lowercase | true | Lowercase the result. |
| transliterate | true | Fold accents and common Latin characters to ASCII, such as é -> e, ß -> ss, and ø -> o. |
| preserveUnicode | false | Preserve Unicode letters and numbers instead of forcing ASCII-only output. |
| wordSubstitutions | true | Replace common symbols like &, @, +, %, and # with words. |
| maxLength | 0 | Maximum slug length. 0 means unlimited. |
slugifyLines(input, options?)
Accepts either a text block or an array of strings. Text blocks are split on \n, \r\n, or \r; arrays are treated as already-split logical lines.
Additional option:
| Option | Default | Description |
| -------------------- | ------- | ---------------------------------------------------- |
| preserveEmptyLines | false | Keep empty slug lines instead of filtering them out. |
Defaults
The default output is ASCII-first for broad compatibility with URLs, logs, APIs, filesystems, and older systems. Use preserveUnicode: true when readable native-language slugs are preferred.
