@visulima/string 2.0.6 → 3.0.0-alpha.2

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE.md +374 -0
  3. package/README.md +57 -22
  4. package/dist/case/camel-case.d.ts +2 -2
  5. package/dist/case/camel-case.js +2 -2
  6. package/dist/case/capital-case.d.ts +2 -2
  7. package/dist/case/capital-case.js +2 -2
  8. package/dist/case/constant-case.d.ts +2 -2
  9. package/dist/case/dot-case.d.ts +2 -2
  10. package/dist/case/flat-case.d.ts +2 -2
  11. package/dist/case/flip-case.d.ts +2 -2
  12. package/dist/case/flip-case.js +8 -2
  13. package/dist/case/identify-case.d.ts +2 -2
  14. package/dist/case/index.d.ts +2 -2
  15. package/dist/case/index.js +1 -1
  16. package/dist/case/kebab-case.d.ts +2 -2
  17. package/dist/case/kebab-case.js +2 -2
  18. package/dist/case/lower-first.d.ts +2 -2
  19. package/dist/case/no-case.d.ts +2 -2
  20. package/dist/case/pascal-case.d.ts +2 -2
  21. package/dist/case/pascal-case.js +2 -2
  22. package/dist/case/pascal-snake-case.d.ts +2 -2
  23. package/dist/case/path-case.d.ts +2 -2
  24. package/dist/case/sentence-case.d.ts +2 -2
  25. package/dist/case/sentence-case.js +2 -2
  26. package/dist/case/snake-case.d.ts +2 -2
  27. package/dist/case/split-by-case.d.ts +2 -2
  28. package/dist/case/split-by-case.js +127 -24
  29. package/dist/case/title-case.d.ts +2 -2
  30. package/dist/case/train-case.d.ts +2 -2
  31. package/dist/case/train-case.js +1 -1
  32. package/dist/case/upper-first.d.ts +2 -2
  33. package/dist/closest-string.js +1 -3
  34. package/dist/get-string-truncated-width.js +1 -1
  35. package/dist/index.d.ts +11 -6
  36. package/dist/index.js +5 -4
  37. package/dist/native-string-types.d.ts +1 -1
  38. package/dist/outdent.js +3 -3
  39. package/dist/packem_shared/closestN-Cvsw0Fue.js +24 -0
  40. package/dist/packem_shared/{constants-CTzC6Gjg.js → constants-CnXdp6qx.js} +1 -1
  41. package/dist/packem_shared/excerpt-GvmR4ESb.js +1502 -0
  42. package/dist/packem_shared/{joinSegments-CuU8RGpP.js → joinSegments-B4H6oZ9b.js} +1 -1
  43. package/dist/packem_shared/{replaceString-vYvRBMfC.js → replaceString-BVlxk27d.js} +8 -8
  44. package/dist/packem_shared/{transliterate-CYnKKT8f.js → transliterate-a6LLM_Ei.js} +3 -5
  45. package/dist/packem_shared/{types-CfPsw9ix.d.ts → types-CHpmpy8C.d.ts} +1 -1
  46. package/dist/packem_shared/{types-Daae0hGf.d.ts → types-D2ydhHCv.d.ts} +1 -1
  47. package/dist/slice.js +1 -1
  48. package/dist/slugify.d.ts +1 -1
  49. package/dist/slugify.js +1 -1
  50. package/dist/truncate.js +38 -13
  51. package/dist/utilities.d.ts +1 -1
  52. package/dist/word-wrap.js +18 -18
  53. package/package.json +3 -3
  54. package/dist/packem_shared/closestN-BREy4E7C.js +0 -19
@@ -1,5 +1,5 @@
1
- import { I as IdentifyCase } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { I as IdentifyCase } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  declare const identifyCase: <T extends string = string>(value?: T) => IdentifyCase<T>;
@@ -1,4 +1,4 @@
1
- export { N as NodeLocale } from '../packem_shared/types-Daae0hGf.js';
1
+ export { N as NodeLocale } from '../packem_shared/types-D2ydhHCv.js';
2
2
  export { default as camelCase } from './camel-case.js';
3
3
  export { default as capitalCase } from './capital-case.js';
4
4
  export { default as constantCase } from './constant-case.js';
@@ -17,7 +17,7 @@ export { default as snakeCase } from './snake-case.js';
17
17
  export { SplitOptions, splitByCase } from './split-by-case.js';
18
18
  export { default as titleCase } from './title-case.js';
19
19
  export { default as trainCase } from './train-case.js';
