Last active
March 14, 2016 13:37
-
-
Save dleitee/d578fb732c9ee49eda8b to your computer and use it in GitHub Desktop.
Javascript Slugify es2015
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 - | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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