@stacksjs/strings 0.70.57 → 0.70.59

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.js CHANGED
@@ -1,1317 +1,2 @@
1
- // @bun
2
- // src/sponge-case.ts
3
- function spongeCase(input, locale) {
4
- let result = "";
5
- for (const char of input) {
6
- result += Math.random() > 0.5 ? char.toLocaleUpperCase(locale) : char.toLocaleLowerCase(locale);
7
- }
8
- return result;
9
- }
10
- // src/swap-case.ts
11
- function swapCase(input, locale) {
12
- let result = "";
13
- for (const char of input) {
14
- const lower = char.toLocaleLowerCase(locale);
15
- result += char === lower ? char.toLocaleUpperCase(locale) : lower;
16
- }
17
- return result;
18
- }
19
- // src/title-case.ts
20
- var TOKENS = /(\S+)|(.)/g;
21
- var IS_SPECIAL_CASE = /[.#][\p{L}\p{N}]/u;
22
- var IS_MANUAL_CASE = /\p{Ll}(?=\p{Lu})/u;
23
- var ALPHANUMERIC_PATTERN = /[\p{L}\p{N}]+/gu;
24
- var IS_ACRONYM = /^(\P{L})*(?:\p{L}\.){2,}(\P{L})*$/u;
25
- var WORD_SEPARATORS = new Set(["\u2014", "\u2013", "-", "\u2015", "/"]);
26
- var SENTENCE_TERMINATORS = new Set([".", "!", "?"]);
27
- var TITLE_TERMINATORS = new Set([
28
- ...SENTENCE_TERMINATORS,
29
- ":",
30
- '"',
31
- "'",
32
- "\u201D"
33
- ]);
34
- var SMALL_WORDS = new Set([
35
- "a",
36
- "an",
37
- "and",
38
- "as",
39
- "at",
40
- "because",
41
- "but",
42
- "by",
43
- "en",
44
- "for",
45
- "if",
46
- "in",
47
- "neither",
48
- "nor",
49
- "of",
50
- "on",
51
- "only",
52
- "or",
53
- "over",
54
- "per",
55
- "so",
56
- "some",
57
- "than",
58
- "that",
59
- "the",
60
- "to",
61
- "up",
62
- "upon",
63
- "v",
64
- "versus",
65
- "via",
66
- "vs",
67
- "when",
68
- "with",
69
- "without",
70
- "yet"
71
- ]);
72
- function titleCase(input, options = {}) {
73
- const {
74
- locale = undefined,
75
- sentenceCase = false,
76
- sentenceTerminators = SENTENCE_TERMINATORS,
77
- titleTerminators = TITLE_TERMINATORS,
78
- smallWords = SMALL_WORDS,
79
- wordSeparators = WORD_SEPARATORS
80
- } = typeof options === "string" || Array.isArray(options) ? { locale: options } : options;
81
- const terminators = sentenceCase ? sentenceTerminators : titleTerminators;
82
- let result = "";
83
- let isNewSentence = true;
84
- for (const m of input.matchAll(TOKENS)) {
85
- const { 1: token, 2: whiteSpace, index = 0 } = m;
86
- if (whiteSpace) {
87
- result += whiteSpace;
88
- continue;
89
- }
90
- if (token === undefined)
91
- continue;
92
- if (IS_SPECIAL_CASE.test(token)) {
93
- const acronym = token.match(IS_ACRONYM);
94
- if (acronym) {
95
- const [_, prefix = "", suffix = ""] = acronym;
96
- result += sentenceCase && !isNewSentence ? token : upperAt(token, prefix.length, locale);
97
- isNewSentence = terminators.has(suffix.charAt(0));
98
- continue;
99
- }
100
- result += token;
101
- isNewSentence = terminators.has(token.charAt(token.length - 1));
102
- } else {
103
- const matches = Array.from(token.matchAll(ALPHANUMERIC_PATTERN));
104
- let value = token;
105
- let isSentenceEnd = false;
106
- for (let i = 0;i < matches.length; i++) {
107
- const match = matches[i];
108
- if (!match)
109
- continue;
110
- const { 0: word, index: wordIndex = 0 } = match;
111
- const nextChar = token.charAt(wordIndex + word.length);
112
- isSentenceEnd = terminators.has(nextChar);
113
- if (isNewSentence) {
114
- isNewSentence = false;
115
- } else if (sentenceCase || IS_MANUAL_CASE.test(word)) {
116
- continue;
117
- } else if (matches.length === 1) {
118
- if (smallWords.has(word)) {
119
- const isFinalToken = index + token.length === input.length;
120
- if (!isFinalToken && !isSentenceEnd) {
121
- continue;
122
- }
123
- }
124
- } else if (i > 0) {
125
- if (!wordSeparators.has(token.charAt(wordIndex - 1))) {
126
- continue;
127
- }
128
- if (smallWords.has(word) && wordSeparators.has(nextChar)) {
129
- continue;
130
- }
131
- }
132
- value = upperAt(value, wordIndex, locale);
133
- }
134
- result += value;
135
- isNewSentence = isSentenceEnd || terminators.has(token.charAt(token.length - 1));
136
- }
137
- }
138
- return result;
139
- }
140
- function upperAt(input, index, locale) {
141
- return input.slice(0, index) + input.charAt(index).toLocaleUpperCase(locale) + input.slice(index + 1);
142
- }
143
-
144
- // src/case.ts
145
- function capitalize(str) {
146
- return str[0] ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
147
- }
148
- function lowercase(str) {
149
- return str.toLowerCase();
150
- }
151
- var SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
152
- var SPLIT_UPPER_UPPER_RE = /(\p{Lu})(\p{Lu}\p{Ll})/gu;
153
- var SPLIT_SEPARATE_NUMBER_RE = /(\d)\p{Ll}|(\p{L})\d/u;
154
- var DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu;
155
- var SPLIT_REPLACE_VALUE = "$1\x00$2";
156
- var DEFAULT_PREFIX_SUFFIX_CHARACTERS = "";
157
- function split(value) {
158
- let result = value.trim();
159
- result = result.replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE).replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
160
- result = result.replace(DEFAULT_STRIP_REGEXP, "\x00");
161
- let start = 0;
162
- let end = result.length;
163
- while (result.charAt(start) === "\x00")
164
- start++;
165
- if (start === end)
166
- return [];
167
- while (result.charAt(end - 1) === "\x00")
168
- end--;
169
- return result.slice(start, end).split(/\0/g);
170
- }
171
- function splitSeparateNumbers(value) {
172
- const words = split(value);
173
- for (let i = 0;i < words.length; i++) {
174
- const word = words[i];
175
- if (word === undefined)
176
- continue;
177
- const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);
178
- if (match) {
179
- const offset = match.index + (match[1] ?? match[2] ?? "").length;
180
- words.splice(i, 1, word.slice(0, offset), word.slice(offset));
181
- }
182
- }
183
- return words;
184
- }
185
- function noCase(input, options) {
186
- const [prefix, words, suffix] = splitPrefixSuffix(input, options);
187
- return prefix + words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? " ") + suffix;
188
- }
189
- function camelCase(input, options) {
190
- const [prefix, words, suffix] = splitPrefixSuffix(input, options);
191
- const lower = lowerFactory(options?.locale);
192
- const upper = upperFactory(options?.locale);
193
- const transform = options?.mergeAmbiguousCharacters ? capitalCaseTransformFactory(lower, upper) : pascalCaseTransformFactory(lower, upper);
194
- return prefix + words.map((word, index) => {
195
- if (index === 0)
196
- return lower(word);
197
- return transform(word, index);
198
- }).join(options?.delimiter ?? "") + suffix;
199
- }
200
- function pascalCase(input, options) {
201
- const [prefix, words, suffix] = splitPrefixSuffix(input, options);
202
- const lower = lowerFactory(options?.locale);
203
- const upper = upperFactory(options?.locale);
204
- const transform = options?.mergeAmbiguousCharacters ? capitalCaseTransformFactory(lower, upper) : pascalCaseTransformFactory(lower, upper);
205
- return prefix + words.map(transform).join(options?.delimiter ?? "") + suffix;
206
- }
207
- function pascalSnakeCase(input, options) {
208
- return capitalCase(input, { delimiter: "_", ...options });
209
- }
210
- function capitalCase(input, options) {
211
- const [prefix, words, suffix] = splitPrefixSuffix(input, options);
212
- const lower = lowerFactory(options?.locale);
213
- const upper = upperFactory(options?.locale);
214
- return prefix + words.map(capitalCaseTransformFactory(lower, upper)).join(options?.delimiter ?? " ") + suffix;
215
- }
216
- function constantCase(input, options) {
217
- const [prefix, words, suffix] = splitPrefixSuffix(input, options);
218
- return prefix + words.map(upperFactory(options?.locale)).join(options?.delimiter ?? "_") + suffix;
219
- }
220
- function dotCase(input, options) {
221
- return noCase(input, { delimiter: ".", ...options });
222
- }
223
- function kebabCase(input, options) {
224
- return noCase(input, { delimiter: "-", ...options });
225
- }
226
- function pathCase(input, options) {
227
- return noCase(input, { delimiter: "/", ...options });
228
- }
229
- function sentenceCase(input, options) {
230
- const [prefix, words, suffix] = splitPrefixSuffix(input, options);
231
- const lower = lowerFactory(options?.locale);
232
- const upper = upperFactory(options?.locale);
233
- const transform = capitalCaseTransformFactory(lower, upper);
234
- return prefix + words.map((word, index) => {
235
- if (index === 0)
236
- return transform(word);
237
- return lower(word);
238
- }).join(options?.delimiter ?? " ") + suffix;
239
- }
240
- function snakeCase(input, options) {
241
- return noCase(input, { delimiter: "_", ...options });
242
- }
243
- function trainCase(input, options) {
244
- return capitalCase(input, { delimiter: "-", ...options });
245
- }
246
- function paramCase(input, options) {
247
- return kebabCase(input, options);
248
- }
249
- function lowerFactory(locale) {
250
- return locale === false ? (input) => input.toLowerCase() : (input) => input.toLocaleLowerCase(locale);
251
- }
252
- function upperFactory(locale) {
253
- return locale === false ? (input) => input.toUpperCase() : (input) => input.toLocaleUpperCase(locale);
254
- }
255
- function capitalCaseTransformFactory(lower, upper) {
256
- return (word) => {
257
- if (!word)
258
- return word;
259
- return `${upper(word[0] ?? "")}${lower(word.slice(1))}`;
260
- };
261
- }
262
- function pascalCaseTransformFactory(lower, upper) {
263
- return (word, index) => {
264
- if (!word)
265
- return word;
266
- const char0 = word[0] ?? "";
267
- const initial = index > 0 && char0 >= "0" && char0 <= "9" ? `_${char0}` : upper(char0);
268
- return initial + lower(word.slice(1));
269
- };
270
- }
271
- function splitPrefixSuffix(input, options = {}) {
272
- const splitFn = options.split ?? split;
273
- const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
274
- const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
275
- let prefixIndex = 0;
276
- let suffixIndex = input.length;
277
- while (prefixIndex < input.length) {
278
- const char = input.charAt(prefixIndex);
279
- if (!prefixCharacters.includes(char))
280
- break;
281
- prefixIndex++;
282
- }
283
- while (suffixIndex > prefixIndex) {
284
- const index = suffixIndex - 1;
285
- const char = input.charAt(index);
286
- if (!suffixCharacters.includes(char))
287
- break;
288
- suffixIndex = index;
289
- }
290
- return [
291
- input.slice(0, prefixIndex),
292
- splitFn(input.slice(prefixIndex, suffixIndex)),
293
- input.slice(suffixIndex)
294
- ];
295
- }
296
-
297
- // src/helpers.ts
298
- function toString(v) {
299
- return Object.prototype.toString.call(v);
300
- }
301
- function mask(value, character, index, length) {
302
- if (character === "")
303
- return value;
304
- const len = value.length;
305
- const start = index < 0 ? Math.max(0, len + index) : index;
306
- if (start >= len)
307
- return value;
308
- const maskLen = length === undefined ? len - start : Math.max(0, length);
309
- if (maskLen === 0)
310
- return value;
311
- const end = Math.min(len, start + maskLen);
312
- const fill = character.charAt(0).repeat(end - start);
313
- return value.slice(0, start) + fill + value.slice(end);
314
- }
315
-
316
- // src/pluralize.ts
317
- var pluralRules = [];
318
- var singularRules = [];
319
- var uncountables = {};
320
- var irregularPlurals = {};
321
- var irregularSingles = {};
322
- function sanitizeRule(rule) {
323
- return typeof rule === "string" ? new RegExp(`^${rule}$`, "i") : rule;
324
- }
325
- function restoreCase(word, token) {
326
- if (word === token)
327
- return token;
328
- if (word === word.toLowerCase())
329
- return token.toLowerCase();
330
- if (word === word.toUpperCase())
331
- return token.toUpperCase();
332
- const firstChar = word[0];
333
- if (firstChar !== undefined && firstChar === firstChar.toUpperCase()) {
334
- return token.charAt(0).toUpperCase() + token.slice(1).toLowerCase();
335
- }
336
- return token.toLowerCase();
337
- }
338
- function interpolate(str, ...args) {
339
- return str.replace(/\$(\d{1,2})/g, (_match, index) => args[Number(index)] || "");
340
- }
341
- function replace(word, rule) {
342
- return word.replace(rule[0], (...matchArgs) => {
343
- const result = interpolate(rule[1], ...matchArgs);
344
- if (matchArgs[0] === "") {
345
- return restoreCase(word[matchArgs[matchArgs.length - 2] - 1] ?? "", result);
346
- }
347
- return restoreCase(matchArgs[0], result);
348
- });
349
- }
350
- function sanitizeWord(token, word, rules) {
351
- if (!token.length || uncountables[token]) {
352
- return word;
353
- }
354
- for (let i = rules.length - 1;i >= 0; i--) {
355
- const rule = rules[i];
356
- if (rule && rule[0].test(word))
357
- return replace(word, rule);
358
- }
359
- return word;
360
- }
361
- function replaceWord(replaceMap, keepMap, rules) {
362
- return (word) => {
363
- const token = word.toLowerCase();
364
- if (keepMap[token])
365
- return restoreCase(word, token);
366
- if (replaceMap[token])
367
- return restoreCase(word, replaceMap[token]);
368
- return sanitizeWord(token, word, rules);
369
- };
370
- }
371
- function checkWord(replaceMap, keepMap, rules) {
372
- return (word) => {
373
- const token = word.toLowerCase();
374
- if (keepMap[token])
375
- return true;
376
- if (replaceMap[token])
377
- return false;
378
- return sanitizeWord(token, token, rules) === token;
379
- };
380
- }
381
- var pluralize = (word, options = {}) => {
382
- const { count = 2, inclusive = false } = options;
383
- if (typeof word !== "string") {
384
- throw new TypeError("Word must be a string");
385
- }
386
- const pluralized = count === 1 ? pluralize.singular(word) : pluralize.plural(word);
387
- return inclusive ? `${count} ${pluralized}` : pluralized;
388
- };
389
- var singular = (word) => {
390
- return pluralize.singular(word);
391
- };
392
- var plural = (word, count = 2) => {
393
- return pluralize(word, { count });
394
- };
395
- pluralize.plural = replaceWord(irregularSingles, irregularPlurals, pluralRules);
396
- pluralize.isPlural = checkWord(irregularSingles, irregularPlurals, pluralRules);
397
- pluralize.singular = replaceWord(irregularPlurals, irregularSingles, singularRules);
398
- pluralize.isSingular = checkWord(irregularPlurals, irregularSingles, singularRules);
399
- pluralize.addPluralRule = (rule, replacement) => {
400
- pluralRules.push([sanitizeRule(rule), replacement]);
401
- };
402
- pluralize.addSingularRule = (rule, replacement) => {
403
- singularRules.push([sanitizeRule(rule), replacement]);
404
- };
405
- pluralize.addUncountableRule = (word) => {
406
- if (typeof word === "string") {
407
- uncountables[word.toLowerCase()] = true;
408
- return;
409
- }
410
- pluralize.addPluralRule(word, "$0");
411
- pluralize.addSingularRule(word, "$0");
412
- };
413
- pluralize.addIrregularRule = (single, plural2) => {
414
- const lowerPlural = plural2.toLowerCase();
415
- const lowerSingle = single.toLowerCase();
416
- irregularSingles[lowerSingle] = lowerPlural;
417
- irregularPlurals[lowerPlural] = lowerSingle;
418
- };
419
- [
420
- ["I", "we"],
421
- ["me", "us"],
422
- ["he", "they"],
423
- ["she", "they"],
424
- ["them", "them"],
425
- ["myself", "ourselves"],
426
- ["yourself", "yourselves"],
427
- ["itself", "themselves"],
428
- ["herself", "themselves"],
429
- ["himself", "themselves"],
430
- ["themself", "themselves"],
431
- ["is", "are"],
432
- ["was", "were"],
433
- ["has", "have"],
434
- ["this", "these"],
435
- ["that", "those"],
436
- ["my", "our"],
437
- ["its", "their"],
438
- ["his", "their"],
439
- ["her", "their"],
440
- ["echo", "echoes"],
441
- ["dingo", "dingoes"],
442
- ["volcano", "volcanoes"],
443
- ["tornado", "tornadoes"],
444
- ["torpedo", "torpedoes"],
445
- ["genus", "genera"],
446
- ["viscus", "viscera"],
447
- ["stigma", "stigmata"],
448
- ["stoma", "stomata"],
449
- ["dogma", "dogmata"],
450
- ["lemma", "lemmata"],
451
- ["schema", "schemata"],
452
- ["anathema", "anathemata"],
453
- ["ox", "oxen"],
454
- ["axe", "axes"],
455
- ["die", "dice"],
456
- ["yes", "yeses"],
457
- ["foot", "feet"],
458
- ["eave", "eaves"],
459
- ["goose", "geese"],
460
- ["tooth", "teeth"],
461
- ["quiz", "quizzes"],
462
- ["human", "humans"],
463
- ["proof", "proofs"],
464
- ["carve", "carves"],
465
- ["valve", "valves"],
466
- ["looey", "looies"],
467
- ["thief", "thieves"],
468
- ["groove", "grooves"],
469
- ["pickaxe", "pickaxes"],
470
- ["passerby", "passersby"],
471
- ["canvas", "canvases"]
472
- ].forEach(([single, plural2]) => pluralize.addIrregularRule(single ?? "", plural2 ?? ""));
473
- [
474
- [/s?$/i, "s"],
475
- [/[^\x20-\x7F]$/, "$0"],
476
- [/([^aeiou]ese)$/i, "$1"],
477
- [/(ax|test)is$/i, "$1es"],
478
- [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, "$1es"],
479
- [/(e[mn]u)s?$/i, "$1s"],
480
- [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, "$1"],
481
- [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1i"],
482
- [/(alumn|alg|vertebr)(?:a|ae)$/i, "$1ae"],
483
- [/(seraph|cherub)(?:im)?$/i, "$1im"],
484
- [/(her|at|gr)o$/i, "$1oes"],
485
- [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, "$1a"],
486
- [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, "$1a"],
487
- [/sis$/i, "ses"],
488
- [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, "$1$2ves"],
489
- [/([^aeiouy]|qu)y$/i, "$1ies"],
490
- [/([^ch][ieo][ln])ey$/i, "$1ies"],
491
- [/(x|ch|ss|sh|zz)$/i, "$1es"],
492
- [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, "$1ices"],
493
- [/\b((?:tit)?m|l)(?:ice|ouse)$/i, "$1ice"],
494
- [/(pe)(?:rson|ople)$/i, "$1ople"],
495
- [/(child)(?:ren)?$/i, "$1ren"],
496
- [/eaux$/i, "$0"],
497
- [/m[ae]n$/i, "men"],
498
- ["thou", "you"]
499
- ].forEach(([rule, replacement]) => {
500
- if (rule === undefined)
501
- return;
502
- pluralize.addPluralRule(rule, replacement);
503
- });
504
- [
505
- [/s$/i, ""],
506
- [/(ss)$/i, "$1"],
507
- [/(wi|kni|(?:after|half|high|low|mid|non|night|\W|^)li)ves$/i, "$1fe"],
508
- [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, "$1f"],
509
- [/ies$/i, "y"],
510
- [/(dg|ss|ois|lk|ok|wn|mb|th|ch|ec|oal|is|ck|ix|sser|ts|wb)ies$/i, "$1ie"],
511
- [/\b(l|(?:neck|cross|hog|aun)?t|coll|faer|food|gen|goon|group|hipp|junk|vegg|(?:pork)?p|charl|calor|cut)ies$/i, "$1ie"],
512
- [/\b(mon|smil)ies$/i, "$1ey"],
513
- [/\b((?:tit)?m|l)ice$/i, "$1ouse"],
514
- [/(seraph|cherub)im$/i, "$1"],
515
- [/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, "$1"],
516
- [/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, "$1sis"],
517
- [/(movie|twelve|abuse|e[mn]u)s$/i, "$1"],
518
- [/(test)(?:is|es)$/i, "$1is"],
519
- [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1us"],
520
- [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, "$1um"],
521
- [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, "$1on"],
522
- [/(alumn|alg|vertebr)ae$/i, "$1a"],
523
- [/(cod|mur|sil|vert|ind)ices$/i, "$1ex"],
524
- [/(matr|append)ices$/i, "$1ix"],
525
- [/(pe)(rson|ople)$/i, "$1rson"],
526
- [/(child)ren$/i, "$1"],
527
- [/(eau)x?$/i, "$1"],
528
- [/men$/i, "man"]
529
- ].forEach(([rule, replacement]) => {
530
- if (rule === undefined)
531
- return;
532
- pluralize.addSingularRule(rule, replacement);
533
- });
534
- [
535
- "adulthood",
536
- "advice",
537
- "agenda",
538
- "aid",
539
- "aircraft",
540
- "alcohol",
541
- "ammo",
542
- "analytics",
543
- "anime",
544
- "athletics",
545
- "audio",
546
- "bison",
547
- "blood",
548
- "bream",
549
- "buffalo",
550
- "butter",
551
- "carp",
552
- "cash",
553
- "chassis",
554
- "chess",
555
- "clothing",
556
- "cod",
557
- "commerce",
558
- "cooperation",
559
- "corps",
560
- "debris",
561
- "diabetes",
562
- "digestion",
563
- "elk",
564
- "energy",
565
- "equipment",
566
- "excretion",
567
- "expertise",
568
- "firmware",
569
- "flounder",
570
- "fun",
571
- "gallows",
572
- "garbage",
573
- "graffiti",
574
- "hardware",
575
- "headquarters",
576
- "health",
577
- "herpes",
578
- "highjinks",
579
- "homework",
580
- "housework",
581
- "information",
582
- "jeans",
583
- "justice",
584
- "kudos",
585
- "labour",
586
- "literature",
587
- "machinery",
588
- "mackerel",
589
- "mail",
590
- "media",
591
- "mews",
592
- "moose",
593
- "music",
594
- "mud",
595
- "manga",
596
- "news",
597
- "only",
598
- "personnel",
599
- "pike",
600
- "plankton",
601
- "pliers",
602
- "police",
603
- "pollution",
604
- "premises",
605
- "rain",
606
- "research",
607
- "rice",
608
- "salmon",
609
- "scissors",
610
- "series",
611
- "sewage",
612
- "shambles",
613
- "shrimp",
614
- "software",
615
- "staff",
616
- "swine",
617
- "tennis",
618
- "traffic",
619
- "transportation",
620
- "trout",
621
- "tuna",
622
- "wealth",
623
- "welfare",
624
- "whiting",
625
- "wildebeest",
626
- "wildlife",
627
- "you",
628
- /pok[e\u00E9]mon$/i,
629
- /[^aeiou]ese$/i,
630
- /deer$/i,
631
- /fish$/i,
632
- /measles$/i,
633
- /o[iu]s$/i,
634
- /pox$/i,
635
- /sheep$/i
636
- ].forEach(pluralize.addUncountableRule);
637
- var pluralize_default = pluralize;
638
-
639
- // src/slug.ts
640
- var charMap = JSON.parse('{"$":"dollar","%":"percent","&":"and","<":"less",">":"greater","|":"or","\xA2":"cent","\xA3":"pound","\xA4":"currency","\xA5":"yen","\xA9":"(c)","\xAA":"a","\xAE":"(r)","\xBA":"o","\xC0":"A","\xC1":"A","\xC2":"A","\xC3":"A","\xC4":"A","\xC5":"A","\xC6":"AE","\xC7":"C","\xC8":"E","\xC9":"E","\xCA":"E","\xCB":"E","\xCC":"I","\xCD":"I","\xCE":"I","\xCF":"I","\xD0":"D","\xD1":"N","\xD2":"O","\xD3":"O","\xD4":"O","\xD5":"O","\xD6":"O","\xD8":"O","\xD9":"U","\xDA":"U","\xDB":"U","\xDC":"U","\xDD":"Y","\xDE":"TH","\xDF":"ss","\xE0":"a","\xE1":"a","\xE2":"a","\xE3":"a","\xE4":"a","\xE5":"a","\xE6":"ae","\xE7":"c","\xE8":"e","\xE9":"e","\xEA":"e","\xEB":"e","\xEC":"i","\xED":"i","\xEE":"i","\xEF":"i","\xF0":"d","\xF1":"n","\xF2":"o","\xF3":"o","\xF4":"o","\xF5":"o","\xF6":"o","\xF8":"o","\xF9":"u","\xFA":"u","\xFB":"u","\xFC":"u","\xFD":"y","\xFE":"th","\xFF":"y","\u0100":"A","\u0101":"a","\u0102":"A","\u0103":"a","\u0104":"A","\u0105":"a","\u0106":"C","\u0107":"c","\u010C":"C","\u010D":"c","\u010E":"D","\u010F":"d","\u0110":"DJ","\u0111":"dj","\u0112":"E","\u0113":"e","\u0116":"E","\u0117":"e","\u0118":"e","\u0119":"e","\u011A":"E","\u011B":"e","\u011E":"G","\u011F":"g","\u0122":"G","\u0123":"g","\u0128":"I","\u0129":"i","\u012A":"i","\u012B":"i","\u012E":"I","\u012F":"i","\u0130":"I","\u0131":"i","\u0136":"k","\u0137":"k","\u013B":"L","\u013C":"l","\u013D":"L","\u013E":"l","\u0141":"L","\u0142":"l","\u0143":"N","\u0144":"n","\u0145":"N","\u0146":"n","\u0147":"N","\u0148":"n","\u014C":"O","\u014D":"o","\u0150":"O","\u0151":"o","\u0152":"OE","\u0153":"oe","\u0154":"R","\u0155":"r","\u0158":"R","\u0159":"r","\u015A":"S","\u015B":"s","\u015E":"S","\u015F":"s","\u0160":"S","\u0161":"s","\u0162":"T","\u0163":"t","\u0164":"T","\u0165":"t","\u0168":"U","\u0169":"u","\u016A":"u","\u016B":"u","\u016E":"U","\u016F":"u","\u0170":"U","\u0171":"u","\u0172":"U","\u0173":"u","\u0174":"W","\u0175":"w","\u0176":"Y","\u0177":"y","\u0178":"Y","\u0179":"Z","\u017A":"z","\u017B":"Z","\u017C":"z","\u017D":"Z","\u017E":"z","\u018F":"E","\u0192":"f","\u01A0":"O","\u01A1":"o","\u01AF":"U","\u01B0":"u","\u01C8":"LJ","\u01C9":"lj","\u01CB":"NJ","\u01CC":"nj","\u0218":"S","\u0219":"s","\u021A":"T","\u021B":"t","\u0259":"e","\u02DA":"o","\u0386":"A","\u0388":"E","\u0389":"H","\u038A":"I","\u038C":"O","\u038E":"Y","\u038F":"W","\u0390":"i","\u0391":"A","\u0392":"B","\u0393":"G","\u0394":"D","\u0395":"E","\u0396":"Z","\u0397":"H","\u0398":"8","\u0399":"I","\u039A":"K","\u039B":"L","\u039C":"M","\u039D":"N","\u039E":"3","\u039F":"O","\u03A0":"P","\u03A1":"R","\u03A3":"S","\u03A4":"T","\u03A5":"Y","\u03A6":"F","\u03A7":"X","\u03A8":"PS","\u03A9":"W","\u03AA":"I","\u03AB":"Y","\u03AC":"a","\u03AD":"e","\u03AE":"h","\u03AF":"i","\u03B0":"y","\u03B1":"a","\u03B2":"b","\u03B3":"g","\u03B4":"d","\u03B5":"e","\u03B6":"z","\u03B7":"h","\u03B8":"8","\u03B9":"i","\u03BA":"k","\u03BB":"l","\u03BC":"m","\u03BD":"n","\u03BE":"3","\u03BF":"o","\u03C0":"p","\u03C1":"r","\u03C2":"s","\u03C3":"s","\u03C4":"t","\u03C5":"y","\u03C6":"f","\u03C7":"x","\u03C8":"ps","\u03C9":"w","\u03CA":"i","\u03CB":"y","\u03CC":"o","\u03CD":"y","\u03CE":"w","\u0401":"Yo","\u0402":"DJ","\u0404":"Ye","\u0406":"I","\u0407":"Yi","\u0408":"J","\u0409":"LJ","\u040A":"NJ","\u040B":"C","\u040F":"DZ","\u0410":"A","\u0411":"B","\u0412":"V","\u0413":"G","\u0414":"D","\u0415":"E","\u0416":"Zh","\u0417":"Z","\u0418":"I","\u0419":"J","\u041A":"K","\u041B":"L","\u041C":"M","\u041D":"N","\u041E":"O","\u041F":"P","\u0420":"R","\u0421":"S","\u0422":"T","\u0423":"U","\u0424":"F","\u0425":"H","\u0426":"C","\u0427":"Ch","\u0428":"Sh","\u0429":"Sh","\u042A":"U","\u042B":"Y","\u042C":"","\u042D":"E","\u042E":"Yu","\u042F":"Ya","\u0430":"a","\u0431":"b","\u0432":"v","\u0433":"g","\u0434":"d","\u0435":"e","\u0436":"zh","\u0437":"z","\u0438":"i","\u0439":"j","\u043A":"k","\u043B":"l","\u043C":"m","\u043D":"n","\u043E":"o","\u043F":"p","\u0440":"r","\u0441":"s","\u0442":"t","\u0443":"u","\u0444":"f","\u0445":"h","\u0446":"c","\u0447":"ch","\u0448":"sh","\u0449":"sh","\u044A":"u","\u044B":"y","\u044C":"","\u044D":"e","\u044E":"yu","\u044F":"ya","\u0451":"yo","\u0452":"dj","\u0454":"ye","\u0456":"i","\u0457":"yi","\u0458":"j","\u0459":"lj","\u045A":"nj","\u045B":"c","\u045D":"u","\u045F":"dz","\u0490":"G","\u0491":"g","\u0492":"GH","\u0493":"gh","\u049A":"KH","\u049B":"kh","\u04A2":"NG","\u04A3":"ng","\u04AE":"UE","\u04AF":"ue","\u04B0":"U","\u04B1":"u","\u04BA":"H","\u04BB":"h","\u04D8":"AE","\u04D9":"ae","\u04E8":"OE","\u04E9":"oe","\u0531":"A","\u0532":"B","\u0533":"G","\u0534":"D","\u0535":"E","\u0536":"Z","\u0537":"E\'","\u0538":"Y\'","\u0539":"T\'","\u053A":"JH","\u053B":"I","\u053C":"L","\u053D":"X","\u053E":"C\'","\u053F":"K","\u0540":"H","\u0541":"D\'","\u0542":"GH","\u0543":"TW","\u0544":"M","\u0545":"Y","\u0546":"N","\u0547":"SH","\u0549":"CH","\u054A":"P","\u054B":"J","\u054C":"R\'","\u054D":"S","\u054E":"V","\u054F":"T","\u0550":"R","\u0551":"C","\u0553":"P\'","\u0554":"Q\'","\u0555":"O\'\'","\u0556":"F","\u0587":"EV","\u0621":"a","\u0622":"aa","\u0623":"a","\u0624":"u","\u0625":"i","\u0626":"e","\u0627":"a","\u0628":"b","\u0629":"h","\u062A":"t","\u062B":"th","\u062C":"j","\u062D":"h","\u062E":"kh","\u062F":"d","\u0630":"th","\u0631":"r","\u0632":"z","\u0633":"s","\u0634":"sh","\u0635":"s","\u0636":"dh","\u0637":"t","\u0638":"z","\u0639":"a","\u063A":"gh","\u0641":"f","\u0642":"q","\u0643":"k","\u0644":"l","\u0645":"m","\u0646":"n","\u0647":"h","\u0648":"w","\u0649":"a","\u064A":"y","\u064B":"an","\u064C":"on","\u064D":"en","\u064E":"a","\u064F":"u","\u0650":"e","\u0652":"","\u0660":"0","\u0661":"1","\u0662":"2","\u0663":"3","\u0664":"4","\u0665":"5","\u0666":"6","\u0667":"7","\u0668":"8","\u0669":"9","\u067E":"p","\u0686":"ch","\u0698":"zh","\u06A9":"k","\u06AF":"g","\u06CC":"y","\u06F0":"0","\u06F1":"1","\u06F2":"2","\u06F3":"3","\u06F4":"4","\u06F5":"5","\u06F6":"6","\u06F7":"7","\u06F8":"8","\u06F9":"9","\u0E3F":"baht","\u10D0":"a","\u10D1":"b","\u10D2":"g","\u10D3":"d","\u10D4":"e","\u10D5":"v","\u10D6":"z","\u10D7":"t","\u10D8":"i","\u10D9":"k","\u10DA":"l","\u10DB":"m","\u10DC":"n","\u10DD":"o","\u10DE":"p","\u10DF":"zh","\u10E0":"r","\u10E1":"s","\u10E2":"t","\u10E3":"u","\u10E4":"f","\u10E5":"k","\u10E6":"gh","\u10E7":"q","\u10E8":"sh","\u10E9":"ch","\u10EA":"ts","\u10EB":"dz","\u10EC":"ts","\u10ED":"ch","\u10EE":"kh","\u10EF":"j","\u10F0":"h","\u1E62":"S","\u1E63":"s","\u1E80":"W","\u1E81":"w","\u1E82":"W","\u1E83":"w","\u1E84":"W","\u1E85":"w","\u1E9E":"SS","\u1EA0":"A","\u1EA1":"a","\u1EA2":"A","\u1EA3":"a","\u1EA4":"A","\u1EA5":"a","\u1EA6":"A","\u1EA7":"a","\u1EA8":"A","\u1EA9":"a","\u1EAA":"A","\u1EAB":"a","\u1EAC":"A","\u1EAD":"a","\u1EAE":"A","\u1EAF":"a","\u1EB0":"A","\u1EB1":"a","\u1EB2":"A","\u1EB3":"a","\u1EB4":"A","\u1EB5":"a","\u1EB6":"A","\u1EB7":"a","\u1EB8":"E","\u1EB9":"e","\u1EBA":"E","\u1EBB":"e","\u1EBC":"E","\u1EBD":"e","\u1EBE":"E","\u1EBF":"e","\u1EC0":"E","\u1EC1":"e","\u1EC2":"E","\u1EC3":"e","\u1EC4":"E","\u1EC5":"e","\u1EC6":"E","\u1EC7":"e","\u1EC8":"I","\u1EC9":"i","\u1ECA":"I","\u1ECB":"i","\u1ECC":"O","\u1ECD":"o","\u1ECE":"O","\u1ECF":"o","\u1ED0":"O","\u1ED1":"o","\u1ED2":"O","\u1ED3":"o","\u1ED4":"O","\u1ED5":"o","\u1ED6":"O","\u1ED7":"o","\u1ED8":"O","\u1ED9":"o","\u1EDA":"O","\u1EDB":"o","\u1EDC":"O","\u1EDD":"o","\u1EDE":"O","\u1EDF":"o","\u1EE0":"O","\u1EE1":"o","\u1EE2":"O","\u1EE3":"o","\u1EE4":"U","\u1EE5":"u","\u1EE6":"U","\u1EE7":"u","\u1EE8":"U","\u1EE9":"u","\u1EEA":"U","\u1EEB":"u","\u1EEC":"U","\u1EED":"u","\u1EEE":"U","\u1EEF":"u","\u1EF0":"U","\u1EF1":"u","\u1EF2":"Y","\u1EF3":"y","\u1EF4":"Y","\u1EF5":"y","\u1EF6":"Y","\u1EF7":"y","\u1EF8":"Y","\u1EF9":"y","\u2013":"-","\u2018":"\'","\u2019":"\'","\u201C":"\\"","\u201D":"\\"","\u201E":"\\"","\u2020":"+","\u2022":"*","\u2026":"...","\u20A0":"ecu","\u20A2":"cruzeiro","\u20A3":"french franc","\u20A4":"lira","\u20A5":"mill","\u20A6":"naira","\u20A7":"peseta","\u20A8":"rupee","\u20A9":"won","\u20AA":"new shequel","\u20AB":"dong","\u20AC":"euro","\u20AD":"kip","\u20AE":"tugrik","\u20AF":"drachma","\u20B0":"penny","\u20B1":"peso","\u20B2":"guarani","\u20B3":"austral","\u20B4":"hryvnia","\u20B5":"cedi","\u20B8":"kazakhstani tenge","\u20B9":"indian rupee","\u20BA":"turkish lira","\u20BD":"russian ruble","\u20BF":"bitcoin","\u2120":"sm","\u2122":"tm","\u2202":"d","\u2206":"delta","\u2211":"sum","\u221E":"infinity","\u2665":"love","\u5143":"yuan","\u5186":"yen","\uFDFC":"rial","\uFEF5":"laa","\uFEF7":"laa","\uFEF9":"lai","\uFEFB":"la"}');
641
- var locales = JSON.parse('{"bg":{"\u0419":"Y","\u0426":"Ts","\u0429":"Sht","\u042A":"A","\u042C":"Y","\u0439":"y","\u0446":"ts","\u0449":"sht","\u044A":"a","\u044C":"y"},"de":{"\xC4":"AE","\xE4":"ae","\xD6":"OE","\xF6":"oe","\xDC":"UE","\xFC":"ue","\xDF":"ss","%":"prozent","&":"und","|":"oder","\u2211":"summe","\u221E":"unendlich","\u2665":"liebe"},"es":{"%":"por ciento","&":"y","<":"menor que",">":"mayor que","|":"o","\xA2":"centavos","\xA3":"libras","\xA4":"moneda","\u20A3":"francos","\u2211":"suma","\u221E":"infinito","\u2665":"amor"},"fr":{"%":"pourcent","&":"et","<":"plus petit",">":"plus grand","|":"ou","\xA2":"centime","\xA3":"livre","\xA4":"devise","\u20A3":"franc","\u2211":"somme","\u221E":"infini","\u2665":"amour"},"pt":{"%":"porcento","&":"e","<":"menor",">":"maior","|":"ou","\xA2":"centavo","\u2211":"soma","\xA3":"libra","\u221E":"infinito","\u2665":"amor"},"uk":{"\u0418":"Y","\u0438":"y","\u0419":"Y","\u0439":"y","\u0426":"Ts","\u0446":"ts","\u0425":"Kh","\u0445":"kh","\u0429":"Shch","\u0449":"shch","\u0413":"H","\u0433":"h"},"vi":{"\u0110":"D","\u0111":"d"},"da":{"\xD8":"OE","\xF8":"oe","\xC5":"AA","\xE5":"aa","%":"procent","&":"og","|":"eller","$":"dollar","<":"mindre end",">":"st\xF8rre end"},"nb":{"&":"og","\xC5":"AA","\xC6":"AE","\xD8":"OE","\xE5":"aa","\xE6":"ae","\xF8":"oe"},"it":{"&":"e"},"nl":{"&":"en"},"sv":{"&":"och","\xC5":"AA","\xC4":"AE","\xD6":"OE","\xE5":"aa","\xE4":"ae","\xF6":"oe"}}');
642
- function slugify(string, options = {}) {
643
- if (typeof string !== "string") {
644
- throw new TypeError("slugify: string argument expected");
645
- }
646
- const {
647
- replacement = "-",
648
- remove = /[^\w\s$*+~.()'"!\-:@]+/g,
649
- lower = false,
650
- strict = false,
651
- locale,
652
- trim = true
653
- } = options;
654
- const localeMap = locale ? locales[locale] || {} : {};
655
- const slug = string.normalize().split("").reduce((result, ch) => {
656
- let appendChar = localeMap[ch] ?? charMap[ch] ?? ch;
657
- appendChar = appendChar === replacement ? " " : appendChar;
658
- return result + appendChar;
659
- }, "").replace(remove, "");
660
- const strictSlug = strict ? slug.replace(/[^A-Z0-9\s]/gi, "") : slug;
661
- const trimmedSlug = trim ? strictSlug.trim() : strictSlug;
662
- const finalSlug = trimmedSlug.replace(/\s+/g, replacement);
663
- return lower ? finalSlug.toLowerCase() : finalSlug;
664
- }
665
- function extendCharMap(customMap) {
666
- Object.assign(charMap, customMap);
667
- }
668
-
669
- // src/detect-indent.ts
670
- var INDENT_REGEX = /^(?:( )+|\t+)/;
671
- var INDENT_TYPE_SPACE = "space";
672
- var INDENT_TYPE_TAB = "tab";
673
- function makeIndentsMap(string, ignoreSingleSpaces = true) {
674
- const indents = new Map;
675
- let previousSize = 0;
676
- let previousIndentType;
677
- let key = "";
678
- for (const line of string.split(/\n/g)) {
679
- if (!line) {
680
- continue;
681
- }
682
- let indent;
683
- let indentType;
684
- let use;
685
- let weight;
686
- let entry;
687
- const matches = line.match(INDENT_REGEX);
688
- if (matches === null) {
689
- previousSize = 0;
690
- previousIndentType = "";
691
- } else {
692
- indent = matches[0].length;
693
- indentType = matches[1] ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
694
- if (ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && indent === 1) {
695
- continue;
696
- }
697
- if (indentType !== previousIndentType) {
698
- previousSize = 0;
699
- }
700
- previousIndentType = indentType;
701
- use = 1;
702
- weight = 0;
703
- const indentDifference = indent - previousSize;
704
- previousSize = indent;
705
- if (indentDifference === 0) {
706
- use = 0;
707
- weight = 1;
708
- } else {
709
- const absoluteIndentDifference = indentDifference > 0 ? indentDifference : -indentDifference;
710
- key = encodeIndentsKey(indentType, absoluteIndentDifference);
711
- }
712
- entry = indents.get(key);
713
- entry = entry === undefined ? [1, 0] : [entry[0] + use, entry[1] + weight];
714
- indents.set(key, entry);
715
- }
716
- }
717
- return indents;
718
- }
719
- function encodeIndentsKey(indentType, indentAmount) {
720
- const typeCharacter = indentType === INDENT_TYPE_SPACE ? "s" : "t";
721
- return typeCharacter + String(indentAmount);
722
- }
723
- function decodeIndentsKey(indentsKey) {
724
- const keyHasTypeSpace = indentsKey[0] === "s";
725
- const type = keyHasTypeSpace ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
726
- const amount = Number(indentsKey.slice(1));
727
- return { type, amount };
728
- }
729
- function getMostUsedKey(indents) {
730
- let result;
731
- let maxUsed = 0;
732
- let maxWeight = 0;
733
- for (const [key, [usedCount, weight]] of indents) {
734
- if (usedCount > maxUsed || usedCount === maxUsed && weight > maxWeight) {
735
- maxUsed = usedCount;
736
- maxWeight = weight;
737
- result = key;
738
- }
739
- }
740
- return result;
741
- }
742
- function makeIndentString(type, amount) {
743
- const indentCharacter = type === INDENT_TYPE_SPACE ? " " : "\t";
744
- return indentCharacter.repeat(amount);
745
- }
746
- function detectIndent(string) {
747
- if (typeof string !== "string") {
748
- throw new TypeError("Expected a string");
749
- }
750
- let indents = makeIndentsMap(string, true);
751
- if (indents.size === 0) {
752
- indents = makeIndentsMap(string, false);
753
- }
754
- const keyOfMostUsedIndent = getMostUsedKey(indents);
755
- const decoded = keyOfMostUsedIndent !== undefined ? decodeIndentsKey(keyOfMostUsedIndent) : undefined;
756
- const type = decoded?.type;
757
- const amount = decoded?.amount ?? 0;
758
- const indent = decoded ? makeIndentString(type, amount) : "";
759
- return {
760
- amount,
761
- type,
762
- indent
763
- };
764
- }
765
- // src/detect-newline.ts
766
- function detectNewline(string) {
767
- if (typeof string !== "string") {
768
- throw new TypeError("Expected a string");
769
- }
770
- const newlines = string.match(/\r?\n/g) || [];
771
- if (newlines.length === 0) {
772
- return;
773
- }
774
- const crlf = newlines.filter((newline) => newline === `\r
775
- `).length;
776
- const lf = newlines.length - crlf;
777
- return crlf > lf ? `\r
778
- ` : `
779
- `;
780
- }
781
- function detectNewlineGraceful(string) {
782
- return typeof string === "string" && detectNewline(string) || `
783
- `;
784
- }
785
-
786
- // src/utils.ts
787
- var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
788
- function slash(str) {
789
- return str.replace(/\\/g, "/");
790
- }
791
- function ensurePrefix(prefix, str) {
792
- if (!str.startsWith(prefix))
793
- return prefix + str;
794
- return str;
795
- }
796
- function ensureSuffix(suffix, str) {
797
- return str.endsWith(suffix) ? str : str + suffix;
798
- }
799
- function template(str, ...args) {
800
- return str.replace(/\{(\d+)\}/g, (match, key) => {
801
- const index = Number(key);
802
- return Number.isNaN(index) || args[index] === undefined ? match : args[index];
803
- });
804
- }
805
- function truncate(str, length, end = "...") {
806
- if (str.length <= length)
807
- return str;
808
- return str.slice(0, length - end.length) + end;
809
- }
810
- function random(size = 16, dict = urlAlphabet) {
811
- const len = dict.length;
812
- const g = globalThis;
813
- if (!g.crypto?.getRandomValues)
814
- throw new Error("[strings.random] crypto.getRandomValues is not available; cannot generate secure random string.");
815
- const bytes = new Uint8Array(size);
816
- g.crypto.getRandomValues(bytes);
817
- let id = "";
818
- for (let i = 0;i < size; i++)
819
- id += dict[(bytes[i] ?? 0) % len];
820
- return id;
821
- }
822
- function slug(str, options) {
823
- if (options)
824
- return slugify(str, options);
825
- return slugify(str, {
826
- lower: true,
827
- strict: true
828
- });
829
- }
830
-
831
- // src/macro.ts
832
- var Str = {
833
- slash(str) {
834
- return slash(str);
835
- },
836
- ensurePrefix(prefix, str) {
837
- return ensurePrefix(prefix, str);
838
- },
839
- ensureSuffix(suffix, str) {
840
- return ensureSuffix(suffix, str);
841
- },
842
- template(str, ...args) {
843
- return template(str, ...args);
844
- },
845
- truncate(str, length, end = "...") {
846
- return truncate(str, length, end);
847
- },
848
- random(length = 16, dict) {
849
- return random(length, dict);
850
- },
851
- capitalize(str) {
852
- return capitalize(str);
853
- },
854
- slug(str) {
855
- return slug(str);
856
- },
857
- detectIndent(str) {
858
- return detectIndent(str);
859
- },
860
- detectNewline(str) {
861
- return detectNewline(str);
862
- },
863
- camelCase(str) {
864
- return camelCase(str);
865
- },
866
- capitalCase(str) {
867
- return capitalCase(str);
868
- },
869
- constantCase(str) {
870
- return constantCase(str);
871
- },
872
- dotCase(str) {
873
- return dotCase(str);
874
- },
875
- noCase(str) {
876
- return noCase(str);
877
- },
878
- paramCase(str) {
879
- return paramCase(str);
880
- },
881
- pascalCase(str) {
882
- return pascalCase(str);
883
- },
884
- pathCase(str) {
885
- return pathCase(str);
886
- },
887
- sentenceCase(str) {
888
- return sentenceCase(str);
889
- },
890
- snakeCase(str) {
891
- return snakeCase(str);
892
- },
893
- titleCase(str) {
894
- return titleCase(str);
895
- },
896
- kebabCase(str) {
897
- return kebabCase(str);
898
- },
899
- plural(str) {
900
- return pluralize_default.plural(str);
901
- },
902
- singular(str) {
903
- return pluralize_default.singular(str);
904
- },
905
- isPlural(str) {
906
- return pluralize_default.isPlural(str);
907
- },
908
- isSingular(str) {
909
- return pluralize_default.isSingular(str);
910
- },
911
- addPluralRule(rule, repl) {
912
- pluralize_default.addPluralRule(rule, repl);
913
- },
914
- addSingularRule(rule, repl) {
915
- pluralize_default.addSingularRule(rule, repl);
916
- },
917
- addIrregularRule(single, plural2) {
918
- pluralize_default.addIrregularRule(single, plural2);
919
- },
920
- addUncountableRule(word) {
921
- pluralize_default.addUncountableRule(word);
922
- }
923
- };
924
- var str = Str;
925
-
926
- // src/validators.ts
927
- function isEmail(email) {
928
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
929
- return emailRegex.test(email);
930
- }
931
- function isStrongPassword(password) {
932
- if (password.length < 8)
933
- return false;
934
- const hasUpperCase = /[A-Z]/.test(password);
935
- const hasLowerCase = /[a-z]/.test(password);
936
- const hasNumber = /\d/.test(password);
937
- const hasSymbol = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password);
938
- return hasUpperCase && hasLowerCase && hasNumber && hasSymbol;
939
- }
940
- function isAlphanumeric(str2) {
941
- return /^[a-zA-Z0-9]+$/.test(str2);
942
- }
943
- function isURL(url) {
944
- try {
945
- const parsed = new URL(url);
946
- return parsed.protocol === "http:" || parsed.protocol === "https:";
947
- } catch {
948
- return false;
949
- }
950
- }
951
- function isMobilePhone(phoneNumber) {
952
- const phoneRegex = /^\+?[1-9]\d{6,14}$/;
953
- const cleaned = phoneNumber.replace(/[\s()-]/g, "");
954
- return phoneRegex.test(cleaned);
955
- }
956
- function isAlpha(str2) {
957
- return /^[a-zA-Z]+$/.test(str2);
958
- }
959
- function isPostalCode(zipCode) {
960
- const usZip = /^\d{5}(?:-\d{4})?$/;
961
- const ukPostcode = /^[A-Z]{1,2}\d{1,2}[A-Z]?\s?\d[A-Z]{2}$/i;
962
- const canadaPostcode = /^[A-Z]\d[A-Z]\s?\d[A-Z]\d$/i;
963
- const generic = /^[a-zA-Z0-9]{3,10}$/;
964
- return usZip.test(zipCode) || ukPostcode.test(zipCode) || canadaPostcode.test(zipCode) || generic.test(zipCode);
965
- }
966
- function isNumeric(str2) {
967
- return /^\d+$/.test(str2);
968
- }
969
- function isHexColor(color) {
970
- return /^#(?:[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(color);
971
- }
972
- function isHexadecimal(hex) {
973
- return /^[A-Fa-f0-9]+$/.test(hex);
974
- }
975
- function isBase64(base64) {
976
- try {
977
- return btoa(atob(base64)) === base64;
978
- } catch {
979
- return false;
980
- }
981
- }
982
- function isUUID(uuid) {
983
- const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
984
- return uuidRegex.test(uuid);
985
- }
986
- function isJSON(json) {
987
- try {
988
- JSON.parse(json);
989
- return true;
990
- } catch {
991
- return false;
992
- }
993
- }
994
- function isCreditCard(creditCard) {
995
- const cleaned = creditCard.replace(/[\s-]/g, "");
996
- if (!/^\d{13,19}$/.test(cleaned))
997
- return false;
998
- let sum = 0;
999
- let isEven = false;
1000
- for (let i = cleaned.length - 1;i >= 0; i--) {
1001
- let digit = parseInt(cleaned.charAt(i), 10);
1002
- if (isEven) {
1003
- digit *= 2;
1004
- if (digit > 9)
1005
- digit -= 9;
1006
- }
1007
- sum += digit;
1008
- isEven = !isEven;
1009
- }
1010
- return sum % 10 === 0;
1011
- }
1012
- function isISBN(isbn) {
1013
- const cleaned = isbn.replace(/[\s-]/g, "");
1014
- if (cleaned.length === 10) {
1015
- let sum = 0;
1016
- for (let i = 0;i < 9; i++) {
1017
- const digit = parseInt(cleaned.charAt(i), 10);
1018
- if (isNaN(digit))
1019
- return false;
1020
- sum += digit * (10 - i);
1021
- }
1022
- const checkChar = cleaned.charAt(9);
1023
- const checkDigit = checkChar === "X" ? 10 : parseInt(checkChar, 10);
1024
- if (isNaN(checkDigit) && checkChar !== "X")
1025
- return false;
1026
- sum += checkDigit;
1027
- return sum % 11 === 0;
1028
- }
1029
- if (cleaned.length === 13) {
1030
- let sum = 0;
1031
- for (let i = 0;i < 12; i++) {
1032
- const digit = parseInt(cleaned.charAt(i), 10);
1033
- if (isNaN(digit))
1034
- return false;
1035
- sum += digit * (i % 2 === 0 ? 1 : 3);
1036
- }
1037
- const checkDigit = parseInt(cleaned.charAt(12), 10);
1038
- if (isNaN(checkDigit))
1039
- return false;
1040
- return (10 - sum % 10) % 10 === checkDigit;
1041
- }
1042
- return false;
1043
- }
1044
- function isIP(ip) {
1045
- const ipv4Regex = /^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
1046
- if (ipv4Regex.test(ip))
1047
- return true;
1048
- const ipv6Regex = /^(?:(?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
1049
- return ipv6Regex.test(ip);
1050
- }
1051
- function isIPRange(ip) {
1052
- const parts = ip.split("/");
1053
- if (parts.length !== 2)
1054
- return false;
1055
- const [address, cidr] = parts;
1056
- if (address === undefined || cidr === undefined)
1057
- return false;
1058
- const cidrNum = parseInt(cidr, 10);
1059
- if (!isIP(address))
1060
- return false;
1061
- if (address.includes(":")) {
1062
- return cidrNum >= 0 && cidrNum <= 128;
1063
- } else {
1064
- return cidrNum >= 0 && cidrNum <= 32;
1065
- }
1066
- }
1067
- function isMACAddress(macAddress) {
1068
- const macRegex = /^(?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2})$/;
1069
- return macRegex.test(macAddress);
1070
- }
1071
- function isLatLong(latlong) {
1072
- const parts = latlong.split(",");
1073
- if (parts.length !== 2)
1074
- return false;
1075
- const lat = parseFloat((parts[0] ?? "").trim());
1076
- const long = parseFloat((parts[1] ?? "").trim());
1077
- return !isNaN(lat) && !isNaN(long) && lat >= -90 && lat <= 90 && long >= -180 && long <= 180;
1078
- }
1079
- function isCurrency(currency) {
1080
- const currencyRegex = /^[$\u00A3\u20AC\u00A5]?\d{1,3}(?:,?\d{3})*(?:\.\d{2})?$/;
1081
- return currencyRegex.test(currency.trim());
1082
- }
1083
- function isDataURI(dataURI) {
1084
- const dataURIRegex = /^data:(?:[a-z]+\/[a-z0-9-+.]+(?:;[a-z-]+=[a-z0-9-]+)*)?;base64,(?:[a-z0-9+/]+=*)/i;
1085
- return dataURIRegex.test(dataURI) || /^data:,/.test(dataURI);
1086
- }
1087
- function isMimeType(mimeType) {
1088
- const mimeTypeRegex = /^[a-z]+\/[a-z0-9\-+.]+$/i;
1089
- return mimeTypeRegex.test(mimeType);
1090
- }
1091
- function isJWT(jwt) {
1092
- const parts = jwt.split(".");
1093
- if (parts.length !== 3)
1094
- return false;
1095
- try {
1096
- parts.forEach((part) => {
1097
- atob(part.replace(/-/g, "+").replace(/_/g, "/"));
1098
- });
1099
- return true;
1100
- } catch {
1101
- return false;
1102
- }
1103
- }
1104
- function isAscii(ascii) {
1105
- return /^[\x00-\x7F]*$/.test(ascii);
1106
- }
1107
- function isBase32(base32) {
1108
- return /^[A-Z2-7]+=*$/.test(base32.toUpperCase());
1109
- }
1110
- function isByteLength(str2, options) {
1111
- const min = options?.min ?? 0;
1112
- const max = options?.max ?? Infinity;
1113
- const byteLength = new TextEncoder().encode(str2).length;
1114
- return byteLength >= min && byteLength <= max;
1115
- }
1116
- function isFQDN(fqdn) {
1117
- const fqdnRegex = /^(?=.{1,253}$)(?:(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,}$/;
1118
- return fqdnRegex.test(fqdn);
1119
- }
1120
- function isFullWidth(fullWidth) {
1121
- return /^[\uFF00-\uFFEF]+$/.test(fullWidth);
1122
- }
1123
- function isHalfWidth(halfWidth) {
1124
- return /^[\u0020-\u007E\uFF61-\uFF9F]+$/.test(halfWidth);
1125
- }
1126
- function isHash(hash, algorithm) {
1127
- const hashLengths = {
1128
- md5: 32,
1129
- sha1: 40,
1130
- sha256: 64,
1131
- sha384: 96,
1132
- sha512: 128
1133
- };
1134
- const expectedLength = hashLengths[algorithm];
1135
- if (!expectedLength)
1136
- return false;
1137
- return hash.length === expectedLength && /^[a-f0-9]+$/i.test(hash);
1138
- }
1139
- function isHSL(hsl) {
1140
- const hslRegex = /^hsl\(?:\s*(?:\d+)\s*,\s*(?:\d+(?:\.\d+)?%)\s*,\s*(?:\d+(?:\.\d+)?%)\s*\)$/;
1141
- return hslRegex.test(hsl);
1142
- }
1143
- function isIBAN(iban) {
1144
- const cleaned = iban.replace(/\s/g, "").toUpperCase();
1145
- if (!/^[A-Z]{2}\d{2}[A-Z0-9]+$/.test(cleaned))
1146
- return false;
1147
- if (cleaned.length < 15 || cleaned.length > 34)
1148
- return false;
1149
- const rearranged = cleaned.slice(4) + cleaned.slice(0, 4);
1150
- const digits = rearranged.split("").map((char) => {
1151
- const code = char.charCodeAt(0);
1152
- return code >= 65 && code <= 90 ? (code - 55).toString() : char;
1153
- }).join("");
1154
- let remainder = digits.slice(0, 2);
1155
- for (let i = 2;i < digits.length; i += 7) {
1156
- remainder = (parseInt(remainder + digits.slice(i, i + 7), 10) % 97).toString();
1157
- }
1158
- return parseInt(remainder, 10) === 1;
1159
- }
1160
- function isIdentityCard(identityCard) {
1161
- const cleaned = identityCard.replace(/[\s-]/g, "");
1162
- return /^[A-Z0-9]{5,20}$/i.test(cleaned);
1163
- }
1164
- function isISIN(isin) {
1165
- if (!/^[A-Z]{2}[A-Z0-9]{9}\d$/.test(isin))
1166
- return false;
1167
- const digits = isin.split("").map((char) => {
1168
- const code = char.charCodeAt(0);
1169
- return code >= 65 && code <= 90 ? (code - 55).toString() : char;
1170
- }).join("");
1171
- let sum = 0;
1172
- let isEven = true;
1173
- for (let i = digits.length - 1;i >= 0; i--) {
1174
- let digit = parseInt(digits.charAt(i), 10);
1175
- if (isEven) {
1176
- digit *= 2;
1177
- if (digit > 9)
1178
- digit -= 9;
1179
- }
1180
- sum += digit;
1181
- isEven = !isEven;
1182
- }
1183
- return sum % 10 === 0;
1184
- }
1185
- function isISO8601(iso8601) {
1186
- const iso8601Regex = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|[+-]\d{2}:\d{2})?)?$/;
1187
- if (!iso8601Regex.test(iso8601))
1188
- return false;
1189
- try {
1190
- const date = new Date(iso8601);
1191
- return !isNaN(date.getTime());
1192
- } catch {
1193
- return false;
1194
- }
1195
- }
1196
- function isISRC(isrc) {
1197
- return /^[A-Z]{2}[A-Z0-9]{3}\d{2}\d{5}$/.test(isrc.replace(/-/g, ""));
1198
- }
1199
- function isISSN(issn) {
1200
- const cleaned = issn.replace(/[\s-]/g, "");
1201
- if (!/^\d{7}[\dX]$/.test(cleaned))
1202
- return false;
1203
- let sum = 0;
1204
- for (let i = 0;i < 7; i++) {
1205
- sum += parseInt(cleaned.charAt(i), 10) * (8 - i);
1206
- }
1207
- const checkChar = cleaned.charAt(7);
1208
- const checkDigit = checkChar === "X" ? 10 : parseInt(checkChar, 10);
1209
- sum += checkDigit;
1210
- return sum % 11 === 0;
1211
- }
1212
- function isISO31661Alpha2(iso31661Alpha2) {
1213
- return /^[A-Z]{2}$/.test(iso31661Alpha2);
1214
- }
1215
- function isISO31661Alpha3(iso31661Alpha3) {
1216
- return /^[A-Z]{3}$/.test(iso31661Alpha3);
1217
- }
1218
- function validateUsername(username) {
1219
- return isAlphanumeric(username);
1220
- }
1221
- function isLatitude(latitude) {
1222
- const lat = parseFloat(latitude);
1223
- return !isNaN(lat) && lat >= -90 && lat <= 90;
1224
- }
1225
- function isLongitude(longitude) {
1226
- const long = parseFloat(longitude);
1227
- return !isNaN(long) && long >= -180 && long <= 180;
1228
- }
1229
- export {
1230
- validateUsername,
1231
- urlAlphabet,
1232
- truncate,
1233
- trainCase,
1234
- toString,
1235
- titleCase,
1236
- template,
1237
- swapCase,
1238
- string2 as string,
1239
- str,
1240
- spongeCase,
1241
- splitSeparateNumbers,
1242
- split,
1243
- snakeCase,
1244
- slugify,
1245
- slug,
1246
- slash,
1247
- singular,
1248
- sentenceCase,
1249
- random,
1250
- pluralize,
1251
- plural,
1252
- pathCase,
1253
- pascalSnakeCase,
1254
- pascalCase,
1255
- paramCase,
1256
- noCase,
1257
- mask,
1258
- lowercase,
1259
- kebabCase,
1260
- isUUID,
1261
- isURL,
1262
- isStrongPassword,
1263
- isPostalCode,
1264
- isNumeric,
1265
- isMobilePhone,
1266
- isMimeType,
1267
- isMACAddress,
1268
- isLongitude,
1269
- isLatitude,
1270
- isLatLong,
1271
- isJWT,
1272
- isJSON,
1273
- isIdentityCard,
1274
- isISSN,
1275
- isISRC,
1276
- isISO8601,
1277
- isISO31661Alpha3,
1278
- isISO31661Alpha2,
1279
- isISIN,
1280
- isISBN,
1281
- isIPRange,
1282
- isIP,
1283
- isIBAN,
1284
- isHexadecimal,
1285
- isHexColor,
1286
- isHash,
1287
- isHalfWidth,
1288
- isHSL,
1289
- isFullWidth,
1290
- isFQDN,
1291
- isEmail,
1292
- isDataURI,
1293
- isCurrency,
1294
- isCreditCard,
1295
- isByteLength,
1296
- isBase64,
1297
- isBase32,
1298
- isAscii,
1299
- isAlphanumeric,
1300
- isAlpha,
1301
- extendCharMap,
1302
- ensureSuffix,
1303
- ensurePrefix,
1304
- dotCase,
1305
- detectNewlineGraceful,
1306
- detectNewline,
1307
- detectIndent,
1308
- constantCase,
1309
- capitalize,
1310
- capitalCase,
1311
- camelCase,
1312
- WORD_SEPARATORS,
1313
- TITLE_TERMINATORS,
1314
- Str,
1315
- SMALL_WORDS,
1316
- SENTENCE_TERMINATORS
1317
- };
1
+ export * from "./string";
2
+ export * as string from "./string";