20
- export { a as CamelCase, b as CapitalCase, C as CaseOptions, c as ConstantCase, D as DotCase, F as FlatCase, d as FlipCase, I as IdentifyCase, K as KebabCase, L as LocaleOptions, e as LowerFirst, N as NoCase, P as PascalCase, f as PascalSnakeCase, g as PathCase, S as SentenceCase, h as SnakeCase, i as SplitByCase, T as TitleCase, j as TrainCase, U as UpperFirst } from '../packem_shared/types-CfPsw9ix.js';
20
+ export { a as CamelCase, b as CapitalCase, C as CaseOptions, c as ConstantCase, D as DotCase, F as FlatCase, d as FlipCase, I as IdentifyCase, K as KebabCase, L as LocaleOptions, e as LowerFirst, N as NoCase, P as PascalCase, f as PascalSnakeCase, g as PathCase, S as SentenceCase, h as SnakeCase, i as SplitByCase, T as TitleCase, j as TrainCase, U as UpperFirst } from '../packem_shared/types-CHpmpy8C.js';
21
21
  export { default as upperFirst } from './upper-first.js';
22
22
  import '../packem_shared/lru-cache-B_t27XwI.js';
23
23
 
@@ -17,4 +17,4 @@ export { splitByCase } from './split-by-case.js';
17
17
  export { default as titleCase } from './title-case.js';
18
18
  export { default as trainCase } from './train-case.js';
19
19
  export { default as upperFirst } from './upper-first.js';
