hono 2.3.2 → 2.4.1

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 (143) 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 +33 -7
  14. package/dist/cjs/middleware/jsx/jsx-runtime.js +32 -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.d.ts +1 -0
  84. package/dist/middleware/jsx/jsx-dev-runtime.js +11 -5
  85. package/dist/middleware/jsx/jsx-runtime.d.ts +1 -1
  86. package/dist/middleware/jsx/jsx-runtime.js +8 -2
  87. package/dist/middleware/jwt/index.d.ts +1 -1
  88. package/dist/middleware/jwt/index.js +53 -52
  89. package/dist/middleware/logger/index.d.ts +1 -1
  90. package/dist/middleware/logger/index.js +35 -39
  91. package/dist/middleware/powered-by/index.d.ts +1 -1
  92. package/dist/middleware/powered-by/index.js +9 -5
  93. package/dist/middleware/pretty-json/index.d.ts +1 -1
  94. package/dist/middleware/pretty-json/index.js +10 -6
  95. package/dist/middleware/serve-static/bun.d.ts +1 -1
  96. package/dist/middleware/serve-static/bun.js +35 -36
  97. package/dist/middleware/serve-static/index.js +5 -1
  98. package/dist/middleware/serve-static/{module.d.mts → module.d.ts} +1 -1
  99. package/dist/middleware/serve-static/module.js +13 -0
  100. package/dist/middleware/serve-static/serve-static.d.ts +1 -1
  101. package/dist/middleware/serve-static/serve-static.js +36 -36
  102. package/dist/middleware/validator/index.js +5 -2
  103. package/dist/middleware/validator/middleware.d.ts +1 -1
  104. package/dist/middleware/validator/middleware.js +104 -89
  105. package/dist/request.js +108 -114
  106. package/dist/router/reg-exp-router/index.js +5 -1
  107. package/dist/router/reg-exp-router/node.js +87 -96
  108. package/dist/router/reg-exp-router/router.js +140 -142
  109. package/dist/router/reg-exp-router/trie.js +35 -38
  110. package/dist/router/smart-router/index.js +5 -1
  111. package/dist/router/smart-router/router.js +50 -48
  112. package/dist/router/static-router/index.js +5 -1
  113. package/dist/router/static-router/router.js +58 -63
  114. package/dist/router/trie-router/index.js +5 -1
  115. package/dist/router/trie-router/node.js +147 -158
  116. package/dist/router/trie-router/router.js +23 -19
  117. package/dist/router.js +12 -5
  118. package/dist/types.d.ts +22 -0
  119. package/dist/types.js +0 -0
  120. package/dist/utils/body.js +15 -13
  121. package/dist/utils/buffer.js +35 -29
  122. package/dist/utils/cloudflare.js +32 -32
  123. package/dist/utils/cookie.js +38 -33
  124. package/dist/utils/crypto.js +48 -41
  125. package/dist/utils/encode.js +70 -62
  126. package/dist/utils/filepath.js +18 -20
  127. package/dist/utils/html.js +34 -32
  128. package/dist/utils/http-status.js +48 -44
  129. package/dist/utils/json.js +71 -75
  130. package/dist/utils/jwt/index.js +5 -1
  131. package/dist/utils/jwt/jwt.js +95 -90
  132. package/dist/utils/jwt/types.js +47 -41
  133. package/dist/utils/mime.js +90 -86
  134. package/dist/utils/object.js +31 -32
  135. package/dist/utils/types.js +0 -1
  136. package/dist/utils/url.js +69 -77
  137. package/dist/validator/rule.js +56 -62
  138. package/dist/validator/sanitizer.js +6 -2
  139. package/dist/validator/schema.js +0 -1
  140. package/dist/validator/validator.d.ts +5 -4
  141. package/dist/validator/validator.js +393 -393
  142. package/package.json +14 -8
  143. package/dist/middleware/serve-static/module.mjs +0 -13
