@stacksjs/strings 0.70.56 → 0.70.58

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/is.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * String validation utilities
3
+ * Re-exports from native validators
4
+ */
5
+ export * from './validators';
package/dist/is.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./validators";
package/dist/macro.js ADDED
@@ -0,0 +1,95 @@
1
+ import * as c from "./case";
2
+ import p from "./pluralize";
3
+ import * as u from "./utils";
4
+ export const Str = {
5
+ slash(str) {
6
+ return u.slash(str);
7
+ },
8
+ ensurePrefix(prefix, str) {
9
+ return u.ensurePrefix(prefix, str);
10
+ },
11
+ ensureSuffix(suffix, str) {
12
+ return u.ensureSuffix(suffix, str);
13
+ },
14
+ template(str, ...args) {
15
+ return u.template(str, ...args);
16
+ },
17
+ truncate(str, length, end = "...") {
18
+ return u.truncate(str, length, end);
19
+ },
20
+ random(length = 16, dict) {
21
+ return u.random(length, dict);
22
+ },
23
+ capitalize(str) {
24
+ return c.capitalize(str);
25
+ },
26
+ slug(str) {
27
+ return u.slug(str);
28
+ },
29
+ detectIndent(str) {
30
+ return u.detectIndent(str);
31
+ },
32
+ detectNewline(str) {
33
+ return u.detectNewline(str);
34
+ },
35
+ camelCase(str) {
36
+ return c.camelCase(str);
37
+ },
38
+ capitalCase(str) {
39
+ return c.capitalCase(str);
40
+ },
41
+ constantCase(str) {
42
+ return c.constantCase(str);
43
+ },
44
+ dotCase(str) {
45
+ return c.dotCase(str);
46
+ },
47
+ noCase(str) {
48
+ return c.noCase(str);
49
+ },
50
+ paramCase(str) {
51
+ return c.paramCase(str);
52
+ },
53
+ pascalCase(str) {
54
+ return c.pascalCase(str);
55
+ },
56
+ pathCase(str) {
57
+ return c.pathCase(str);
58
+ },
59
+ sentenceCase(str) {
60
+ return c.sentenceCase(str);
61
+ },
62
+ snakeCase(str) {
63
+ return c.snakeCase(str);
64
+ },
65
+ titleCase(str) {
66
+ return c.titleCase(str);
67
+ },
68
+ kebabCase(str) {
69
+ return c.kebabCase(str);
70
+ },
71
+ plural(str) {
72
+ return p.plural(str);
73
+ },
74
+ singular(str) {
75
+ return p.singular(str);
76
+ },
77
+ isPlural(str) {
78
+ return p.isPlural(str);
79
+ },
80
+ isSingular(str) {
81
+ return p.isSingular(str);
82
+ },
83
+ addPluralRule(rule, repl) {
84
+ p.addPluralRule(rule, repl);
85
+ },
86
+ addSingularRule(rule, repl) {
87
+ p.addSingularRule(rule, repl);
88
+ },
89
+ addIrregularRule(single, plural) {
90
+ p.addIrregularRule(single, plural);
91
+ },
92
+ addUncountableRule(word) {
93
+ p.addUncountableRule(word);
94
+ }
95
+ }, str = Str;
@@ -0,0 +1,310 @@
1
+ const pluralRules = [], singularRules = [], uncountables = {}, irregularPlurals = {}, irregularSingles = {};
2
+ function sanitizeRule(rule) {
3
+ return typeof rule === "string" ? new RegExp(`^${rule}$`, "i") : rule;
4
+ }
5
+ function restoreCase(word, token) {
6
+ if (word === token)
7
+ return token;
8
+ if (word === word.toLowerCase())
9
+ return token.toLowerCase();
10
+ if (word === word.toUpperCase())
11
+ return token.toUpperCase();
12
+ const firstChar = word[0];
13
+ if (firstChar !== void 0 && firstChar === firstChar.toUpperCase())
14
+ return token.charAt(0).toUpperCase() + token.slice(1).toLowerCase();
15
+ return token.toLowerCase();
16
+ }
17
+ function interpolate(str, ...args) {
18
+ return str.replace(/\$(\d{1,2})/g, (_match, index) => args[Number(index)] || "");
19
+ }
20
+ function replace(word, rule) {
21
+ return word.replace(rule[0], (...matchArgs) => {
22
+ const result = interpolate(rule[1], ...matchArgs);
23
+ if (matchArgs[0] === "")
24
+ return restoreCase(word[matchArgs[matchArgs.length - 2] - 1] ?? "", result);
25
+ return restoreCase(matchArgs[0], result);
26
+ });
27
+ }
28
+ function sanitizeWord(token, word, rules) {
29
+ if (!token.length || uncountables[token])
30
+ return word;
31
+ for (let i = rules.length - 1;i >= 0; i--) {
32
+ const rule = rules[i];
33
+ if (rule && rule[0].test(word))
34
+ return replace(word, rule);
35
+ }
36
+ return word;
37
+ }
38
+ function replaceWord(replaceMap, keepMap, rules) {
39
+ return (word) => {
40
+ const token = word.toLowerCase();
41
+ if (keepMap[token])
42
+ return restoreCase(word, token);
43
+ if (replaceMap[token])
44
+ return restoreCase(word, replaceMap[token]);
45
+ return sanitizeWord(token, word, rules);
46
+ };
47
+ }
48
+ function checkWord(replaceMap, keepMap, rules) {
49
+ return (word) => {
50
+ const token = word.toLowerCase();
51
+ if (keepMap[token])
52
+ return !0;
53
+ if (replaceMap[token])
54
+ return !1;
55
+ return sanitizeWord(token, token, rules) === token;
56
+ };
57
+ }
58
+ export const pluralize = (word, options = {}) => {
59
+ const { count = 2, inclusive = !1 } = options;
60
+ if (typeof word !== "string")
61
+ throw TypeError("Word must be a string");
62
+ const pluralized = count === 1 ? pluralize.singular(word) : pluralize.plural(word);
63
+ return inclusive ? `${count} ${pluralized}` : pluralized;
64
+ }, singular = (word) => {
65
+ return pluralize.singular(word);
66
+ }, plural = (word, count = 2) => {
67
+ return pluralize(word, { count });
68
+ };
69
+ pluralize.plural = replaceWord(irregularSingles, irregularPlurals, pluralRules);
70
+ pluralize.isPlural = checkWord(irregularSingles, irregularPlurals, pluralRules);
71
+ pluralize.singular = replaceWord(irregularPlurals, irregularSingles, singularRules);
72
+ pluralize.isSingular = checkWord(irregularPlurals, irregularSingles, singularRules);
73
+ pluralize.addPluralRule = (rule, replacement) => {
74
+ pluralRules.push([sanitizeRule(rule), replacement]);
75
+ };
76
+ pluralize.addSingularRule = (rule, replacement) => {
77
+ singularRules.push([sanitizeRule(rule), replacement]);
78
+ };
79
+ pluralize.addUncountableRule = (word) => {
80
+ if (typeof word === "string") {
81
+ uncountables[word.toLowerCase()] = !0;
82
+ return;
83
+ }
84
+ pluralize.addPluralRule(word, "$0");
85
+ pluralize.addSingularRule(word, "$0");
86
+ };
87
+ pluralize.addIrregularRule = (single, plural) => {
88
+ const lowerPlural = plural.toLowerCase(), lowerSingle = single.toLowerCase();
89
+ irregularSingles[lowerSingle] = lowerPlural;
90
+ irregularPlurals[lowerPlural] = lowerSingle;
91
+ };
92
+ [
93
+ ["I", "we"],
94
+ ["me", "us"],
95
+ ["he", "they"],
96
+ ["she", "they"],
97
+ ["them", "them"],
98
+ ["myself", "ourselves"],
99
+ ["yourself", "yourselves"],
100
+ ["itself", "themselves"],
101
+ ["herself", "themselves"],
102
+ ["himself", "themselves"],
103
+ ["themself", "themselves"],
104
+ ["is", "are"],
105
+ ["was", "were"],
106
+ ["has", "have"],
107
+ ["this", "these"],
108
+ ["that", "those"],
109
+ ["my", "our"],
110
+ ["its", "their"],
111
+ ["his", "their"],
112
+ ["her", "their"],
113
+ ["echo", "echoes"],
114
+ ["dingo", "dingoes"],
115
+ ["volcano", "volcanoes"],
116
+ ["tornado", "tornadoes"],
117
+ ["torpedo", "torpedoes"],
118
+ ["genus", "genera"],
119
+ ["viscus", "viscera"],
120
+ ["stigma", "stigmata"],
121
+ ["stoma", "stomata"],
122
+ ["dogma", "dogmata"],
123
+ ["lemma", "lemmata"],
124
+ ["schema", "schemata"],
125
+ ["anathema", "anathemata"],
126
+ ["ox", "oxen"],
127
+ ["axe", "axes"],
128
+ ["die", "dice"],
129
+ ["yes", "yeses"],
130
+ ["foot", "feet"],
131
+ ["eave", "eaves"],
132
+ ["goose", "geese"],
133
+ ["tooth", "teeth"],
134
+ ["quiz", "quizzes"],
135
+ ["human", "humans"],
136
+ ["proof", "proofs"],
137
+ ["carve", "carves"],
138
+ ["valve", "valves"],
139
+ ["looey", "looies"],
140
+ ["thief", "thieves"],
141
+ ["groove", "grooves"],
142
+ ["pickaxe", "pickaxes"],
143
+ ["passerby", "passersby"],
144
+ ["canvas", "canvases"]
145
+ ].forEach(([single, plural]) => pluralize.addIrregularRule(single ?? "", plural ?? ""));
146
+ [
147
+ [/s?$/i, "s"],
148
+ [/[^\x20-\x7F]$/, "$0"],
149
+ [/([^aeiou]ese)$/i, "$1"],
150
+ [/(ax|test)is$/i, "$1es"],
151
+ [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, "$1es"],
152
+ [/(e[mn]u)s?$/i, "$1s"],
153
+ [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, "$1"],
154
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1i"],
155
+ [/(alumn|alg|vertebr)(?:a|ae)$/i, "$1ae"],
156
+ [/(seraph|cherub)(?:im)?$/i, "$1im"],
157
+ [/(her|at|gr)o$/i, "$1oes"],
158
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, "$1a"],
159
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, "$1a"],
160
+ [/sis$/i, "ses"],
161
+ [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, "$1$2ves"],
162
+ [/([^aeiouy]|qu)y$/i, "$1ies"],
163
+ [/([^ch][ieo][ln])ey$/i, "$1ies"],
164
+ [/(x|ch|ss|sh|zz)$/i, "$1es"],
165
+ [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, "$1ices"],
166
+ [/\b((?:tit)?m|l)(?:ice|ouse)$/i, "$1ice"],
167
+ [/(pe)(?:rson|ople)$/i, "$1ople"],
168
+ [/(child)(?:ren)?$/i, "$1ren"],
169
+ [/eaux$/i, "$0"],
170
+ [/m[ae]n$/i, "men"],
171
+ ["thou", "you"]
172
+ ].forEach(([rule, replacement]) => {
173
+ if (rule === void 0)
174
+ return;
175
+ pluralize.addPluralRule(rule, replacement);
176
+ });
177
+ [
178
+ [/s$/i, ""],
179
+ [/(ss)$/i, "$1"],
180
+ [/(wi|kni|(?:after|half|high|low|mid|non|night|\W|^)li)ves$/i, "$1fe"],
181
+ [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, "$1f"],
182
+ [/ies$/i, "y"],
183
+ [/(dg|ss|ois|lk|ok|wn|mb|th|ch|ec|oal|is|ck|ix|sser|ts|wb)ies$/i, "$1ie"],
184
+ [/\b(l|(?:neck|cross|hog|aun)?t|coll|faer|food|gen|goon|group|hipp|junk|vegg|(?:pork)?p|charl|calor|cut)ies$/i, "$1ie"],
185
+ [/\b(mon|smil)ies$/i, "$1ey"],
186
+ [/\b((?:tit)?m|l)ice$/i, "$1ouse"],
187
+ [/(seraph|cherub)im$/i, "$1"],
188
+ [/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, "$1"],
189
+ [/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, "$1sis"],
190
+ [/(movie|twelve|abuse|e[mn]u)s$/i, "$1"],
191
+ [/(test)(?:is|es)$/i, "$1is"],
192
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1us"],
193
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, "$1um"],
194
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, "$1on"],
195
+ [/(alumn|alg|vertebr)ae$/i, "$1a"],
196
+ [/(cod|mur|sil|vert|ind)ices$/i, "$1ex"],
197
+ [/(matr|append)ices$/i, "$1ix"],
198
+ [/(pe)(rson|ople)$/i, "$1rson"],
199
+ [/(child)ren$/i, "$1"],
200
+ [/(eau)x?$/i, "$1"],
201
+ [/men$/i, "man"]
202
+ ].forEach(([rule, replacement]) => {
203
+ if (rule === void 0)
204
+ return;
205
+ pluralize.addSingularRule(rule, replacement);
206
+ });
207
+ [
208
+ "adulthood",
209
+ "advice",
210
+ "agenda",
211
+ "aid",
212
+ "aircraft",
213
+ "alcohol",
214
+ "ammo",
215
+ "analytics",
216
+ "anime",
217
+ "athletics",
218
+ "audio",
219
+ "bison",
220
+ "blood",
221
+ "bream",
222
+ "buffalo",
223
+ "butter",
224
+ "carp",
225
+ "cash",
226
+ "chassis",
227
+ "chess",
228
+ "clothing",
229
+ "cod",
230
+ "commerce",
231
+ "cooperation",
232
+ "corps",
233
+ "debris",
234
+ "diabetes",
235
+ "digestion",
236
+ "elk",
237
+ "energy",
238
+ "equipment",
239
+ "excretion",
240
+ "expertise",
241
+ "firmware",
242
+ "flounder",
243
+ "fun",
244
+ "gallows",
245
+ "garbage",
246
+ "graffiti",
247
+ "hardware",
248
+ "headquarters",
249
+ "health",
250
+ "herpes",
251
+ "highjinks",
252
+ "homework",
253
+ "housework",
254
+ "information",
255
+ "jeans",
256
+ "justice",
257
+ "kudos",
258
+ "labour",
259
+ "literature",
260
+ "machinery",
261
+ "mackerel",
262
+ "mail",
263
+ "media",
264
+ "mews",
265
+ "moose",
266
+ "music",
267
+ "mud",
268
+ "manga",
269
+ "news",
270
+ "only",
271
+ "personnel",
272
+ "pike",
273
+ "plankton",
274
+ "pliers",
275
+ "police",
276
+ "pollution",
277
+ "premises",
278
+ "rain",
279
+ "research",
280
+ "rice",
281
+ "salmon",
282
+ "scissors",
283
+ "series",
284
+ "sewage",
285
+ "shambles",
286
+ "shrimp",
287
+ "software",
288
+ "staff",
289
+ "swine",
290
+ "tennis",
291
+ "traffic",
292
+ "transportation",
293
+ "trout",
294
+ "tuna",
295
+ "wealth",
296
+ "welfare",
297
+ "whiting",
298
+ "wildebeest",
299
+ "wildlife",
300
+ "you",
301
+ /pok[e\u00E9]mon$/i,
302
+ /[^aeiou]ese$/i,
303
+ /deer$/i,
304
+ /fish$/i,
305
+ /measles$/i,
306
+ /o[iu]s$/i,
307
+ /pox$/i,
308
+ /sheep$/i
309
+ ].forEach(pluralize.addUncountableRule);
310
+ export default pluralize;
package/dist/slug.js ADDED
@@ -0,0 +1,21 @@
1
+ const 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"}'), 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"}}');
2
+ export function slugify(string, options = {}) {
3
+ if (typeof string !== "string")
4
+ throw TypeError("slugify: string argument expected");
5
+ const {
6
+ replacement = "-",
7
+ remove = /[^\w\s$*+~.()'"!\-:@]+/g,
8
+ lower = !1,
9
+ strict = !1,
10
+ locale,
11
+ trim = !0
12
+ } = options, localeMap = locale ? locales[locale] || {} : {}, slug = string.normalize().split("").reduce((result, ch) => {
13
+ let appendChar = localeMap[ch] ?? charMap[ch] ?? ch;
14
+ appendChar = appendChar === replacement ? " " : appendChar;
15
+ return result + appendChar;
16
+ }, "").replace(remove, ""), strictSlug = strict ? slug.replace(/[^A-Z0-9\s]/gi, "") : slug, finalSlug = (trim ? strictSlug.trim() : strictSlug).replace(/\s+/g, replacement);
17
+ return lower ? finalSlug.toLowerCase() : finalSlug;
18
+ }
19
+ export function extendCharMap(customMap) {
20
+ Object.assign(charMap, customMap);
21
+ }
@@ -0,0 +1,6 @@
1
+ export function spongeCase(input, locale) {
2
+ let result = "";
3
+ for (const char of input)
4
+ result += Math.random() > 0.5 ? char.toLocaleUpperCase(locale) : char.toLocaleLowerCase(locale);
5
+ return result;
6
+ }
package/dist/string.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./case";
2
+ export * from "./helpers";
3
+ export * from "./macro";
4
+ export * from "./pluralize";
5
+ export * from "./slug";
6
+ export * from "./utils";
7
+ export * from "./validators";
@@ -0,0 +1,8 @@
1
+ export function swapCase(input, locale) {
2
+ let result = "";
3
+ for (const char of input) {
4
+ const lower = char.toLocaleLowerCase(locale);
5
+ result += char === lower ? char.toLocaleUpperCase(locale) : lower;
6
+ }
7
+ return result;
8
+ }
@@ -0,0 +1,108 @@
1
+ const TOKENS = /(\S+)|(.)/g, IS_SPECIAL_CASE = /[.#][\p{L}\p{N}]/u, IS_MANUAL_CASE = /\p{Ll}(?=\p{Lu})/u, ALPHANUMERIC_PATTERN = /[\p{L}\p{N}]+/gu, IS_ACRONYM = /^(\P{L})*(?:\p{L}\.){2,}(\P{L})*$/u;
2
+ export const WORD_SEPARATORS = new Set(["\u2014", "\u2013", "-", "\u2015", "/"]), SENTENCE_TERMINATORS = new Set([".", "!", "?"]), TITLE_TERMINATORS = new Set([
3
+ ...SENTENCE_TERMINATORS,
4
+ ":",
5
+ '"',
6
+ "'",
7
+ "\u201D"
8
+ ]), SMALL_WORDS = new Set([
9
+ "a",
10
+ "an",
11
+ "and",
12
+ "as",
13
+ "at",
14
+ "because",
15
+ "but",
16
+ "by",
17
+ "en",
18
+ "for",
19
+ "if",
20
+ "in",
21
+ "neither",
22
+ "nor",
23
+ "of",
24
+ "on",
25
+ "only",
26
+ "or",
27
+ "over",
28
+ "per",
29
+ "so",
30
+ "some",
31
+ "than",
32
+ "that",
33
+ "the",
34
+ "to",
35
+ "up",
36
+ "upon",
37
+ "v",
38
+ "versus",
39
+ "via",
40
+ "vs",
41
+ "when",
42
+ "with",
43
+ "without",
44
+ "yet"
45
+ ]);
46
+ export function titleCase(input, options = {}) {
47
+ const {
48
+ locale = void 0,
49
+ sentenceCase = !1,
50
+ sentenceTerminators = SENTENCE_TERMINATORS,
51
+ titleTerminators = TITLE_TERMINATORS,
52
+ smallWords = SMALL_WORDS,
53
+ wordSeparators = WORD_SEPARATORS
54
+ } = typeof options === "string" || Array.isArray(options) ? { locale: options } : options, terminators = sentenceCase ? sentenceTerminators : titleTerminators;
55
+ let result = "", isNewSentence = !0;
56
+ for (const m of input.matchAll(TOKENS)) {
57
+ const { 1: token, 2: whiteSpace, index = 0 } = m;
58
+ if (whiteSpace) {
59
+ result += whiteSpace;
60
+ continue;
61
+ }
62
+ if (token === void 0)
63
+ continue;
64
+ if (IS_SPECIAL_CASE.test(token)) {
65
+ const acronym = token.match(IS_ACRONYM);
66
+ if (acronym) {
67
+ const [_, prefix = "", suffix = ""] = acronym;
68
+ result += sentenceCase && !isNewSentence ? token : upperAt(token, prefix.length, locale);
69
+ isNewSentence = terminators.has(suffix.charAt(0));
70
+ continue;
71
+ }
72
+ result += token;
73
+ isNewSentence = terminators.has(token.charAt(token.length - 1));
74
+ } else {
75
+ const matches = Array.from(token.matchAll(ALPHANUMERIC_PATTERN));
76
+ let value = token, isSentenceEnd = !1;
77
+ for (let i = 0;i < matches.length; i++) {
78
+ const match = matches[i];
79
+ if (!match)
80
+ continue;
81
+ const { 0: word, index: wordIndex = 0 } = match, nextChar = token.charAt(wordIndex + word.length);
82
+ isSentenceEnd = terminators.has(nextChar);
83
+ if (isNewSentence)
84
+ isNewSentence = !1;
85
+ else if (sentenceCase || IS_MANUAL_CASE.test(word))
86
+ continue;
87
+ else if (matches.length === 1) {
88
+ if (smallWords.has(word)) {
89
+ if (index + token.length !== input.length && !isSentenceEnd)
90
+ continue;
91
+ }
92
+ } else if (i > 0) {
93
+ if (!wordSeparators.has(token.charAt(wordIndex - 1)))
94
+ continue;
95
+ if (smallWords.has(word) && wordSeparators.has(nextChar))
96
+ continue;
97
+ }
98
+ value = upperAt(value, wordIndex, locale);
99
+ }
100
+ result += value;
101
+ isNewSentence = isSentenceEnd || terminators.has(token.charAt(token.length - 1));
102
+ }
103
+ }
104
+ return result;
105
+ }
106
+ function upperAt(input, index, locale) {
107
+ return input.slice(0, index) + input.charAt(index).toLocaleUpperCase(locale) + input.slice(index + 1);
108
+ }
package/dist/utils.js ADDED
@@ -0,0 +1,46 @@
1
+ import { slugify } from "./slug";
2
+ export const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
3
+ export function slash(str) {
4
+ return str.replace(/\\/g, "/");
5
+ }
6
+ export function ensurePrefix(prefix, str) {
7
+ if (!str.startsWith(prefix))
8
+ return prefix + str;
9
+ return str;
10
+ }
11
+ export function ensureSuffix(suffix, str) {
12
+ return str.endsWith(suffix) ? str : str + suffix;
13
+ }
14
+ export function template(str, ...args) {
15
+ return str.replace(/\{(\d+)\}/g, (match, key) => {
16
+ const index = Number(key);
17
+ return Number.isNaN(index) || args[index] === void 0 ? match : args[index];
18
+ });
19
+ }
20
+ export function truncate(str, length, end = "...") {
21
+ if (str.length <= length)
22
+ return str;
23
+ return str.slice(0, length - end.length) + end;
24
+ }
25
+ export function random(size = 16, dict = urlAlphabet) {
26
+ const len = dict.length, g = globalThis;
27
+ if (!g.crypto?.getRandomValues)
28
+ throw Error("[strings.random] crypto.getRandomValues is not available; cannot generate secure random string.");
29
+ const bytes = new Uint8Array(size);
30
+ g.crypto.getRandomValues(bytes);
31
+ let id = "";
32
+ for (let i = 0;i < size; i++)
33
+ id += dict[(bytes[i] ?? 0) % len];
34
+ return id;
35
+ }
36
+ export function slug(str, options) {
37
+ if (options)
38
+ return slugify(str, options);
39
+ return slugify(str, {
40
+ lower: !0,
41
+ strict: !0
42
+ });
43
+ }
44
+
45
+ export * from "./detect-indent";
46
+ export * from "./detect-newline";