20
- export { default as joinSegments } from '../packem_shared/joinSegments-CuU8RGpP.js';
20
+ export { default as joinSegments } from '../packem_shared/joinSegments-B4H6oZ9b.js';
@@ -1,5 +1,5 @@
1
- import { C as CaseOptions, K as KebabCase } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { C as CaseOptions, K as KebabCase } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  interface KebabCaseOptions extends CaseOptions {
@@ -1,8 +1,8 @@
1
- import { R as RE_FAST_ANSI } from '../packem_shared/constants-CTzC6Gjg.js';
1
+ import { R as RE_FAST_ANSI } from '../packem_shared/constants-CnXdp6qx.js';
2
2
  import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
3
3
  import { splitByCase } from './split-by-case.js';
4
4
  import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
5
- import joinSegments from '../packem_shared/joinSegments-CuU8RGpP.js';
5
+ import joinSegments from '../packem_shared/joinSegments-B4H6oZ9b.js';
6
6
  import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-DEB8-ZPT.js';
7
7
 
8
8
  const defaultCacheStore = new LRUCache(1e3);
@@ -1,5 +1,5 @@
1
- import { L as LocaleOptions, e as LowerFirst } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { L as LocaleOptions, e as LowerFirst } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  declare const lowerFirst: <T extends string = string>(value?: T, options?: LocaleOptions) => LowerFirst<T>;
@@ -1,5 +1,5 @@
1
- import { C as CaseOptions, N as NoCase } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { C as CaseOptions, N as NoCase } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  declare const noCase: <T extends string = string>(value?: T, options?: CaseOptions) => NoCase<T>;
@@ -1,5 +1,5 @@
1
- import { C as CaseOptions, P as PascalCase } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { C as CaseOptions, P as PascalCase } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  declare const pascalCase: <T extends string = string>(value?: T, options?: CaseOptions) => PascalCase<T>;
@@ -1,9 +1,9 @@
1
- import { R as RE_FAST_ANSI } from '../packem_shared/constants-CTzC6Gjg.js';
1
+ import { R as RE_FAST_ANSI } from '../packem_shared/constants-CnXdp6qx.js';
2
2
  import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
3
3
  import { splitByCase } from './split-by-case.js';
4
4
  import upperFirst from './upper-first.js';
5
5
  import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
6
- import joinSegments from '../packem_shared/joinSegments-CuU8RGpP.js';
6
+ import joinSegments from '../packem_shared/joinSegments-B4H6oZ9b.js';
7
7
  import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-DEB8-ZPT.js';
8
8
 
9
9
  const defaultCacheStore = new LRUCache(1e3);
@@ -1,5 +1,5 @@
1
- import { C as CaseOptions, f as PascalSnakeCase } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { C as CaseOptions, f as PascalSnakeCase } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  declare const pascalSnakeCase: <T extends string = string>(value?: T, options?: CaseOptions) => PascalSnakeCase<T>;
@@ -1,5 +1,5 @@
1
- import { C as CaseOptions, g as PathCase } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { C as CaseOptions, g as PathCase } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  declare const pathCase: <T extends string = string>(value?: T, options?: CaseOptions) => PathCase<T>;
@@ -1,5 +1,5 @@
1
- import { C as CaseOptions, S as SentenceCase } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { C as CaseOptions, S as SentenceCase } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  declare const sentenceCase: <T extends string = string>(value?: T, options?: CaseOptions) => SentenceCase<T>;
@@ -1,9 +1,9 @@
1
- import { R as RE_FAST_ANSI } from '../packem_shared/constants-CTzC6Gjg.js';
1
+ import { R as RE_FAST_ANSI } from '../packem_shared/constants-CnXdp6qx.js';
2
2
  import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
3
3
  import { splitByCase } from './split-by-case.js';
4
4
  import upperFirst from './upper-first.js';
5
5
  import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
6
- import joinSegments from '../packem_shared/joinSegments-CuU8RGpP.js';
6
+ import joinSegments from '../packem_shared/joinSegments-B4H6oZ9b.js';
7
7
  import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-DEB8-ZPT.js';
8
8
 
9
9
  const defaultCacheStore = new LRUCache(1e3);
@@ -1,5 +1,5 @@
1
- import { C as CaseOptions, h as SnakeCase } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { C as CaseOptions, h as SnakeCase } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  declare const snakeCase: <T extends string = string>(value?: T, options?: CaseOptions) => SnakeCase<T>;
@@ -1,5 +1,5 @@
1
- import { L as LocaleOptions, i as SplitByCase } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { L as LocaleOptions, i as SplitByCase } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  interface SplitOptions extends LocaleOptions {
@@ -20,7 +20,7 @@ const __cjs_getBuiltinModule = (module) => {
20
20
  const {
21
21
  stripVTControlCharacters
22
22
  } = __cjs_getBuiltinModule("node:util");
23
- import { j as RE_EMOJI, s as stripEmoji, k as RE_SEPARATORS, R as RE_FAST_ANSI, l as RE_CYRILLIC, m as RE_LATIN, n as RE_GREEK, o as RE_GREEK_LATIN_SPLIT, p as RE_UZBEK_LATIN_MODIFIER, q as RE_KATAKANA, r as RE_KANJI, t as RE_HIRAGANA, u as RE_HANGUL, v as RE_HEBREW, w as RE_ARABIC, x as RE_DEVANAGARI, y as RE_BENGALI, z as RE_GUJARATI, A as RE_GURMUKHI, B as RE_KANNADA, C as RE_TAMIL, D as RE_TELUGU, E as RE_MALAYALAM, F as RE_SINHALA, G as RE_THAI, H as RE_LAO, I as RE_TIBETAN, J as RE_MYANMAR, K as RE_ETHIOPIC, L as RE_KHMER, M as RE_ORIYA } from '../packem_shared/constants-CTzC6Gjg.js';
23
+ import { j as RE_EMOJI, s as stripEmoji, R as RE_FAST_ANSI, k as RE_CYRILLIC, l as RE_LATIN, m as RE_GREEK, n as RE_GREEK_LATIN_SPLIT, o as RE_UZBEK_LATIN_MODIFIER, p as RE_KATAKANA, q as RE_KANJI, r as RE_HIRAGANA, t as RE_HANGUL, u as RE_HEBREW, v as RE_ARABIC, w as RE_DEVANAGARI, x as RE_BENGALI, y as RE_GUJARATI, z as RE_GURMUKHI, A as RE_KANNADA, B as RE_TAMIL, C as RE_TELUGU, D as RE_MALAYALAM, E as RE_SINHALA, F as RE_THAI, G as RE_LAO, H as RE_TIBETAN, I as RE_MYANMAR, J as RE_ETHIOPIC, K as RE_KHMER, L as RE_ORIYA, M as RE_SEPARATORS } from '../packem_shared/constants-CnXdp6qx.js';
24
24
  import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
25
25
 
26
26
  const regexCache = new LRUCache(1e3);
@@ -126,6 +126,18 @@ const handleScriptTransitions = (s, scriptDetectors, caseSensitive, locale, cust
126
126
  }
127
127
  return result.length > 0 ? result : [s];
128
128
  };
129
+ const detectAndProcessAcronym = (s, start, knownAcronyms, tokens) => {
130
+ if (knownAcronyms.size === 0) {
131
+ return start;
132
+ }
133
+ for (const acronym of knownAcronyms) {
134
+ if (s.startsWith(acronym, start)) {
135
+ tokens.push(acronym);
136
+ return start + acronym.length;
137
+ }
138
+ }
139
+ return start;
140
+ };
129
141
  const splitCamelCaseFast = (s, knownAcronyms = /* @__PURE__ */ new Set()) => {
130
142
  if (s.length === 0) {
131
143
  return [];
@@ -137,21 +149,14 @@ const splitCamelCaseFast = (s, knownAcronyms = /* @__PURE__ */ new Set()) => {
137
149
  const tokens = [];
138
150
  const width = s.length;
139
151
  for (let index = 1; index < width; index++) {
152
+ const newStart = detectAndProcessAcronym(s, start, knownAcronyms, tokens);
153
+ if (newStart !== start) {
154
+ start = newStart;
155
+ index = start - 1;
156
+ continue;
157
+ }
140
158
  const previousCode = s.codePointAt(index - 1);
141
159
  const currentCode = s.codePointAt(index);
142
- if (knownAcronyms.size > 0) {
143
- for (const acronym of knownAcronyms) {
144
- if (s.startsWith(acronym, start)) {
145
- tokens.push(acronym);
146
- start += acronym.length;
147
- index = start - 1;
148
- break;
149
- }
150
- }
151
- if (index < start) {
152
- continue;
153
- }
154
- }
155
160
  const previousIsUpper = previousCode && previousCode < 128 && isUpper(previousCode);
156
161
  const currentIsUpper = currentCode && currentCode < 128 && isUpper(currentCode);
157
162
  const previousIsLower = previousCode && previousCode < 128 && isLower(previousCode);
@@ -255,11 +260,26 @@ const splitCamelCaseLocale = (s, locale, knownAcronyms) => {
255
260
  const width_2 = chars2.length;
256
261
  const result2 = [];
257
262
  let currentSegment2 = chars2[0];
258
- let previousType = RE_CYRILLIC.test(chars2[0]) ? 1 : RE_LATIN.test(chars2[0]) ? 2 : 0;
259
- let previousIsUpper2 = chars2[0] === chars2[0].toLocaleUpperCase(locale);
263
+ const firstChar = chars2[0];
264
+ let previousType;
265
+ if (RE_CYRILLIC.test(firstChar)) {
266
+ previousType = 1;
267
+ } else if (RE_LATIN.test(firstChar)) {
268
+ previousType = 2;
269
+ } else {
270
+ previousType = 0;
271
+ }
272
+ let previousIsUpper2 = firstChar === firstChar.toLocaleUpperCase(locale);
260
273
  for (let index = 1; index < width_2; index++) {
261
274
  const char = chars2[index];
262
- const currentType = RE_CYRILLIC.test(char) ? 1 : RE_LATIN.test(char) ? 2 : 0;
275
+ let currentType;
276
+ if (RE_CYRILLIC.test(char)) {
277
+ currentType = 1;
278
+ } else if (RE_LATIN.test(char)) {
279
+ currentType = 2;
280
+ } else {
281
+ currentType = 0;
282
+ }
263
283
  const isUpperCaseChar = char === char.toLocaleUpperCase(locale);
264
284
  if (previousType !== currentType && (previousType === 1 || previousType === 2) && (currentType === 1 || currentType === 2) || currentType === previousType && !previousIsUpper2 && isUpperCaseChar) {
265
285
  result2.push(currentSegment2);
@@ -540,17 +560,21 @@ const splitCamelCaseLocale = (s, locale, knownAcronyms) => {
540
560
  for (let index = 1; index < width_; index++) {
541
561
  const char = chars[index];
542
562
  const isUpperCaseChar = char === char.toLocaleUpperCase(locale);
543
- let isAcronym = false;
563
+ let acronymLength = 0;
544
564
  for (const acronym of knownAcronyms) {
545
565
  if (s.startsWith(acronym, index)) {
546
566
  result.push(currentSegment, acronym);
547
- index += acronym.length - 1;
567
+ acronymLength = acronym.length;
548
568
  currentSegment = "";
549
- isAcronym = true;
569
+ const lastAcronymChar = acronym[acronym.length - 1];
570
+ if (lastAcronymChar) {
571
+ previousIsUpper = lastAcronymChar === lastAcronymChar.toLocaleUpperCase(locale);
572
+ }
550
573
  break;
551
574
  }
552
575
  }
553
- if (isAcronym) {
576
+ if (acronymLength > 0) {
577
+ index += acronymLength - 1;
554
578
  continue;
555
579
  }
556
580
  if (!previousIsUpper && isUpperCaseChar) {
@@ -604,7 +628,7 @@ const splitByCase = (input, options = {}) => {
604
628
  stripAnsi: stripAnsiOption = false,
605
629
  stripEmoji: stripEmojiOption = false
606
630
  } = options;
607
- const acronymSet = new Set([...knownAcronyms].sort((a, b) => b.length - a.length));
631
+ const acronymSet = new Set([...knownAcronyms].toSorted((a, b) => b.length - a.length));
608
632
  let cleanedInput = input;
609
633
  if (stripAnsiOption) {
610
634
  cleanedInput = stripVTControlCharacters(cleanedInput);
@@ -612,8 +636,87 @@ const splitByCase = (input, options = {}) => {
612
636
  if (stripEmojiOption) {
613
637
  cleanedInput = stripEmoji(cleanedInput);
614
638
  }
615
- const separatorRegex = Array.isArray(separators) ? getSeparatorsRegex(separators) : separators instanceof RegExp ? separators : RE_SEPARATORS;
616
- const parts = cleanedInput.split(separatorRegex).filter(Boolean);
639
+ let separatorRegex;
640
+ if (Array.isArray(separators)) {
641
+ separatorRegex = getSeparatorsRegex(separators);
642
+ } else if (separators instanceof RegExp) {
643
+ separatorRegex = separators;
644
+ } else {
645
+ separatorRegex = RE_SEPARATORS;
646
+ }
647
+ const parts = [];
648
+ let workingInput = cleanedInput;
649
+ const regex = separatorRegex.flags.includes("g") ? separatorRegex : new RegExp(separatorRegex.source, `${separatorRegex.flags}g`);
650
+ while (workingInput.length > 0) {
651
+ const match = regex.exec(workingInput);
652
+ if (!match) {
653
+ if (workingInput === "..") {
654
+ parts.push("..");
655
+ } else if (workingInput === ".") {
656
+ parts.push(".");
657
+ } else if (workingInput.length > 0) {
658
+ parts.push(workingInput);
659
+ }
660
+ break;
661
+ }
662
+ const matchIndex = match.index;
663
+ const matchText = match[0];
664
+ const matchLength = matchText.length;
665
+ const beforeMatch = workingInput.slice(0, matchIndex);
666
+ const afterMatch = workingInput.slice(matchIndex + matchLength);
667
+ if (matchText.startsWith("../")) {
668
+ parts.push("..");
669
+ workingInput = workingInput.slice(matchIndex + 3);
670
+ } else if (matchText.startsWith("./")) {
671
+ parts.push(".");
672
+ workingInput = workingInput.slice(matchIndex + 2);
673
+ } else if (matchIndex === 0 && matchText === "..") {
674
+ parts.push("..");
675
+ workingInput = workingInput.slice(2);
676
+ } else if (matchIndex === 0 && matchText === ".") {
677
+ parts.push(".");
678
+ workingInput = workingInput.slice(1);
679
+ } else {
680
+ if (beforeMatch.length > 0) {
681
+ parts.push(beforeMatch);
682
+ }
683
+ let pos = 0;
684
+ while ((pos = matchText.indexOf("../", pos)) !== -1) {
685
+ parts.push("..");
686
+ pos += 3;
687
+ }
688
+ pos = 0;
689
+ while ((pos = matchText.indexOf("./", pos)) !== -1) {
690
+ if (pos === 0 || matchText[pos - 1] !== ".") {
691
+ parts.push(".");
692
+ }
693
+ pos += 2;
694
+ }
695
+ let remainingAfterMatch = afterMatch;
696
+ while (remainingAfterMatch.startsWith("../")) {
697
+ parts.push("..");
698
+ remainingAfterMatch = remainingAfterMatch.slice(3);
699
+ }
700
+ while (remainingAfterMatch.startsWith("./")) {
701
+ parts.push(".");
702
+ remainingAfterMatch = remainingAfterMatch.slice(2);
703
+ }
704
+ if (remainingAfterMatch === "..") {
705
+ parts.push("..");
706
+ break;
707
+ } else if (remainingAfterMatch === ".") {
708
+ parts.push(".");
709
+ break;
710
+ } else {
711
+ workingInput = remainingAfterMatch;
712
+ }
713
+ }
714
+ regex.lastIndex = 0;
715
+ }
716
+ if (parts.length === 0) {
717
+ const standardParts = cleanedInput.split(separatorRegex).filter(Boolean);
718
+ parts.push(...standardParts);
719
+ }
617
720
  let tokens = [];
618
721
  for (const part of parts) {
619
722
  if (handleAnsi || handleEmoji) {
@@ -1,5 +1,5 @@
1
- import { C as CaseOptions, T as TitleCase } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { C as CaseOptions, T as TitleCase } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  declare function titleCase<T extends string = string>(value?: T, options?: CaseOptions): TitleCase<T>;
@@ -1,5 +1,5 @@
1
- import { C as CaseOptions, j as TrainCase } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { C as CaseOptions, j as TrainCase } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  declare const trainCase: <T extends string = string>(value?: T, options?: CaseOptions) => TrainCase<T>;
@@ -2,7 +2,7 @@ import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
2
2
  import { splitByCase } from './split-by-case.js';
3
3
  import upperFirst from './upper-first.js';
4
4
  import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
5
- import joinSegments from '../packem_shared/joinSegments-CuU8RGpP.js';
5
+ import joinSegments from '../packem_shared/joinSegments-B4H6oZ9b.js';
6
6
 
7
7
  const defaultCacheStore = new LRUCache(1e3);
8
8
  const trainCase = (value, options) => {
@@ -1,5 +1,5 @@
1
- import { L as LocaleOptions, U as UpperFirst } from '../packem_shared/types-CfPsw9ix.js';
2
- import '../packem_shared/types-Daae0hGf.js';
1
+ import { L as LocaleOptions, U as UpperFirst } from '../packem_shared/types-CHpmpy8C.js';
2
+ import '../packem_shared/types-D2ydhHCv.js';
3
3
  import '../packem_shared/lru-cache-B_t27XwI.js';
4
4
 
5
5
  declare const upperFirst: <T extends string = string>(value?: T, options?: LocaleOptions) => UpperFirst<T>;
@@ -2,9 +2,7 @@ import { distance } from './packem_shared/closest-IHuSvnSn.js';
2
2
 
3
3
  const closestString = (givenWord, possibleWords, options) => {
4
4
  if (possibleWords.length === 0) {
5
- throw new TypeError(
6
- "When using closestString(), the possibleWords array must contain at least one word"
7
- );
5
+ throw new TypeError("When using closestString(), the possibleWords array must contain at least one word");
8
6
  }
9
7
  const { caseSensitive, compareFn: compareFunction = distance } = { ...options };
10
8
  if (!caseSensitive) {
@@ -1,4 +1,4 @@
1
- import { c as RE_ANSI, N as RE_CONTROL, j as RE_EMOJI } from './packem_shared/constants-CTzC6Gjg.js';
1
+ import { i as RE_ANSI, N as RE_CONTROL, j as RE_EMOJI } from './packem_shared/constants-CnXdp6qx.js';
2
2
 
3
3
  function isAmbiguous(x) {
4
4
  return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
package/dist/index.d.ts CHANGED
@@ -17,31 +17,36 @@ export { default as snakeCase } from './case/snake-case.js';
17
17
  export { SplitOptions, splitByCase } from './case/split-by-case.js';
18
18
  export { default as titleCase } from './case/title-case.js';
19
19
  export { default as trainCase } from './case/train-case.js';
20
- export { a as CamelCase, b as CapitalCase, C as CaseOptions, c as ConstantCase, D as DotCase, F as FlatCase, d as FlipCase, I as IdentifyCase, K as KebabCase, L as LocaleOptions, e as LowerFirst, N as NoCase, P as PascalCase, f as PascalSnakeCase, g as PathCase, S as SentenceCase, h as SnakeCase, i as SplitByCase, T as TitleCase, j as TrainCase, U as UpperFirst } from './packem_shared/types-CfPsw9ix.js';
20
+ export { a as CamelCase, b as CapitalCase, C as CaseOptions, c as ConstantCase, D as DotCase, F as FlatCase, d as FlipCase, I as IdentifyCase, K as KebabCase, L as LocaleOptions, e as LowerFirst, N as NoCase, P as PascalCase, f as PascalSnakeCase, g as PathCase, S as SentenceCase, h as SnakeCase, i as SplitByCase, T as TitleCase, j as TrainCase, U as UpperFirst } from './packem_shared/types-CHpmpy8C.js';
21
21
  export { default as upperFirst } from './case/upper-first.js';
22
22
  export { joinSegments } from './case/index.js';
23
23
  export { ClosestStringOptions, closestString } from './closest-string.js';
24
24
  export { CompareSimilarityOptions, compareSimilarity } from './compare-similarity.js';
25
+ import { TruncateOptions } from './truncate.js';
26
+ export { truncate } from './truncate.js';
25
27
  export { StringTruncatedWidthOptions, StringTruncatedWidthResult, getStringTruncatedWidth } from './get-string-truncated-width.js';
26
28
  export { StringWidthOptions, getStringWidth } from './get-string-width.js';
27
29
  export { Outdent, Options as OutdentOptions, outdent } from './outdent.js';
28
- import { O as OptionReplaceArray, l as IntervalArray, m as OptionsTransliterate } from './packem_shared/types-Daae0hGf.js';
29
- export { A as All, n as Any, C as CharAt, o as Charmap, a as Concat, E as EndsWith, I as Includes, p as Interval, q as IsBooleanLiteral, r as IsNumberLiteral, k as IsStringLiteral, s as IsStringLiteralArray, J as Join, L as Length, M as Math, N as NodeLocale, t as OptionReplaceCombined, u as OptionReplaceObject, P as PadEnd, b as PadStart, v as Repeat, R as Replace, c as ReplaceAll, w as Reverse, S as Slice, j as SlugifyOptions, d as Split, e as StartsWith, T as ToLowerCase, f as ToUpperCase, g as Trim, h as TrimEnd, i as TrimStart } from './packem_shared/types-Daae0hGf.js';
30
+ import { O as OptionReplaceArray, l as IntervalArray, m as OptionsTransliterate } from './packem_shared/types-D2ydhHCv.js';
31
+ export { A as All, n as Any, C as CharAt, o as Charmap, a as Concat, E as EndsWith, I as Includes, p as Interval, q as IsBooleanLiteral, r as IsNumberLiteral, k as IsStringLiteral, s as IsStringLiteralArray, J as Join, L as Length, M as Math, N as NodeLocale, t as OptionReplaceCombined, u as OptionReplaceObject, P as PadEnd, b as PadStart, v as Repeat, R as Replace, c as ReplaceAll, w as Reverse, S as Slice, j as SlugifyOptions, d as Split, e as StartsWith, T as ToLowerCase, f as ToUpperCase, g as Trim, h as TrimEnd, i as TrimStart } from './packem_shared/types-D2ydhHCv.js';
30
32
  export { SliceOptions, slice } from './slice.js';
31
33
  export { default as slugify } from './slugify.js';
32
- export { TruncateOptions, truncate } from './truncate.js';
33
34
  export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange } from './utilities.js';
34
35
  export { WordSimilaritySortOptions, wordSimilaritySort } from './word-similarity-sort.js';
35
36
  export { WordWrapOptions, WrapMode, wordWrap } from './word-wrap.js';
36
37
  import './packem_shared/lru-cache-B_t27XwI.js';
37
38
 
39
+ declare const excerpt: (html: string, limit: number, options?: ExcerptOptions) => string;
40
+ type ExcerptOptions = Omit<TruncateOptions, "position">;
41
+
38
42
  declare const distance: (a: string, b: string) => number;
39
43
  declare const closest: (str: string, arr: readonly string[]) => string;
40
44
 
41
- declare const closestN: (string_: string, array: ReadonlyArray<string>, n: number) => (string | null)[];
45
+ declare const closestN: (string_: string, array: ReadonlyArray<string>, n: number) => (string | undefined)[];
42
46
 
43
47
  declare const replaceString: (source: string, searches: OptionReplaceArray, ignoreRanges: IntervalArray) => string;
44
48
 
45
49
  declare const transliterate: (source: string, options?: OptionsTransliterate) => string;
46
50
 
47
- export { IntervalArray, OptionReplaceArray, OptionsTransliterate, closest, closestN, distance, replaceString, transliterate };
51
+ export { IntervalArray, OptionReplaceArray, OptionsTransliterate, TruncateOptions, closest, closestN, distance, excerpt, replaceString, transliterate };
52
+ export type { ExcerptOptions };
package/dist/index.js CHANGED
@@ -18,17 +18,18 @@ export { splitByCase } from './case/split-by-case.js';
18
18
  export { default as titleCase } from './case/title-case.js';
19
19
  export { default as trainCase } from './case/train-case.js';
20
20
  export { default as upperFirst } from './case/upper-first.js';
21
- export { default as joinSegments } from './packem_shared/joinSegments-CuU8RGpP.js';
21
+ export { default as joinSegments } from './packem_shared/joinSegments-B4H6oZ9b.js';
22
22
  export { closestString } from './closest-string.js';
23
23
  export { compareSimilarity } from './compare-similarity.js';
24
+ export { excerpt } from './packem_shared/excerpt-GvmR4ESb.js';
24
25
  export { getStringTruncatedWidth } from './get-string-truncated-width.js';
25
26
  export { getStringWidth } from './get-string-width.js';
26
- export { closestN } from './packem_shared/closestN-BREy4E7C.js';
27
+ export { closestN } from './packem_shared/closestN-Cvsw0Fue.js';
27
28
  export { outdent } from './outdent.js';
28
- export { default as replaceString } from './packem_shared/replaceString-vYvRBMfC.js';
29
+ export { default as replaceString } from './packem_shared/replaceString-BVlxk27d.js';
29
30
  export { slice } from './slice.js';
30
31
  export { default as slugify } from './slugify.js';
31
- export { default as transliterate } from './packem_shared/transliterate-CYnKKT8f.js';
32
+ export { default as transliterate } from './packem_shared/transliterate-a6LLM_Ei.js';
32
33
  export { truncate } from './truncate.js';
33
34
  export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange } from './utilities.js';
34
35
  export { wordSimilaritySort } from './word-similarity-sort.js';
@@ -1,4 +1,4 @@
1
- import { C as CharAt, a as Concat, E as EndsWith, I as Includes, L as Length, P as PadEnd, b as PadStart, R as Replace, c as ReplaceAll, S as Slice, d as Split, e as StartsWith, T as ToLowerCase, f as ToUpperCase, g as Trim, h as TrimEnd, i as TrimStart } from './packem_shared/types-Daae0hGf.js';
1
+ import { C as CharAt, a as Concat, E as EndsWith, I as Includes, L as Length, P as PadEnd, b as PadStart, R as Replace, c as ReplaceAll, S as Slice, d as Split, e as StartsWith, T as ToLowerCase, f as ToUpperCase, g as Trim, h as TrimEnd, i as TrimStart } from './packem_shared/types-D2ydhHCv.js';
2
2
 
3
3
  /* eslint-disable @typescript-eslint/method-signature-style */
4
4
 
package/dist/outdent.js CHANGED
@@ -1,4 +1,4 @@
1
- import { d as RE_LEADING_NEWLINE, e as RE_TRAILING_NEWLINE, f as RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE, g as RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY, h as RE_DETECT_INDENTATION, i as RE_MATCH_NEWLINES } from './packem_shared/constants-CTzC6Gjg.js';
1
+ import { a as RE_LEADING_NEWLINE, b as RE_TRAILING_NEWLINE, c as RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE, d as RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY, e as RE_DETECT_INDENTATION, f as RE_MATCH_NEWLINES } from './packem_shared/constants-CnXdp6qx.js';
2
2
 
3
3
  const hop = Object.prototype.hasOwnProperty;
4
4
  const has = (object, property) => hop.call(object, property);
@@ -17,7 +17,7 @@ const internalOutdentArray = (strings, firstInterpolatedValueSetsIndentationLeve
17
17
  if (match) {
18
18
  indentationLevel = match[1].length;
19
19
  }
20
- const reSource = `(\\r\\n|\\r|\\n).{0,${indentationLevel}}`;
20
+ const reSource = String.raw`(\r\n|\r|\n).{0,${indentationLevel}}`;
21
21
  const reMatchIndent = new RegExp(reSource, "g");
22
22
  if (firstInterpolatedValueSetsIndentationLevel) {
23
23
  strings = strings.slice(1);
@@ -57,7 +57,7 @@ const isTemplateStringsArray = (v) => has(v, "raw") && has(v, "length");
57
57
  const templateCache = /* @__PURE__ */ new WeakMap();
58
58
  const createInstance = (options) => {
59
59
  const enableCache = options.cache !== false;
60
- const cache = enableCache ? options.cacheStore ?? templateCache : null;
60
+ const cache = enableCache ? options.cacheStore ?? templateCache : void 0;
61
61
  const hasNewlineOption = options.newline !== void 0;
62
62
  function outdent2(stringsOrOptions, ...values) {
63
63
  if (isTemplateStringsArray(stringsOrOptions)) {
@@ -0,0 +1,24 @@
1
+ import { distance } from './closest-IHuSvnSn.js';
2
+ export { closest } from './closest-IHuSvnSn.js';
3
+
4
+ const closestN = (string_, array, n) => {
5
+ const distances = Array.from({ length: n }, () => Infinity);
6
+ const values = Array.from({ length: n }, () => void 0);
7
+ for (const candidateValue of array) {
8
+ let currentDistance = distance(string_, candidateValue);
9
+ let currentValue = candidateValue;
10
+ for (let index = 0; index < n; index += 1) {
11
+ if (currentDistance < distances[index]) {
12
+ const temporaryDistance = distances[index];
13
+ const temporaryValue = values[index];
14
+ distances[index] = currentDistance;
15
+ values[index] = currentValue;
16
+ currentDistance = temporaryDistance;
17
+ currentValue = temporaryValue ?? "";
18
+ }
19
+ }
20
+ }
21
+ return values;
22
+ };
23
+
24
+ export { closestN, distance };
@@ -92,4 +92,4 @@ const RE_TIBETAN = new RegExp("\\p{Script=Tibetan}", "u");
92
92
  const RE_UZBEK_LATIN_MODIFIER = /[\u02BB\u02BC\u0027]/u;
93
93
  const stripEmoji = (stringValue) => stringValue.replace(RE_EMOJI, "");
94
94
 
95
- export { RE_GURMUKHI as A, RE_KANNADA as B, RE_TAMIL as C, RE_TELUGU as D, RE_MALAYALAM as E, RE_SINHALA as F, RE_THAI as G, RE_LAO as H, RE_TIBETAN as I, RE_MYANMAR as J, RE_ETHIOPIC as K, RE_KHMER as L, RE_ORIYA as M, RE_CONTROL as N, ESCAPES as O, ANSI_ESCAPE_LINK as P, ANSI_SGR_TERMINATOR as Q, RE_FAST_ANSI as R, ANSI_ESCAPE_BELL as S, ANSI_CSI as T, RE_ESCAPE_PATTERN as U, ANSI_RESET_CODES as V, END_CODE as W, RE_ZERO_WIDTH as X, RE_VALID_ANSI_PAIRS as a, RE_VALID_HYPERLINKS as b, RE_ANSI as c, RE_LEADING_NEWLINE as d, RE_TRAILING_NEWLINE as e, RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE as f, RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY as g, RE_DETECT_INDENTATION as h, RE_MATCH_NEWLINES as i, RE_EMOJI as j, RE_SEPARATORS as k, RE_CYRILLIC as l, RE_LATIN as m, RE_GREEK as n, RE_GREEK_LATIN_SPLIT as o, RE_UZBEK_LATIN_MODIFIER as p, RE_KATAKANA as q, RE_KANJI as r, stripEmoji as s, RE_HIRAGANA as t, RE_HANGUL as u, RE_HEBREW as v, RE_ARABIC as w, RE_DEVANAGARI as x, RE_BENGALI as y, RE_GUJARATI as z };
95
+ export { RE_KANNADA as A, RE_TAMIL as B, RE_TELUGU as C, RE_MALAYALAM as D, RE_SINHALA as E, RE_THAI as F, RE_LAO as G, RE_TIBETAN as H, RE_MYANMAR as I, RE_ETHIOPIC as J, RE_KHMER as K, RE_ORIYA as L, RE_SEPARATORS as M, RE_CONTROL as N, ESCAPES as O, ANSI_ESCAPE_LINK as P, ANSI_SGR_TERMINATOR as Q, RE_FAST_ANSI as R, ANSI_ESCAPE_BELL as S, ANSI_CSI as T, RE_ESCAPE_PATTERN as U, ANSI_RESET_CODES as V, END_CODE as W, RE_ZERO_WIDTH as X, RE_LEADING_NEWLINE as a, RE_TRAILING_NEWLINE as b, RE_ONLY_WHITESPACE_WITH_AT_LEAST_ONE_NEWLINE as c, RE_STARTS_WITH_NEWLINE_OR_IS_EMPTY as d, RE_DETECT_INDENTATION as e, RE_MATCH_NEWLINES as f, RE_VALID_ANSI_PAIRS as g, RE_VALID_HYPERLINKS as h, RE_ANSI as i, RE_EMOJI as j, RE_CYRILLIC as k, RE_LATIN as l, RE_GREEK as m, RE_GREEK_LATIN_SPLIT as n, RE_UZBEK_LATIN_MODIFIER as o, RE_KATAKANA as p, RE_KANJI as q, RE_HIRAGANA as r, stripEmoji as s, RE_HANGUL as t, RE_HEBREW as u, RE_ARABIC as v, RE_DEVANAGARI as w, RE_BENGALI as x, RE_GUJARATI as y, RE_GURMUKHI as z };