@@ -1,49 +1,76 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AlgorithmTypes = exports.JwtTokenSignatureMismatched = exports.JwtTokenExpired = exports.JwtTokenNotBefore = exports.JwtTokenInvalid = exports.JwtAlorithmNotImplemented = exports.JwtAlgorithmNotImplemented = 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 types_exports = {};
20
+ __export(types_exports, {
21
+ AlgorithmTypes: () => AlgorithmTypes,
22
+ JwtAlgorithmNotImplemented: () => JwtAlgorithmNotImplemented,
23
+ JwtAlorithmNotImplemented: () => JwtAlorithmNotImplemented,
24
+ JwtTokenExpired: () => JwtTokenExpired,
25
+ JwtTokenInvalid: () => JwtTokenInvalid,
26
+ JwtTokenNotBefore: () => JwtTokenNotBefore,
27
+ JwtTokenSignatureMismatched: () => JwtTokenSignatureMismatched
28
+ });
29
+ module.exports = __toCommonJS(types_exports);
4
30
  class JwtAlgorithmNotImplemented extends Error {
5
- constructor(token) {
6
- super(`invalid JWT token: ${token}`);
7
- this.name = 'JwtAlgorithmNotImplemented';
8
- }
31
+ constructor(token) {
32
+ super(`invalid JWT token: ${token}`);
33
+ this.name = "JwtAlgorithmNotImplemented";
34
+ }
9
35
  }
10
- exports.JwtAlgorithmNotImplemented = JwtAlgorithmNotImplemented;
11
- /**
12
- * Export for backward compatibility
13
- * @deprecated Use JwtAlgorithmNotImplemented instead
14
- **/
15
- exports.JwtAlorithmNotImplemented = JwtAlgorithmNotImplemented;
36
+ const JwtAlorithmNotImplemented = JwtAlgorithmNotImplemented;
16
37
  class JwtTokenInvalid extends Error {
17
- constructor(token) {
18
- super(`invalid JWT token: ${token}`);
19
- this.name = 'JwtTokenInvalid';
20
- }
38
+ constructor(token) {
39
+ super(`invalid JWT token: ${token}`);
40
+ this.name = "JwtTokenInvalid";
41
+ }
21
42
  }
22
- exports.JwtTokenInvalid = JwtTokenInvalid;
23
43
  class JwtTokenNotBefore extends Error {
24
- constructor(token) {
25
- super(`token (${token}) is being used before it's valid`);
26
- this.name = 'JwtTokenNotBefore';
27
- }
44
+ constructor(token) {
45
+ super(`token (${token}) is being used before it's valid`);
46
+ this.name = "JwtTokenNotBefore";
47
+ }
28
48
  }
29
- exports.JwtTokenNotBefore = JwtTokenNotBefore;
30
49
  class JwtTokenExpired extends Error {
31
- constructor(token) {
32
- super(`token (${token}) expired`);
33
- this.name = 'JwtTokenExpired';
34
- }
50
+ constructor(token) {
51
+ super(`token (${token}) expired`);
52
+ this.name = "JwtTokenExpired";
53
+ }
35
54
  }
36
- exports.JwtTokenExpired = JwtTokenExpired;
37
55
  class JwtTokenSignatureMismatched extends Error {
38
- constructor(token) {
39
- super(`token(${token}) signature mismatched`);
40
- this.name = 'JwtTokenSignatureMismatched';
41
- }
56
+ constructor(token) {
57
+ super(`token(${token}) signature mismatched`);
58
+ this.name = "JwtTokenSignatureMismatched";
59
+ }
42
60
  }
