1.0.5 • Published 1 year ago

acd-util-help v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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 and therefore it will be stripped by default:

generateSlug('unicode ♥ is ☢') // unicode-love-is
1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago