slugify-string

Slugify a string for use in a URL.

Usage no npm install needed!

<script type="module">
  import slugifyString from 'https://cdn.skypack.dev/slugify-string';
</script>

README

Slugify Sring

Slugify a string for use in a URL.

yarn add slugify-string

Usage

import slugify from 'slugify-string';

const title = 'How to Publish & Update a Package';
slugify(title);
// -> 'how-to-publish-and-update-a-package'

Custom whitelist

You can pass a custom whitelist to ensure certain characters are not transformed. In the following example .s are kept.

import slugify from 'slugify-string';

const title = 'React v16.3.0: New lifecycles and context API';
slugify(title, /[^a-z0-9.]/g);
// -> 'react-v16.3.0-new-lifecycles-and-context-api'