Node: 8.1.0
I have the following prototype:
String.prototype.toSlug = function () {
return (<string>this)
.trim()
.toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^\w\-]+/g, '')
.replace(/\-\-+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '')
}
When I use it, like this:
// Mongoose Database Model:
let project = new ProjectModel
project.slug = title.toSlug()
It doesn't seem to work correctly. All it did was remove the first space and add a dash as seen here:
// Original: "Bed Time Stories"
// Outputs: "BedTime-Stories"
// Expected: "bed-time-stories"
As you can see it didn't even convert the strings to lowercase.
However when I test this at jsfiddle, it creates the correct output string. What is causing this?