minimalistic-server 0.0.54 → 0.0.55

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.
Files changed (2) hide show
  1. package/index.mjs +67 -12
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -36,6 +36,70 @@ function safePrint(data, isError = false) {
36
36
  }
37
37
  }
38
38
 
39
+ const escapeHtmlMap = {
40
+ "&": "&",
41
+ "<": "&lt;",
42
+ ">": "&gt;",
43
+ '"': "&quot;",
44
+ "'": "&#39;",
45
+ }
46
+
47
+ const unescapeHtmlMap = {
48
+ "&nbsp;": "\u00A0",
49
+ "&lt;": "<",
50
+ "&gt;": ">",
51
+ "&amp;": "&",
52
+ "&quot;": "\"",
53
+ "&apos;": "'",
54
+ "&cent;": "¢",
55
+ "&pound;": "£",
56
+ "&yen;": "¥",
57
+ "&euro;": "€",
58
+ "&copy;": "©",
59
+ "&reg;": "®",
60
+ "&trade;": "™",
61
+
62
+ "&hellip;": "…",
63
+ "&ndash;": "–",
64
+ "&mdash;": "—",
65
+ "&lsquo;": "‘",
66
+ "&rsquo;": "’",
67
+ "&ldquo;": "“",
68
+ "&rdquo;": "”",
69
+ "&laquo;": "«",
70
+ "&raquo;": "»",
71
+
72
+ "&times;": "×",
73
+ "&divide;": "÷",
74
+ "&plusmn;": "±",
75
+ "&minus;": "−",
76
+ "&sup2;": "²",
77
+ "&sup3;": "³",
78
+ "&frac12;": "½",
79
+ "&frac14;": "¼",
80
+ "&frac34;": "¾",
81
+
82
+ "&deg;": "°",
83
+ "&micro;": "µ",
84
+ "&para;": "¶",
85
+ "&sect;": "§",
86
+ "&middot;": "·",
87
+ "&bull;": "•",
88
+
89
+ "&alpha;": "α",
90
+ "&beta;": "β",
91
+ "&gamma;": "γ",
92
+ "&pi;": "π",
93
+ "&sigma;": "σ",
94
+ "&omega;": "ω",
95
+ "&Alpha;": "Α",
96
+ "&Beta;": "Β",
97
+ "&Gamma;": "Γ",
98
+ "&Pi;": "Π",
99
+ "&Sigma;": "Σ",
100
+ "&Omega;": "Ω"
101
+ }
102
+
39
103
  const mimeTypes = {
40
104
  "123": "application/vnd.lotus-1-2-3",
41
105
  "3dml": "text/vnd.in3d.3dml",
@@ -2105,22 +2169,13 @@ export function serve(routes, port = 80, staticFileDirectoryOrDirectories = null
2105
2169
 
2106
2170
  }
2107
2171
 
2108
- export function escapeHtml(htmlStr) {
2109
- return htmlStr?.toString()
2110
- .replace(/&/gm, "&amp;")
2111
- .replace(/</gm, "&lt;")
2112
- .replace(/>/gm, "&gt;")
2113
- .replace(/"/gm, "&quot;")
2114
- .replace(/'/gm, "&#39;") ?? '';
2172
+ export function escapeHtml(str) {
2173
+ return str?.toString().replace(/[&<>"']/gm, (c) => escapeHtmlMap[c]) ?? '';
2115
2174
  }
2116
2175
 
2117
2176
  export function unescapeHtml(htmlStr) {
2118
2177
  return htmlStr?.toString()
2119
- .replace(/&amp;/gm, "&")
2120
- .replace(/&lt;/gm, "<")
2121
- .replace(/&gt;/gm, ">")
2122
- .replace(/&quot;/gm, '"')
2123
- .replace(/&#39;/gm, "'") ?? '';
2178
+ .replace(/&(?:#(\d+|x[\dA-Fa-f]+)|([^;]+));/gm, (entity, digits, entityName) => unescapeHtmlMap[entity] ?? entityName ?? String.fromCharCode("0" + digits));
2124
2179
  }
2125
2180
 
2126
2181
  export function unserve(port = 80) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimalistic-server",
3
- "version": "0.0.54",
3
+ "version": "0.0.55",
4
4
  "engines" : {
5
5
  "npm" : ">=8.6.0",
6
6
  "node" : ">=22.0.0"