@art-suite/art-core-ts-string-lib 0.2.12 → 0.3.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.
package/dist/index.cjs CHANGED
@@ -1,487 +1,544 @@
1
- "use strict";
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
9
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
15
10
  var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
22
19
  };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
-
33
- // ../../node_modules/pluralize/pluralize.js
34
- var require_pluralize = __commonJS({
35
- "../../node_modules/pluralize/pluralize.js"(exports2, module2) {
36
- "use strict";
37
- (function(root, pluralize2) {
38
- if (typeof require === "function" && typeof exports2 === "object" && typeof module2 === "object") {
39
- module2.exports = pluralize2();
40
- } else if (typeof define === "function" && define.amd) {
41
- define(function() {
42
- return pluralize2();
43
- });
44
- } else {
45
- root.pluralize = pluralize2();
46
- }
47
- })(exports2, function() {
48
- var pluralRules = [];
49
- var singularRules = [];
50
- var uncountables = {};
51
- var irregularPlurals = {};
52
- var irregularSingles = {};
53
- function sanitizeRule(rule) {
54
- if (typeof rule === "string") {
55
- return new RegExp("^" + rule + "$", "i");
56
- }
57
- return rule;
58
- }
59
- function restoreCase(word, token) {
60
- if (word === token) return token;
61
- if (word === word.toLowerCase()) return token.toLowerCase();
62
- if (word === word.toUpperCase()) return token.toUpperCase();
63
- if (word[0] === word[0].toUpperCase()) {
64
- return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
65
- }
66
- return token.toLowerCase();
67
- }
68
- function interpolate(str, args) {
69
- return str.replace(/\$(\d{1,2})/g, function(match, index) {
70
- return args[index] || "";
71
- });
72
- }
73
- function replace(word, rule) {
74
- return word.replace(rule[0], function(match, index) {
75
- var result = interpolate(rule[1], arguments);
76
- if (match === "") {
77
- return restoreCase(word[index - 1], result);
78
- }
79
- return restoreCase(match, result);
80
- });
81
- }
82
- function sanitizeWord(token, word, rules) {
83
- if (!token.length || uncountables.hasOwnProperty(token)) {
84
- return word;
85
- }
86
- var len = rules.length;
87
- while (len--) {
88
- var rule = rules[len];
89
- if (rule[0].test(word)) return replace(word, rule);
90
- }
91
- return word;
92
- }
93
- function replaceWord(replaceMap, keepMap, rules) {
94
- return function(word) {
95
- var token = word.toLowerCase();
96
- if (keepMap.hasOwnProperty(token)) {
97
- return restoreCase(word, token);
98
- }
99
- if (replaceMap.hasOwnProperty(token)) {
100
- return restoreCase(word, replaceMap[token]);
101
- }
102
- return sanitizeWord(token, word, rules);
103
- };
104
- }
105
- function checkWord(replaceMap, keepMap, rules, bool) {
106
- return function(word) {
107
- var token = word.toLowerCase();
108
- if (keepMap.hasOwnProperty(token)) return true;
109
- if (replaceMap.hasOwnProperty(token)) return false;
110
- return sanitizeWord(token, token, rules) === token;
111
- };
112
- }
113
- function pluralize2(word, count, inclusive) {
114
- var pluralized = count === 1 ? pluralize2.singular(word) : pluralize2.plural(word);
115
- return (inclusive ? count + " " : "") + pluralized;
116
- }
117
- pluralize2.plural = replaceWord(
118
- irregularSingles,
119
- irregularPlurals,
120
- pluralRules
121
- );
122
- pluralize2.isPlural = checkWord(
123
- irregularSingles,
124
- irregularPlurals,
125
- pluralRules
126
- );
127
- pluralize2.singular = replaceWord(
128
- irregularPlurals,
129
- irregularSingles,
130
- singularRules
131
- );
132
- pluralize2.isSingular = checkWord(
133
- irregularPlurals,
134
- irregularSingles,
135
- singularRules
136
- );
137
- pluralize2.addPluralRule = function(rule, replacement) {
138
- pluralRules.push([sanitizeRule(rule), replacement]);
139
- };
140
- pluralize2.addSingularRule = function(rule, replacement) {
141
- singularRules.push([sanitizeRule(rule), replacement]);
142
- };
143
- pluralize2.addUncountableRule = function(word) {
144
- if (typeof word === "string") {
145
- uncountables[word.toLowerCase()] = true;
146
- return;
147
- }
148
- pluralize2.addPluralRule(word, "$0");
149
- pluralize2.addSingularRule(word, "$0");
150
- };
151
- pluralize2.addIrregularRule = function(single, plural2) {
152
- plural2 = plural2.toLowerCase();
153
- single = single.toLowerCase();
154
- irregularSingles[single] = plural2;
155
- irregularPlurals[plural2] = single;
156
- };
157
- [
158
- // Pronouns.
159
- ["I", "we"],
160
- ["me", "us"],
161
- ["he", "they"],
162
- ["she", "they"],
163
- ["them", "them"],
164
- ["myself", "ourselves"],
165
- ["yourself", "yourselves"],
166
- ["itself", "themselves"],
167
- ["herself", "themselves"],
168
- ["himself", "themselves"],
169
- ["themself", "themselves"],
170
- ["is", "are"],
171
- ["was", "were"],
172
- ["has", "have"],
173
- ["this", "these"],
174
- ["that", "those"],
175
- // Words ending in with a consonant and `o`.
176
- ["echo", "echoes"],
177
- ["dingo", "dingoes"],
178
- ["volcano", "volcanoes"],
179
- ["tornado", "tornadoes"],
180
- ["torpedo", "torpedoes"],
181
- // Ends with `us`.
182
- ["genus", "genera"],
183
- ["viscus", "viscera"],
184
- // Ends with `ma`.
185
- ["stigma", "stigmata"],
186
- ["stoma", "stomata"],
187
- ["dogma", "dogmata"],
188
- ["lemma", "lemmata"],
189
- ["schema", "schemata"],
190
- ["anathema", "anathemata"],
191
- // Other irregular rules.
192
- ["ox", "oxen"],
193
- ["axe", "axes"],
194
- ["die", "dice"],
195
- ["yes", "yeses"],
196
- ["foot", "feet"],
197
- ["eave", "eaves"],
198
- ["goose", "geese"],
199
- ["tooth", "teeth"],
200
- ["quiz", "quizzes"],
201
- ["human", "humans"],
202
- ["proof", "proofs"],
203
- ["carve", "carves"],
204
- ["valve", "valves"],
205
- ["looey", "looies"],
206
- ["thief", "thieves"],
207
- ["groove", "grooves"],
208
- ["pickaxe", "pickaxes"],
209
- ["passerby", "passersby"]
210
- ].forEach(function(rule) {
211
- return pluralize2.addIrregularRule(rule[0], rule[1]);
212
- });
213
- [
214
- [/s?$/i, "s"],
215
- [/[^\u0000-\u007F]$/i, "$0"],
216
- [/([^aeiou]ese)$/i, "$1"],
217
- [/(ax|test)is$/i, "$1es"],
218
- [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, "$1es"],
219
- [/(e[mn]u)s?$/i, "$1s"],
220
- [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, "$1"],
221
- [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1i"],
222
- [/(alumn|alg|vertebr)(?:a|ae)$/i, "$1ae"],
223
- [/(seraph|cherub)(?:im)?$/i, "$1im"],
224
- [/(her|at|gr)o$/i, "$1oes"],
225
- [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, "$1a"],
226
- [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, "$1a"],
227
- [/sis$/i, "ses"],
228
- [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, "$1$2ves"],
229
- [/([^aeiouy]|qu)y$/i, "$1ies"],
230
- [/([^ch][ieo][ln])ey$/i, "$1ies"],
231
- [/(x|ch|ss|sh|zz)$/i, "$1es"],
232
- [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, "$1ices"],
233
- [/\b((?:tit)?m|l)(?:ice|ouse)$/i, "$1ice"],
234
- [/(pe)(?:rson|ople)$/i, "$1ople"],
235
- [/(child)(?:ren)?$/i, "$1ren"],
236
- [/eaux$/i, "$0"],
237
- [/m[ae]n$/i, "men"],
238
- ["thou", "you"]
239
- ].forEach(function(rule) {
240
- return pluralize2.addPluralRule(rule[0], rule[1]);
241
- });
242
- [
243
- [/s$/i, ""],
244
- [/(ss)$/i, "$1"],
245
- [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, "$1fe"],
246
- [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, "$1f"],
247
- [/ies$/i, "y"],
248
- [/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, "$1ie"],
249
- [/\b(mon|smil)ies$/i, "$1ey"],
250
- [/\b((?:tit)?m|l)ice$/i, "$1ouse"],
251
- [/(seraph|cherub)im$/i, "$1"],
252
- [/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, "$1"],
253
- [/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, "$1sis"],
254
- [/(movie|twelve|abuse|e[mn]u)s$/i, "$1"],
255
- [/(test)(?:is|es)$/i, "$1is"],
256
- [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1us"],
257
- [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, "$1um"],
258
- [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, "$1on"],
259
- [/(alumn|alg|vertebr)ae$/i, "$1a"],
260
- [/(cod|mur|sil|vert|ind)ices$/i, "$1ex"],
261
- [/(matr|append)ices$/i, "$1ix"],
262
- [/(pe)(rson|ople)$/i, "$1rson"],
263
- [/(child)ren$/i, "$1"],
264
- [/(eau)x?$/i, "$1"],
265
- [/men$/i, "man"]
266
- ].forEach(function(rule) {
267
- return pluralize2.addSingularRule(rule[0], rule[1]);
268
- });
269
- [
270
- // Singular words with no plurals.
271
- "adulthood",
272
- "advice",
273
- "agenda",
274
- "aid",
275
- "aircraft",
276
- "alcohol",
277
- "ammo",
278
- "analytics",
279
- "anime",
280
- "athletics",
281
- "audio",
282
- "bison",
283
- "blood",
284
- "bream",
285
- "buffalo",
286
- "butter",
287
- "carp",
288
- "cash",
289
- "chassis",
290
- "chess",
291
- "clothing",
292
- "cod",
293
- "commerce",
294
- "cooperation",
295
- "corps",
296
- "debris",
297
- "diabetes",
298
- "digestion",
299
- "elk",
300
- "energy",
301
- "equipment",
302
- "excretion",
303
- "expertise",
304
- "firmware",
305
- "flounder",
306
- "fun",
307
- "gallows",
308
- "garbage",
309
- "graffiti",
310
- "hardware",
311
- "headquarters",
312
- "health",
313
- "herpes",
314
- "highjinks",
315
- "homework",
316
- "housework",
317
- "information",
318
- "jeans",
319
- "justice",
320
- "kudos",
321
- "labour",
322
- "literature",
323
- "machinery",
324
- "mackerel",
325
- "mail",
326
- "media",
327
- "mews",
328
- "moose",
329
- "music",
330
- "mud",
331
- "manga",
332
- "news",
333
- "only",
334
- "personnel",
335
- "pike",
336
- "plankton",
337
- "pliers",
338
- "police",
339
- "pollution",
340
- "premises",
341
- "rain",
342
- "research",
343
- "rice",
344
- "salmon",
345
- "scissors",
346
- "series",
347
- "sewage",
348
- "shambles",
349
- "shrimp",
350
- "software",
351
- "species",
352
- "staff",
353
- "swine",
354
- "tennis",
355
- "traffic",
356
- "transportation",
357
- "trout",
358
- "tuna",
359
- "wealth",
360
- "welfare",
361
- "whiting",
362
- "wildebeest",
363
- "wildlife",
364
- "you",
365
- /pok[eé]mon$/i,
366
- // Regexes.
367
- /[^aeiou]ese$/i,
368
- // "chinese", "japanese"
369
- /deer$/i,
370
- // "deer", "reindeer"
371
- /fish$/i,
372
- // "fish", "blowfish", "angelfish"
373
- /measles$/i,
374
- /o[iu]s$/i,
375
- // "carnivorous"
376
- /pox$/i,
377
- // "chickpox", "smallpox"
378
- /sheep$/i
379
- ].forEach(pluralize2.addUncountableRule);
380
- return pluralize2;
381
- });
382
- }
383
- });
384
-
385
- // src/index.ts
386
- var index_exports = {};
387
- __export(index_exports, {
388
- addIrregularRule: () => addIrregularRule,
389
- addPluralRule: () => addPluralRule,
390
- addSingularRule: () => addSingularRule,
391
- addUncountableRule: () => addUncountableRule,
392
- base62Characters: () => base62Characters,
393
- commaize: () => commaize,
394
- cryptoRandomString: () => cryptoRandomString,
395
- isPlural: () => isPlural,
396
- isSingular: () => isSingular,
397
- plural: () => plural,
398
- pluralize: () => pluralize,
399
- randomString: () => randomString,
400
- singular: () => singular
401
- });
402
- module.exports = __toCommonJS(index_exports);
403
-
404
- // src/commaize.ts
405
- var commaize = (x) => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
406
-
407
- // src/pluralize.ts
408
- var import_pluralize = __toESM(require_pluralize(), 1);
409
- var import_art_core_ts_types = require("@art-suite/art-core-ts-types");
410
- var patchedNpmPluralize = (noun, count, inclusive) => {
411
- const match = /^(.*?)([_\W]+)$/.exec(noun);
412
- if (match) {
413
- const [__, mainNoun, append] = match;
414
- const out = (0, import_pluralize.default)(mainNoun, count, inclusive);
415
- return out + append;
416
- }
417
- return (0, import_pluralize.default)(noun, count, inclusive);
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+ //#endregion
25
+ let _art_suite_art_core_ts_types = require("@art-suite/art-core-ts-types");
26
+ //#region src/commaize.ts
27
+ /**
28
+ * Adds commas to a number or string
29
+ * @param x - The number or string to commaize
30
+ * @returns The commaized number or string
31
+ */
32
+ const commaize = (x) => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
33
+ //#endregion
34
+ //#region src/pluralize.ts
35
+ var import_pluralize = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
36
+ (function(root, pluralize) {
37
+ /* istanbul ignore else */
38
+ if (typeof require === "function" && typeof exports === "object" && typeof module === "object") module.exports = pluralize();
39
+ else if (typeof define === "function" && define.amd) define(function() {
40
+ return pluralize();
41
+ });
42
+ else root.pluralize = pluralize();
43
+ })(exports, function() {
44
+ var pluralRules = [];
45
+ var singularRules = [];
46
+ var uncountables = {};
47
+ var irregularPlurals = {};
48
+ var irregularSingles = {};
49
+ /**
50
+ * Sanitize a pluralization rule to a usable regular expression.
51
+ *
52
+ * @param {(RegExp|string)} rule
53
+ * @return {RegExp}
54
+ */
55
+ function sanitizeRule(rule) {
56
+ if (typeof rule === "string") return new RegExp("^" + rule + "$", "i");
57
+ return rule;
58
+ }
59
+ /**
60
+ * Pass in a word token to produce a function that can replicate the case on
61
+ * another word.
62
+ *
63
+ * @param {string} word
64
+ * @param {string} token
65
+ * @return {Function}
66
+ */
67
+ function restoreCase(word, token) {
68
+ if (word === token) return token;
69
+ if (word === word.toLowerCase()) return token.toLowerCase();
70
+ if (word === word.toUpperCase()) return token.toUpperCase();
71
+ if (word[0] === word[0].toUpperCase()) return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
72
+ return token.toLowerCase();
73
+ }
74
+ /**
75
+ * Interpolate a regexp string.
76
+ *
77
+ * @param {string} str
78
+ * @param {Array} args
79
+ * @return {string}
80
+ */
81
+ function interpolate(str, args) {
82
+ return str.replace(/\$(\d{1,2})/g, function(match, index) {
83
+ return args[index] || "";
84
+ });
85
+ }
86
+ /**
87
+ * Replace a word using a rule.
88
+ *
89
+ * @param {string} word
90
+ * @param {Array} rule
91
+ * @return {string}
92
+ */
93
+ function replace(word, rule) {
94
+ return word.replace(rule[0], function(match, index) {
95
+ var result = interpolate(rule[1], arguments);
96
+ if (match === "") return restoreCase(word[index - 1], result);
97
+ return restoreCase(match, result);
98
+ });
99
+ }
100
+ /**
101
+ * Sanitize a word by passing in the word and sanitization rules.
102
+ *
103
+ * @param {string} token
104
+ * @param {string} word
105
+ * @param {Array} rules
106
+ * @return {string}
107
+ */
108
+ function sanitizeWord(token, word, rules) {
109
+ if (!token.length || uncountables.hasOwnProperty(token)) return word;
110
+ var len = rules.length;
111
+ while (len--) {
112
+ var rule = rules[len];
113
+ if (rule[0].test(word)) return replace(word, rule);
114
+ }
115
+ return word;
116
+ }
117
+ /**
118
+ * Replace a word with the updated word.
119
+ *
120
+ * @param {Object} replaceMap
121
+ * @param {Object} keepMap
122
+ * @param {Array} rules
123
+ * @return {Function}
124
+ */
125
+ function replaceWord(replaceMap, keepMap, rules) {
126
+ return function(word) {
127
+ var token = word.toLowerCase();
128
+ if (keepMap.hasOwnProperty(token)) return restoreCase(word, token);
129
+ if (replaceMap.hasOwnProperty(token)) return restoreCase(word, replaceMap[token]);
130
+ return sanitizeWord(token, word, rules);
131
+ };
132
+ }
133
+ /**
134
+ * Check if a word is part of the map.
135
+ */
136
+ function checkWord(replaceMap, keepMap, rules, bool) {
137
+ return function(word) {
138
+ var token = word.toLowerCase();
139
+ if (keepMap.hasOwnProperty(token)) return true;
140
+ if (replaceMap.hasOwnProperty(token)) return false;
141
+ return sanitizeWord(token, token, rules) === token;
142
+ };
143
+ }
144
+ /**
145
+ * Pluralize or singularize a word based on the passed in count.
146
+ *
147
+ * @param {string} word The word to pluralize
148
+ * @param {number} count How many of the word exist
149
+ * @param {boolean} inclusive Whether to prefix with the number (e.g. 3 ducks)
150
+ * @return {string}
151
+ */
152
+ function pluralize(word, count, inclusive) {
153
+ var pluralized = count === 1 ? pluralize.singular(word) : pluralize.plural(word);
154
+ return (inclusive ? count + " " : "") + pluralized;
155
+ }
156
+ /**
157
+ * Pluralize a word.
158
+ *
159
+ * @type {Function}
160
+ */
161
+ pluralize.plural = replaceWord(irregularSingles, irregularPlurals, pluralRules);
162
+ /**
163
+ * Check if a word is plural.
164
+ *
165
+ * @type {Function}
166
+ */
167
+ pluralize.isPlural = checkWord(irregularSingles, irregularPlurals, pluralRules);
168
+ /**
169
+ * Singularize a word.
170
+ *
171
+ * @type {Function}
172
+ */
173
+ pluralize.singular = replaceWord(irregularPlurals, irregularSingles, singularRules);
174
+ /**
175
+ * Check if a word is singular.
176
+ *
177
+ * @type {Function}
178
+ */
179
+ pluralize.isSingular = checkWord(irregularPlurals, irregularSingles, singularRules);
180
+ /**
181
+ * Add a pluralization rule to the collection.
182
+ *
183
+ * @param {(string|RegExp)} rule
184
+ * @param {string} replacement
185
+ */
186
+ pluralize.addPluralRule = function(rule, replacement) {
187
+ pluralRules.push([sanitizeRule(rule), replacement]);
188
+ };
189
+ /**
190
+ * Add a singularization rule to the collection.
191
+ *
192
+ * @param {(string|RegExp)} rule
193
+ * @param {string} replacement
194
+ */
195
+ pluralize.addSingularRule = function(rule, replacement) {
196
+ singularRules.push([sanitizeRule(rule), replacement]);
197
+ };
198
+ /**
199
+ * Add an uncountable word rule.
200
+ *
201
+ * @param {(string|RegExp)} word
202
+ */
203
+ pluralize.addUncountableRule = function(word) {
204
+ if (typeof word === "string") {
205
+ uncountables[word.toLowerCase()] = true;
206
+ return;
207
+ }
208
+ pluralize.addPluralRule(word, "$0");
209
+ pluralize.addSingularRule(word, "$0");
210
+ };
211
+ /**
212
+ * Add an irregular word definition.
213
+ *
214
+ * @param {string} single
215
+ * @param {string} plural
216
+ */
217
+ pluralize.addIrregularRule = function(single, plural) {
218
+ plural = plural.toLowerCase();
219
+ single = single.toLowerCase();
220
+ irregularSingles[single] = plural;
221
+ irregularPlurals[plural] = single;
222
+ };
223
+ /**
224
+ * Irregular rules.
225
+ */
226
+ [
227
+ ["I", "we"],
228
+ ["me", "us"],
229
+ ["he", "they"],
230
+ ["she", "they"],
231
+ ["them", "them"],
232
+ ["myself", "ourselves"],
233
+ ["yourself", "yourselves"],
234
+ ["itself", "themselves"],
235
+ ["herself", "themselves"],
236
+ ["himself", "themselves"],
237
+ ["themself", "themselves"],
238
+ ["is", "are"],
239
+ ["was", "were"],
240
+ ["has", "have"],
241
+ ["this", "these"],
242
+ ["that", "those"],
243
+ ["echo", "echoes"],
244
+ ["dingo", "dingoes"],
245
+ ["volcano", "volcanoes"],
246
+ ["tornado", "tornadoes"],
247
+ ["torpedo", "torpedoes"],
248
+ ["genus", "genera"],
249
+ ["viscus", "viscera"],
250
+ ["stigma", "stigmata"],
251
+ ["stoma", "stomata"],
252
+ ["dogma", "dogmata"],
253
+ ["lemma", "lemmata"],
254
+ ["schema", "schemata"],
255
+ ["anathema", "anathemata"],
256
+ ["ox", "oxen"],
257
+ ["axe", "axes"],
258
+ ["die", "dice"],
259
+ ["yes", "yeses"],
260
+ ["foot", "feet"],
261
+ ["eave", "eaves"],
262
+ ["goose", "geese"],
263
+ ["tooth", "teeth"],
264
+ ["quiz", "quizzes"],
265
+ ["human", "humans"],
266
+ ["proof", "proofs"],
267
+ ["carve", "carves"],
268
+ ["valve", "valves"],
269
+ ["looey", "looies"],
270
+ ["thief", "thieves"],
271
+ ["groove", "grooves"],
272
+ ["pickaxe", "pickaxes"],
273
+ ["passerby", "passersby"]
274
+ ].forEach(function(rule) {
275
+ return pluralize.addIrregularRule(rule[0], rule[1]);
276
+ });
277
+ /**
278
+ * Pluralization rules.
279
+ */
280
+ [
281
+ [/s?$/i, "s"],
282
+ [/[^\u0000-\u007F]$/i, "$0"],
283
+ [/([^aeiou]ese)$/i, "$1"],
284
+ [/(ax|test)is$/i, "$1es"],
285
+ [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, "$1es"],
286
+ [/(e[mn]u)s?$/i, "$1s"],
287
+ [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, "$1"],
288
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1i"],
289
+ [/(alumn|alg|vertebr)(?:a|ae)$/i, "$1ae"],
290
+ [/(seraph|cherub)(?:im)?$/i, "$1im"],
291
+ [/(her|at|gr)o$/i, "$1oes"],
292
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, "$1a"],
293
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, "$1a"],
294
+ [/sis$/i, "ses"],
295
+ [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, "$1$2ves"],
296
+ [/([^aeiouy]|qu)y$/i, "$1ies"],
297
+ [/([^ch][ieo][ln])ey$/i, "$1ies"],
298
+ [/(x|ch|ss|sh|zz)$/i, "$1es"],
299
+ [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, "$1ices"],
300
+ [/\b((?:tit)?m|l)(?:ice|ouse)$/i, "$1ice"],
301
+ [/(pe)(?:rson|ople)$/i, "$1ople"],
302
+ [/(child)(?:ren)?$/i, "$1ren"],
303
+ [/eaux$/i, "$0"],
304
+ [/m[ae]n$/i, "men"],
305
+ ["thou", "you"]
306
+ ].forEach(function(rule) {
307
+ return pluralize.addPluralRule(rule[0], rule[1]);
308
+ });
309
+ /**
310
+ * Singularization rules.
311
+ */
312
+ [
313
+ [/s$/i, ""],
314
+ [/(ss)$/i, "$1"],
315
+ [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, "$1fe"],
316
+ [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, "$1f"],
317
+ [/ies$/i, "y"],
318
+ [/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, "$1ie"],
319
+ [/\b(mon|smil)ies$/i, "$1ey"],
320
+ [/\b((?:tit)?m|l)ice$/i, "$1ouse"],
321
+ [/(seraph|cherub)im$/i, "$1"],
322
+ [/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, "$1"],
323
+ [/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, "$1sis"],
324
+ [/(movie|twelve|abuse|e[mn]u)s$/i, "$1"],
325
+ [/(test)(?:is|es)$/i, "$1is"],
326
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1us"],
327
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, "$1um"],
328
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, "$1on"],
329
+ [/(alumn|alg|vertebr)ae$/i, "$1a"],
330
+ [/(cod|mur|sil|vert|ind)ices$/i, "$1ex"],
331
+ [/(matr|append)ices$/i, "$1ix"],
332
+ [/(pe)(rson|ople)$/i, "$1rson"],
333
+ [/(child)ren$/i, "$1"],
334
+ [/(eau)x?$/i, "$1"],
335
+ [/men$/i, "man"]
336
+ ].forEach(function(rule) {
337
+ return pluralize.addSingularRule(rule[0], rule[1]);
338
+ });
339
+ /**
340
+ * Uncountable rules.
341
+ */
342
+ [
343
+ "adulthood",
344
+ "advice",
345
+ "agenda",
346
+ "aid",
347
+ "aircraft",
348
+ "alcohol",
349
+ "ammo",
350
+ "analytics",
351
+ "anime",
352
+ "athletics",
353
+ "audio",
354
+ "bison",
355
+ "blood",
356
+ "bream",
357
+ "buffalo",
358
+ "butter",
359
+ "carp",
360
+ "cash",
361
+ "chassis",
362
+ "chess",
363
+ "clothing",
364
+ "cod",
365
+ "commerce",
366
+ "cooperation",
367
+ "corps",
368
+ "debris",
369
+ "diabetes",
370
+ "digestion",
371
+ "elk",
372
+ "energy",
373
+ "equipment",
374
+ "excretion",
375
+ "expertise",
376
+ "firmware",
377
+ "flounder",
378
+ "fun",
379
+ "gallows",
380
+ "garbage",
381
+ "graffiti",
382
+ "hardware",
383
+ "headquarters",
384
+ "health",
385
+ "herpes",
386
+ "highjinks",
387
+ "homework",
388
+ "housework",
389
+ "information",
390
+ "jeans",
391
+ "justice",
392
+ "kudos",
393
+ "labour",
394
+ "literature",
395
+ "machinery",
396
+ "mackerel",
397
+ "mail",
398
+ "media",
399
+ "mews",
400
+ "moose",
401
+ "music",
402
+ "mud",
403
+ "manga",
404
+ "news",
405
+ "only",
406
+ "personnel",
407
+ "pike",
408
+ "plankton",
409
+ "pliers",
410
+ "police",
411
+ "pollution",
412
+ "premises",
413
+ "rain",
414
+ "research",
415
+ "rice",
416
+ "salmon",
417
+ "scissors",
418
+ "series",
419
+ "sewage",
420
+ "shambles",
421
+ "shrimp",
422
+ "software",
423
+ "species",
424
+ "staff",
425
+ "swine",
426
+ "tennis",
427
+ "traffic",
428
+ "transportation",
429
+ "trout",
430
+ "tuna",
431
+ "wealth",
432
+ "welfare",
433
+ "whiting",
434
+ "wildebeest",
435
+ "wildlife",
436
+ "you",
437
+ /pok[eé]mon$/i,
438
+ /[^aeiou]ese$/i,
439
+ /deer$/i,
440
+ /fish$/i,
441
+ /measles$/i,
442
+ /o[iu]s$/i,
443
+ /pox$/i,
444
+ /sheep$/i
445
+ ].forEach(pluralize.addUncountableRule);
446
+ return pluralize;
447
+ });
448
+ })))(), 1);
449
+ const patchedNpmPluralize = (noun, count, inclusive) => {
450
+ const match = /^(.*?)([_\W]+)$/.exec(noun);
451
+ if (match) {
452
+ const [__, mainNoun, append] = match;
453
+ return (0, import_pluralize.default)(mainNoun, count, inclusive) + append;
454
+ }
455
+ return (0, import_pluralize.default)(noun, count, inclusive);
418
456
  };
