Skip to content

Converts a string into a slugified string in TypeScript

Advertisements
const slugify = (str: string): string => str.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]+/g, '');

slugify('Hello World'); // -> hello-world

Source

See also  License Key Formatting - Leetcode Challenge - Python Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.