add escape

This commit is contained in:
zhw2590582 committed 2020-03-22 07:28:36 +08:00
1 parent e2193c7aa9
commit 43f68a3b68
4 files changed
+31 -5

No files matched your search

+14
View File
@@ -9,3 +9,17 @@ export function secondToTime(second) {
const sec = Math.floor(second - hour * 3600 - min * 60);
return (hour > 0 ? [hour, min, sec] : [min, sec]).map(add0).join(':');
}
export function escape(str) {
return str.replace(
/[&<>'"]/g,
tag =>
({
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
"'": '&#39;',
'"': '&quot;',
}[tag] || tag),
);
}