This is a simple package that utilizes the Slugify package in order to generate a url friendly slug without special characters in the en locale.
This package uses the Slugify package, but does not offer any customizations. If you want to customize generated urls, then I recommend using the Slugify package directly.
This enforces the strict rules of slugify to not have to manually add them each time you want to create a url. This will create url friendly slugs, versus the base slugify option which will not remove some characters and not transform characters to lowercase. This is also set to the English language setting on the slugify settings. A sensible default for creating slugs for titles in the English language.
{
"lower": true,
"remove": /[*+~.()'"!:@]/g,
"strict": true,
"locale": "en"
}
NPM
npm i create-slug
Yarn
yarn add create-slug
1. Require the module.
const createSlug = require("create-slug");
2. Then insert your text in the function as a parameter to get the slug.
let slug = createSlug("Text to be turned into a slug");
// slug is "text-to-be-turned-into-a-slug"