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