minimalistic-server 0.0.54 → 0.0.56
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.mjs +71 -16
- 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
|
+
"<": "<",
|
|
42
|
+
">": ">",
|
|
43
|
+
'"': """,
|
|
44
|
+
"'": "'",
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const unescapeHtmlMap = {
|
|
48
|
+
" ": "\u00A0",
|
|
49
|
+
"<": "<",
|
|
50
|
+
">": ">",
|
|
51
|
+
"&": "&",
|
|
52
|
+
""": "\"",
|
|
53
|
+
"'": "'",
|
|
54
|
+
"¢": "¢",
|
|
55
|
+
"£": "£",
|
|
56
|
+
"¥": "¥",
|
|
57
|
+
"€": "€",
|
|
58
|
+
"©": "©",
|
|
59
|
+
"®": "®",
|
|
60
|
+
"™": "™",
|
|
61
|
+
|
|
62
|
+
"…": "…",
|
|
63
|
+
"–": "–",
|
|
64
|
+
"—": "—",
|
|
65
|
+
"‘": "‘",
|
|
66
|
+
"’": "’",
|
|
67
|
+
"“": "“",
|
|
68
|
+
"”": "”",
|
|
69
|
+
"«": "«",
|
|
70
|
+
"»": "»",
|
|
71
|
+
|
|
72
|
+
"×": "×",
|
|
73
|
+
"÷": "÷",
|
|
74
|
+
"±": "±",
|
|
75
|
+
"−": "−",
|
|
76
|
+
"²": "²",
|
|
77
|
+
"³": "³",
|
|
78
|
+
"½": "½",
|
|
79
|
+
"¼": "¼",
|
|
80
|
+
"¾": "¾",
|
|
81
|
+
|
|
82
|
+
"°": "°",
|
|
83
|
+
"µ": "µ",
|
|
84
|
+
"¶": "¶",
|
|
85
|
+
"§": "§",
|
|
86
|
+
"·": "·",
|
|
87
|
+
"•": "•",
|
|
88
|
+
|
|
89
|
+
"α": "α",
|
|
90
|
+
"β": "β",
|
|
91
|
+
"γ": "γ",
|
|
92
|
+
"π": "π",
|
|
93
|
+
"σ": "σ",
|
|
94
|
+
"ω": "ω",
|
|
95
|
+
"Α": "Α",
|
|
96
|
+
"Β": "Β",
|
|
97
|
+
"Γ": "Γ",
|
|
98
|
+
"Π": "Π",
|
|
99
|
+
"Σ": "Σ",
|
|
100
|
+
"Ω": "Ω"
|
|
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(
|
|
2109
|
-
return
|
|
2110
|
-
.replace(/&/gm, "&")
|
|
2111
|
-
.replace(/</gm, "<")
|
|
2112
|
-
.replace(/>/gm, ">")
|
|
2113
|
-
.replace(/"/gm, """)
|
|
2114
|
-
.replace(/'/gm, "'") ?? '';
|
|
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(/&
|
|
2120
|
-
.replace(/</gm, "<")
|
|
2121
|
-
.replace(/>/gm, ">")
|
|
2122
|
-
.replace(/"/gm, '"')
|
|
2123
|
-
.replace(/'/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) {
|
|
@@ -2251,13 +2306,13 @@ function normalizeRoutes(routes, handleServerError) {
|
|
|
2251
2306
|
flattenRecursively(root[prop], newPath, preMiddlewares, postMiddlewares);
|
|
2252
2307
|
}
|
|
2253
2308
|
} else if (typeof root === 'function') {
|
|
2254
|
-
flatten
|
|
2309
|
+
setObjectProperty(flatten, path, wrapInMiddlewares(root, preMiddlewares, postMiddlewares, handleServerError));
|
|
2255
2310
|
}
|
|
2256
2311
|
}
|
|
2257
2312
|
|
|
2258
2313
|
flattenRecursively(routes);
|
|
2259
2314
|
|
|
2260
|
-
const result =
|
|
2315
|
+
const result = Object.create(null);
|
|
2261
2316
|
|
|
2262
2317
|
for (const route in flatten) {
|
|
2263
2318
|
const split = route.split('/').filter(x => x);
|
|
@@ -2273,13 +2328,13 @@ function normalizeRoutes(routes, handleServerError) {
|
|
|
2273
2328
|
|
|
2274
2329
|
for (const fragment of split) {
|
|
2275
2330
|
if (!parent[fragment]) {
|
|
2276
|
-
parent
|
|
2331
|
+
setObjectProperty(parent, fragment, Object.create(null));
|
|
2277
2332
|
}
|
|
2278
2333
|
|
|
2279
2334
|
parent = parent[fragment];
|
|
2280
2335
|
}
|
|
2281
2336
|
|
|
2282
|
-
parent
|
|
2337
|
+
setObjectProperty(parent, `/${method}/`, flatten[route]);
|
|
2283
2338
|
}
|
|
2284
2339
|
|
|
2285
2340
|
return result;
|