@splendidlabz/utils 1.12.0 → 1.13.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 (62) hide show
  1. package/dist/cjs/dom/font-size.cjs +1 -1
  2. package/dist/cjs/dom/index.cjs +1 -1
  3. package/dist/cjs/lib/colors.cjs +39 -0
  4. package/dist/cjs/lib/date/index.cjs +1 -1
  5. package/dist/cjs/lib/date/time.cjs +1 -1
  6. package/dist/cjs/lib/http/index.cjs +100 -0
  7. package/dist/cjs/lib/http/status-text.cjs +98 -0
  8. package/dist/cjs/lib/index.cjs +584 -11
  9. package/dist/cjs/lib/numbers/index.cjs +12 -1
  10. package/dist/cjs/lib/numbers/random.cjs +35 -0
  11. package/dist/cjs/lib/numbers/split-unit.cjs +35 -0
  12. package/dist/cjs/lib/promises/index.cjs +72 -15
  13. package/dist/cjs/lib/promises/reject.cjs +72 -13
  14. package/dist/cjs/lib/strings/index.cjs +368 -6
  15. package/dist/cjs/lib/strings/pluralize.cjs +372 -14
  16. package/dist/cjs/lib/strings/query-string.cjs +0 -6
  17. package/dist/cjs/lib/style/index.cjs +35 -1
  18. package/dist/cjs/lib/style/scatter.cjs +60 -0
  19. package/dist/cjs/lib/style/to-style-string.cjs +64 -0
  20. package/dist/cjs/lib/svg/displace.cjs +94 -0
  21. package/dist/cjs/lib/svg/index.cjs +126 -0
  22. package/dist/cjs/lib/svg/noise.cjs +56 -0
  23. package/dist/esm/lib/colors.js +14 -0
  24. package/dist/esm/lib/http/index.js +1 -0
  25. package/dist/esm/lib/http/status-text.js +72 -0
  26. package/dist/esm/lib/index.js +3 -0
  27. package/dist/esm/lib/numbers/index.js +2 -10
  28. package/dist/esm/lib/numbers/random.js +10 -0
  29. package/dist/esm/lib/numbers/split-unit.js +10 -0
  30. package/dist/esm/lib/promises/reject.js +2 -2
  31. package/dist/esm/lib/strings/pluralize.js +366 -3
  32. package/dist/esm/lib/strings/query-string.js +0 -5
  33. package/dist/esm/lib/style/index.js +2 -12
  34. package/dist/esm/lib/style/scatter.js +25 -0
  35. package/dist/esm/lib/style/to-style-string.js +12 -0
  36. package/dist/esm/lib/svg/displace.js +68 -0
  37. package/dist/esm/lib/svg/index.js +2 -0
  38. package/dist/esm/lib/svg/noise.js +16 -0
  39. package/dist/types/dom/font-size.d.cts +1 -1
  40. package/dist/types/lib/colors.d.cts +12 -0
  41. package/dist/types/lib/http/index.d.cts +1 -0
  42. package/dist/types/lib/http/status-text.d.cts +73 -0
  43. package/dist/types/lib/index.d.cts +11 -5
  44. package/dist/types/lib/numbers/index.d.cts +2 -4
  45. package/dist/types/lib/numbers/random.d.cts +14 -0
  46. package/dist/types/lib/numbers/split-unit.d.cts +8 -0
  47. package/dist/types/lib/strings/index.d.cts +2 -2
  48. package/dist/types/lib/strings/pluralize.d.cts +24 -2
  49. package/dist/types/lib/strings/query-string.d.cts +1 -2
  50. package/dist/types/lib/style/index.d.cts +2 -3
  51. package/dist/types/lib/style/scatter.d.cts +48 -0
  52. package/dist/types/lib/style/to-style-string.d.cts +8 -0
  53. package/dist/types/lib/svg/displace.d.cts +54 -0
  54. package/dist/types/lib/svg/index.d.cts +2 -0
  55. package/dist/types/lib/svg/noise.d.cts +24 -0
  56. package/dist/types/node/dirname.d.cts +2 -2
  57. package/dist/types/node/file.d.cts +1 -1
  58. package/dist/types/node/hash.d.cts +1 -1
  59. package/dist/types/node/pkce.d.cts +4 -4
  60. package/dist/types/node/random-string.d.cts +1 -1
  61. package/dist/types/node/uuid.d.cts +1 -1
  62. package/package.json +3 -6
@@ -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,