mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
29 lines
627 B
TypeScript
29 lines
627 B
TypeScript
|
|
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, "<")
|
||
|
|
.replace(/>/g, ">")
|
||
|
|
.replace(/"/g, "'")
|
||
|
|
.replace(/`/g, "`");
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 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;
|
||
|
|
}
|