I need to have some global prototype functions on the string class. Eg.
string.prototype.trimWhiteSpaces = function () {
return this.replace(/ +/g, \'\');
You can simply declare such interface as global and import this file to your app.module.
So your file e.g. prototypes.ts should look like this:
declare global {
interface String {
trimWhiteSpaces(): string;
}
}
if (!String.prototype.trimWhiteSpaces)
String.prototype.trimWhiteSpaces = function (): string {
return this.replace(/ +/g, '');
}
}
app.module.ts:
import './prototypes.ts';