@samline/string 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  // src/core/words.ts
4
4
  var words = (input) => {
5
5
  if (typeof input !== "string" || input === "") return [];
6
- return input.replace(/([\p{Ll}\p{N}])(\p{Lu})/gu, "$1 $2").replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu, "$1 $2").split(/[^\p{L}\p{N}]+/u).filter(Boolean);
6
+ return input.replace(/([\p{Ll}\p{N}]\p{M}*)(\p{Lu})/gu, "$1 $2").replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu, "$1 $2").split(/[^\p{L}\p{M}\p{N}]+/u).filter(Boolean);
7
7
  };
8
8
 
9
9
  // src/core/accents.ts
@@ -27,7 +27,105 @@ var TRANSLITERATIONS = {
27
27
  \u0131: "i"
28
28
  };
29
29
  var SPECIAL = new RegExp(`[${Object.keys(TRANSLITERATIONS).join("")}]`, "g");
30
- var removeAccents = (input) => String(input ?? "").normalize("NFKD").replace(/\p{M}+/gu, "").replace(SPECIAL, (char) => TRANSLITERATIONS[char] ?? char);
30
+ var escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
31
+ var patterns = /* @__PURE__ */ new WeakMap();
32
+ var patternFor = (map) => {
33
+ if (patterns.has(map)) return patterns.get(map);
34
+ const keys = Object.keys(map).filter(Boolean).sort((a, b) => b.length - a.length);
35
+ const pattern = keys.length ? new RegExp(keys.map(escape).join("|"), "gu") : null;
36
+ patterns.set(map, pattern);
37
+ return pattern;
38
+ };
39
+ var applyMap = (value, map) => {
40
+ const pattern = patternFor(map);
41
+ return pattern ? value.replace(pattern, (key) => map[key] ?? key) : value;
42
+ };
43
+ var removeAccents = (input, { charMap } = {}) => {
44
+ let value = String(input ?? "");
45
+ if (charMap) value = applyMap(value, charMap);
46
+ value = value.normalize("NFKD").replace(/\p{M}+/gu, "").replace(SPECIAL, (char) => TRANSLITERATIONS[char] ?? char);
47
+ return charMap ? applyMap(value, charMap) : value;
48
+ };
49
+
50
+ // src/core/charmaps.ts
51
+ var withUpper = (lower2) => {
52
+ const map = { ...lower2 };
53
+ for (const [char, latin] of Object.entries(lower2)) {
54
+ const upper2 = char.toUpperCase();
55
+ if (upper2 !== char && !(upper2 in map))
56
+ map[upper2] = latin.charAt(0).toUpperCase() + latin.slice(1);
57
+ }
58
+ return map;
59
+ };
60
+ var CYRILLIC = withUpper({
61
+ \u0430: "a",
62
+ \u0431: "b",
63
+ \u0432: "v",
64
+ \u0433: "g",
65
+ \u0491: "g",
66
+ \u0434: "d",
67
+ \u0435: "e",
68
+ \u0451: "yo",
69
+ \u0454: "ye",
70
+ \u0436: "zh",
71
+ \u0437: "z",
72
+ \u0438: "i",
73
+ \u0456: "i",
74
+ \u0457: "yi",
75
+ \u0439: "y",
76
+ \u043A: "k",
77
+ \u043B: "l",
78
+ \u043C: "m",
79
+ \u043D: "n",
80
+ \u043E: "o",
81
+ \u043F: "p",
82
+ \u0440: "r",
83
+ \u0441: "s",
84
+ \u0442: "t",
85
+ \u0443: "u",
86
+ \u045E: "u",
87
+ \u0444: "f",
88
+ \u0445: "kh",
89
+ \u0446: "ts",
90
+ \u0447: "ch",
91
+ \u0448: "sh",
92
+ \u0449: "shch",
93
+ \u044A: "",
94
+ \u044B: "y",
95
+ \u044C: "",
96
+ \u044D: "e",
97
+ \u044E: "yu",
98
+ \u044F: "ya"
99
+ });
100
+ var GREEK = withUpper({
101
+ \u03B1: "a",
102
+ \u03B2: "v",
103
+ \u03B3: "g",
104
+ \u03B4: "d",
105
+ \u03B5: "e",
106
+ \u03B6: "z",
107
+ \u03B7: "i",
108
+ \u03B8: "th",
109
+ \u03B9: "i",
110
+ \u03BA: "k",
111
+ \u03BB: "l",
112
+ \u03BC: "m",
113
+ \u03BD: "n",
114
+ \u03BE: "x",
115
+ \u03BF: "o",
116
+ \u03C0: "p",
117
+ \u03C1: "r",
118
+ \u03C3: "s",
119
+ \u03C2: "s",
120
+ \u03C4: "t",
121
+ \u03C5: "y",
122
+ \u03C6: "f",
123
+ \u03C7: "ch",
124
+ \u03C8: "ps",
125
+ \u03C9: "o"
126
+ });
127
+ var GERMAN = withUpper({ \u00E4: "ae", \u00F6: "oe", \u00FC: "ue" });
128
+ var CHAR_MAPS = { cyrillic: CYRILLIC, greek: GREEK, german: GERMAN };
31
129
 