43
- exports.JwtTokenSignatureMismatched = JwtTokenSignatureMismatched;
44
- var AlgorithmTypes;
45
- (function (AlgorithmTypes) {
46
- AlgorithmTypes["HS256"] = "HS256";
47
- AlgorithmTypes["HS384"] = "HS384";
48
- AlgorithmTypes["HS512"] = "HS512";
49
- })(AlgorithmTypes = exports.AlgorithmTypes || (exports.AlgorithmTypes = {}));
61
+ var AlgorithmTypes = /* @__PURE__ */ ((AlgorithmTypes2) => {
62
+ AlgorithmTypes2["HS256"] = "HS256";
63
+ AlgorithmTypes2["HS384"] = "HS384";
64
+ AlgorithmTypes2["HS512"] = "HS512";
65
+ return AlgorithmTypes2;
66
+ })(AlgorithmTypes || {});
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ AlgorithmTypes,
70
+ JwtAlgorithmNotImplemented,
71
+ JwtAlorithmNotImplemented,
72
+ JwtTokenExpired,
73
+ JwtTokenInvalid,
74
+ JwtTokenNotBefore,
75
+ JwtTokenSignatureMismatched
76
+ });
@@ -1,92 +1,115 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMimeType = 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 mime_exports = {};
20
+ __export(mime_exports, {
21
+ getMimeType: () => getMimeType
22
+ });
23
+ module.exports = __toCommonJS(mime_exports);
4
24
  const getMimeType = (filename) => {
5
- const regexp = /\.([a-zA-Z0-9]+?)$/;
6
- const match = filename.match(regexp);
7
- if (!match)
8
- return;
9
- let mimeType = mimes[match[1]];
10
- if ((mimeType && mimeType.startsWith('text')) || mimeType === 'application/json') {
11
- mimeType += '; charset=utf-8';
12
- }
13
- return mimeType;
25
+ const regexp = /\.([a-zA-Z0-9]+?)$/;
26
+ const match = filename.match(regexp);
27
+ if (!match)
28
+ return;
29
+ let mimeType = mimes[match[1]];
30
+ if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
31
+ mimeType += "; charset=utf-8";
32
+ }
33
+ return mimeType;
14
34
  };
