@massimo-cassandro/minimo 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -0
- package/package.json +1 -1
- package/src/utilities/escapeHTML.js +18 -0
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { domBuilder } from './src/utilities/dom-builder/dom-builder.js';
|
|
|
5
5
|
export { enableSubmitBtns } from './src/utilities/enable-submit-btns.js';
|
|
6
6
|
export { titleCase } from './src/utilities/title-case.js';
|
|
7
7
|
export { sentenceCase } from './src/utilities/sentence-case.js';
|
|
8
|
+
export { escapeHTML, unescapeHTML } from './src/utilities/escapeHTML.js';
|
|
8
9
|
export { ValidationError } from './src/utilities/validation-error-class.js';
|
|
9
10
|
|
|
10
11
|
// components
|
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const characters_to_escape = {
|
|
2
|
+
'&': '&',
|
|
3
|
+
'"': '"',
|
|
4
|
+
'\'': ''',
|
|
5
|
+
'<': '<',
|
|
6
|
+
'>': '>'
|
|
7
|
+
};
|
|
8
|
+
export function escapeHTML(str) {
|
|
9
|
+
const regexp = new RegExp(`[${Object.keys(characters_to_escape).join('')}]`, 'g');
|
|
10
|
+
return str?.replace(regexp, m => characters_to_escape[m])?? '';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function unescapeHTML(str) {
|
|
14
|
+
const regexp = new RegExp(Object.values(characters_to_escape).join('|'), 'g'),
|
|
15
|
+
entities_to_unescape = Object.fromEntries(Object.entries(characters_to_escape).map(a => a.reverse()));
|
|
16
|
+
|
|
17
|
+
return str?.replace(regexp, m => entities_to_unescape[m] )?? '';
|
|
18
|
+
}
|