@splendidlabz/utils 1.12.0 → 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.
@@ -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,14 +14,6 @@ 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/promises/reject.js
@@ -32,7 +22,6 @@ __export(reject_exports, {
32
22
  reject: () => reject
33
23
  });
34
24
  module.exports = __toCommonJS(reject_exports);
35
- var import_statuses = __toESM(require("statuses"), 1);
36
25
 
37
26
  // src/lib/objects/omit-empty.js
38
27
  function omitEmpty(obj, shallow = false) {
@@ -48,13 +37,83 @@ function omitEmpty(obj, shallow = false) {
48
37
  return result;
49
38
  }
50
39
 
40
+ // src/lib/http/status-text.js
41
+ var statusTexts = {
42
+ 100: "Continue",
43
+ 101: "Switching Protocols",
44
+ 102: "Processing",
45
+ 103: "Early Hints",
46
+ 200: "OK",
47
+ 201: "Created",
48
+ 202: "Accepted",
49
+ 203: "Non-Authoritative Information",
50
+ 204: "No Content",
51
+ 205: "Reset Content",
52
+ 206: "Partial Content",
53
+ 207: "Multi-Status",
54
+ 208: "Already Reported",
55
+ 226: "IM Used",
56
+ 300: "Multiple Choices",
57
+ 301: "Moved Permanently",
58
+ 302: "Found",
59
+ 303: "See Other",
60
+ 304: "Not Modified",
61
+ 305: "Use Proxy",
62
+ 307: "Temporary Redirect",
63
+ 308: "Permanent Redirect",
64
+ 400: "Bad Request",
65
+ 401: "Unauthorized",
66
+ 402: "Payment Required",
67
+ 403: "Forbidden",
68
+ 404: "Not Found",
69
+ 405: "Method Not Allowed",
70
+ 406: "Not Acceptable",
71
+ 407: "Proxy Authentication Required",
72
+ 408: "Request Timeout",
73
+ 409: "Conflict",
74
+ 410: "Gone",
75
+ 411: "Length Required",
76
+ 412: "Precondition Failed",
77
+ 413: "Payload Too Large",
78
+ 414: "URI Too Long",
79
+ 415: "Unsupported Media Type",
80
+ 416: "Range Not Satisfiable",
81
+ 417: "Expectation Failed",
82
+ 418: "I'm a Teapot",
83
+ 421: "Misdirected Request",
84
+ 422: "Unprocessable Entity",
85
+ 423: "Locked",
86
+ 424: "Failed Dependency",
87
+ 425: "Too Early",
88
+ 426: "Upgrade Required",
89
+ 428: "Precondition Required",
90
+ 429: "Too Many Requests",
91
+ 431: "Request Header Fields Too Large",
92
+ 451: "Unavailable For Legal Reasons",
93
+ 500: "Internal Server Error",
94
+ 501: "Not Implemented",
95
+ 502: "Bad Gateway",
96
+ 503: "Service Unavailable",
97
+ 504: "Gateway Timeout",
98
+ 505: "HTTP Version Not Supported",
99
+ 506: "Variant Also Negotiates",
100
+ 507: "Insufficient Storage",
101
+ 508: "Loop Detected",
102
+ 509: "Bandwidth Limit Exceeded",
103
+ 510: "Not Extended",
104
+ 511: "Network Authentication Required"
105
+ };
106
+ function statusText(code) {
107
+ return statusTexts[code];
108
+ }
109
+
51
110
  // src/lib/promises/reject.js
52
111
  function reject(props, { includeStack = true } = {}) {
53
- const { status, statusText, body, message } = props;
112
+ const { status, statusText: statusText2, body, message } = props;
54
113
  const e = new Error();
55
114
  const err = {
56
115
  status,
57
- statusText: statusText || status && (0, import_statuses.default)(status),
116
+ statusText: statusText2 || status && statusText(status),
58
117
  body,
59
118
  message,
60
119
  stack: includeStack && e.stack
@@ -29,11 +29,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/lib/strings/index.js
30
30
  var strings_exports = {};
31
31
  __export(strings_exports, {
32
+ createPluralize: () => createPluralize,
33
+ isPlural: () => isPlural,
34
+ isSingular: () => isSingular,
32
35
  markdown: () => markdown,
33
36
  parseFullName: () => parseFullName,
34
37
  parseQueryString: () => parseQueryString,
35
38
  plural: () => plural,
36
39
  pluralize: () => pluralize,
40
+ singular: () => singular,
37
41
  stripNumbers: () => stripNumbers,
38
42
  toCamel: () => toCamel,
39
43
  toKebab: () => toKebab,
@@ -163,8 +167,366 @@ function parseFullName(name) {
163
167
  }
164
168
 
165
169
  // src/lib/strings/pluralize.js
166
- var import_pluralize = __toESM(require("pluralize"), 1);
167
- var pluralize = import_pluralize.default;
170
+ function sanitizeRule(rule) {
171
+ if (typeof rule === "string") return new RegExp("^" + rule + "$", "i");
172
+ return rule;
173
+ }
174
+ function restoreCase(word, token) {
175
+ if (word === token) return token;
176
+ if (word === word.toLowerCase()) return token.toLowerCase();
177
+ if (word === word.toUpperCase()) return token.toUpperCase();
178
+ if (word[0] === word[0].toUpperCase()) {
179
+ return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
180
+ }
181
+ return token.toLowerCase();
182
+ }
183
+ function interpolate(str, args) {
184
+ return str.replace(/\$(\d{1,2})/g, (match, index) => args[index] || "");
185
+ }
186
+ function replace(word, rule) {
187
+ return word.replace(rule[0], function(match, index) {
188
+ const result = interpolate(rule[1], arguments);
189
+ if (match === "") return restoreCase(word[index - 1], result);
190
+ return restoreCase(match, result);
191
+ });
192
+ }
193
+ function sanitizeWord(token, word, rules, uncountables) {
194
+ if (!token.length || uncountables.hasOwnProperty(token)) return word;
195
+ let len = rules.length;
196
+ while (len--) {
197
+ const rule = rules[len];
198
+ if (rule[0].test(word)) return replace(word, rule);
199
+ }
200
+ return word;
201
+ }
202
+ function replaceWord(replaceMap, keepMap, rules, uncountables) {
203
+ return function(word) {
204
+ const token = word.toLowerCase();
205
+ if (keepMap.hasOwnProperty(token)) return restoreCase(word, token);
206
+ if (replaceMap.hasOwnProperty(token)) {
207
+ return restoreCase(word, replaceMap[token]);
208
+ }
209
+ return sanitizeWord(token, word, rules, uncountables);
210
+ };
211
+ }
212
+ function checkWord(replaceMap, keepMap, rules, uncountables) {
213
+ return function(word) {
214
+ const token = word.toLowerCase();
215
+ if (keepMap.hasOwnProperty(token)) return true;
216
+ if (replaceMap.hasOwnProperty(token)) return false;
217
+ return sanitizeWord(token, token, rules, uncountables) === token;
218
+ };
219
+ }
220
+ var BASE_IRREGULAR = [
221
+ // Pronouns.
222
+ ["I", "we"],
223
+ ["me", "us"],
224
+ ["he", "they"],
225
+ ["she", "they"],
226
+ ["them", "them"],
227
+ ["myself", "ourselves"],
228
+ ["yourself", "yourselves"],
229
+ ["itself", "themselves"],
230
+ ["herself", "themselves"],
231
+ ["himself", "themselves"],
232
+ ["themself", "themselves"],
233
+ ["is", "are"],
234
+ ["was", "were"],
235
+ ["has", "have"],
236
+ ["this", "these"],
237
+ ["that", "those"],
238
+ // Words ending with a consonant and `o`.
239
+ ["echo", "echoes"],
240
+ ["dingo", "dingoes"],
241
+ ["volcano", "volcanoes"],
242
+ ["tornado", "tornadoes"],
243
+ ["torpedo", "torpedoes"],
244
+ // Ends with `us`.
245
+ ["genus", "genera"],
246
+ ["viscus", "viscera"],
247
+ // Ends with `ma`.
248
+ ["stigma", "stigmata"],
249
+ ["stoma", "stomata"],
250
+ ["dogma", "dogmata"],
251
+ ["lemma", "lemmata"],
252
+ ["schema", "schemata"],
253
+ ["anathema", "anathemata"],
254
+ // Other irregular rules.
255
+ ["ox", "oxen"],
256
+ ["axe", "axes"],
257
+ ["die", "dice"],
258
+ ["yes", "yeses"],
259
+ ["foot", "feet"],
260
+ ["eave", "eaves"],
261
+ ["goose", "geese"],
262
+ ["tooth", "teeth"],
263
+ ["quiz", "quizzes"],
264
+ ["human", "humans"],
265
+ ["proof", "proofs"],
266
+ ["carve", "carves"],
267
+ ["valve", "valves"],
268
+ ["looey", "looies"],
269
+ ["thief", "thieves"],
270
+ ["groove", "grooves"],
271
+ ["pickaxe", "pickaxes"],
272
+ ["passerby", "passersby"]
273
+ ];
274
+ var BASE_PLURAL = [
275
+ [/s?$/i, "s"],
276
+ // eslint-disable-next-line no-control-regex
277
+ [/[^\u0000-\u007F]$/i, "$0"],
278
+ [/([^aeiou]ese)$/i, "$1"],
279
+ [/(ax|test)is$/i, "$1es"],
280
+ [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, "$1es"],
281
+ [/(e[mn]u)s?$/i, "$1s"],
282
+ [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, "$1"],
283
+ [
284
+ /(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
285
+ "$1i"
286
+ ],
287
+ [/(alumn|alg|vertebr)(?:a|ae)$/i, "$1ae"],
288
+ [/(seraph|cherub)(?:im)?$/i, "$1im"],
289
+ [/(her|at|gr)o$/i, "$1oes"],
290
+ [
291
+ /(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i,
292
+ "$1a"
293
+ ],
294
+ [
295
+ /(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i,
296
+ "$1a"
297
+ ],
298
+ [/sis$/i, "ses"],
299
+ [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, "$1$2ves"],
300
+ [/([^aeiouy]|qu)y$/i, "$1ies"],
301
+ [/([^ch][ieo][ln])ey$/i, "$1ies"],
302
+ [/(x|ch|ss|sh|zz)$/i, "$1es"],
303
+ [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, "$1ices"],
304
+ [/\b((?:tit)?m|l)(?:ice|ouse)$/i, "$1ice"],
305
+ [/(pe)(?:rson|ople)$/i, "$1ople"],
306
+ [/(child)(?:ren)?$/i, "$1ren"],
307
+ [/eaux$/i, "$0"],
308
+ [/m[ae]n$/i, "men"],
309
+ ["thou", "you"]
310
+ ];
311
+ var BASE_SINGULAR = [
312
+ [/s$/i, ""],
313
+ [/(ss)$/i, "$1"],
314
+ [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, "$1fe"],
315
+ [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, "$1f"],
316
+ [/ies$/i, "y"],
317
+ [
318
+ /\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i,
319
+ "$1ie"
320
+ ],
321
+ [/\b(mon|smil)ies$/i, "$1ey"],
322
+ [/\b((?:tit)?m|l)ice$/i, "$1ouse"],
323
+ [/(seraph|cherub)im$/i, "$1"],
324
+ [
325
+ /(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,
326
+ "$1"
327
+ ],
328
+ [
329
+ /(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i,
330
+ "$1sis"
331
+ ],
332
+ [/(movie|twelve|abuse|e[mn]u)s$/i, "$1"],
333
+ [/(test)(?:is|es)$/i, "$1is"],
334
+ [
335
+ /(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
336
+ "$1us"
337
+ ],
338
+ [
339
+ /(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,
340
+ "$1um"
341
+ ],
342
+ [
343
+ /(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,
344
+ "$1on"
345
+ ],
346
+ [/(alumn|alg|vertebr)ae$/i, "$1a"],
347
+ [/(cod|mur|sil|vert|ind)ices$/i, "$1ex"],
348
+ [/(matr|append)ices$/i, "$1ix"],
349
+ [/(pe)(rson|ople)$/i, "$1rson"],
350
+ [/(child)ren$/i, "$1"],
351
+ [/(eau)x?$/i, "$1"],
352
+ [/men$/i, "man"]
353
+ ];
354
+ var BASE_UNCOUNTABLE = [
355
+ // Singular words with no plurals.
356
+ "adulthood",
357
+ "advice",
358
+ "agenda",
359
+ "aid",
360
+ "aircraft",
361
+ "alcohol",
362
+ "ammo",
363
+ "analytics",
364
+ "anime",
365
+ "athletics",
366
+ "audio",
367
+ "bison",
368
+ "blood",
369
+ "bream",
370
+ "buffalo",
371
+ "butter",
372
+ "carp",
373
+ "cash",
374
+ "chassis",
375
+ "chess",
376
+ "clothing",
377
+ "cod",
378
+ "commerce",
379
+ "cooperation",
380
+ "corps",
381
+ "debris",
382
+ "diabetes",
383
+ "digestion",
384
+ "elk",
385
+ "energy",
386
+ "equipment",
387
+ "excretion",
388
+ "expertise",
389
+ "firmware",
390
+ "flounder",
391
+ "fun",
392
+ "gallows",
393
+ "garbage",
394
+ "graffiti",
395
+ "hardware",
396
+ "headquarters",
397
+ "health",
398
+ "herpes",
399
+ "highjinks",
400
+ "homework",
401
+ "housework",
402
+ "information",
403
+ "jeans",
404
+ "justice",
405
+ "kudos",
406
+ "labour",
407
+ "literature",
408
+ "machinery",
409
+ "mackerel",
410
+ "mail",
411
+ "media",
412
+ "mews",
413
+ "moose",
414
+ "music",
415
+ "mud",
416
+ "manga",
417
+ "news",
418
+ "only",
419
+ "personnel",
420
+ "pike",
421
+ "plankton",
422
+ "pliers",
423
+ "police",
424
+ "pollution",
425
+ "premises",
426
+ "rain",
427
+ "research",
428
+ "rice",
429
+ "salmon",
430
+ "scissors",
431
+ "series",
432
+ "sewage",
433
+ "shambles",
434
+ "shrimp",
435
+ "software",
436
+ "species",
437
+ "staff",
438
+ "swine",
439
+ "tennis",
440
+ "traffic",
441
+ "transportation",
442
+ "trout",
443
+ "tuna",
444
+ "wealth",
445
+ "welfare",
446
+ "whiting",
447
+ "wildebeest",
448
+ "wildlife",
449
+ "you",
450
+ /pok[eé]mon$/i,
451
+ // Regexes.
452
+ /[^aeiou]ese$/i,
453
+ // "chinese", "japanese"
454
+ /deer$/i,
455
+ // "deer", "reindeer"
456
+ /fish$/i,
457
+ // "fish", "blowfish", "angelfish"
458
+ /measles$/i,
459
+ /o[iu]s$/i,
460
+ // "carnivorous"
461
+ /pox$/i,
462
+ // "chickpox", "smallpox"
463
+ /sheep$/i
464
+ ];
465
+ function createPluralize(config = {}) {
466
+ const pluralRules = [];
467
+ const singularRules = [];
468
+ const uncountables = {};
469
+ const irregularPlurals = {};
470
+ const irregularSingles = {};
471
+ for (const [single, plur] of [
472
+ ...BASE_IRREGULAR,
473
+ ...config.irregular || []
474
+ ]) {
475
+ irregularSingles[single.toLowerCase()] = plur.toLowerCase();
476
+ irregularPlurals[plur.toLowerCase()] = single.toLowerCase();
477
+ }
478
+ for (const [rule, replacement] of [...BASE_PLURAL, ...config.plural || []]) {
479
+ pluralRules.push([sanitizeRule(rule), replacement]);
480
+ }
481
+ for (const [rule, replacement] of [
482
+ ...BASE_SINGULAR,
483
+ ...config.singular || []
484
+ ]) {
485
+ singularRules.push([sanitizeRule(rule), replacement]);
486
+ }
487
+ for (const word of [...BASE_UNCOUNTABLE, ...config.uncountable || []]) {
488
+ if (typeof word === "string") {
489
+ uncountables[word.toLowerCase()] = true;
490
+ } else {
491
+ pluralRules.push([sanitizeRule(word), "$0"]);
492
+ singularRules.push([sanitizeRule(word), "$0"]);
493
+ }
494
+ }
495
+ const plural2 = replaceWord(
496
+ irregularSingles,
497
+ irregularPlurals,
498
+ pluralRules,
499
+ uncountables
500
+ );
501
+ const singular2 = replaceWord(
502
+ irregularPlurals,
503
+ irregularSingles,
504
+ singularRules,
505
+ uncountables
506
+ );
507
+ const isPlural2 = checkWord(
508
+ irregularSingles,
509
+ irregularPlurals,
510
+ pluralRules,
511
+ uncountables
512
+ );
513
+ const isSingular2 = checkWord(
514
+ irregularPlurals,
515
+ irregularSingles,
516
+ singularRules,
517
+ uncountables
518
+ );
519
+ function pluralize2(word, count, inclusive) {
520
+ const out = count === 1 ? singular2(word) : plural2(word);
521
+ return (inclusive ? count + " " : "") + out;
522
+ }
523
+ return Object.assign(pluralize2, { plural: plural2, singular: singular2, isPlural: isPlural2, isSingular: isSingular2 });
524
+ }
525
+ var pluralize = createPluralize();
526
+ var plural = pluralize.plural;
527
+ var singular = pluralize.singular;
528
+ var isPlural = pluralize.isPlural;
529
+ var isSingular = pluralize.isSingular;
168
530
 
169
531
  // src/lib/strings/query-string.js
170
532
  function toQueryString(object) {
@@ -198,20 +560,20 @@ function parseQueryString(string = "") {
198
560
  }
199
561
  return result;
200
562
  }
201
- function plural(count, noun, suffix = "s") {
202
- console.warn("plural is deprecated. Use pluralize instead");
203
- return `${count} ${noun}${count !== 1 ? suffix : ""}`;
204
- }
205
563
  function stripNumbers(string) {
206
564
  return string.replace(/\d*/, "");
207
565
  }
208
566
  // Annotate the CommonJS export names for ESM import in node:
209
567
  0 && (module.exports = {
568
+ createPluralize,
569
+ isPlural,
570
+ isSingular,
210
571
  markdown,
211
572
  parseFullName,
212
573
  parseQueryString,
213
574
  plural,
214
575
  pluralize,
576
+ singular,
215
577
  stripNumbers,
216
578
  toCamel,
217
579
  toKebab,