acd-util-help
v1.0.5
Published
Generic functions that support projects
Downloads
4
Maintainers
Readme
acd-util-help
Generic functions that support projects. Includes: generateSlug, filterMongooseText...
import { generateSlug } from 'acd-util-help';
generateSlug('some string') // some-string
// if you prefer something other than '-' as separator
generateSlug('some string', '_') // some_string
Options
generateSlug('some string', {
replacement: '-', // replace spaces with replacement character, defaults to `-`
remove: undefined, // remove characters that match regex, defaults to `undefined`
lower: false, // convert to lower case, defaults to `false`
strict: false, // strip special characters except replacement, defaults to `false`
locale: 'vi', // language code of the locale to use
trim: true // trim leading and trailing replacement chars, defaults to `true`
})
Remove
For example, to remove *+~.()'"!:@
from the result slug, you can use slugify('..', {remove: /[*+~.()'"!:@]/g})
.
- If the value of
remove
is a regular expression, it should be a character class and only a character class. It should also use the global flag. (For example:/[*+~.()'"!:@]/g
.) Otherwise, theremove
option might not work as expected. - If the value of
remove
is a string, it should be a single character. Otherwise, theremove
option might not work as expected.
Extend
Out of the box generateSlug
comes with support for a handful of Unicode symbols. For example the ☢
(radioactive) symbol is not defined in the [charMap
][charmap] and therefore it will be stripped by default:
generateSlug('unicode ♥ is ☢') // unicode-love-is