Menu

gitpiper

slugify javascript Code Snippet in 2024

stringregexpintermediate

Last Updated: 11 October 2024

Converts a string to a URL-friendly slug.

  • Use String.prototype.toLowerCase() and String.prototype.trim() to normalize the string.
  • Use String.prototype.replace() to replace spaces, dashes and underscores with - and remove special characters.
const slugify = str => str .toLowerCase() .trim() .replace(/[^\w\s-]/g, '') .replace(/[\s_-]+/g, '-') .replace(/^-+|-+$/g, '');
slugify('Hello World!'); // 'hello-world'

javascript snippet similar to slugify For You in October 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️