@splendidlabz/utils 1.11.6 → 1.12.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.
- package/dist/cjs/lib/http/index.cjs +100 -0
- package/dist/cjs/lib/http/status-text.cjs +98 -0
- package/dist/cjs/lib/index.cjs +472 -8
- package/dist/cjs/lib/promises/index.cjs +72 -15
- package/dist/cjs/lib/promises/reject.cjs +72 -13
- package/dist/cjs/lib/strings/index.cjs +396 -5
- package/dist/cjs/lib/strings/pluralize.cjs +372 -14
- package/dist/cjs/lib/strings/query-string.cjs +28 -5
- package/dist/esm/lib/http/index.js +1 -0
- package/dist/esm/lib/http/status-text.js +72 -0
- package/dist/esm/lib/index.js +1 -0
- package/dist/esm/lib/promises/reject.js +2 -2
- package/dist/esm/lib/strings/pluralize.js +366 -3
- package/dist/esm/lib/strings/query-string.js +27 -4
- package/dist/types/lib/http/index.d.cts +1 -0
- package/dist/types/lib/http/status-text.d.cts +73 -0
- package/dist/types/lib/index.d.cts +3 -2
- package/dist/types/lib/strings/index.d.cts +2 -2
- package/dist/types/lib/strings/pluralize.d.cts +24 -2
- package/dist/types/lib/strings/query-string.d.cts +10 -2
- package/package.json +3 -5
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
6
|
for (var name in all)
|
|
@@ -16,25 +14,385 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
14
|
}
|
|
17
15
|
return to;
|
|
18
16
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
18
|
|
|
29
19
|
// src/lib/strings/pluralize.js
|
|
30
20
|
var pluralize_exports = {};
|
|
31
21
|
__export(pluralize_exports, {
|
|
32
|
-
|
|
22
|
+
createPluralize: () => createPluralize,
|
|
23
|
+
isPlural: () => isPlural,
|
|
24
|
+
isSingular: () => isSingular,
|
|
25
|
+
plural: () => plural,
|
|
26
|
+
pluralize: () => pluralize,
|
|
27
|
+
singular: () => singular
|
|
33
28
|
});
|
|
34
29
|
module.exports = __toCommonJS(pluralize_exports);
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
function sanitizeRule(rule) {
|
|
31
|
+
if (typeof rule === "string") return new RegExp("^" + rule + "$", "i");
|
|
32
|
+
return rule;
|
|
33
|
+
}
|
|
34
|
+
function restoreCase(word, token) {
|
|
35
|
+
if (word === token) return token;
|
|
36
|
+
if (word === word.toLowerCase()) return token.toLowerCase();
|
|
37
|
+
if (word === word.toUpperCase()) return token.toUpperCase();
|
|
38
|
+
if (word[0] === word[0].toUpperCase()) {
|
|
39
|
+
return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
|
|
40
|
+
}
|
|
41
|
+
return token.toLowerCase();
|
|
42
|
+
}
|
|
43
|
+
function interpolate(str, args) {
|
|
44
|
+
return str.replace(/\$(\d{1,2})/g, (match, index) => args[index] || "");
|
|
45
|
+
}
|
|
46
|
+
function replace(word, rule) {
|
|
47
|
+
return word.replace(rule[0], function(match, index) {
|
|
48
|
+
const result = interpolate(rule[1], arguments);
|
|
49
|
+
if (match === "") return restoreCase(word[index - 1], result);
|
|
50
|
+
return restoreCase(match, result);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function sanitizeWord(token, word, rules, uncountables) {
|
|
54
|
+
if (!token.length || uncountables.hasOwnProperty(token)) return word;
|
|
55
|
+
let len = rules.length;
|
|
56
|
+
while (len--) {
|
|
57
|
+
const rule = rules[len];
|
|
58
|
+
if (rule[0].test(word)) return replace(word, rule);
|
|
59
|
+
}
|
|
60
|
+
return word;
|
|
61
|
+
}
|
|
62
|
+
function replaceWord(replaceMap, keepMap, rules, uncountables) {
|
|
63
|
+
return function(word) {
|
|
64
|
+
const token = word.toLowerCase();
|
|
65
|
+
if (keepMap.hasOwnProperty(token)) return restoreCase(word, token);
|
|
66
|
+
if (replaceMap.hasOwnProperty(token)) {
|
|
67
|
+
return restoreCase(word, replaceMap[token]);
|
|
68
|
+
}
|
|
69
|
+
return sanitizeWord(token, word, rules, uncountables);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function checkWord(replaceMap, keepMap, rules, uncountables) {
|
|
73
|
+
return function(word) {
|
|
74
|
+
const token = word.toLowerCase();
|
|
75
|
+
if (keepMap.hasOwnProperty(token)) return true;
|
|
76
|
+
if (replaceMap.hasOwnProperty(token)) return false;
|
|
77
|
+
return sanitizeWord(token, token, rules, uncountables) === token;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
var BASE_IRREGULAR = [
|
|
81
|
+
// Pronouns.
|
|
82
|
+
["I", "we"],
|
|
83
|
+
["me", "us"],
|
|
84
|
+
["he", "they"],
|
|
85
|
+
["she", "they"],
|
|
86
|
+
["them", "them"],
|
|
87
|
+
["myself", "ourselves"],
|
|
88
|
+
["yourself", "yourselves"],
|
|
89
|
+
["itself", "themselves"],
|
|
90
|
+
["herself", "themselves"],
|
|
91
|
+
["himself", "themselves"],
|
|
92
|
+
["themself", "themselves"],
|
|
93
|
+
["is", "are"],
|
|
94
|
+
["was", "were"],
|
|
95
|
+
["has", "have"],
|
|
96
|
+
["this", "these"],
|
|
97
|
+
["that", "those"],
|
|
98
|
+
// Words ending with a consonant and `o`.
|
|
99
|
+
["echo", "echoes"],
|
|
100
|
+
["dingo", "dingoes"],
|
|
101
|
+
["volcano", "volcanoes"],
|
|
102
|
+
["tornado", "tornadoes"],
|
|
103
|
+
["torpedo", "torpedoes"],
|
|
104
|
+
// Ends with `us`.
|
|
105
|
+
["genus", "genera"],
|
|
106
|
+
["viscus", "viscera"],
|
|
107
|
+
// Ends with `ma`.
|
|
108
|
+
["stigma", "stigmata"],
|
|
109
|
+
["stoma", "stomata"],
|
|
110
|
+
["dogma", "dogmata"],
|
|
111
|
+
["lemma", "lemmata"],
|
|
112
|
+
["schema", "schemata"],
|
|
113
|
+
["anathema", "anathemata"],
|
|
114
|
+
// Other irregular rules.
|
|
115
|
+
["ox", "oxen"],
|
|
116
|
+
["axe", "axes"],
|
|
117
|
+
["die", "dice"],
|
|
118
|
+
["yes", "yeses"],
|
|
119
|
+
["foot", "feet"],
|
|
120
|
+
["eave", "eaves"],
|
|
121
|
+
["goose", "geese"],
|
|
122
|
+
["tooth", "teeth"],
|
|
123
|
+
["quiz", "quizzes"],
|
|
124
|
+
["human", "humans"],
|
|
125
|
+
["proof", "proofs"],
|
|
126
|
+
["carve", "carves"],
|
|
127
|
+
["valve", "valves"],
|
|
128
|
+
["looey", "looies"],
|
|
129
|
+
["thief", "thieves"],
|
|
130
|
+
["groove", "grooves"],
|
|
131
|
+
["pickaxe", "pickaxes"],
|
|
132
|
+
["passerby", "passersby"]
|
|
133
|
+
];
|
|
134
|
+
var BASE_PLURAL = [
|
|
135
|
+
[/s?$/i, "s"],
|
|
136
|
+
// eslint-disable-next-line no-control-regex
|
|
137
|
+
[/[^\u0000-\u007F]$/i, "$0"],
|
|
138
|
+
[/([^aeiou]ese)$/i, "$1"],
|
|
139
|
+
[/(ax|test)is$/i, "$1es"],
|
|
140
|
+
[/(alias|[^aou]us|t[lm]as|gas|ris)$/i, "$1es"],
|
|
141
|
+
[/(e[mn]u)s?$/i, "$1s"],
|
|
142
|
+
[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, "$1"],
|
|
143
|
+
[
|
|
144
|
+
/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
|
|
145
|
+
"$1i"
|
|
146
|
+
],
|
|
147
|
+
[/(alumn|alg|vertebr)(?:a|ae)$/i, "$1ae"],
|
|
148
|
+
[/(seraph|cherub)(?:im)?$/i, "$1im"],
|
|
149
|
+
[/(her|at|gr)o$/i, "$1oes"],
|
|
150
|
+
[
|
|
151
|
+
/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i,
|
|
152
|
+
"$1a"
|
|
153
|
+
],
|
|
154
|
+
[
|
|
155
|
+
/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i,
|
|
156
|
+
"$1a"
|
|
157
|
+
],
|
|
158
|
+
[/sis$/i, "ses"],
|
|
159
|
+
[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, "$1$2ves"],
|
|
160
|
+
[/([^aeiouy]|qu)y$/i, "$1ies"],
|
|
161
|
+
[/([^ch][ieo][ln])ey$/i, "$1ies"],
|
|
162
|
+
[/(x|ch|ss|sh|zz)$/i, "$1es"],
|
|
163
|
+
[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, "$1ices"],
|
|
164
|
+
[/\b((?:tit)?m|l)(?:ice|ouse)$/i, "$1ice"],
|
|
165
|
+
[/(pe)(?:rson|ople)$/i, "$1ople"],
|
|
166
|
+
[/(child)(?:ren)?$/i, "$1ren"],
|
|
167
|
+
[/eaux$/i, "$0"],
|
|
168
|
+
[/m[ae]n$/i, "men"],
|
|
169
|
+
["thou", "you"]
|
|
170
|
+
];
|
|
171
|
+
var BASE_SINGULAR = [
|
|
172
|
+
[/s$/i, ""],
|
|
173
|
+
[/(ss)$/i, "$1"],
|
|
174
|
+
[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, "$1fe"],
|
|
175
|
+
[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, "$1f"],
|
|
176
|
+
[/ies$/i, "y"],
|
|
177
|
+
[
|
|
178
|
+
/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i,
|
|
179
|
+
"$1ie"
|
|
180
|
+
],
|
|
181
|
+
[/\b(mon|smil)ies$/i, "$1ey"],
|
|
182
|
+
[/\b((?:tit)?m|l)ice$/i, "$1ouse"],
|
|
183
|
+
[/(seraph|cherub)im$/i, "$1"],
|
|
184
|
+
[
|
|
185
|
+
/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,
|
|
186
|
+
"$1"
|
|
187
|
+
],
|
|
188
|
+
[
|
|
189
|
+
/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i,
|
|
190
|
+
"$1sis"
|
|
191
|
+
],
|
|
192
|
+
[/(movie|twelve|abuse|e[mn]u)s$/i, "$1"],
|
|
193
|
+
[/(test)(?:is|es)$/i, "$1is"],
|
|
194
|
+
[
|
|
195
|
+
/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
|
|
196
|
+
"$1us"
|
|
197
|
+
],
|
|
198
|
+
[
|
|
199
|
+
/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,
|
|
200
|
+
"$1um"
|
|
201
|
+
],
|
|
202
|
+
[
|
|
203
|
+
/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,
|
|
204
|
+
"$1on"
|
|
205
|
+
],
|
|
206
|
+
[/(alumn|alg|vertebr)ae$/i, "$1a"],
|
|
207
|
+
[/(cod|mur|sil|vert|ind)ices$/i, "$1ex"],
|
|
208
|
+
[/(matr|append)ices$/i, "$1ix"],
|
|
209
|
+
[/(pe)(rson|ople)$/i, "$1rson"],
|
|
210
|
+
[/(child)ren$/i, "$1"],
|
|
211
|
+
[/(eau)x?$/i, "$1"],
|
|
212
|
+
[/men$/i, "man"]
|
|
213
|
+
];
|
|
214
|
+
var BASE_UNCOUNTABLE = [
|
|
215
|
+
// Singular words with no plurals.
|
|
216
|
+
"adulthood",
|
|
217
|
+
"advice",
|
|
218
|
+
"agenda",
|
|
219
|
+
"aid",
|
|
220
|
+
"aircraft",
|
|
221
|
+
"alcohol",
|
|
222
|
+
"ammo",
|
|
223
|
+
"analytics",
|
|
224
|
+
"anime",
|
|
225
|
+
"athletics",
|
|
226
|
+
"audio",
|
|
227
|
+
"bison",
|
|
228
|
+
"blood",
|
|
229
|
+
"bream",
|
|
230
|
+
"buffalo",
|
|
231
|
+
"butter",
|
|
232
|
+
"carp",
|
|
233
|
+
"cash",
|
|
234
|
+
"chassis",
|
|
235
|
+
"chess",
|
|
236
|
+
"clothing",
|
|
237
|
+
"cod",
|
|
238
|
+
"commerce",
|
|
239
|
+
"cooperation",
|
|
240
|
+
"corps",
|
|
241
|
+
"debris",
|
|
242
|
+
"diabetes",
|
|
243
|
+
"digestion",
|
|
244
|
+
"elk",
|
|
245
|
+
"energy",
|
|
246
|
+
"equipment",
|
|
247
|
+
"excretion",
|
|
248
|
+
"expertise",
|
|
249
|
+
"firmware",
|
|
250
|
+
"flounder",
|
|
251
|
+
"fun",
|
|
252
|
+
"gallows",
|
|
253
|
+
"garbage",
|
|
254
|
+
"graffiti",
|
|
255
|
+
"hardware",
|
|
256
|
+
"headquarters",
|
|
257
|
+
"health",
|
|
258
|
+
"herpes",
|
|
259
|
+
"highjinks",
|
|
260
|
+
"homework",
|
|
261
|
+
"housework",
|
|
262
|
+
"information",
|
|
263
|
+
"jeans",
|
|
264
|
+
"justice",
|
|
265
|
+
"kudos",
|
|
266
|
+
"labour",
|
|
267
|
+
"literature",
|
|
268
|
+
"machinery",
|
|
269
|
+
"mackerel",
|
|
270
|
+
"mail",
|
|
271
|
+
"media",
|
|
272
|
+
"mews",
|
|
273
|
+
"moose",
|
|
274
|
+
"music",
|
|
275
|
+
"mud",
|
|
276
|
+
"manga",
|
|
277
|
+
"news",
|
|
278
|
+
"only",
|
|
279
|
+
"personnel",
|
|
280
|
+
"pike",
|
|
281
|
+
"plankton",
|
|
282
|
+
"pliers",
|
|
283
|
+
"police",
|
|
284
|
+
"pollution",
|
|
285
|
+
"premises",
|
|
286
|
+
"rain",
|
|
287
|
+
"research",
|
|
288
|
+
"rice",
|
|
289
|
+
"salmon",
|
|
290
|
+
"scissors",
|
|
291
|
+
"series",
|
|
292
|
+
"sewage",
|
|
293
|
+
"shambles",
|
|
294
|
+
"shrimp",
|
|
295
|
+
"software",
|
|
296
|
+
"species",
|
|
297
|
+
"staff",
|
|
298
|
+
"swine",
|
|
299
|
+
"tennis",
|
|
300
|
+
"traffic",
|
|
301
|
+
"transportation",
|
|
302
|
+
"trout",
|
|
303
|
+
"tuna",
|
|
304
|
+
"wealth",
|
|
305
|
+
"welfare",
|
|
306
|
+
"whiting",
|
|
307
|
+
"wildebeest",
|
|
308
|
+
"wildlife",
|
|
309
|
+
"you",
|
|
310
|
+
/pok[eé]mon$/i,
|
|
311
|
+
// Regexes.
|
|
312
|
+
/[^aeiou]ese$/i,
|
|
313
|
+
// "chinese", "japanese"
|
|
314
|
+
/deer$/i,
|
|
315
|
+
// "deer", "reindeer"
|
|
316
|
+
/fish$/i,
|
|
317
|
+
// "fish", "blowfish", "angelfish"
|
|
318
|
+
/measles$/i,
|
|
319
|
+
/o[iu]s$/i,
|
|
320
|
+
// "carnivorous"
|
|
321
|
+
/pox$/i,
|
|
322
|
+
// "chickpox", "smallpox"
|
|
323
|
+
/sheep$/i
|
|
324
|
+
];
|
|
325
|
+
function createPluralize(config = {}) {
|
|
326
|
+
const pluralRules = [];
|
|
327
|
+
const singularRules = [];
|
|
328
|
+
const uncountables = {};
|
|
329
|
+
const irregularPlurals = {};
|
|
330
|
+
const irregularSingles = {};
|
|
331
|
+
for (const [single, plur] of [
|
|
332
|
+
...BASE_IRREGULAR,
|
|
333
|
+
...config.irregular || []
|
|
334
|
+
]) {
|
|
335
|
+
irregularSingles[single.toLowerCase()] = plur.toLowerCase();
|
|
336
|
+
irregularPlurals[plur.toLowerCase()] = single.toLowerCase();
|
|
337
|
+
}
|
|
338
|
+
for (const [rule, replacement] of [...BASE_PLURAL, ...config.plural || []]) {
|
|
339
|
+
pluralRules.push([sanitizeRule(rule), replacement]);
|
|
340
|
+
}
|
|
341
|
+
for (const [rule, replacement] of [
|
|
342
|
+
...BASE_SINGULAR,
|
|
343
|
+
...config.singular || []
|
|
344
|
+
]) {
|
|
345
|
+
singularRules.push([sanitizeRule(rule), replacement]);
|
|
346
|
+
}
|
|
347
|
+
for (const word of [...BASE_UNCOUNTABLE, ...config.uncountable || []]) {
|
|
348
|
+
if (typeof word === "string") {
|
|
349
|
+
uncountables[word.toLowerCase()] = true;
|
|
350
|
+
} else {
|
|
351
|
+
pluralRules.push([sanitizeRule(word), "$0"]);
|
|
352
|
+
singularRules.push([sanitizeRule(word), "$0"]);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const plural2 = replaceWord(
|
|
356
|
+
irregularSingles,
|
|
357
|
+
irregularPlurals,
|
|
358
|
+
pluralRules,
|
|
359
|
+
uncountables
|
|
360
|
+
);
|
|
361
|
+
const singular2 = replaceWord(
|
|
362
|
+
irregularPlurals,
|
|
363
|
+
irregularSingles,
|
|
364
|
+
singularRules,
|
|
365
|
+
uncountables
|
|
366
|
+
);
|
|
367
|
+
const isPlural2 = checkWord(
|
|
368
|
+
irregularSingles,
|
|
369
|
+
irregularPlurals,
|
|
370
|
+
pluralRules,
|
|
371
|
+
uncountables
|
|
372
|
+
);
|
|
373
|
+
const isSingular2 = checkWord(
|
|
374
|
+
irregularPlurals,
|
|
375
|
+
irregularSingles,
|
|
376
|
+
singularRules,
|
|
377
|
+
uncountables
|
|
378
|
+
);
|
|
379
|
+
function pluralize2(word, count, inclusive) {
|
|
380
|
+
const out = count === 1 ? singular2(word) : plural2(word);
|
|
381
|
+
return (inclusive ? count + " " : "") + out;
|
|
382
|
+
}
|
|
383
|
+
return Object.assign(pluralize2, { plural: plural2, singular: singular2, isPlural: isPlural2, isSingular: isSingular2 });
|
|
384
|
+
}
|
|
385
|
+
var pluralize = createPluralize();
|
|
386
|
+
var plural = pluralize.plural;
|
|
387
|
+
var singular = pluralize.singular;
|
|
388
|
+
var isPlural = pluralize.isPlural;
|
|
389
|
+
var isSingular = pluralize.isSingular;
|
|
37
390
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
391
|
0 && (module.exports = {
|
|
39
|
-
|
|
392
|
+
createPluralize,
|
|
393
|
+
isPlural,
|
|
394
|
+
isSingular,
|
|
395
|
+
plural,
|
|
396
|
+
pluralize,
|
|
397
|
+
singular
|
|
40
398
|
});
|
|
@@ -19,7 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/lib/strings/query-string.js
|
|
20
20
|
var query_string_exports = {};
|
|
21
21
|
__export(query_string_exports, {
|
|
22
|
-
|
|
22
|
+
parseQueryString: () => parseQueryString,
|
|
23
23
|
stripNumbers: () => stripNumbers,
|
|
24
24
|
toQueryString: () => toQueryString
|
|
25
25
|
});
|
|
@@ -28,16 +28,39 @@ function toQueryString(object) {
|
|
|
28
28
|
const searchParams = new URLSearchParams(object);
|
|
29
29
|
return searchParams.toString();
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
function parseQueryString(string = "") {
|
|
32
|
+
const query = string.startsWith("?") ? string.slice(1) : string;
|
|
33
|
+
const result = {};
|
|
34
|
+
if (!query) return result;
|
|
35
|
+
const decode = (str) => decodeURIComponent(str.replace(/\+/g, " "));
|
|
36
|
+
const keyToPath = (key) => key.replace(/\]/g, "").split("[").map(decode);
|
|
37
|
+
for (const pair of query.split("&")) {
|
|
38
|
+
if (!pair) continue;
|
|
39
|
+
const eq = pair.indexOf("=");
|
|
40
|
+
const path = keyToPath(eq === -1 ? pair : pair.slice(0, eq));
|
|
41
|
+
const value = decode(eq === -1 ? "" : pair.slice(eq + 1));
|
|
42
|
+
let current = result;
|
|
43
|
+
path.forEach((key, i) => {
|
|
44
|
+
const index = Array.isArray(current) ? Number(key) : key;
|
|
45
|
+
if (i === path.length - 1) {
|
|
46
|
+
if (key === "") current.push(value);
|
|
47
|
+
else current[index] = value;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const next = path[i + 1];
|
|
51
|
+
const childIsArray = next === "" || /^\d+$/.test(next);
|
|
52
|
+
if (current[index] == null) current[index] = childIsArray ? [] : {};
|
|
53
|
+
current = current[index];
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
34
57
|
}
|
|
35
58
|
function stripNumbers(string) {
|
|
36
59
|
return string.replace(/\d*/, "");
|
|
37
60
|
}
|
|
38
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
62
|
0 && (module.exports = {
|
|
40
|
-
|
|
63
|
+
parseQueryString,
|
|
41
64
|
stripNumbers,
|
|
42
65
|
toQueryString
|
|
43
66
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./status-text.js";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const statusTexts = {
|
|
2
|
+
100: "Continue",
|
|
3
|
+
101: "Switching Protocols",
|
|
4
|
+
102: "Processing",
|
|
5
|
+
103: "Early Hints",
|
|
6
|
+
200: "OK",
|
|
7
|
+
201: "Created",
|
|
8
|
+
202: "Accepted",
|
|
9
|
+
203: "Non-Authoritative Information",
|
|
10
|
+
204: "No Content",
|
|
11
|
+
205: "Reset Content",
|
|
12
|
+
206: "Partial Content",
|
|
13
|
+
207: "Multi-Status",
|
|
14
|
+
208: "Already Reported",
|
|
15
|
+
226: "IM Used",
|
|
16
|
+
300: "Multiple Choices",
|
|
17
|
+
301: "Moved Permanently",
|
|
18
|
+
302: "Found",
|
|
19
|
+
303: "See Other",
|
|
20
|
+
304: "Not Modified",
|
|
21
|
+
305: "Use Proxy",
|
|
22
|
+
307: "Temporary Redirect",
|
|
23
|
+
308: "Permanent Redirect",
|
|
24
|
+
400: "Bad Request",
|
|
25
|
+
401: "Unauthorized",
|
|
26
|
+
402: "Payment Required",
|
|
27
|
+
403: "Forbidden",
|
|
28
|
+
404: "Not Found",
|
|
29
|
+
405: "Method Not Allowed",
|
|
30
|
+
406: "Not Acceptable",
|
|
31
|
+
407: "Proxy Authentication Required",
|
|
32
|
+
408: "Request Timeout",
|
|
33
|
+
409: "Conflict",
|
|
34
|
+
410: "Gone",
|
|
35
|
+
411: "Length Required",
|
|
36
|
+
412: "Precondition Failed",
|
|
37
|
+
413: "Payload Too Large",
|
|
38
|
+
414: "URI Too Long",
|
|
39
|
+
415: "Unsupported Media Type",
|
|
40
|
+
416: "Range Not Satisfiable",
|
|
41
|
+
417: "Expectation Failed",
|
|
42
|
+
418: "I'm a Teapot",
|
|
43
|
+
421: "Misdirected Request",
|
|
44
|
+
422: "Unprocessable Entity",
|
|
45
|
+
423: "Locked",
|
|
46
|
+
424: "Failed Dependency",
|
|
47
|
+
425: "Too Early",
|
|
48
|
+
426: "Upgrade Required",
|
|
49
|
+
428: "Precondition Required",
|
|
50
|
+
429: "Too Many Requests",
|
|
51
|
+
431: "Request Header Fields Too Large",
|
|
52
|
+
451: "Unavailable For Legal Reasons",
|
|
53
|
+
500: "Internal Server Error",
|
|
54
|
+
501: "Not Implemented",
|
|
55
|
+
502: "Bad Gateway",
|
|
56
|
+
503: "Service Unavailable",
|
|
57
|
+
504: "Gateway Timeout",
|
|
58
|
+
505: "HTTP Version Not Supported",
|
|
59
|
+
506: "Variant Also Negotiates",
|
|
60
|
+
507: "Insufficient Storage",
|
|
61
|
+
508: "Loop Detected",
|
|
62
|
+
509: "Bandwidth Limit Exceeded",
|
|
63
|
+
510: "Not Extended",
|
|
64
|
+
511: "Network Authentication Required"
|
|
65
|
+
};
|
|
66
|
+
function statusText(code) {
|
|
67
|
+
return statusTexts[code];
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
statusText,
|
|
71
|
+
statusTexts
|
|
72
|
+
};
|
package/dist/esm/lib/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./date/index.js";
|
|
|
5
5
|
export * from "./form/index.js";
|
|
6
6
|
export * from "./functions/index.js";
|
|
7
7
|
export * from "./hash.js";
|
|
8
|
+
export * from "./http/index.js";
|
|
8
9
|
export * from "./numbers/index.js";
|
|
9
10
|
export * from "./objects/index.js";
|
|
10
11
|
export * from "./promises/index.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import statuses from "statuses";
|
|
2
1
|
import { omitEmpty } from "../objects/omit-empty.js";
|
|
2
|
+
import { statusText as httpStatusText } from "../http/status-text.js";
|
|
3
3
|
function reject(props, { includeStack = true } = {}) {
|
|
4
4
|
const { status, statusText, body, message } = props;
|
|
5
5
|
const e = new Error();
|
|
6
6
|
const err = {
|
|
7
7
|
status,
|
|
8
|
-
statusText: statusText || status &&
|
|
8
|
+
statusText: statusText || status && httpStatusText(status),
|
|
9
9
|
body,
|
|
10
10
|
message,
|
|
11
11
|
stack: includeStack && e.stack
|