32
130
  // src/core/case.ts
33
131
  var lower = (value, locale) => value.toLocaleLowerCase(locale);
@@ -43,11 +141,13 @@ var joinLower = (separator) => (input, { locale } = {}) => words(input).map((wor
43
141
  var kebabCase = joinLower("-");
44
142
  var snakeCase = joinLower("_");
45
143
  var dotCase = joinLower(".");
144
+ var pathCase = joinLower("/");
145
+ var trainCase = (input, { locale } = {}) => words(input).map((word) => titleWord(word, locale)).join("-");
46
146
  var constantCase = (input, { locale } = {}) => words(input).map((word) => upper(word, locale)).join("_");
47
147
  var titleCase = (input, { locale, smallWords = [] } = {}) => {
48
148
  const small = new Set(smallWords.map((word) => lower(word, locale)));
49
149
  let index = 0;
50
- return String(input ?? "").replace(/[\p{L}\p{N}]+/gu, (word) => {
150
+ return String(input ?? "").replace(/[\p{L}\p{M}\p{N}]+/gu, (word) => {
51
151
  const first = index++ === 0;
52
152
  const lowered = lower(word, locale);
53
153
  return !first && small.has(lowered) ? lowered : upperFirst(lowered, locale);
@@ -61,21 +161,27 @@ var uncapitalize = (input, { locale } = {}) => {
61
161
  };
62
162
 
63
163
  // src/core/slugify.ts
64
- var escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
164
+ var escape2 = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
65
165
  var slugify = (input, {
66
166
  separator = "-",
67
167
  lower: lower2 = true,
68
168
  replacements = {},
69
169
  maxLength,
70
170
  trim = true,
71
- locale
171
+ locale,
172
+ charMap,
173
+ preserve = ""
72
174
  } = {}) => {
73
175
  let value = String(input ?? "");
74
- for (const [from, to] of Object.entries(replacements)) value = value.split(from).join(` ${to} `);
176
+ const pairs = Array.isArray(replacements) ? replacements : Object.entries(replacements);
177
+ for (const [from, to] of pairs) {
178
+ value = typeof from === "string" ? value.split(from).join(` ${to} `) : value.replace(from, ` ${to} `);
179
+ }
75
180
  if (lower2) value = value.toLocaleLowerCase(locale);
76
- value = removeAccents(value);
77
- const sep = escape(separator);
78
- value = value.replace(/[^A-Za-z0-9]+/g, separator);
181
+ value = removeAccents(value, charMap ? { charMap } : {});
182
+ const sep = escape2(separator);
183
+ const kept = preserve.replace(/[\]\\^-]/g, "\\$&");
184
+ value = value.replace(new RegExp(`[^A-Za-z0-9${kept}]+`, "g"), separator);
79
185
  if (separator) value = value.replace(new RegExp(`(?:${sep}){2,}`, "g"), separator);
80
186
  if (trim && separator) value = value.replace(new RegExp(`^(?:${sep})+|(?:${sep})+$`, "g"), "");
81
187
  else if (separator) value = value.replace(new RegExp(`^(?:${sep})+`), "");
@@ -87,35 +193,417 @@ var slugify = (input, {
87
193
  }
88
194
  return value;
89
195
  };
196
+ var LIMIT = 1e5;
197
+ var uniqueSlug = (input, taken, { start = 2, ...options } = {}) => {
198
+ const base = slugify(input, options);
199
+ let isTaken;
200
+ if (typeof taken === "function") isTaken = taken;
201
+ else {
202
+ const set = new Set(taken);
203
+ isTaken = (slug) => set.has(slug);
204
+ }
205
+ if (base && !isTaken(base)) return base;
206
+ const separator = options.separator ?? "-";
207
+ const { maxLength } = options;
208
+ const first = Number.isFinite(start) ? Math.floor(start) : 2;
209
+ for (let n = first; n < first + LIMIT; n++) {
210
+ const suffix = base ? `${separator}${n}` : String(n);
211
+ let head = base;
212
+ if (maxLength !== void 0 && maxLength >= 0 && head.length + suffix.length > maxLength) {
213
+ head = head.slice(0, Math.max(0, maxLength - suffix.length));
214
+ if (separator) while (head.endsWith(separator)) head = head.slice(0, -separator.length);
215
+ }
216
+ const candidate = head ? head + suffix : String(n);
217
+ if (!isTaken(candidate)) return candidate;
218
+ }
219
+ throw new RangeError(`uniqueSlug: no free slug for "${base}" after ${LIMIT} tries`);
220
+ };
221
+
222
+ // src/core/graphemes.ts
223
+ var SegmenterImpl = globalThis.Intl?.Segmenter;
224
+ var segmenters = /* @__PURE__ */ new Map();
225
+ var segmenter = (granularity, locale) => {
226
+ if (!SegmenterImpl) return void 0;
227
+ const key = `${granularity}|${locale === void 0 ? "" : [locale].flat().join(",")}`;
228
+ let instance = segmenters.get(key);
229
+ if (!instance) {
230
+ instance = new SegmenterImpl(locale, { granularity });
231
+ segmenters.set(key, instance);
232
+ }
233
+ return instance;
234
+ };
235
+ var graphemes = (input) => {
236
+ const text = String(input ?? "");
237
+ const instance = segmenter("grapheme");
238
+ return instance ? Array.from(instance.segment(text), (part) => part.segment) : Array.from(text);
239
+ };
90
240
 
91
241
  // src/core/text.ts
92
- var truncate = (input, length, { ellipsis = "\u2026", wordBoundary = true } = {}) => {
93
- const chars = Array.from(String(input ?? ""));
242
+ var WORD_CHAR = /[\p{L}\p{N}]/u;
243
+ var EDGE = "[\\s.,;:!?-]+";
244
+ var TRAILING = new RegExp(`${EDGE}$`, "u");
245
+ var LEADING = new RegExp(`^${EDGE}`, "u");
246
+ var truncate = (input, length, { ellipsis = "\u2026", wordBoundary = true, position = "end" } = {}) => {
247
+ const chars = graphemes(input);
94
248
  if (!Number.isFinite(length) || length < 0 || chars.length <= length) return chars.join("");
95
- const room = Math.max(0, length - Array.from(ellipsis).length);
249
+ const room = Math.max(0, length - graphemes(ellipsis).length);
250
+ if (position === "middle") {
251
+ const head = chars.slice(0, Math.ceil(room / 2)).join("");
252
+ const tail = room > 1 ? chars.slice(chars.length - Math.floor(room / 2)).join("") : "";
253
+ return head.replace(/\s+$/u, "") + ellipsis + tail.replace(/^\s+/u, "");
254
+ }
255
+ if (position === "start") {
256
+ const start = chars.length - room;
257
+ let cut2 = chars.slice(start).join("");
258
+ if (wordBoundary && room > 0 && WORD_CHAR.test(chars[start - 1])) {
259
+ const firstSpace = cut2.search(/\s/u);
260
+ if (firstSpace >= 0 && firstSpace < cut2.length - 1) cut2 = cut2.slice(firstSpace);
261
+ }
262
+ return ellipsis + cut2.replace(LEADING, "");
263
+ }
96
264
  let cut = chars.slice(0, room).join("");
97
- if (wordBoundary && chars[room] !== void 0 && /[\p{L}\p{N}]/u.test(chars[room])) {
265
+ if (wordBoundary && chars[room] !== void 0 && WORD_CHAR.test(chars[room])) {
98
266
  const lastSpace = cut.search(/\s\S*$/u);
99
267
  if (lastSpace > 0) cut = cut.slice(0, lastSpace);
100
268
  }
101
- return cut.replace(/[\s.,;:!?-]+$/u, "") + ellipsis;
269
+ return cut.replace(TRAILING, "") + ellipsis;
270
+ };
271
+ var initials = (input, { max = 2, locale } = {}) => words(String(input ?? "")).slice(0, Math.max(0, max)).map((word) => graphemes(word)[0].toLocaleUpperCase(locale)).join("");
272
+
273
+ // src/core/convert.ts
274
+ var CONVERSIONS = [
275
+ "camel",
276
+ "pascal",
277
+ "kebab",
278
+ "snake",
279
+ "dot",
280
+ "path",
281
+ "constant",
282
+ "train",
283
+ "title",
284
+ "sentence",
285
+ "capitalize",
286
+ "uncapitalize",
287
+ "lower",
288
+ "upper",
289
+ "slug",
290
+ "accents",
291
+ "truncate",
292
+ "initials"
293
+ ];
294
+ var isConversion = (value) => CONVERSIONS.includes(value);
295
+ var convert = (input, to, options = {}) => {
296
+ const text = String(input ?? "");
297
+ const { locale } = options;
298
+ const caseOptions = locale === void 0 ? {} : { locale };
299
+ switch (to) {
300
+ case "camel":
301
+ return camelCase(text, caseOptions);
302
+ case "pascal":
303
+ return pascalCase(text, caseOptions);
304
+ case "kebab":
305
+ return kebabCase(text, caseOptions);
306
+ case "snake":
307
+ return snakeCase(text, caseOptions);
308
+ case "dot":
309
+ return dotCase(text, caseOptions);
310
+ case "path":
311
+ return pathCase(text, caseOptions);
312
+ case "constant":
313
+ return constantCase(text, caseOptions);
314
+ case "train":
315
+ return trainCase(text, caseOptions);
316
+ case "title":
317
+ return titleCase(text, options);
318
+ case "sentence":
319
+ return sentenceCase(text, caseOptions);
320
+ case "capitalize":
321
+ return capitalize(text, caseOptions);
322
+ case "uncapitalize":
323
+ return uncapitalize(text, caseOptions);
324
+ case "lower":
325
+ return text.toLocaleLowerCase(locale);
326
+ case "upper":
327
+ return text.toLocaleUpperCase(locale);
328
+ case "slug":
329
+ return options.taken === void 0 ? slugify(text, options) : uniqueSlug(text, options.taken, options);
330
+ case "accents":
331
+ return removeAccents(text, options.charMap ? { charMap: options.charMap } : {});
332
+ case "truncate":
333
+ return options.length === void 0 ? text : truncate(text, options.length, options);
334
+ case "initials":
335
+ return initials(text, options);
336
+ default:
337
+ return text;
338
+ }
339
+ };
340
+
341
+ // src/core/search.ts
342
+ var fold = (input, { locale } = {}) => removeAccents(String(input ?? "").toLocaleLowerCase(locale));
343
+ var termsOf = (query, { locale, split = true }) => {
344
+ const folded = fold(query, locale === void 0 ? {} : { locale }).trim();
345
+ if (!folded) return [];
346
+ return split ? Array.from(new Set(folded.split(/\s+/u))) : [folded];
347
+ };
348
+ var contains = (input, query, options = {}) => {
349
+ const terms = termsOf(query, options);
350
+ if (terms.length === 0) return true;
351
+ const text = fold(input, options.locale === void 0 ? {} : { locale: options.locale });
352
+ return terms.every((term) => text.includes(term));
353
+ };
354
+ var ASCII = /^[\u0000-\u007f]*$/;
355
+ var highlight = (input, query, options = {}) => {
356
+ const chars = Array.from(String(input ?? ""));
357
+ if (chars.length === 0) return [];
358
+ const terms = termsOf(query, options);
359
+ if (terms.length === 0) return [{ text: chars.join(""), match: false }];
360
+ const locale = options.locale;
361
+ let folded = "";
362
+ const owner = [];
363
+ const empty = /* @__PURE__ */ new Set();
364
+ chars.forEach((char, index) => {
365
+ const lower2 = char.toLocaleLowerCase(locale);
366
+ const piece = ASCII.test(lower2) ? lower2 : removeAccents(lower2);
367
+ folded += piece;
368
+ if (piece === "") empty.add(index);
369
+ for (let unit = 0; unit < piece.length; unit++) owner.push(index);
370
+ });
371
+ const marked = new Array(chars.length).fill(false);
372
+ for (const term of terms) {
373
+ for (let at = folded.indexOf(term); at !== -1; at = folded.indexOf(term, at + term.length)) {
374
+ for (let index = owner[at]; index <= owner[at + term.length - 1]; index++) {
375
+ marked[index] = true;
376
+ }
377
+ }
378
+ }
379
+ empty.forEach((index) => {
380
+ if (index > 0) marked[index] = marked[index - 1];
381
+ });
382
+ const segments = [];
383
+ chars.forEach((char, index) => {
384
+ const match = marked[index];
385
+ const last = segments[segments.length - 1];
386
+ if (last && last.match === match) last.text += char;
387
+ else segments.push({ text: char, match });
388
+ });
389
+ return segments;
390
+ };
391
+ var collators = /* @__PURE__ */ new Map();
392
+ var compareNatural = (a, b, { locale, sensitivity = "base" } = {}) => {
393
+ const key = `${locale === void 0 ? "" : [locale].flat().join(",")}|${sensitivity}`;
394
+ let collator = collators.get(key);
395
+ if (!collator) {
396
+ collator = new Intl.Collator(locale, { numeric: true, sensitivity });
397
+ collators.set(key, collator);
398
+ }
399
+ return collator.compare(String(a ?? ""), String(b ?? ""));
400
+ };
401
+ var distance = (a, b) => {
402
+ const left = Array.from(String(a ?? ""));
403
+ const right = Array.from(String(b ?? ""));
404
+ if (left.length === 0) return right.length;
405
+ if (right.length === 0) return left.length;
406
+ let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
407
+ for (let i = 1; i <= left.length; i++) {
408
+ const current = [i];
409
+ for (let j = 1; j <= right.length; j++) {
410
+ const cost = left[i - 1] === right[j - 1] ? 0 : 1;
411
+ current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + cost);
412
+ }
413
+ previous = current;
414
+ }
415
+ return previous[right.length];
416
+ };
417
+ var similarity = (a, b, { fold: shouldFold = true, locale } = {}) => {
418
+ const options = locale === void 0 ? {} : { locale };
419
+ const left = shouldFold ? fold(a, options) : String(a ?? "");
420
+ const right = shouldFold ? fold(b, options) : String(b ?? "");
421
+ const longest = Math.max(Array.from(left).length, Array.from(right).length);
422
+ return longest === 0 ? 1 : 1 - distance(left, right) / longest;
423
+ };
424
+ var PARTIAL_WEIGHT = 0.98;
425
+ var partialScore = (input, candidate) => {
426
+ const left = Array.from(input);
427
+ const right = Array.from(candidate);
428
+ if (left.length < 3 || right.length <= left.length) return 0;
429
+ const needle = left.join("");
430
+ let best = 0;
431
+ right.forEach((char, index) => {
432
+ if (index > 0 && !/[\s\p{P}]/u.test(right[index - 1])) return;
433
+ if (/\s/u.test(char)) return;
434
+ const piece = right.slice(index, index + left.length).join("");
435
+ best = Math.max(best, similarity(needle, piece, { fold: false }));
436
+ });
437
+ return best * PARTIAL_WEIGHT;
438
+ };
439
+ var closest = (input, candidates, { threshold = 0.5, partial = true, ...options } = {}) => {
440
+ const shouldFold = options.fold ?? true;
441
+ const foldOptions = options.locale === void 0 ? {} : { locale: options.locale };
442
+ const prepare = (value) => shouldFold ? fold(value, foldOptions) : String(value ?? "");
443
+ const needle = prepare(input);
444
+ let best;
445
+ let bestScore = -1;
446
+ for (const candidate of candidates) {
447
+ const whole = similarity(input, candidate, options);
448
+ const score = partial ? Math.max(whole, partialScore(needle, prepare(candidate))) : whole;
449
+ if (score > bestScore) {
450
+ best = candidate;
451
+ bestScore = score;
452
+ }
453
+ }
454
+ return bestScore >= threshold ? best : void 0;
455
+ };
456
+
457
+ // src/core/prose.ts
458
+ var wordCount = (input, { locale } = {}) => {
459
+ const text = String(input ?? "");
460
+ const instance = segmenter("word", locale);
461
+ if (!instance) return text.split(/[^\p{L}\p{M}\p{N}'’]+/u).filter(Boolean).length;
462
+ let count = 0;
463
+ for (const part of instance.segment(text)) if (part.isWordLike) count++;
464
+ return count;
465
+ };
466
+ var readingTime = (input, { wordsPerMinute = 200, ...options } = {}) => {
467
+ const words2 = wordCount(input, options);
468
+ const speed = Number.isFinite(wordsPerMinute) && wordsPerMinute > 0 ? wordsPerMinute : 200;
469
+ return { words: words2, minutes: words2 === 0 ? 0 : Math.max(1, Math.ceil(words2 / speed)) };
470
+ };
471
+ var pluralRules = /* @__PURE__ */ new Map();
472
+ var numberFormats = /* @__PURE__ */ new Map();
473
+ var keyOf = (locale) => locale === void 0 ? "" : [locale].flat().join(",");
474
+ var pluralize = (count, forms, { locale, ordinal = false } = {}) => {
475
+ const key = keyOf(locale);
476
+ const rulesKey = `${key}|${ordinal}`;
477
+ let rules = pluralRules.get(rulesKey);
478
+ if (!rules) {
479
+ rules = new Intl.PluralRules(locale, { type: ordinal ? "ordinal" : "cardinal" });
480
+ pluralRules.set(rulesKey, rules);
481
+ }
482
+ let format = numberFormats.get(key);
483
+ if (!format) {
484
+ format = new Intl.NumberFormat(locale);
485
+ numberFormats.set(key, format);
486
+ }
487
+ const category = rules.select(count);
488
+ const form = count === 0 && forms.zero || forms[category] || forms.other;
489
+ return form.replace(/#/g, format.format(count));
490
+ };
491
+ var template = (input, values, { missing } = {}) => String(input ?? "").replace(
492
+ /\{\{|\}\}|\{\s*([^{}\s]+)\s*\}/g,
493
+ (match, path) => {
494
+ if (path === void 0) return match[0];
495
+ let value = values;
496
+ for (const key of path.split(".")) {
497
+ value = value !== null && typeof value === "object" && Object.prototype.hasOwnProperty.call(value, key) ? value[key] : void 0;
498
+ }
499
+ if (value !== void 0 && value !== null) return String(value);
500
+ if (missing === void 0) return match;
501
+ return typeof missing === "function" ? missing(path) : missing;
502
+ }
503
+ );
504
+
505
+ // src/core/html.ts
506
+ var ESCAPES = {
507
+ "&": "&amp;",
508
+ "<": "&lt;",
509
+ ">": "&gt;",
510
+ '"': "&quot;",
511
+ "'": "&#39;"
512
+ };
513
+ var escapeHtml = (input) => String(input ?? "").replace(/[&<>"']/g, (char) => ESCAPES[char]);
514
+ var NAMED = {
515
+ amp: "&",
516
+ lt: "<",
517
+ gt: ">",
518
+ quot: '"',
519
+ apos: "'",
520
+ nbsp: "\xA0",
521
+ copy: "\xA9",
522
+ reg: "\xAE",
523
+ hellip: "\u2026",
524
+ mdash: "\u2014",
525
+ ndash: "\u2013",
526
+ laquo: "\xAB",
527
+ raquo: "\xBB"
528
+ };
529
+ var fromCodePoint = (code, entity) => Number.isInteger(code) && code > 0 && code <= 1114111 && (code < 55296 || code > 57343) ? String.fromCodePoint(code) : entity;
530
+ var unescapeHtml = (input) => String(input ?? "").replace(/&(#x[\da-f]+|#\d+|[a-z]+);/gi, (entity, body) => {
531
+ if (body[0] !== "#") return NAMED[body.toLowerCase()] ?? entity;
532
+ const hex = body[1] === "x" || body[1] === "X";
533
+ return fromCodePoint(parseInt(body.slice(hex ? 2 : 1), hex ? 16 : 10), entity);
534
+ });
535
+ var BLOCK = /<\/?(?:p|div|br|li|ul|ol|h[1-6]|tr|td|th|table|section|article|header|footer|blockquote|pre|hr)\b[^>]*>/gi;
536
+ var stripTags = (input) => unescapeHtml(
537
+ String(input ?? "").replace(/<!--[\s\S]*?-->/g, "").replace(/<(script|style|template|noscript)\b[\s\S]*?<\/\1\s*>/gi, "").replace(BLOCK, " ").replace(/<[^>]*>/g, "")
538
+ ).replace(/\s+/g, " ").trim();
539
+
540
+ // src/core/color.ts
541
+ var hash = (text) => {
542
+ let value = 2166136261;
543
+ for (let index = 0; index < text.length; index++) {
544
+ value ^= text.charCodeAt(index);
545
+ value = Math.imul(value, 16777619);
546
+ }
547
+ return value >>> 0;
548
+ };
549
+ var whiteContrast = (hue, saturation, lightness) => {
550
+ const s = saturation / 100;
551
+ const l = lightness / 100;
552
+ const channel = (n) => {
553
+ const k = (n + hue / 30) % 12;
554
+ const value = l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k - 3, 9 - k, 1));
555
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
556
+ };
557
+ const luminance = 0.2126 * channel(0) + 0.7152 * channel(8) + 0.0722 * channel(4);
558
+ return 1.05 / (luminance + 0.05);
559
+ };
560
+ var hashColor = (input, { saturation = 55, lightness = 45, contrast = 4.5 } = {}) => {
561
+ const hue = hash(fold(String(input ?? "").trim())) % 360;
562
+ let light = Math.max(0, Math.min(100, lightness));
563
+ while (light > 0 && whiteContrast(hue, saturation, light) < contrast) light--;
564
+ return `hsl(${hue} ${saturation}% ${light}%)`;
102
565
  };
103
- var initials = (input, { max = 2, locale } = {}) => words(String(input ?? "")).slice(0, Math.max(0, max)).map((word) => Array.from(word)[0].toLocaleUpperCase(locale)).join("");
104
566
 
567
+ exports.CHAR_MAPS = CHAR_MAPS;
568
+ exports.CONVERSIONS = CONVERSIONS;
569
+ exports.CYRILLIC = CYRILLIC;
570
+ exports.GERMAN = GERMAN;
571
+ exports.GREEK = GREEK;
105
572
  exports.camelCase = camelCase;
106
573
  exports.capitalize = capitalize;
574
+ exports.closest = closest;
575
+ exports.compareNatural = compareNatural;
107
576
  exports.constantCase = constantCase;
577
+ exports.contains = contains;
578
+ exports.convert = convert;
579
+ exports.distance = distance;
108
580
  exports.dotCase = dotCase;
581
+ exports.escapeHtml = escapeHtml;
582
+ exports.fold = fold;
583
+ exports.graphemes = graphemes;
584
+ exports.hashColor = hashColor;
585
+ exports.highlight = highlight;
109
586
  exports.initials = initials;
587
+ exports.isConversion = isConversion;
110
588
  exports.kebabCase = kebabCase;
111
589
  exports.pascalCase = pascalCase;
590
+ exports.pathCase = pathCase;
591
+ exports.pluralize = pluralize;
592
+ exports.readingTime = readingTime;
112
593
  exports.removeAccents = removeAccents;
113
594
  exports.sentenceCase = sentenceCase;
595
+ exports.similarity = similarity;
114
596
  exports.slugify = slugify;
115
597
  exports.snakeCase = snakeCase;
598
+ exports.stripTags = stripTags;
599
+ exports.template = template;
116
600
  exports.titleCase = titleCase;
601
+ exports.trainCase = trainCase;
117
602
  exports.truncate = truncate;
118
603
  exports.uncapitalize = uncapitalize;
604
+ exports.unescapeHtml = unescapeHtml;
605
+ exports.uniqueSlug = uniqueSlug;
606
+ exports.wordCount = wordCount;
119
607
  exports.words = words;
120
608
  //# sourceMappingURL=index.cjs.map
121
609
  //# sourceMappingURL=index.cjs.map