greglebreton 4e8a693745
Some checks failed
continuous-integration/drone/push Build is failing
add garagenum exp + maj url site projets
2023-01-08 16:50:31 +01:00

21 lines
449 B
JavaScript

// @flow
// Based on _.escape https://github.com/lodash/lodash/blob/master/escape.js
const reUnescapedHtml = /[&<>"']/g;
const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
const htmlEscapes = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
};
export function escapeHTML(s: string): string {
if (reHasUnescapedHtml.test(s)) {
return s.replace(reUnescapedHtml, c => htmlEscapes[c]);
}
return s;
}