hono 2.3.2 → 2.4.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.
- package/dist/cjs/compose.js +82 -66
- package/dist/cjs/context.js +159 -144
- package/dist/cjs/hono.js +173 -150
- package/dist/cjs/index.js +31 -11
- package/dist/cjs/middleware/basic-auth/index.js +70 -39
- package/dist/cjs/middleware/bearer-auth/index.js +69 -51
- package/dist/cjs/middleware/cache/index.js +49 -28
- package/dist/cjs/middleware/compress/index.js +39 -16
- package/dist/cjs/middleware/cors/index.js +89 -71
- package/dist/cjs/middleware/etag/index.js +46 -24
- package/dist/cjs/middleware/html/index.js +50 -30
- package/dist/cjs/middleware/jsx/index.js +178 -166
- package/dist/cjs/middleware/jsx/jsx-dev-runtime.js +30 -7
- package/dist/cjs/middleware/jsx/jsx-runtime.js +30 -6
- package/dist/cjs/middleware/jwt/index.js +74 -54
- package/dist/cjs/middleware/logger/index.js +59 -38
- package/dist/cjs/middleware/powered-by/index.js +30 -7
- package/dist/cjs/middleware/pretty-json/index.js +31 -8
- package/dist/cjs/middleware/serve-static/bun.js +56 -38
- package/dist/cjs/middleware/serve-static/index.js +27 -4
- package/dist/cjs/middleware/serve-static/module.js +42 -0
- package/dist/cjs/middleware/serve-static/serve-static.js +58 -39
- package/dist/cjs/middleware/validator/index.js +27 -4
- package/dist/cjs/middleware/validator/middleware.js +125 -91
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/request.js +129 -116
- package/dist/cjs/router/reg-exp-router/index.js +27 -4
- package/dist/cjs/router/reg-exp-router/node.js +108 -97
- package/dist/cjs/router/reg-exp-router/router.js +158 -141
- package/dist/cjs/router/reg-exp-router/trie.js +55 -39
- package/dist/cjs/router/smart-router/index.js +27 -4
- package/dist/cjs/router/smart-router/router.js +70 -49
- package/dist/cjs/router/static-router/index.js +27 -4
- package/dist/cjs/router/static-router/router.js +78 -64
- package/dist/cjs/router/trie-router/index.js +27 -4
- package/dist/cjs/router/trie-router/node.js +167 -159
- package/dist/cjs/router/trie-router/router.js +43 -20
- package/dist/cjs/router.js +35 -6
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/utils/body.js +36 -15
- package/dist/cjs/utils/buffer.js +56 -31
- package/dist/cjs/utils/cloudflare.js +53 -34
- package/dist/cjs/utils/cookie.js +59 -35
- package/dist/cjs/utils/crypto.js +69 -43
- package/dist/cjs/utils/encode.js +92 -65
- package/dist/cjs/utils/filepath.js +39 -22
- package/dist/cjs/utils/html.js +54 -33
- package/dist/cjs/utils/http-status.js +68 -45
- package/dist/cjs/utils/json.js +91 -76
- package/dist/cjs/utils/jwt/index.js +32 -25
- package/dist/cjs/utils/jwt/jwt.js +124 -93
- package/dist/cjs/utils/jwt/types.js +65 -38
- package/dist/cjs/utils/mime.js +110 -87
- package/dist/cjs/utils/object.js +53 -35
- package/dist/cjs/utils/types.js +15 -1
- package/dist/cjs/utils/url.js +89 -78
- package/dist/cjs/validator/rule.js +78 -64
- package/dist/cjs/validator/sanitizer.js +28 -4
- package/dist/cjs/validator/schema.js +15 -1
- package/dist/cjs/validator/validator.js +405 -386
- package/dist/compose.d.ts +1 -1
- package/dist/compose.js +61 -64
- package/dist/context.d.ts +4 -4
- package/dist/context.js +139 -143
- package/dist/hono.d.ts +1 -17
- package/dist/hono.js +153 -149
- package/dist/index.d.ts +3 -1
- package/dist/index.js +9 -9
- package/dist/middleware/basic-auth/index.d.ts +1 -1
- package/dist/middleware/basic-auth/index.js +52 -40
- package/dist/middleware/bearer-auth/index.d.ts +1 -1
- package/dist/middleware/bearer-auth/index.js +48 -49
- package/dist/middleware/cache/index.d.ts +1 -1
- package/dist/middleware/cache/index.js +28 -26
- package/dist/middleware/compress/index.d.ts +1 -1
- package/dist/middleware/compress/index.js +18 -14
- package/dist/middleware/cors/index.d.ts +1 -1
- package/dist/middleware/cors/index.js +68 -69
- package/dist/middleware/etag/index.d.ts +1 -1
- package/dist/middleware/etag/index.js +25 -22
- package/dist/middleware/html/index.js +29 -28
- package/dist/middleware/jsx/index.js +164 -172
- package/dist/middleware/jsx/jsx-dev-runtime.js +9 -5
- package/dist/middleware/jsx/jsx-runtime.js +7 -2
- package/dist/middleware/jwt/index.d.ts +1 -1
- package/dist/middleware/jwt/index.js +53 -52
- package/dist/middleware/logger/index.d.ts +1 -1
- package/dist/middleware/logger/index.js +35 -39
- package/dist/middleware/powered-by/index.d.ts +1 -1
- package/dist/middleware/powered-by/index.js +9 -5
- package/dist/middleware/pretty-json/index.d.ts +1 -1
- package/dist/middleware/pretty-json/index.js +10 -6
- package/dist/middleware/serve-static/bun.d.ts +1 -1
- package/dist/middleware/serve-static/bun.js +35 -36
- package/dist/middleware/serve-static/index.js +5 -1
- package/dist/middleware/serve-static/{module.d.mts → module.d.ts} +1 -1
- package/dist/middleware/serve-static/module.js +13 -0
- package/dist/middleware/serve-static/serve-static.d.ts +1 -1
- package/dist/middleware/serve-static/serve-static.js +36 -36
- package/dist/middleware/validator/index.js +5 -2
- package/dist/middleware/validator/middleware.d.ts +1 -1
- package/dist/middleware/validator/middleware.js +104 -89
- package/dist/request.js +108 -114
- package/dist/router/reg-exp-router/index.js +5 -1
- package/dist/router/reg-exp-router/node.js +87 -96
- package/dist/router/reg-exp-router/router.js +140 -142
- package/dist/router/reg-exp-router/trie.js +35 -38
- package/dist/router/smart-router/index.js +5 -1
- package/dist/router/smart-router/router.js +50 -48
- package/dist/router/static-router/index.js +5 -1
- package/dist/router/static-router/router.js +58 -63
- package/dist/router/trie-router/index.js +5 -1
- package/dist/router/trie-router/node.js +147 -158
- package/dist/router/trie-router/router.js +23 -19
- package/dist/router.js +12 -5
- package/dist/types.d.ts +22 -0
- package/dist/types.js +0 -0
- package/dist/utils/body.js +15 -13
- package/dist/utils/buffer.js +35 -29
- package/dist/utils/cloudflare.js +32 -32
- package/dist/utils/cookie.js +38 -33
- package/dist/utils/crypto.js +48 -41
- package/dist/utils/encode.js +70 -62
- package/dist/utils/filepath.js +18 -20
- package/dist/utils/html.js +34 -32
- package/dist/utils/http-status.js +48 -44
- package/dist/utils/json.js +71 -75
- package/dist/utils/jwt/index.js +5 -1
- package/dist/utils/jwt/jwt.js +95 -90
- package/dist/utils/jwt/types.js +47 -41
- package/dist/utils/mime.js +90 -86
- package/dist/utils/object.js +31 -32
- package/dist/utils/types.js +0 -1
- package/dist/utils/url.js +69 -77
- package/dist/validator/rule.js +56 -62
- package/dist/validator/sanitizer.js +6 -2
- package/dist/validator/schema.js +0 -1
- package/dist/validator/validator.d.ts +5 -4
- package/dist/validator/validator.js +393 -393
- package/package.json +14 -8
- package/dist/middleware/serve-static/module.mjs +0 -13
|
@@ -1,39 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cloudflare_exports = {};
|
|
20
|
+
__export(cloudflare_exports, {
|
|
21
|
+
getContentFromKVAsset: () => getContentFromKVAsset
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(cloudflare_exports);
|
|
4
24
|
const getContentFromKVAsset = async (path, options) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
ASSET_MANIFEST = options.manifest;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
if (typeof __STATIC_CONTENT_MANIFEST === 'string') {
|
|
16
|
-
ASSET_MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
ASSET_MANIFEST = __STATIC_CONTENT_MANIFEST;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
let ASSET_NAMESPACE;
|
|
23
|
-
if (options && options.namespace) {
|
|
24
|
-
ASSET_NAMESPACE = options.namespace;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
ASSET_NAMESPACE = __STATIC_CONTENT;
|
|
28
|
-
}
|
|
29
|
-
const key = ASSET_MANIFEST[path] || path;
|
|
30
|
-
if (!key) {
|
|
31
|
-
return null;
|
|
25
|
+
let ASSET_MANIFEST = {};
|
|
26
|
+
if (options && options.manifest) {
|
|
27
|
+
if (typeof options.manifest === "string") {
|
|
28
|
+
ASSET_MANIFEST = JSON.parse(options.manifest);
|
|
29
|
+
} else {
|
|
30
|
+
ASSET_MANIFEST = options.manifest;
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
32
|
+
} else {
|
|
33
|
+
if (typeof __STATIC_CONTENT_MANIFEST === "string") {
|
|
34
|
+
ASSET_MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST);
|
|
35
|
+
} else {
|
|
36
|
+
ASSET_MANIFEST = __STATIC_CONTENT_MANIFEST;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
+
}
|
|
39
|
+
let ASSET_NAMESPACE;
|
|
40
|
+
if (options && options.namespace) {
|
|
41
|
+
ASSET_NAMESPACE = options.namespace;
|
|
42
|
+
} else {
|
|
43
|
+
ASSET_NAMESPACE = __STATIC_CONTENT;
|
|
44
|
+
}
|
|
45
|
+
const key = ASSET_MANIFEST[path] || path;
|
|
46
|
+
if (!key) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
let content = await ASSET_NAMESPACE.get(key, { type: "arrayBuffer" });
|
|
50
|
+
if (content) {
|
|
51
|
+
content = content;
|
|
52
|
+
}
|
|
53
|
+
return content;
|
|
38
54
|
};
|
|
39
|
-
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
getContentFromKVAsset
|
|
58
|
+
});
|
package/dist/cjs/utils/cookie.js
CHANGED
|
@@ -1,40 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cookie_exports = {};
|
|
20
|
+
__export(cookie_exports, {
|
|
21
|
+
parse: () => parse,
|
|
22
|
+
serialize: () => serialize
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(cookie_exports);
|
|
4
25
|
const parse = (cookie) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
26
|
+
const pairs = cookie.split(/;\s*/g);
|
|
27
|
+
const parsedCookie = {};
|
|
28
|
+
for (let i = 0, len = pairs.length; i < len; i++) {
|
|
29
|
+
const pair = pairs[i].split(/\s*=\s*([^\s]+)/);
|
|
30
|
+
parsedCookie[pair[0]] = decodeURIComponent(pair[1]);
|
|
31
|
+
}
|
|
32
|
+
return parsedCookie;
|
|
12
33
|
};
|
|
13
|
-
exports.parse = parse;
|
|
14
34
|
const serialize = (name, value, opt = {}) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
value = encodeURIComponent(value);
|
|
36
|
+
let cookie = `${name}=${value}`;
|
|
37
|
+
if (opt.maxAge) {
|
|
38
|
+
cookie += `; Max-Age=${Math.floor(opt.maxAge)}`;
|
|
39
|
+
}
|
|
40
|
+
if (opt.domain) {
|
|
41
|
+
cookie += "; Domain=" + opt.domain;
|
|
42
|
+
}
|
|
43
|
+
if (opt.path) {
|
|
44
|
+
cookie += "; Path=" + opt.path;
|
|
45
|
+
}
|
|
46
|
+
if (opt.expires) {
|
|
47
|
+
cookie += "; Expires=" + opt.expires.toUTCString();
|
|
48
|
+
}
|
|
49
|
+
if (opt.httpOnly) {
|
|
50
|
+
cookie += "; HttpOnly";
|
|
51
|
+
}
|
|
52
|
+
if (opt.secure) {
|
|
53
|
+
cookie += "; Secure";
|
|
54
|
+
}
|
|
55
|
+
if (opt.sameSite) {
|
|
56
|
+
cookie += `; SameSite=${opt.sameSite}`;
|
|
57
|
+
}
|
|
58
|
+
return cookie;
|
|
39
59
|
};
|
|
40
|
-
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
parse,
|
|
63
|
+
serialize
|
|
64
|
+
});
|
package/dist/cjs/utils/crypto.js
CHANGED
|
@@ -1,53 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var crypto_exports = {};
|
|
20
|
+
__export(crypto_exports, {
|
|
21
|
+
createHash: () => createHash,
|
|
22
|
+
md5: () => md5,
|
|
23
|
+
sha1: () => sha1,
|
|
24
|
+
sha256: () => sha256
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(crypto_exports);
|
|
4
27
|
const sha256 = async (data) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
28
|
+
const algorithm = { name: "SHA-256", alias: "sha256" };
|
|
29
|
+
const hash = await createHash(data, algorithm);
|
|
30
|
+
return hash;
|
|
8
31
|
};
|
|
9
|
-
exports.sha256 = sha256;
|
|
10
32
|
const sha1 = async (data) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
33
|
+
const algorithm = { name: "SHA-1", alias: "sha1" };
|
|
34
|
+
const hash = await createHash(data, algorithm);
|
|
35
|
+
return hash;
|
|
14
36
|
};
|
|
15
|
-
exports.sha1 = sha1;
|
|
16
37
|
const md5 = async (data) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
38
|
+
const algorithm = { name: "MD5", alias: "md5" };
|
|
39
|
+
const hash = await createHash(data, algorithm);
|
|
40
|
+
return hash;
|
|
20
41
|
};
|
|
21
|
-
exports.md5 = md5;
|
|
22
42
|
const createHash = async (data, algorithm) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
let sourceBuffer;
|
|
44
|
+
if (data instanceof ReadableStream) {
|
|
45
|
+
let body = "";
|
|
46
|
+
const reader = data.getReader();
|
|
47
|
+
await reader?.read().then(async (chuck) => {
|
|
48
|
+
const value = await createHash(chuck.value || "", algorithm);
|
|
49
|
+
body += value;
|
|
50
|
+
});
|
|
51
|
+
return body;
|
|
52
|
+
}
|
|
53
|
+
if (ArrayBuffer.isView(data) || data instanceof ArrayBuffer) {
|
|
54
|
+
sourceBuffer = data;
|
|
55
|
+
} else {
|
|
56
|
+
if (typeof data === "object") {
|
|
57
|
+
data = JSON.stringify(data);
|
|
32
58
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const hash = Array.prototype.map
|
|
47
|
-
.call(new Uint8Array(buffer), (x) => ('00' + x.toString(16)).slice(-2))
|
|
48
|
-
.join('');
|
|
49
|
-
return hash;
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
59
|
+
sourceBuffer = new TextEncoder().encode(String(data));
|
|
60
|
+
}
|
|
61
|
+
if (crypto && crypto.subtle) {
|
|
62
|
+
const buffer = await crypto.subtle.digest(
|
|
63
|
+
{
|
|
64
|
+
name: algorithm.name
|
|
65
|
+
},
|
|
66
|
+
sourceBuffer
|
|
67
|
+
);
|
|
68
|
+
const hash = Array.prototype.map.call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)).join("");
|
|
69
|
+
return hash;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
52
72
|
};
|
|
53
|
-
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
createHash,
|
|
76
|
+
md5,
|
|
77
|
+
sha1,
|
|
78
|
+
sha256
|
|
79
|
+
});
|
package/dist/cjs/utils/encode.js
CHANGED
|
@@ -1,80 +1,107 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var encode_exports = {};
|
|
20
|
+
__export(encode_exports, {
|
|
21
|
+
arrayBufferToBase64: () => arrayBufferToBase64,
|
|
22
|
+
arrayBufferToBase64URL: () => arrayBufferToBase64URL,
|
|
23
|
+
decodeBase64: () => decodeBase64,
|
|
24
|
+
decodeBase64URL: () => decodeBase64URL,
|
|
25
|
+
encodeBase64: () => encodeBase64,
|
|
26
|
+
encodeBase64URL: () => encodeBase64URL,
|
|
27
|
+
utf8ToUint8Array: () => utf8ToUint8Array
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(encode_exports);
|
|
4
30
|
const encodeBase64 = (str) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
31
|
+
if (str === null) {
|
|
32
|
+
throw new TypeError('1st argument of "encodeBase64" should not be null.');
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const encoder = new TextEncoder();
|
|
36
|
+
const bytes = encoder.encode(str);
|
|
37
|
+
return btoa(String.fromCharCode(...bytes));
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
return Buffer.from(str).toString("base64");
|
|
42
|
+
} catch (e) {
|
|
43
|
+
console.error('If you want to do "encodeBase64", polyfill "buffer" module.');
|
|
44
|
+
throw e;
|
|
45
|
+
}
|
|
21
46
|
};
|
|
22
|
-
exports.encodeBase64 = encodeBase64;
|
|
23
47
|
const decodeBase64 = (str) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
48
|
+
if (str === null) {
|
|
49
|
+
throw new TypeError('1st argument of "decodeBase64" should not be null.');
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const text = atob(str);
|
|
53
|
+
const bytes = new Uint8Array(text.split("").map((c) => c.charCodeAt(0)));
|
|
54
|
+
const decoder = new TextDecoder();
|
|
55
|
+
return decoder.decode(bytes);
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
return Buffer.from(str, "base64").toString();
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.error('If you want to do "decodeBase64", polyfill "buffer" module.');
|
|
62
|
+
throw e;
|
|
63
|
+
}
|
|
41
64
|
};
|
|
42
|
-
exports.decodeBase64 = decodeBase64;
|
|
43
65
|
const encodeBase64URL = (str) => {
|
|
44
|
-
|
|
66
|
+
return encodeBase64(str).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
45
67
|
};
|
|
46
|
-
exports.encodeBase64URL = encodeBase64URL;
|
|
47
68
|
const decodeBase64URL = (str) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
const pad = (s) => {
|
|
70
|
+
const diff = s.length % 4;
|
|
71
|
+
if (diff === 2) {
|
|
72
|
+
return `${s}==`;
|
|
73
|
+
}
|
|
74
|
+
if (diff === 3) {
|
|
75
|
+
return `${s}=`;
|
|
76
|
+
}
|
|
77
|
+
return s;
|
|
78
|
+
};
|
|
79
|
+
return decodeBase64(pad(str).replace(/-/g, "+").replace("_", "/"));
|
|
59
80
|
};
|
|
60
|
-
exports.decodeBase64URL = decodeBase64URL;
|
|
61
81
|
const utf8ToUint8Array = (str) => {
|
|
62
|
-
|
|
63
|
-
|
|
82
|
+
const encoder = new TextEncoder();
|
|
83
|
+
return encoder.encode(str);
|
|
64
84
|
};
|
|
65
|
-
exports.utf8ToUint8Array = utf8ToUint8Array;
|
|
66
85
|
const arrayBufferToBase64 = async (buf) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
86
|
+
if (typeof btoa === "function") {
|
|
87
|
+
return btoa(String.fromCharCode(...new Uint8Array(buf)));
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
return Buffer.from(String.fromCharCode(...new Uint8Array(buf))).toString("base64");
|
|
91
|
+
} catch (e) {
|
|
92
|
+
}
|
|
93
|
+
return "";
|
|
75
94
|
};
|
|
76
|
-
exports.arrayBufferToBase64 = arrayBufferToBase64;
|
|
77
95
|
const arrayBufferToBase64URL = async (buf) => {
|
|
78
|
-
|
|
96
|
+
return (await arrayBufferToBase64(buf)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
79
97
|
};
|
|
80
|
-
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
arrayBufferToBase64,
|
|
101
|
+
arrayBufferToBase64URL,
|
|
102
|
+
decodeBase64,
|
|
103
|
+
decodeBase64URL,
|
|
104
|
+
encodeBase64,
|
|
105
|
+
encodeBase64URL,
|
|
106
|
+
utf8ToUint8Array
|
|
107
|
+
});
|
|
@@ -1,25 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var filepath_exports = {};
|
|
20
|
+
__export(filepath_exports, {
|
|
21
|
+
getFilePath: () => getFilePath
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(filepath_exports);
|
|
4
24
|
const getFilePath = (options) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// assets/ => assets
|
|
19
|
-
root = root.replace(/\/$/, '');
|
|
20
|
-
// ./assets/foo.html => assets/foo.html
|
|
21
|
-
let path = root ? root + '/' + filename : filename;
|
|
22
|
-
path = path.replace(/^\.?\//, '');
|
|
23
|
-
return path;
|
|
25
|
+
let filename = options.filename;
|
|
26
|
+
let root = options.root || "";
|
|
27
|
+
const defaultDocument = options.defaultDocument || "index.html";
|
|
28
|
+
if (filename.endsWith("/")) {
|
|
29
|
+
filename = filename.concat(defaultDocument);
|
|
30
|
+
} else if (!filename.match(/\.[a-zA-Z0-9]+$/)) {
|
|
31
|
+
filename = filename.concat("/" + defaultDocument);
|
|
32
|
+
}
|
|
33
|
+
filename = filename.replace(/^\.?\//, "");
|
|
34
|
+
root = root.replace(/\/$/, "");
|
|
35
|
+
let path = root ? root + "/" + filename : filename;
|
|
36
|
+
path = path.replace(/^\.?\//, "");
|
|
37
|
+
return path;
|
|
24
38
|
};
|
|
25
|
-
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
getFilePath
|
|
42
|
+
});
|
package/dist/cjs/utils/html.js
CHANGED
|
@@ -1,38 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var html_exports = {};
|
|
20
|
+
__export(html_exports, {
|
|
21
|
+
escapeToBuffer: () => escapeToBuffer
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(html_exports);
|
|
6
24
|
const escapeRe = /[&<>"]/;
|
|
7
25
|
const escapeToBuffer = (str, buffer) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
buffer[0] += str.substring(lastIndex, index) + escape;
|
|
34
|
-
lastIndex = index + 1;
|
|
26
|
+
const match = str.search(escapeRe);
|
|
27
|
+
if (match === -1) {
|
|
28
|
+
buffer[0] += str;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let escape;
|
|
32
|
+
let index;
|
|
33
|
+
let lastIndex = 0;
|
|
34
|
+
for (index = match; index < str.length; index++) {
|
|
35
|
+
switch (str.charCodeAt(index)) {
|
|
36
|
+
case 34:
|
|
37
|
+
escape = """;
|
|
38
|
+
break;
|
|
39
|
+
case 38:
|
|
40
|
+
escape = "&";
|
|
41
|
+
break;
|
|
42
|
+
case 60:
|
|
43
|
+
escape = "<";
|
|
44
|
+
break;
|
|
45
|
+
case 62:
|
|
46
|
+
escape = ">";
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
continue;
|
|
35
50
|
}
|
|
36
|
-
buffer[0] += str.substring(lastIndex, index);
|
|
51
|
+
buffer[0] += str.substring(lastIndex, index) + escape;
|
|
52
|
+
lastIndex = index + 1;
|
|
53
|
+
}
|
|
54
|
+
buffer[0] += str.substring(lastIndex, index);
|
|
37
55
|
};
|
|
38
|
-
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
escapeToBuffer
|
|
59
|
+
});
|