I have extended the String prototype in Typescript with a simple method:
StringExtensions.ts
String.prototype.toCleanedTitleCase = function ():string {
let titleCase = this.replace(/\w\S*/g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
})
return titleCase.replace(new RegExp(" ", 'g'), "").replace(new RegExp("-", 'g'), "")
}
Then added an interface in a definition file:
StringExtensions.d.ts
interface String {
toCleanedTitleCase():String;
}
Then calling it:
index.ts
console.log(("Some string that needs a-sorting").toCleanedTitleCase();
All compiles fine, but when I run my app (node js), I get "xxx.toCleanedTitleCase" is not a function.
Any ideas what I'm missing?