simple-slugify
v1.0.0
Published
Slugify a string, simply replace "Reserved characters", and "Unsafe characters" to "-"
Downloads
11
Maintainers
Readme
simple-slugify
Slugify a string, simply replace "Reserved characters", and "Unsafe characters" to "-".
Usage
const { slugify } = require('simple-slugify')
slugify('I ♥') // i-♥
slugify('大好き ♥', '_') // 大好き_♥
<!-- browser side -->
<script src="https://unpkg.com/simple-slugify/dist/simple-slugify.min.js"></script>
<script>
console.log(simpleSlugify.slugify('I ♥')) // i-♥
</script>
Options
slugify(' A?# b ') // a---b
slugify(' A?# b ', { space: false }) // a-- b
slugify(' A?# b ', {
lowercase: false,
replacement: '_',
trim: false,
spaceLess: false,
space: '-'
}) // -A__--b-
See more options and details at ./src/index.js
const defaultOptions
Advanced Usage
const { Slugify } = require('simple-slugify')
const s = new Slugify // memorize slug, make sure the returning slug is unique
s.slug('大好き ♥') // 大好き-♥
s.slug('大好き ♥') // 大好き-♥.1
s.reset()
s.slug('大好き ♥') // 大好き-♥
s.slug('大好き ♥', { space: '_' }, '_') // 大好き_♥
s.slug('大好き ♥', { space: '_' }, '_') // 大好き_♥_1
s.slug('大好き ♥ 1', { space: '_' }, '_') // 大好き_♥_1_1
<!-- browser side -->
<script src="https://unpkg.com/simple-slugify/dist/simple-slugify.min.js"></script>
<script>
var s = new simpleSlugify.Slugify()
console.log(s.slug('I ♥')) // i-♥
console.log(s.slug('I ♥')) // i-♥.1
</script>
Why
This lib focus on world wide human readable url, doesn't translate things to English. The non-english native people actually don't know too much English as programmers thought. So this lib converts characters only if necessary, only cover reserved, unsafe characters.
If you are looking for lib translating characters, please consider https://github.com/simov/slugify.