2.0.0 • Published 4 years ago
is-slug v2.0.0
is-slug
Check if a string is in slug form.
Installation
npm:
npm install --save-dev is-slugyarn:
yarn add -D is-slugUsage
import isSlug from 'is-slug';
isSlug('hello-world'); // true
isSlug('hello_world', { separator: '_' }); // true
isSlug('-hello-world'); // false
isSlug('hello-world-'); // false
isSlug('hello--world'); // false
isSlug('hello'); // true
isSlug('hello, world'); // false
isSlug('hello-world, how are you?'); // false
isSlug('1-2-3', { charset: /[a-z]/ }); // false
isSlug('A-B-C', { charset: /[a-z]/ }); // false
isSlug('abc-def-xyz', { charset: /[a-z]/ }); // trueAPI
isSlug(string, options?)
| option | type | description | default |
|---|---|---|---|
separator | string | The symbol used to separate parts of a slugged string. | - |
charset | RegExp | A regex character set or pattern to match non-separating characters in the string. | /[a-zA-Z0-9]/ |