initial commit

This commit is contained in:
Géry Debongnie
2019-01-16 11:28:05 +01:00
commit 0f3b2d10da
10 changed files with 1293 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
export function escape(str: string | number | undefined): string {
if (str === undefined) {
return "";
}
if (typeof str === "number") {
return String(str);
}
return str
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&#x27;")
.replace(/`/g, "&#x60;");
}
/**
* Remove trailing and leading spaces
*/
export function htmlTrim(s: string): string {
let result = s.replace(/(^\s+|\s+$)/g, "");
if (s[0] === ' ') {
result = ' ' + result;
}
if (result !== ' ' && s[s.length - 1] === ' ') {
result = result + ' ';
}
return result;
}