15
- exports.getMimeType = getMimeType;
16
35
  const mimes = {
17
- aac: 'audio/aac',
18
- abw: 'application/x-abiword',
19
- arc: 'application/x-freearc',
20
- avi: 'video/x-msvideo',
21
- azw: 'application/vnd.amazon.ebook',
22
- bin: 'application/octet-stream',
23
- bmp: 'image/bmp',
24
- bz: 'application/x-bzip',
25
- bz2: 'application/x-bzip2',
26
- csh: 'application/x-csh',
27
- css: 'text/css',
28
- csv: 'text/csv',
29
- doc: 'application/msword',
30
- docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
31
- eot: 'application/vnd.ms-fontobject',
32
- epub: 'application/epub+zip',
33
- gz: 'application/gzip',
34
- gif: 'image/gif',
35
- htm: 'text/html',
36
- html: 'text/html',
37
- ico: 'image/x-icon',
38
- ics: 'text/calendar',
39
- jar: 'application/java-archive',
40
- jpeg: 'image/jpeg',
41
- jpg: 'image/jpeg',
42
- js: 'text/javascript',
43
- json: 'application/json',
44
- jsonld: 'application/ld+json',
45
- map: 'application/json',
46
- mid: 'audio/x-midi',
47
- midi: 'audio/x-midi',
48
- mjs: 'text/javascript',
49
- mp3: 'audio/mpeg',
50
- mpeg: 'video/mpeg',
51
- mpkg: 'application/vnd.apple.installer+xml',
52
- odp: 'application/vnd.oasis.opendocument.presentation',
53
- ods: 'application/vnd.oasis.opendocument.spreadsheet',
54
- odt: 'application/vnd.oasis.opendocument.text',
55
- oga: 'audio/ogg',
56
- ogv: 'video/ogg',
57
- ogx: 'application/ogg',
58
- opus: 'audio/opus',
59
- otf: 'font/otf',
60
- png: 'image/png',
61
- pdf: 'application/pdf',
62
- php: 'application/php',
63
- ppt: 'application/vnd.ms-powerpoint',
64
- pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
65
- rar: 'application/vnd.rar',
66
- rtf: 'application/rtf',
67
- sh: 'application/x-sh',
68
- svg: 'image/svg+xml',
69
- swf: 'application/x-shockwave-flash',
70
- tar: 'application/x-tar',
71
- tif: 'image/tiff',
72
- tiff: 'image/tiff',
73
- ts: 'video/mp2t',
74
- ttf: 'font/ttf',
75
- txt: 'text/plain',
76
- vsd: 'application/vnd.visio',
77
- wav: 'audio/wav',
78
- weba: 'audio/webm',
79
- webm: 'video/webm',
80
- webp: 'image/webp',
81
- woff: 'font/woff',
82
- woff2: 'font/woff2',
83
- xhtml: 'application/xhtml+xml',
84
- xls: 'application/vnd.ms-excel',
85
- xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
86
- xml: 'application/xml',
87
- xul: 'application/vnd.mozilla.xul+xml',
88
- zip: 'application/zip',
89
- '3gp': 'video/3gpp',
90
- '3g2': 'video/3gpp2',
91
- '7z': 'application/x-7z-compressed',
36
+ aac: "audio/aac",
37
+ abw: "application/x-abiword",
38
+ arc: "application/x-freearc",
39
+ avi: "video/x-msvideo",
40
+ azw: "application/vnd.amazon.ebook",
41
+ bin: "application/octet-stream",
42
+ bmp: "image/bmp",
43
+ bz: "application/x-bzip",
44
+ bz2: "application/x-bzip2",
45
+ csh: "application/x-csh",
46
+ css: "text/css",
47
+ csv: "text/csv",
48
+ doc: "application/msword",
49
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
50
+ eot: "application/vnd.ms-fontobject",
51
+ epub: "application/epub+zip",
52
+ gz: "application/gzip",
53
+ gif: "image/gif",
54
+ htm: "text/html",
55
+ html: "text/html",
56
+ ico: "image/x-icon",
57
+ ics: "text/calendar",
58
+ jar: "application/java-archive",
59
+ jpeg: "image/jpeg",
60
+ jpg: "image/jpeg",
61
+ js: "text/javascript",
62
+ json: "application/json",
63
+ jsonld: "application/ld+json",
64
+ map: "application/json",
65
+ mid: "audio/x-midi",
66
+ midi: "audio/x-midi",
67
+ mjs: "text/javascript",
68
+ mp3: "audio/mpeg",
69
+ mpeg: "video/mpeg",
70
+ mpkg: "application/vnd.apple.installer+xml",
71
+ odp: "application/vnd.oasis.opendocument.presentation",
72
+ ods: "application/vnd.oasis.opendocument.spreadsheet",
73
+ odt: "application/vnd.oasis.opendocument.text",
74
+ oga: "audio/ogg",
75
+ ogv: "video/ogg",
76
+ ogx: "application/ogg",
77
+ opus: "audio/opus",
78
+ otf: "font/otf",
79
+ png: "image/png",
80
+ pdf: "application/pdf",
81
+ php: "application/php",
82
+ ppt: "application/vnd.ms-powerpoint",
83
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
84
+ rar: "application/vnd.rar",
85
+ rtf: "application/rtf",
86
+ sh: "application/x-sh",
87
+ svg: "image/svg+xml",
88
+ swf: "application/x-shockwave-flash",
89
+ tar: "application/x-tar",
90
+ tif: "image/tiff",
91
+ tiff: "image/tiff",
92
+ ts: "video/mp2t",
93
+ ttf: "font/ttf",
94
+ txt: "text/plain",
95
+ vsd: "application/vnd.visio",
96
+ wav: "audio/wav",
97
+ weba: "audio/webm",
98
+ webm: "video/webm",
99
+ webp: "image/webp",
100
+ woff: "font/woff",
101
+ woff2: "font/woff2",
102
+ xhtml: "application/xhtml+xml",
103
+ xls: "application/vnd.ms-excel",
104
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
105
+ xml: "application/xml",
106
+ xul: "application/vnd.mozilla.xul+xml",
107
+ zip: "application/zip",
108
+ "3gp": "video/3gpp",
109
+ "3g2": "video/3gpp2",
110
+ "7z": "application/x-7z-compressed"
92
111
  };
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ getMimeType
115
+ });
@@ -1,40 +1,58 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeObjects = exports.isObject = void 0;
4
- /* eslint-disable @typescript-eslint/no-explicit-any */
5
- const isObject = (val) => val && typeof val === 'object' && !Array.isArray(val);
6
- exports.isObject = isObject;
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 object_exports = {};
20
+ __export(object_exports, {
21
+ isObject: () => isObject,
22
+ mergeObjects: () => mergeObjects
23
+ });
24
+ module.exports = __toCommonJS(object_exports);
25
+ const isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
7
26
  const mergeObjects = (target, source) => {
8
- const merged = Object.assign({}, target);
9
- if ((0, exports.isObject)(target) && (0, exports.isObject)(source)) {
10
- for (const key of Object.keys(source)) {
11
- if ((0, exports.isObject)(source[key])) {
12
- if (target[key] === undefined)
13
- Object.assign(merged, { [key]: source[key] });
14
- else
15
- merged[key] = (0, exports.mergeObjects)(target[key], source[key]);
16
- }
17
- else if (Array.isArray(source[key]) && Array.isArray(target[key])) {
18
- const srcArr = source[key];
19
- const tgtArr = target[key];
20
- const outArr = [];
21
- for (let i = 0; i < srcArr.length; i += 1) {
22
- // If corresponding index for both arrays is an object, then merge them
23
- // Otherwise just copy src arr index into out arr index
24
- if ((0, exports.isObject)(srcArr[i]) && (0, exports.isObject)(tgtArr[i])) {
25
- outArr[i] = (0, exports.mergeObjects)(tgtArr[i], srcArr[i]);
26
- }
27
- else {
28
- outArr[i] = srcArr[i];
29
- }
30
- }
31
- Object.assign(merged, { [key]: outArr });
32
- }
33
- else {
34
- Object.assign(merged, { [key]: source[key] });
35
- }
27
+ const merged = Object.assign({}, target);
28
+ if (isObject(target) && isObject(source)) {
29
+ for (const key of Object.keys(source)) {
30
+ if (isObject(source[key])) {
31
+ if (target[key] === void 0)
32
+ Object.assign(merged, { [key]: source[key] });
33
+ else
34
+ merged[key] = mergeObjects(target[key], source[key]);
35
+ } else if (Array.isArray(source[key]) && Array.isArray(target[key])) {
36
+ const srcArr = source[key];
37
+ const tgtArr = target[key];
38
+ const outArr = [];
39
+ for (let i = 0; i < srcArr.length; i += 1) {
40
+ if (isObject(srcArr[i]) && isObject(tgtArr[i])) {
41
+ outArr[i] = mergeObjects(tgtArr[i], srcArr[i]);
42
+ } else {
43
+ outArr[i] = srcArr[i];
44
+ }
36
45
  }
46
+ Object.assign(merged, { [key]: outArr });
47
+ } else {
48
+ Object.assign(merged, { [key]: source[key] });
49
+ }
37
50
  }
38
- return merged;
51
+ }
52
+ return merged;
39
53
  };
40
- exports.mergeObjects = mergeObjects;
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ isObject,
57
+ mergeObjects
58
+ });
@@ -1,2 +1,16 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -1,94 +1,105 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkOptionalParameter = exports.mergePath = exports.getQueryStringFromURL = exports.getPathFromURL = exports.getPattern = exports.splitPath = 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 url_exports = {};
20
+ __export(url_exports, {
21
+ checkOptionalParameter: () => checkOptionalParameter,
22
+ getPathFromURL: () => getPathFromURL,
23
+ getPattern: () => getPattern,
24
+ getQueryStringFromURL: () => getQueryStringFromURL,
25
+ mergePath: () => mergePath,
26
+ splitPath: () => splitPath
27
+ });
28
+ module.exports = __toCommonJS(url_exports);
4
29
  const splitPath = (path) => {
5
- const paths = path.split(/\//); // faster than path.split('/')
6
- if (paths[0] === '') {
7
- paths.shift();
8
- }
9
- return paths;
30
+ const paths = path.split(/\//);
31
+ if (paths[0] === "") {
32
+ paths.shift();
33
+ }
34
+ return paths;
10
35
  };
11
- exports.splitPath = splitPath;
12
36
  const patternCache = {};
13
37
  const getPattern = (label) => {
14
- // * => wildcard
15
- // :id{[0-9]+} => ([0-9]+)
16
- // :id => (.+)
17
- //const name = ''
18
- if (label === '*') {
19
- return '*';
38
+ if (label === "*") {
39
+ return "*";
40
+ }
41
+ const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
42
+ if (match) {
43
+ if (!patternCache[label]) {
44
+ if (match[2]) {
45
+ patternCache[label] = [label, match[1], new RegExp("^" + match[2] + "$")];
46
+ } else {
47
+ patternCache[label] = [label, match[1], true];
48
+ }
20
49
  }
21
- const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
22
- if (match) {
23
- if (!patternCache[label]) {
24
- if (match[2]) {
25
- patternCache[label] = [label, match[1], new RegExp('^' + match[2] + '$')];
26
- }
27
- else {
28
- patternCache[label] = [label, match[1], true];
29
- }
30
- }
31
- return patternCache[label];
32
- }
33
- return null;
50
+ return patternCache[label];
51
+ }
52
+ return null;
34
53
  };
35
- exports.getPattern = getPattern;
36
54
  const getPathFromURL = (url, strict = true) => {
37
- const queryIndex = url.indexOf('?');
38
- const result = url.substring(url.indexOf('/', 8), queryIndex === -1 ? url.length : queryIndex);
39
- // if strict routing is false => `/hello/hey/` and `/hello/hey` are treated the same
40
- // default is true
41
- if (strict === false && result.endsWith('/')) {
42
- return result.slice(0, -1);
43
- }
44
- return result;
55
+ const queryIndex = url.indexOf("?");
56
+ const result = url.substring(url.indexOf("/", 8), queryIndex === -1 ? url.length : queryIndex);
57
+ if (strict === false && result.endsWith("/")) {
58
+ return result.slice(0, -1);
59
+ }
60
+ return result;
45
61
  };
46
- exports.getPathFromURL = getPathFromURL;
47
62
  const getQueryStringFromURL = (url) => {
48
- const queryIndex = url.indexOf('?');
49
- const result = queryIndex !== -1 ? url.substring(queryIndex) : '';
50
- return result;
63
+ const queryIndex = url.indexOf("?");
64
+ const result = queryIndex !== -1 ? url.substring(queryIndex) : "";
65
+ return result;
51
66
  };
52
- exports.getQueryStringFromURL = getQueryStringFromURL;
53
67
  const mergePath = (...paths) => {
54
- let p = '';
55
- let endsWithSlash = false;
56
- for (let path of paths) {
57
- /* ['/hey/','/say'] => ['/hey', '/say'] */
58
- if (p.endsWith('/')) {
59
- p = p.slice(0, -1);
60
- endsWithSlash = true;
61
- }
62
- /* ['/hey','say'] => ['/hey', '/say'] */
63
- if (!path.startsWith('/')) {
64
- path = `/${path}`;
65
- }
66
- /* ['/hey/', '/'] => `/hey/` */
67
- if (path === '/' && endsWithSlash) {
68
- p = `${p}/`;
69
- }
70
- else if (path !== '/') {
71
- p = `${p}${path}`;
72
- }
73
- /* ['/', '/'] => `/` */
74
- if (path === '/' && p === '') {
75
- p = '/';
76
- }
68
+ let p = "";
69
+ let endsWithSlash = false;
70
+ for (let path of paths) {
71
+ if (p.endsWith("/")) {
72
+ p = p.slice(0, -1);
73
+ endsWithSlash = true;
74
+ }
75
+ if (!path.startsWith("/")) {
76
+ path = `/${path}`;
77
+ }
78
+ if (path === "/" && endsWithSlash) {
79
+ p = `${p}/`;
80
+ } else if (path !== "/") {
81
+ p = `${p}${path}`;
77
82
  }
78
- return p;
83
+ if (path === "/" && p === "") {
84
+ p = "/";
85
+ }
86
+ }
87
+ return p;
79
88
  };
80
- exports.mergePath = mergePath;
81
89
  const checkOptionalParameter = (path) => {
82
- /*
83
- If path is `/api/animals/:type?` it will return:
84
- [`/api/animals`, `/api/animals/:type`]
85
- in other cases it will return null
86
- */
87
- const match = path.match(/(^.+)(\/\:[^\/]+)\?$/);
88
- if (!match)
89
- return null;
90
- const base = match[1];
91
- const optional = base + match[2];
92
- return [base, optional];
90
+ const match = path.match(/(^.+)(\/\:[^\/]+)\?$/);
91
+ if (!match)
92
+ return null;
93
+ const base = match[1];
94
+ const optional = base + match[2];
95
+ return [base, optional];
93
96
  };
94
- exports.checkOptionalParameter = checkOptionalParameter;
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ checkOptionalParameter,
100
+ getPathFromURL,
101
+ getPattern,
102
+ getQueryStringFromURL,
103
+ mergePath,
104
+ splitPath
105
+ });