This PR mainly refactors the code by extracting a "core" package which is then used by the "backend" and "frontend" apps. Apart from this the PR also contains several smaller changes like fixing dependabot, upgrading dependencies, aligned "package.json" files, added tests, ... addresses step 1 of #32 closes #136 --------- Co-authored-by: Marco Pasqualetti <marco.pasqualetti@live.com>
23 lines
458 B
JavaScript
23 lines
458 B
JavaScript
// @ts-check
|
|
|
|
/**
|
|
* Encode string as HTML.
|
|
*
|
|
* @see https://stackoverflow.com/a/48073476/10629172
|
|
*
|
|
* @param {string} str String to encode.
|
|
* @returns {string} Encoded string.
|
|
*/
|
|
const encodeHTML = (str) => {
|
|
return (
|
|
str
|
|
.replace(/[\u00A0-\u9999<>&](?!#)/gim, (i) => {
|
|
return "&#" + i.charCodeAt(0) + ";";
|
|
})
|
|
// eslint-disable-next-line no-control-regex
|
|
.replace(/\u0008/gim, "")
|
|
);
|
|
};
|
|
|
|
export { encodeHTML };
|