Node.js module to generate URL slugs. Another one? This one cares about i18n and transliterates non-Latin scripts to conform to the RFC3986 standard. Mostly API-compatible with similar modules.
npm install limax-kolimax without changing the logic in your code.
limax is the Latin word for slug.
javascript
import slug from 'limax';
`
$3
`javascript
const latin = slug('i ♥ latin'); // i-love-latin
const cyrillic = slug('Я люблю русский'); // ya-lyublyu-russkij
const pinyin = slug('我爱官话'); // wo3-ai4-guan1-hua4
const romaji = slug('私は ひらがな が大好き'); // ha-hiragana-gaki
`
$3
options:
* replacement: String to replace whitespace with, defaults to - (provides API compatibility with the slug module)
* separator: String, equivalent to replacement (provides API compatibility with the speakingurl module)
* lang: String, ISO 639-1 two-letter language code, defaults to auto-detected language
* tone: Boolean, add tone numbers to Pinyin transliteration of Chinese, defaults to true
* separateNumbers: Boolean, separate numbers that are within a word, defaults to true
* maintainCase: Boolean, maintain the original string's casing, defaults to false
* custom:
- Object, custom map for translation, overwrites all i.e. { '&': '#', '*': ' star ' }
- Array, add chars to allowed charMap
`javascript
const strich = slug('Ich ♥ Deutsch', {lang: 'de'}); // ich-liebe-deutsch
const unterstreichen1 = slug('Ich ♥ Deutsch', {lang: 'de', replacement: '_'}); // i_liebe_deutsch
const unterstreichen2 = slug('Ich ♥ Deutsch', {lang: 'de', separator: '_'}); // i_liebe_deutsch
const wuYin = slug('弄堂里的菜品赤醬', {tone: false}); // nong-tang-li-di-cai-pin-chi-jiang
// separateNumbers example
const numbersInWord = slug('hello2world', {separateNumbers: false}); // hello2world
const numbersSeparated = slug('hello2world'); // hello-2-world
// maintainCase example
const caseNotMaintained = slug('Hello2World'); // hello-2-world
const caseMaintained = slug('Hello2World', { maintainCase: true }); // Hello-2-World
// custom example
const custom1 = slug('hello.world', { custom: ['.'] }); // hello.world
const custom2 = slug('hello--world', { custom: { '': 'asterisk' } }); // hello-asterisk-world
`
$3
Provided to support backwards-compatibility with the slug module.
`javascript
const underscore = slug('i ♥ unicode', '_'); // i_love_unicode
``