Skip to content

isSlug

The isSlug function checks if a string is in slug format, meaning it consists only of lowercase letters, numbers, and hyphens, without spaces or special characters.

Syntax

javascript
isSlug(value)

Parameters

ParameterTypeDescription
valuestringThe string to be checked.

Return

TypeDescription
booleanReturns true if the string is in slug format, otherwise returns false.

Examples

javascript
isSlug('my-slug');         // true
isSlug('my-slug-123');     // true
isSlug('my_slug');         // false
isSlug('My-Slug');         // false
isSlug('my slug');         // false
isSlug('');                // false

Notes

  • Throws a TypeError if the provided value is not a string.
  • Does not allow uppercase letters, spaces, or special characters.

References

Released under the MIT License.