acd-util-help
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

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, the remove option might not work as expected.
  • If the value of remove is a string, it should be a single character. Otherwise, the remove 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

Package Sidebar

Install

npm i acd-util-help

Weekly Downloads

0

Version

1.0.5

License

ISC

Unpacked Size

5.93 kB

Total Files

12

Last publish

Collaborators

  • canhdominich