419
- var {
420
- plural,
421
- singular,
422
- isSingular,
423
- isPlural,
424
- addPluralRule,
425
- addSingularRule,
426
- addIrregularRule,
427
- addUncountableRule
428
- } = import_pluralize.default;
429
- var pluralize = (a, b, pluralForm) => {
430
- let singleForm;
431
- let number = null;
432
- if ((0, import_art_core_ts_types.isNumber)(b)) {
433
- if (!(0, import_art_core_ts_types.isString)(a)) {
434
- throw new Error(`singleForm and pluralForm(optional) should be non-empty strings (inputs: ${JSON.stringify({ a, b, pluralForm })}`);
435
- }
436
- singleForm = a;
437
- number = b;
438
- } else if ((0, import_art_core_ts_types.isNumber)(a)) {
439
- if (!(0, import_art_core_ts_types.isString)(b)) {
440
- throw new Error(`singleForm and pluralForm(optional) should be non-empty strings (inputs: ${JSON.stringify({ a, b, pluralForm })}`);
441
- }
442
- singleForm = b;
443
- number = a;
444
- } else {
445
- if (!(0, import_art_core_ts_types.isString)(a)) throw new Error(`singleForm and pluralForm(optional) should be non-empty strings (inputs: ${JSON.stringify({ a, b, pluralForm })}`);
446
- singleForm = a;
447
- number = null;
448
- }
449
- if (pluralForm) return `${number} ${number == 1 ? singleForm : pluralForm}`;
450
- if (number != null) return patchedNpmPluralize(singleForm, number, true);
451
- return patchedNpmPluralize(singleForm);
457
+ const { plural, singular, isSingular, isPlural, addPluralRule, addSingularRule, addIrregularRule, addUncountableRule } = import_pluralize.default;
458
+ /**
459
+ * Pluralize a word based on the passed in count. Call signatures:
460
+ *
461
+ * 1 input:
462
+ * pluralize(singleForm: string)
463
+ *
464
+ * 2 inputS:
465
+ * pluralize(singleForm: string, count: number)
466
+ * pluralize(count: number, singleForm: string)
467
+ *
468
+ * 3 inputs:
469
+ * pluralize(singleForm: string, count: number, pluralForm: string)
470
+ * pluralize(count: number, singleForm: string, pluralForm: string)
471
+ *
472
+ * @param a: string | number - The word to pluralize if a string, or the count if a number
473
+ * @param b: string | number - The count to pluralize the word by if a number, or the singleForm if a string
474
+ * @param pluralForm: string - Explicitly provide the plural form of the word (optional)
475
+ * @returns The pluralized word
476
+ */
477
+ const pluralize = (a, b, pluralForm) => {
478
+ let singleForm;
479
+ let number = null;
480
+ if ((0, _art_suite_art_core_ts_types.isNumber)(b)) {
481
+ if (!(0, _art_suite_art_core_ts_types.isString)(a)) throw new Error(`singleForm and pluralForm(optional) should be non-empty strings (inputs: ${JSON.stringify({
482
+ a,
483
+ b,
484
+ pluralForm
485
+ })}`);
486
+ singleForm = a;
487
+ number = b;
488
+ } else if ((0, _art_suite_art_core_ts_types.isNumber)(a)) {
489
+ if (!(0, _art_suite_art_core_ts_types.isString)(b)) throw new Error(`singleForm and pluralForm(optional) should be non-empty strings (inputs: ${JSON.stringify({
490
+ a,
491
+ b,
492
+ pluralForm
493
+ })}`);
494
+ singleForm = b;
495
+ number = a;
496
+ } else {
497
+ if (!(0, _art_suite_art_core_ts_types.isString)(a)) throw new Error(`singleForm and pluralForm(optional) should be non-empty strings (inputs: ${JSON.stringify({
498
+ a,
499
+ b,
500
+ pluralForm
501
+ })}`);
502
+ singleForm = a;
503
+ number = null;
504
+ }
505
+ if (pluralForm) return `${number} ${number == 1 ? singleForm : pluralForm}`;
506
+ if (number != null) return patchedNpmPluralize(singleForm, number, true);
507
+ return patchedNpmPluralize(singleForm);
452
508
  };
453
-
454
- // src/randomString.ts
455
- var base62Characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
456
- var intRand = (max) => {
457
- return Math.floor(Math.random() * max);
509
+ //#endregion
510
+ //#region src/randomString.ts
511
+ const base62Characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
512
+ const intRand = (max) => {
513
+ return Math.floor(Math.random() * max);
458
514
  };
459
- var generateRandomBytes = (size) => typeof crypto?.getRandomValues === "function" ? crypto.getRandomValues(new Uint8Array(size)) : require("crypto").randomFillSync(new Uint8Array(size));
460
- var randomString = (length = 32, chars = base62Characters, randomNumbers) => {
461
- const charsLength = chars.length;
462
- let result = "";
463
- if (randomNumbers) {
464
- for (let i = 0; i < length; i++) result += chars[randomNumbers[i] % charsLength];
465
- } else {
466
- for (let i = 0; i < length; i++) result += chars[intRand(charsLength)];
467
- }
468
- return result;
515
+ /**
516
+ * Generates a Uint8Array of cryptographically secure random bytes.
517
+ * @param size Number of bytes to generate.
518
+ * @returns A Uint8Array filled with random bytes.
519
+ */
520
+ const generateRandomBytes = (size) => typeof crypto?.getRandomValues === "function" ? crypto.getRandomValues(new Uint8Array(size)) : require("crypto").randomFillSync(new Uint8Array(size));
521
+ const randomString = (length = 32, chars = base62Characters, randomNumbers) => {
522
+ const charsLength = chars.length;
523
+ let result = "";
524
+ if (randomNumbers) for (let i = 0; i < length; i++) result += chars[randomNumbers[i] % charsLength];
525
+ else for (let i = 0; i < length; i++) result += chars[intRand(charsLength)];
526
+ return result;
469
527
  };
470
- var cryptoRandomString = (length = 32, chars = base62Characters) => randomString(length, chars, generateRandomBytes(length).map((b) => b % chars.length));
471
- // Annotate the CommonJS export names for ESM import in node:
472
- 0 && (module.exports = {
473
- addIrregularRule,
474
- addPluralRule,
475
- addSingularRule,
476
- addUncountableRule,
477
- base62Characters,
478
- commaize,
479
- cryptoRandomString,
480
- isPlural,
481
- isSingular,
482
- plural,
483
- pluralize,
484
- randomString,
485
- singular
486
- });
528
+ const cryptoRandomString = (length = 32, chars = base62Characters) => randomString(length, chars, generateRandomBytes(length).map((b) => b % chars.length));
529
+ //#endregion
530
+ exports.addIrregularRule = addIrregularRule;
531
+ exports.addPluralRule = addPluralRule;
532
+ exports.addSingularRule = addSingularRule;
533
+ exports.addUncountableRule = addUncountableRule;
534
+ exports.base62Characters = base62Characters;
535
+ exports.commaize = commaize;
536
+ exports.cryptoRandomString = cryptoRandomString;
537
+ exports.isPlural = isPlural;
538
+ exports.isSingular = isSingular;
539
+ exports.plural = plural;
540
+ exports.pluralize = pluralize;
541
+ exports.randomString = randomString;
542
+ exports.singular = singular;
543
+
487
544
  //# sourceMappingURL=index.cjs.map