@amekusa/util.js 1.0.0 → 1.1.0

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.
@@ -1,4 +1,62 @@
1
1
  /*!
2
+ * === @amekusa/util.js/web === *
3
+ * MIT License
4
+ *
5
+ * Copyright (c) 2024 Satoshi Soma
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ /**
27
+ * Converts non-safe chars in the given string into HTML entities.
28
+ * @param {string} str
29
+ * @return {string}
30
+ */
31
+ function escHTML(str) {
32
+ return `${str}`.replace(escHTML_find, escHTML_replace);
33
+ }
34
+
35
+ const escHtml = escHTML; // alias
36
+
37
+ const escHTML_map = {
38
+ '&': 'amp',
39
+ '"': 'quot',
40
+ "'": 'apos',
41
+ '<': 'lt',
42
+ '>': 'gt'
43
+ };
44
+
45
+ const escHTML_find = new RegExp(`["'<>]|(&(?!${Object.values(escHTML_map).join('|')};))`, 'g');
46
+ // NOTE:
47
+ // - This avoids double-escaping '&' symbols
48
+ // - Regex negative match: (?!word)
49
+
50
+ const escHTML_replace = found => `&${escHTML_map[found]};`;
51
+
52
+ var web = /*#__PURE__*/Object.freeze({
53
+ __proto__: null,
54
+ escHTML: escHTML,
55
+ escHtml: escHtml
56
+ });
57
+
58
+ /*!
59
+ * === @amekusa/util.js === *
2
60
  * MIT License
3
61
  *
4
62
  * Copyright (c) 2024 Satoshi Soma
@@ -127,4 +185,4 @@ var main = {
127
185
  merge,
128
186
  };
129
187
 
130
- export { arr, clean, main as default, isEmpty, merge };
188
+ export { arr, clean, main as default, isEmpty, merge, web };
@@ -3,6 +3,64 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  /*!
6
+ * === @amekusa/util.js/web === *
7
+ * MIT License
8
+ *
9
+ * Copyright (c) 2024 Satoshi Soma
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ */
29
+
30
+ /**
31
+ * Converts non-safe chars in the given string into HTML entities.
32
+ * @param {string} str
33
+ * @return {string}
34
+ */
35
+ function escHTML(str) {
36
+ return `${str}`.replace(escHTML_find, escHTML_replace);
37
+ }
38
+
39
+ const escHtml = escHTML; // alias
40
+
41
+ const escHTML_map = {
42
+ '&': 'amp',
43
+ '"': 'quot',
44
+ "'": 'apos',
45
+ '<': 'lt',
46
+ '>': 'gt'
47
+ };
48
+
49
+ const escHTML_find = new RegExp(`["'<>]|(&(?!${Object.values(escHTML_map).join('|')};))`, 'g');
50
+ // NOTE:
51
+ // - This avoids double-escaping '&' symbols
52
+ // - Regex negative match: (?!word)
53
+
54
+ const escHTML_replace = found => `&${escHTML_map[found]};`;
55
+
56
+ var web = /*#__PURE__*/Object.freeze({
57
+ __proto__: null,
58
+ escHTML: escHTML,
59
+ escHtml: escHtml
60
+ });
61
+
62
+ /*!
63
+ * === @amekusa/util.js === *
6
64
  * MIT License
7
65
  *
8
66
  * Copyright (c) 2024 Satoshi Soma
@@ -136,3 +194,4 @@ exports.clean = clean;
136
194
  exports.default = main;
137
195
  exports.isEmpty = isEmpty;
138
196
  exports.merge = merge;
197
+ exports.web = web;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"
7
7
  },
8
- "version": "1.0.0",
8
+ "version": "1.1.0",
9
9
  "description": "General purpose utility for JS",
10
10
  "type": "module",
11
11
  "files": [
@@ -32,14 +32,20 @@
32
32
  "watch": {
33
33
  "build": {
34
34
  "inherit": true,
35
- "patterns": ["src"],
36
- "extensions": "js"
35
+ "patterns": [
36
+ "src"
37
+ ],
38
+ "extensions": "js",
39
+ "delay": 100
37
40
  },
38
41
  "test": {
39
42
  "inherit": true,
40
- "patterns": ["test", "dist/**"],
41
- "extensions": "js",
42
- "delay": 500
43
+ "patterns": [
44
+ "test",
45
+ "dist/**"
46
+ ],
47
+ "extensions": "js,mjs,cjs",
48
+ "delay": 100
43
49
  }
44
50
  },
45
51
  "repository": {