hono 3.1.3 → 3.1.4

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.
@@ -49,18 +49,10 @@ class HonoRequest {
49
49
  return null;
50
50
  }
51
51
  query(key) {
52
- const queryString = (0, import_url.getQueryStringFromURL)(this.url);
53
- const result = (0, import_url.getQueryParam)(queryString, key);
54
- if (result === null)
55
- return void 0;
56
- return result;
52
+ return (0, import_url.getQueryParam)(this.url, key);
57
53
  }
58
54
  queries(key) {
59
- const queryString = (0, import_url.getQueryStringFromURL)(this.url);
60
- const result = (0, import_url.getQueryParams)(queryString, key);
61
- if (result === null)
62
- return void 0;
63
- return result;
55
+ return (0, import_url.getQueryParams)(this.url, key);
64
56
  }
65
57
  header(name) {
66
58
  const headerData = {};
@@ -23,7 +23,6 @@ __export(url_exports, {
23
23
  getPattern: () => getPattern,
24
24
  getQueryParam: () => getQueryParam,
25
25
  getQueryParams: () => getQueryParams,
26
- getQueryStringFromURL: () => getQueryStringFromURL,
27
26
  mergePath: () => mergePath,
28
27
  splitPath: () => splitPath,
29
28
  splitRoutingPath: () => splitRoutingPath
@@ -92,11 +91,6 @@ const getPathFromURL = (url, strict = true) => {
92
91
  }
93
92
  return result;
94
93
  };
95
- const getQueryStringFromURL = (url) => {
96
- const queryIndex = url.indexOf("?", 8);
97
- const result = queryIndex !== -1 ? url.slice(queryIndex + 1) : "";
98
- return result;
99
- };
100
94
  const mergePath = (...paths) => {
101
95
  let p = "";
102
96
  let endsWithSlash = false;
@@ -127,48 +121,71 @@ const checkOptionalParameter = (path) => {
127
121
  const optional = base + match[2];
128
122
  return [base === "" ? "/" : base.replace(/\/$/, ""), optional];
129
123
  };
130
- const getQueryParam = (queryString, key) => {
131
- const results = {};
132
- while (true) {
133
- const andIndex = queryString.indexOf("&");
134
- let strings = "";
135
- if (andIndex === -1) {
136
- strings = queryString;
137
- } else {
138
- strings = queryString.substring(0, andIndex);
124
+ const _decodeURI = (value) => {
125
+ if (!/[%+]/.test(value)) {
126
+ return value;
127
+ }
128
+ if (value.includes("+")) {
129
+ value = value.replace(/\+/g, " ");
130
+ }
131
+ return value.includes("%") ? decodeURIComponent(value) : value;
132
+ };
133
+ const _getQueryParam = (url, key, multiple) => {
134
+ let encoded;
135
+ if (!multiple && key && !/[%+]/.test(key)) {
136
+ let keyIndex2 = url.indexOf(`?${key}`, 8);
137
+ if (keyIndex2 === -1) {
138
+ keyIndex2 = url.indexOf(`&${key}`, 8);
139
139
  }
140
- const eqIndex = strings.indexOf("=");
141
- if (eqIndex !== -1) {
142
- const v = strings.substring(eqIndex + 1);
143
- const k = strings.substring(0, eqIndex);
144
- if (key === k) {
145
- return /\%/.test(v) ? decodeURIComponent(v) : v;
146
- } else {
147
- results[k] || (results[k] = v);
140
+ while (keyIndex2 !== -1) {
141
+ const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
142
+ if (trailingKeyCode === 61) {
143
+ const valueIndex = keyIndex2 + key.length + 2;
144
+ const endIndex = url.indexOf("&", valueIndex);
145
+ const value = url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex);
146
+ return _decodeURI(value);
147
+ } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
148
+ return "";
148
149
  }
149
- } else if (strings === key) {
150
- return "";
150
+ keyIndex2 = url.indexOf(`&${key}`, keyIndex2);
151
+ }
152
+ encoded = /[%+]/.test(url);
153
+ if (!encoded) {
154
+ return void 0;
151
155
  }
152
- if (andIndex === -1)
153
- break;
154
- queryString = queryString.substring(andIndex + 1, queryString.length);
155
156
  }
156
- if (key)
157
- return null;
158
- return results;
159
- };
160
- const getQueryParams = (queryString, key) => {
161
157
  const results = {};
162
- for (const strings of queryString.split("&")) {
163
- let [k, v] = strings.split("=");
164
- if (v === void 0)
165
- v = "";
166
- results[k] || (results[k] = []);
167
- results[k].push(v.indexOf("%") !== -1 ? decodeURIComponent(v) : v);
158
+ encoded ?? (encoded = /[%+]/.test(url));
159
+ let keyIndex = url.indexOf("?", 8);
160
+ while (keyIndex !== -1) {
161
+ const valueIndex = url.indexOf("=", keyIndex);
162
+ let name = url.slice(keyIndex + 1, valueIndex === -1 ? void 0 : valueIndex);
163
+ if (encoded) {
164
+ name = _decodeURI(name);
165
+ }
166
+ let value;
167
+ if (valueIndex === -1) {
168
+ keyIndex = -1;
169
+ value = "";
170
+ } else {
171
+ keyIndex = url.indexOf("&", valueIndex);
172
+ value = url.slice(valueIndex + 1, keyIndex === -1 ? void 0 : keyIndex);
173
+ if (encoded) {
174
+ value = _decodeURI(value);
175
+ }
176
+ }
177
+ if (multiple) {
178
+ ;
179
+ (results[name] ?? (results[name] = [])).push(value);
180
+ } else {
181
+ results[name] ?? (results[name] = value);
182
+ }
168
183
  }
169
- if (key)
170
- return results[key] ? results[key] : null;
171
- return results;
184
+ return key ? results[key] : results;
185
+ };
186
+ const getQueryParam = _getQueryParam;
187
+ const getQueryParams = (url, key) => {
188
+ return _getQueryParam(url, key, true);
172
189
  };
173
190
  // Annotate the CommonJS export names for ESM import in node:
174
191
  0 && (module.exports = {
@@ -177,7 +194,6 @@ const getQueryParams = (queryString, key) => {
177
194
  getPattern,
178
195
  getQueryParam,
179
196
  getQueryParams,
180
- getQueryStringFromURL,
181
197
  mergePath,
182
198
  splitPath,
183
199
  splitRoutingPath
package/dist/request.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/request.ts
2
2
  import { parseBody } from "./utils/body.js";
3
3
  import { parse } from "./utils/cookie.js";
4
- import { getQueryStringFromURL, getQueryParam, getQueryParams } from "./utils/url.js";
4
+ import { getQueryParam, getQueryParams } from "./utils/url.js";
5
5
  var HonoRequest = class {
6
6
  constructor(request, path = "/", paramData) {
7
7
  this.raw = request;
@@ -27,18 +27,10 @@ var HonoRequest = class {
27
27
  return null;
28
28
  }
29
29
  query(key) {
30
- const queryString = getQueryStringFromURL(this.url);
31
- const result = getQueryParam(queryString, key);
32
- if (result === null)
33
- return void 0;
34
- return result;
30
+ return getQueryParam(this.url, key);
35
31
  }
36
32
  queries(key) {
37
- const queryString = getQueryStringFromURL(this.url);
38
- const result = getQueryParams(queryString, key);
39
- if (result === null)
40
- return void 0;
41
- return result;
33
+ return getQueryParams(this.url, key);
42
34
  }
43
35
  header(name) {
44
36
  const headerData = {};
@@ -3,8 +3,7 @@ export declare const splitPath: (path: string) => string[];
3
3
  export declare const splitRoutingPath: (path: string) => string[];
4
4
  export declare const getPattern: (label: string) => Pattern | null;
5
5
  export declare const getPathFromURL: (url: string, strict?: boolean) => string;
6
- export declare const getQueryStringFromURL: (url: string) => string;
7
6
  export declare const mergePath: (...paths: string[]) => string;
8
7
  export declare const checkOptionalParameter: (path: string) => string[] | null;
9
- export declare const getQueryParam: (queryString: string, key?: string) => string | null | Record<string, string>;
10
- export declare const getQueryParams: (queryString: string, key?: string) => string[] | null | Record<string, string[]>;
8
+ export declare const getQueryParam: (url: string, key?: string) => string | undefined | Record<string, string>;
9
+ export declare const getQueryParams: (url: string, key?: string) => string[] | undefined | Record<string, string[]>;
package/dist/utils/url.js CHANGED
@@ -62,11 +62,6 @@ var getPathFromURL = (url, strict = true) => {
62
62
  }
63
63
  return result;
64
64
  };
65
- var getQueryStringFromURL = (url) => {
66
- const queryIndex = url.indexOf("?", 8);
67
- const result = queryIndex !== -1 ? url.slice(queryIndex + 1) : "";
68
- return result;
69
- };
70
65
  var mergePath = (...paths) => {
71
66
  let p = "";
72
67
  let endsWithSlash = false;
@@ -97,48 +92,71 @@ var checkOptionalParameter = (path) => {
97
92
  const optional = base + match[2];
98
93
  return [base === "" ? "/" : base.replace(/\/$/, ""), optional];
99
94
  };
100
- var getQueryParam = (queryString, key) => {
101
- const results = {};
102
- while (true) {
103
- const andIndex = queryString.indexOf("&");
104
- let strings = "";
105
- if (andIndex === -1) {
106
- strings = queryString;
107
- } else {
108
- strings = queryString.substring(0, andIndex);
95
+ var _decodeURI = (value) => {
96
+ if (!/[%+]/.test(value)) {
97
+ return value;
98
+ }
99
+ if (value.includes("+")) {
100
+ value = value.replace(/\+/g, " ");
101
+ }
102
+ return value.includes("%") ? decodeURIComponent(value) : value;
103
+ };
104
+ var _getQueryParam = (url, key, multiple) => {
105
+ let encoded;
106
+ if (!multiple && key && !/[%+]/.test(key)) {
107
+ let keyIndex2 = url.indexOf(`?${key}`, 8);
108
+ if (keyIndex2 === -1) {
109
+ keyIndex2 = url.indexOf(`&${key}`, 8);
109
110
  }
110
- const eqIndex = strings.indexOf("=");
111
- if (eqIndex !== -1) {
112
- const v = strings.substring(eqIndex + 1);
113
- const k = strings.substring(0, eqIndex);
114
- if (key === k) {
115
- return /\%/.test(v) ? decodeURIComponent(v) : v;
116
- } else {
117
- results[k] || (results[k] = v);
111
+ while (keyIndex2 !== -1) {
112
+ const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
113
+ if (trailingKeyCode === 61) {
114
+ const valueIndex = keyIndex2 + key.length + 2;
115
+ const endIndex = url.indexOf("&", valueIndex);
116
+ const value = url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex);
117
+ return _decodeURI(value);
118
+ } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
119
+ return "";
118
120
  }
119
- } else if (strings === key) {
120
- return "";
121
+ keyIndex2 = url.indexOf(`&${key}`, keyIndex2);
122
+ }
123
+ encoded = /[%+]/.test(url);
124
+ if (!encoded) {
125
+ return void 0;
121
126
  }
122
- if (andIndex === -1)
123
- break;
124
- queryString = queryString.substring(andIndex + 1, queryString.length);
125
127
  }
126
- if (key)
127
- return null;
128
- return results;
129
- };
130
- var getQueryParams = (queryString, key) => {
131
128
  const results = {};
132
- for (const strings of queryString.split("&")) {
133
- let [k, v] = strings.split("=");
134
- if (v === void 0)
135
- v = "";
136
- results[k] || (results[k] = []);
137
- results[k].push(v.indexOf("%") !== -1 ? decodeURIComponent(v) : v);
129
+ encoded ?? (encoded = /[%+]/.test(url));
130
+ let keyIndex = url.indexOf("?", 8);
131
+ while (keyIndex !== -1) {
132
+ const valueIndex = url.indexOf("=", keyIndex);
133
+ let name = url.slice(keyIndex + 1, valueIndex === -1 ? void 0 : valueIndex);
134
+ if (encoded) {
135
+ name = _decodeURI(name);
136
+ }
137
+ let value;
138
+ if (valueIndex === -1) {
139
+ keyIndex = -1;
140
+ value = "";
141
+ } else {
142
+ keyIndex = url.indexOf("&", valueIndex);
143
+ value = url.slice(valueIndex + 1, keyIndex === -1 ? void 0 : keyIndex);
144
+ if (encoded) {
145
+ value = _decodeURI(value);
146
+ }
147
+ }
148
+ if (multiple) {
149
+ ;
150
+ (results[name] ?? (results[name] = [])).push(value);
151
+ } else {
152
+ results[name] ?? (results[name] = value);
153
+ }
138
154
  }
139
- if (key)
140
- return results[key] ? results[key] : null;
141
- return results;
155
+ return key ? results[key] : results;
156
+ };
157
+ var getQueryParam = _getQueryParam;
158
+ var getQueryParams = (url, key) => {
159
+ return _getQueryParam(url, key, true);
142
160
  };
143
161
  export {
144
162
  checkOptionalParameter,
@@ -146,7 +164,6 @@ export {
146
164
  getPattern,
147
165
  getQueryParam,
148
166
  getQueryParams,
149
- getQueryStringFromURL,
150
167
  mergePath,
151
168
  splitPath,
152
169
  splitRoutingPath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "description": "Ultrafast web framework for the Edge",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",