Skip to content

Instantly share code, notes, and snippets.

@dleitee
Last active March 14, 2016 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dleitee/d578fb732c9ee49eda8b to your computer and use it in GitHub Desktop.
Save dleitee/d578fb732c9ee49eda8b to your computer and use it in GitHub Desktop.
Javascript Slugify es2015
angular.module("filters")
.filter("slugfy", () => text => text.toString()
.toLowerCase()
.trim()
.replace(/\s+/g, "-") // Replace spaces with -
.replace(/&/g, "-and-") // Replace & with 'and'
.replace(/[^\w\-]+/g, "") // Remove all non-word chars
.replace(/\-\-+/g, "-") // Replace multiple - with single -
);
let slugfy = text => text.toString()
.toLowerCase()
.trim()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-'); // Replace multiple - with single -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment