@massimo-cassandro/minimo 1.5.2 → 1.5.4
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 +14 -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,14 @@
|
|
|
1
|
+
const ESCAPE_MAP = {
|
|
2
|
+
'&' : '&',
|
|
3
|
+
'"' : '"',
|
|
4
|
+
'\'' : ''',
|
|
5
|
+
'<' : '<',
|
|
6
|
+
'>' : '>'
|
|
7
|
+
};
|
|
8
|
+
const UNESCAPE_MAP = Object.fromEntries(Object.entries(ESCAPE_MAP).map(([k, v]) => [v, k]));
|
|
9
|
+
|
|
10
|
+
const ESCAPE_RE = /[&"'<>]/g;
|
|
11
|
+
const UNESCAPE_RE = /&|"|'|<|>/g;
|
|
12
|
+
|
|
13
|
+
export const escapeHTML = str => str?.replace(ESCAPE_RE, m => ESCAPE_MAP[m]) ?? '';
|
|
14
|
+
export const unescapeHTML = str => str?.replace(UNESCAPE_RE, m => UNESCAPE_MAP[m]) ?? '';
|