@nilambar/slugmo
v1.0.1
Published
Convert text to URL-safe slugs.
Readme
slugmo
Convert text to URL-safe slugs.
Install
npm install @nilambar/slugmoOr run without installing:
npx @nilambar/slugmo "Your text here"Usage
From argument:
npx @nilambar/slugmo "Hello World"
# hello-world
npx @nilambar/slugmo "Café résumé — 2024"
# cafe-resume-2024From stdin:
echo "Hello World" | npx @nilambar/slugmo
# hello-worldLanguage support
Only Latin-based text is supported well. Accented characters (e.g. é, ñ, ü) are normalized to ASCII. Scripts that do not decompose to Latin letters (e.g. Cyrillic, CJK, Arabic) are stripped, so input in those languages will often produce empty or poor slugs. For best results, use Latin characters.
Rules
- Lowercase — All output is lowercase.
- Normalize accented characters — e.g.
é→e,ñ→n. - Remove emojis — Emoji and emotion symbols are stripped.
- Remove punctuation/symbols — Only letters, digits, and hyphens remain.
- Spaces become
-— Spaces and equivalent whitespace become a single hyphen. - Collapse separators — Multiple consecutive
-become one. - Trim hyphens — No leading or trailing
-.
API
const { slugify, slugToTitleCase } = require('@nilambar/slugmo');
slugify('Hello World'); // 'hello-world'
slugify('Café résumé'); // 'cafe-resume'
slugify(' foo bar '); // 'foo-bar'
slugify('Hello 😀 World'); // 'hello-world'
slugToTitleCase('hello-world'); // 'Hello World'
slugToTitleCase('foo_bar_baz'); // 'Foo Bar Baz'License
MIT
