@art-suite/art-core-ts-string-lib 0.2.11 → 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 +531 -474
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -12
- package/dist/{index.d.ts → index.d.mts} +9 -12
- package/dist/index.mjs +533 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +8 -8
- package/dist/index.js +0 -467
- package/dist/index.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,487 +1,544 @@
|
|
|
1
|
-
"
|
|
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
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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
|