@visulima/string 3.0.0-alpha.1 → 3.0.0-alpha.11

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 (83) hide show
  1. package/CHANGELOG.md +155 -0
  2. package/LICENSE.md +429 -1
  3. package/README.md +72 -20
  4. package/dist/align-text.d.ts +7 -10
  5. package/dist/align-text.js +7 -5
  6. package/dist/case/camel-case.d.ts +3 -5
  7. package/dist/case/camel-case.js +7 -7
  8. package/dist/case/capital-case.d.ts +3 -5
  9. package/dist/case/capital-case.js +3 -3
  10. package/dist/case/constant-case.d.ts +3 -5
  11. package/dist/case/dot-case.d.ts +3 -5
  12. package/dist/case/flat-case.d.ts +3 -5
  13. package/dist/case/flip-case.d.ts +4 -7
  14. package/dist/case/flip-case.js +8 -2
  15. package/dist/case/identify-case.d.ts +3 -5
  16. package/dist/case/identify-case.js +2 -1
  17. package/dist/case/index.d.ts +23 -25
  18. package/dist/case/index.js +1 -1
  19. package/dist/case/kebab-case.d.ts +6 -9
  20. package/dist/case/kebab-case.js +3 -3
  21. package/dist/case/lower-first.d.ts +3 -5
  22. package/dist/case/no-case.d.ts +3 -5
  23. package/dist/case/pascal-case.d.ts +3 -5
  24. package/dist/case/pascal-case.js +3 -3
  25. package/dist/case/pascal-snake-case.d.ts +3 -5
  26. package/dist/case/path-case.d.ts +3 -5
  27. package/dist/case/sentence-case.d.ts +3 -5
  28. package/dist/case/sentence-case.js +7 -7
  29. package/dist/case/snake-case.d.ts +3 -5
  30. package/dist/case/split-by-case.d.ts +11 -14
  31. package/dist/case/split-by-case.js +171 -52
  32. package/dist/case/title-case.d.ts +3 -5
  33. package/dist/case/title-case.js +3 -5
  34. package/dist/case/train-case.d.ts +3 -5
  35. package/dist/case/train-case.js +1 -1
  36. package/dist/case/upper-first.d.ts +3 -5
  37. package/dist/closest-string.d.ts +3 -5
  38. package/dist/closest-string.js +5 -8
  39. package/dist/compare-similarity.d.ts +3 -5
  40. package/dist/compare-similarity.js +2 -2
  41. package/dist/get-string-truncated-width.d.ts +18 -20
  42. package/dist/get-string-truncated-width.js +2 -33
  43. package/dist/get-string-width.d.ts +2 -5
  44. package/dist/index.d.ts +49 -45
  45. package/dist/index.js +12 -4
  46. package/dist/native-string-types.d.ts +145 -128
  47. package/dist/outdent.d.ts +9 -11
  48. package/dist/outdent.js +7 -15
  49. package/dist/packem_shared/closestN-DUsjgiXb.js +25 -0
  50. package/dist/packem_shared/{constants-CTzC6Gjg.js → constants-BsZS5f0z.js} +1 -1
  51. package/dist/packem_shared/countOccurrences-CS9XprQN.js +22 -0
  52. package/dist/packem_shared/direction-C9gfWWTK.js +16 -0
  53. package/dist/packem_shared/eastAsianWidthType-SD3YniiT.js +20 -0
  54. package/dist/packem_shared/excerpt-COsVNttN.js +1502 -0
  55. package/dist/packem_shared/indent-D3DSCa6s.js +33 -0
  56. package/dist/packem_shared/isFullwidthCodePoint-IFXZxNjq.js +10 -0
  57. package/dist/packem_shared/{joinSegments-CuU8RGpP.js → joinSegments-CvxSgKz0.js} +1 -1
  58. package/dist/packem_shared/lookup-BE8lEqy4.js +104 -0
  59. package/dist/packem_shared/lru-cache.d-BsP6kbVJ.d.ts +13 -0
  60. package/dist/packem_shared/{normalize-german-eszett-DEB8-ZPT.js → normalize-german-eszett-4p3yKEzn.js} +2 -1
  61. package/dist/packem_shared/redent-DSb1IJWn.js +8 -0
  62. package/dist/packem_shared/{replaceString-vYvRBMfC.js → replaceString-Ce8X2ZQ-.js} +19 -17
  63. package/dist/packem_shared/stripIndent-D_TRjxZ_.js +20 -0
  64. package/dist/packem_shared/{transliterate-CYnKKT8f.js → transliterate-CKt9VK7D.js} +10 -12
  65. package/dist/packem_shared/{types-Daae0hGf.d.ts → types.d-BVNv675q.d.ts} +18 -21
  66. package/dist/packem_shared/{types-CfPsw9ix.d.ts → types.d-DfgbcNKh.d.ts} +19 -21
  67. package/dist/slice.d.ts +5 -8
  68. package/dist/slice.js +9 -7
  69. package/dist/slugify.d.ts +1 -3
  70. package/dist/slugify.js +1 -1
  71. package/dist/test/utils.d.ts +20 -22
  72. package/dist/test/utils.js +2 -2
  73. package/dist/test/vitest.d.ts +3 -6
  74. package/dist/truncate.d.ts +7 -10
  75. package/dist/truncate.js +49 -26
  76. package/dist/utilities.d.ts +2 -4
  77. package/dist/utilities.js +6 -8
  78. package/dist/word-similarity-sort.d.ts +3 -5
  79. package/dist/word-wrap.d.ts +9 -11
  80. package/dist/word-wrap.js +37 -35
  81. package/package.json +2 -2
  82. package/dist/packem_shared/closestN-BREy4E7C.js +0 -19
  83. package/dist/packem_shared/lru-cache-B_t27XwI.d.ts +0 -14
package/dist/index.d.ts CHANGED
@@ -1,47 +1,51 @@
1
- export { AlignTextOptions, alignText } from './align-text.js';
2
- export { default as camelCase } from './case/camel-case.js';
3
- export { default as capitalCase } from './case/capital-case.js';
4
- export { default as constantCase } from './case/constant-case.js';
5
- export { default as dotCase } from './case/dot-case.js';
6
- export { default as flatCase } from './case/flat-case.js';
7
- export { FlipOptions, flipCase } from './case/flip-case.js';
8
- export { default as identifyCase } from './case/identify-case.js';
9
- export { KebabCaseOptions, kebabCase } from './case/kebab-case.js';
10
- export { default as lowerFirst } from './case/lower-first.js';
11
- export { default as noCase } from './case/no-case.js';
12
- export { default as pascalCase } from './case/pascal-case.js';
13
- export { default as pascalSnakeCase } from './case/pascal-snake-case.js';
14
- export { default as pathCase } from './case/path-case.js';
15
- export { default as sentenceCase } from './case/sentence-case.js';
16
- export { default as snakeCase } from './case/snake-case.js';
17
- export { SplitOptions, splitByCase } from './case/split-by-case.js';
18
- export { default as titleCase } from './case/title-case.js';
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';
21
- export { default as upperFirst } from './case/upper-first.js';
22
- export { joinSegments } from './case/index.js';
23
- export { ClosestStringOptions, closestString } from './closest-string.js';
24
- export { CompareSimilarityOptions, compareSimilarity } from './compare-similarity.js';
25
- export { StringTruncatedWidthOptions, StringTruncatedWidthResult, getStringTruncatedWidth } from './get-string-truncated-width.js';
26
- export { StringWidthOptions, getStringWidth } from './get-string-width.js';
27
- 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
- export { SliceOptions, slice } from './slice.js';
31
- export { default as slugify } from './slugify.js';
32
- export { TruncateOptions, truncate } from './truncate.js';
33
- export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange } from './utilities.js';
34
- export { WordSimilaritySortOptions, wordSimilaritySort } from './word-similarity-sort.js';
35
- export { WordWrapOptions, WrapMode, wordWrap } from './word-wrap.js';
36
- import './packem_shared/lru-cache-B_t27XwI.js';
37
-
38
- declare const distance: (a: string, b: string) => number;
39
- declare const closest: (str: string, arr: readonly string[]) => string;
40
-
41
- declare const closestN: (string_: string, array: ReadonlyArray<string>, n: number) => (string | null)[];
42
-
1
+ export { type AlignTextOptions, alignText } from "./align-text.js";
2
+ export { default as camelCase } from "./case/camel-case.js";
3
+ export { default as capitalCase } from "./case/capital-case.js";
4
+ export { default as constantCase } from "./case/constant-case.js";
5
+ export { default as dotCase } from "./case/dot-case.js";
6
+ export { default as flatCase } from "./case/flat-case.js";
7
+ export { type FlipOptions, flipCase } from "./case/flip-case.js";
8
+ export { default as identifyCase } from "./case/identify-case.js";
9
+ export { type KebabCaseOptions, kebabCase } from "./case/kebab-case.js";
10
+ export { default as lowerFirst } from "./case/lower-first.js";
11
+ export { default as noCase } from "./case/no-case.js";
12
+ export { default as pascalCase } from "./case/pascal-case.js";
13
+ export { default as pascalSnakeCase } from "./case/pascal-snake-case.js";
14
+ export { default as pathCase } from "./case/path-case.js";
15
+ export { default as sentenceCase } from "./case/sentence-case.js";
16
+ export { default as snakeCase } from "./case/snake-case.js";
17
+ export { type SplitOptions, splitByCase } from "./case/split-by-case.js";
18
+ export { default as titleCase } from "./case/title-case.js";
19
+ export { default as trainCase } from "./case/train-case.js";
20
+ export { type a as CamelCase, type b as CapitalCase, type C as CaseOptions, type c as ConstantCase, type D as DotCase, type F as FlatCase, type d as FlipCase, type I as IdentifyCase, type K as KebabCase, type L as LocaleOptions, type e as LowerFirst, type N as NoCase, type P as PascalCase, type f as PascalSnakeCase, type g as PathCase, type S as SentenceCase, type h as SnakeCase, type i as SplitByCase, type T as TitleCase, type j as TrainCase, type U as UpperFirst } from "./packem_shared/types.d-DfgbcNKh.js";
21
+ export { default as upperFirst } from "./case/upper-first.js";
22
+ export { joinSegments } from "./case/index.js";
23
+ export { type ClosestStringOptions, closestString } from "./closest-string.js";
24
+ export { type CompareSimilarityOptions, compareSimilarity } from "./compare-similarity.js";
25
+ export { type Options as EastAsianWidthOptions, type WidthType as EastAsianWidthType, eastAsianWidth, eastAsianWidthType } from 'get-east-asian-width';
26
+ import { TruncateOptions } from "./truncate.js";
27
+ export { truncate } from "./truncate.js";
28
+ export { type StringTruncatedWidthOptions, type StringTruncatedWidthResult, getStringTruncatedWidth } from "./get-string-truncated-width.js";
29
+ export { type StringWidthOptions, getStringWidth } from "./get-string-width.js";
30
+ export { type Options as IndentOptions, default as indent } from 'indent-string';
31
+ export { default as redent } from 'redent';
32
+ export { dedent, default as stripIndent } from 'strip-indent';
33
+ export { type Outdent, type Options as OutdentOptions, outdent } from "./outdent.js";
34
+ import { O as OptionReplaceArray, a as IntervalArray, b as OptionsTransliterate } from "./packem_shared/types.d-BVNv675q.js";
35
+ export { type A as All, type c as Any, type C as CharAt, type d as Charmap, type e as Concat, type E as EndsWith, type f as Includes, type g as Interval, type h as IsBooleanLiteral, type i as IsNumberLiteral, type I as IsStringLiteral, type j as IsStringLiteralArray, type J as Join, type L as Length, type M as Math, type N as NodeLocale, type k as OptionReplaceCombined, type l as OptionReplaceObject, type P as PadEnd, type m as PadStart, type R as Repeat, type n as Replace, type o as ReplaceAll, type p as Reverse, type q as Slice, type S as SlugifyOptions, type r as Split, type s as StartsWith, type T as ToLowerCase, type t as ToUpperCase, type u as Trim, type v as TrimEnd, type w as TrimStart } from "./packem_shared/types.d-BVNv675q.js";
36
+ export { type SliceOptions, slice } from "./slice.js";
37
+ export { default as slugify } from "./slugify.js";
38
+ export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange } from "./utilities.js";
39
+ export { type WordSimilaritySortOptions, wordSimilaritySort } from "./word-similarity-sort.js";
40
+ export { type WordWrapOptions, WrapMode, wordWrap } from "./word-wrap.js";
41
+ export { closest, distance } from 'fastest-levenshtein';
42
+ import "./packem_shared/lru-cache.d-BsP6kbVJ.js";
43
+ declare const countOccurrences: (value: unknown, substring: string) => number;
44
+ declare const direction: (value?: string) => "rtl" | "ltr" | "neutral";
45
+ declare const excerpt: (html: string, limit: number, options?: ExcerptOptions) => string;
46
+ type ExcerptOptions = Omit<TruncateOptions, "position">;
47
+ declare const isFullwidthCodePoint: (codePoint: number) => boolean;
48
+ declare const closestN: (string_: string, array: ReadonlyArray<string>, n: number) => (string | undefined)[];
43
49
  declare const replaceString: (source: string, searches: OptionReplaceArray, ignoreRanges: IntervalArray) => string;
44
-
45
50
  declare const transliterate: (source: string, options?: OptionsTransliterate) => string;
46
-
47
- export { IntervalArray, OptionReplaceArray, OptionsTransliterate, closest, closestN, distance, replaceString, transliterate };
51
+ export { type ExcerptOptions, type IntervalArray, type OptionReplaceArray, type OptionsTransliterate, type TruncateOptions, closestN, countOccurrences, direction, excerpt, isFullwidthCodePoint, replaceString, transliterate };
package/dist/index.js CHANGED
@@ -18,19 +18,27 @@ 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-CvxSgKz0.js';
22
22
  export { closestString } from './closest-string.js';
23
23
  export { compareSimilarity } from './compare-similarity.js';
24
+ export { countOccurrences } from './packem_shared/countOccurrences-CS9XprQN.js';
25
+ export { direction } from './packem_shared/direction-C9gfWWTK.js';
26
+ export { excerpt } from './packem_shared/excerpt-COsVNttN.js';
24
27
  export { getStringTruncatedWidth } from './get-string-truncated-width.js';
25
28
  export { getStringWidth } from './get-string-width.js';
26
- export { closestN } from './packem_shared/closestN-BREy4E7C.js';
29
+ export { default as isFullwidthCodePoint } from './packem_shared/isFullwidthCodePoint-IFXZxNjq.js';
30
+ export { closestN } from './packem_shared/closestN-DUsjgiXb.js';
27
31
  export { outdent } from './outdent.js';
28
- export { default as replaceString } from './packem_shared/replaceString-vYvRBMfC.js';
32
+ export { default as replaceString } from './packem_shared/replaceString-Ce8X2ZQ-.js';
29
33
  export { slice } from './slice.js';
30
34
  export { default as slugify } from './slugify.js';
31
- export { default as transliterate } from './packem_shared/transliterate-CYnKKT8f.js';
35
+ export { default as transliterate } from './packem_shared/transliterate-CKt9VK7D.js';
32
36
  export { truncate } from './truncate.js';
33
37
  export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange } from './utilities.js';
34
38
  export { wordSimilaritySort } from './word-similarity-sort.js';
35
39
  export { WrapMode, wordWrap } from './word-wrap.js';
40
+ export { default as indent } from './packem_shared/indent-D3DSCa6s.js';
41
+ export { default as redent } from './packem_shared/redent-DSb1IJWn.js';
42
+ export { dedent, default as stripIndent } from './packem_shared/stripIndent-D_TRjxZ_.js';
36
43
  export { closest, distance } from './packem_shared/closest-IHuSvnSn.js';
44
+ export { eastAsianWidth, eastAsianWidthType } from './packem_shared/eastAsianWidthType-SD3YniiT.js';
@@ -1,130 +1,147 @@
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';
2
-
3
- /* eslint-disable @typescript-eslint/method-signature-style */
4
-
1
+ type TupleOf<L extends number, T = unknown, Result extends any[] = []> = Result["length"] extends L ? Result : TupleOf<L, T, [...Result, T]>;
2
+ type InternalSliceType<T extends string, StartIndex extends number, EndIndex extends number, Result extends string = ""> = IsNumberLiteral<EndIndex | StartIndex> extends true ? T extends `${infer Head}${infer Rest}` ? IsStringLiteral<Head> extends true ? StartIndex extends 0 ? EndIndex extends 0 ? Result : InternalSliceType<Rest, 0, Math.Subtract<Math.GetPositiveIndex<T, EndIndex>, 1>, `${Result}${Head}`> : InternalSliceType<Rest, Math.Subtract<Math.GetPositiveIndex<T, StartIndex>, 1>, Math.Subtract<Math.GetPositiveIndex<T, EndIndex>, 1>, Result> : EndIndex | StartIndex extends 0 ? Result : string : IsStringLiteral<T> extends true ? Result : EndIndex | StartIndex extends 0 ? Result : string : string;
3
+ type SliceStartType<T extends string, StartIndex extends number, Result extends string = ""> = IsNumberLiteral<StartIndex> extends true ? T extends `${infer Head}${infer Rest}` ? IsStringLiteral<Head> extends true ? StartIndex extends 0 ? T : SliceStartType<Rest, Math.Subtract<Math.GetPositiveIndex<T, StartIndex>, 1>, Result> : string : IsStringLiteral<T> extends true ? Result : StartIndex extends 0 ? Result : string : string;
4
+ type InternalEndsWithType<T extends string, S extends string, P extends number> = All<[IsStringLiteral<S>, IsNumberLiteral<P>]> extends true ? Math.IsNegative<P> extends false ? P extends Length<T> ? IsStringLiteral<T> extends true ? S extends Slice<T, Math.Subtract<Length<T>, Length<S>>, Length<T>> ? true : false : EndsWithNoPositionType<Slice<T, 0, P>, S> : EndsWithNoPositionType<Slice<T, 0, P>, S> : false : boolean;
5
+ type EndsWithNoPositionType<T extends string, S extends string> = StartsWith<Reverse<T>, Reverse<S>>;
6
+ declare namespace Math {
7
+ type Subtract<A extends number, B extends number> = number extends A | B ? number : TupleOf<A> extends [...infer U, ...TupleOf<B>] ? U["length"] : 0;
8
+ type IsNegative<T extends number> = number extends T ? boolean : `${T}` extends `-${number}` ? true : false;
9
+ type Abs<T extends number> = `${T}` extends `-${infer U extends number}` ? U : T;
10
+ type GetPositiveIndex<T extends string, I extends number> = IsNegative<I> extends false ? I : Subtract<Length<T>, Abs<I>>;
11
+ }
12
+ type IsNumberLiteral<T extends number> = [T] extends [number] ? ([number] extends [T] ? false : true) : false;
13
+ type IsBooleanLiteral<T extends boolean> = [T] extends [boolean] ? ([boolean] extends [T] ? false : true) : false;
14
+ type Reverse<T extends string, Accumulator extends string = ""> = T extends `${infer Head}${infer Tail}` ? Reverse<Tail, `${Head}${Accumulator}`> : Accumulator extends "" ? T : `${T}${Accumulator}`;
15
+ type All<BoolArray extends boolean[]> = IsBooleanLiteral<BoolArray[number]> extends true ? BoolArray extends [infer Head extends boolean, ...infer Rest extends boolean[]] ? Head extends true ? All<Rest> : false : true : false;
16
+ type IsStringLiteral<T extends string> = [T] extends [string] ? [string] extends [T] ? false : Uppercase<T> extends Uppercase<Lowercase<T>> ? Lowercase<T> extends Lowercase<Uppercase<T>> ? true : false : false : false;
17
+ type IsStringLiteralArray<StringArray extends ReadonlyArray<string>> = IsStringLiteral<StringArray[number]> extends true ? true : false;
18
+ type CharAt<T extends string, Index extends number> = All<[IsStringLiteral<T>, IsNumberLiteral<Index>]> extends true ? Split<T>[Index] : string;
19
+ type Concat<T extends string[]> = Join<T>;
20
+ type EndsWith<T extends string, S extends string, P extends number | undefined = undefined> = P extends number ? InternalEndsWithType<T, S, P> : EndsWithNoPositionType<T, S>;
21
+ type Includes<T extends string, S extends string, P extends number = 0> = string extends S | T ? boolean : Math.IsNegative<P> extends false ? P extends 0 ? T extends `${string}${S}${string}` ? true : false : Includes<Slice<T, P>, S> : Includes<T, S>;
22
+ type Join<T extends ReadonlyArray<string>, Delimiter extends string = ""> = All<[IsStringLiteralArray<T>, IsStringLiteral<Delimiter>]> extends true ? T extends readonly [infer First extends string, ...infer Rest extends string[]] ? Rest extends [] ? First : `${First}${Delimiter}${Join<Rest, Delimiter>}` : "" : string;
23
+ type Length<T extends string> = IsStringLiteral<T> extends true ? Split<T>["length"] : number;
24
+ type PadEnd<T extends string, Times extends number = 0, Pad extends string = " "> = All<[IsStringLiteral<Pad | T>, IsNumberLiteral<Times>]> extends true ? Math.IsNegative<Times> extends false ? Math.Subtract<Times, Length<T>> extends infer Missing extends number ? `${T}${Slice<Repeat<Pad, Missing>, 0, Missing>}` : never : T : string;
25
+ type PadStart<T extends string, Times extends number = 0, Pad extends string = " "> = All<[IsStringLiteral<Pad | T>, IsNumberLiteral<Times>]> extends true ? Math.IsNegative<Times> extends false ? Math.Subtract<Times, Length<T>> extends infer Missing extends number ? `${Slice<Repeat<Pad, Missing>, 0, Missing>}${T}` : never : T : string;
26
+ type Repeat<T extends string, Times extends number = 0> = All<[IsStringLiteral<T>, IsNumberLiteral<Times>]> extends true ? Times extends 0 ? "" : Math.IsNegative<Times> extends false ? Join<TupleOf<Times, T>> : never : string;
27
+ type ReplaceAll<Sentence extends string, Lookup extends RegExp | string, Replacement extends string = ""> = Lookup extends string ? IsStringLiteral<Lookup | Replacement | Sentence> extends true ? Sentence extends `${infer Rest}${Lookup}${infer Rest2}` ? `${Rest}${Replacement}${ReplaceAll<Rest2, Lookup, Replacement>}` : Sentence : string : string;
28
+ type Replace<Sentence extends string, Lookup extends RegExp | string, Replacement extends string = ""> = Lookup extends string ? IsStringLiteral<Lookup | Replacement | Sentence> extends true ? Sentence extends `${infer Rest}${Lookup}${infer Rest2}` ? `${Rest}${Replacement}${Rest2}` : Sentence : string : string;
29
+ type Slice<T extends string, StartIndex extends number = 0, EndIndex extends number | undefined = undefined> = EndIndex extends number ? InternalSliceType<T, StartIndex, EndIndex> : SliceStartType<T, StartIndex>;
30
+ type Split<T extends string, Delimiter extends string = ""> = IsStringLiteral<Delimiter | T> extends true ? T extends `${infer First}${Delimiter}${infer Rest}` ? [First, ...Split<Rest, Delimiter>] : T extends "" ? [] : [T] : string[];
31
+ type StartsWith<T extends string, S extends string, P extends number = 0> = All<[IsStringLiteral<S>, IsNumberLiteral<P>]> extends true ? Math.IsNegative<P> extends false ? P extends 0 ? S extends `${infer SHead}${infer SRest}` ? T extends `${infer THead}${infer TRest}` ? IsStringLiteral<SHead | THead> extends true ? THead extends SHead ? StartsWith<TRest, SRest> : false : boolean : IsStringLiteral<T> extends true ? false : boolean : true : StartsWith<Slice<T, P>, S> : StartsWith<T, S> : boolean;
32
+ type TrimEnd<T extends string> = T extends `${infer Rest} ` ? TrimEnd<Rest> : T;
33
+ type TrimStart<T extends string> = T extends ` ${infer Rest}` ? TrimStart<Rest> : T;
34
+ type Trim<T extends string> = TrimEnd<TrimStart<T>>;
35
+ type ToLowerCase<T extends string> = IsStringLiteral<T> extends true ? Lowercase<T> : string;
36
+ type ToUpperCase<T extends string> = IsStringLiteral<T> extends true ? Uppercase<T> : string;
5
37
  declare global {
6
- interface String {
7
- /**
8
- * Returns the character at the specified index.
9
- * @param index The zero-based index of the desired character.
10
- */
11
- charAt<T extends string = string, I extends number = number>(this: T, index: I): CharAt<T, I>;
12
-
13
- /**
14
- * Returns a string that contains the concatenation of two or more strings.
15
- * @param strings The strings to append to the end of the string.
16
- */
17
- concat<T extends string = string, S extends string[] | string = string>(
18
- this: T,
19
- ...strings: S extends string ? [S] : S extends string[] ? S : never
20
- ): S extends string ? Concat<[T, S]> : S extends string[] ? Concat<[T, ...S]> : never;
21
-
22
- /**
23
- * Returns true if the sequence of elements of searchString converted to a String is the
24
- * same as the corresponding elements of this object (converted to a String) starting at
25
- * position. Otherwise returns false.
26
- */
27
- endsWith<T extends string = string, S extends string = string, P extends number | undefined = undefined>(
28
- this: T,
29
- searchString: S,
30
- position?: P,
31
- ): EndsWith<T, S, P>;
32
-
33
- /**
34
- * Returns true if searchString appears as a substring of the result of converting this
35
- * object to a String, at one or more positions that are greater than or equal to
36
- * position; otherwise, returns false.
37
- * @param searchString
38
- * @param position If position is undefined, 0 is assumed, so as to search all of the String.
39
- */
40
- includes<T extends string = string, S extends string = string, P extends number = 0>(this: T, searchString: S, position?: P): Includes<T, S, P>;
41
-
42
- /**
43
- * Returns the length of a String object.
44
- */
45
- length: Length<this>;
46
-
47
- /**
48
- * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
49
- * The padding is applied from the end (right) of the current string.
50
- * @param maxLength The length of the resulting string once the current string has been padded.
51
- * @param fillString The string to pad the current string with. If this string is too long, it will be truncated and the left-most part will be applied.
52
- */
53
- padEnd<T extends string = string, N extends number = number, P extends string = " ">(this: T, maxLength: N, fillString?: P): PadEnd<T, N, P>;
54
-
55
- /**
56
- * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
57
- * The padding is applied from the start (left) of the current string.
58
- * @param maxLength The length of the resulting string once the current string has been padded.
59
- * @param fillString The string to pad the current string with. If this string is too long, it will be truncated and the left-most part will be applied.
60
- */
61
- padStart<T extends string = string, N extends number = number, P extends string = " ">(this: T, maxLength: N, fillString?: P): PadStart<T, N, P>;
62
-
63
- /**
64
- * Replace text in a string, using a regular expression or search string.
65
- * @param searchValue A string to search for.
66
- * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
67
- */
68
- replace<T extends string = string, S extends RegExp | string = string, R extends string = string>(
69
- this: T,
70
- searchValue: S,
71
- replaceValue: R,
72
- ): Replace<T, S, R>;
73
-
74
- /**
75
- * Replace all instances of a substring in a string, using a regular expression or search string.
76
- * @param searchValue A string to search for.
77
- * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
78
- */
79
- replaceAll<T extends string = string, S extends RegExp | string = string, R extends string = string>(
80
- this: T,
81
- searchValue: S,
82
- replaceValue: R,
83
- ): ReplaceAll<T, S, R>;
84
-
85
- /**
86
- * Returns a section of a string.
87
- * @param start The index to the beginning of the specified portion of stringObj.
88
- * @param end The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
89
- */
90
- slice<T extends string = string, S extends number = number, E extends number | undefined = undefined>(this: T, start?: S, end?: E): Slice<T, S, E>;
91
-
92
- /**
93
- * Split a string into substrings using the specified separator and return them as an array.
94
- * @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
95
- */
96
- split<T extends string = string, S extends string = string>(this: T, separator: S): Split<T, S>;
97
-
98
- /**
99
- * Returns true if the sequence of elements of searchString converted to a String is the
100
- * same as the corresponding elements of this object (converted to a String) starting at
101
- * position. Otherwise returns false.
102
- */
103
- startsWith<T extends string = string, S extends string = string, P extends number = 0>(this: T, searchString: S, position?: P): StartsWith<T, S, P>;
104
-
105
- /**
106
- * Converts all alphabetic characters in a string to lowercase.
107
- */
108
- toLowerCase<T extends string = string>(this: T): ToLowerCase<T>;
109
-
110
- /**
111
- * Converts all alphabetic characters in a string to uppercase.
112
- */
113
- toUpperCase<T extends string = string>(this: T): ToUpperCase<T>;
114
-
115
- /**
116
- * Returns a string with all whitespace removed from both ends of a string.
117
- */
118
- trim<T extends string = string>(this: T): Trim<T>;
119
-
120
- /**
121
- * Returns a string with all whitespace removed from the end of a string.
122
- */
123
- trimEnd<T extends string = string>(this: T): TrimEnd<T>;
124
-
125
- /**
126
- * Returns a string with all whitespace removed from the start of a string.
127
- */
128
- trimStart<T extends string = string>(this: T): TrimStart<T>;
129
- }
38
+ interface String {
39
+ /**
40
+ * Returns the character at the specified index.
41
+ * @param index The zero-based index of the desired character.
42
+ */
43
+ charAt<T extends string = string, I extends number = number>(this: T, index: I): CharAt<T, I>;
44
+
45
+ /**
46
+ * Returns a string that contains the concatenation of two or more strings.
47
+ * @param strings The strings to append to the end of the string.
48
+ */
49
+ concat<T extends string = string, S extends string[] | string = string>(this: T, ...strings: S extends string ? [S] : S extends string[] ? S : never): S extends string ? Concat<[T, S]> : S extends string[] ? Concat<[T, ...S]> : never;
50
+
51
+ /**
52
+ * Returns true if the sequence of elements of searchString converted to a String is the
53
+ * same as the corresponding elements of this object (converted to a String) starting at
54
+ * position. Otherwise returns false.
55
+ */
56
+ endsWith<T extends string = string, S extends string = string, P extends number | undefined = undefined>(this: T, searchString: S, position?: P): EndsWith<T, S, P>;
57
+
58
+ /**
59
+ * Returns true if searchString appears as a substring of the result of converting this
60
+ * object to a String, at one or more positions that are greater than or equal to
61
+ * position; otherwise, returns false.
62
+ * @param searchString
63
+ * @param position If position is undefined, 0 is assumed, so as to search all of the String.
64
+ */
65
+ includes<T extends string = string, S extends string = string, P extends number = 0>(this: T, searchString: S, position?: P): Includes<T, S, P>;
66
+
67
+ /**
68
+ * Returns the length of a String object.
69
+ */
70
+ length: Length<this>;
71
+
72
+ /**
73
+ * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
74
+ * The padding is applied from the end (right) of the current string.
75
+ * @param maxLength The length of the resulting string once the current string has been padded.
76
+ * @param fillString The string to pad the current string with. If this string is too long, it will be truncated and the left-most part will be applied.
77
+ */
78
+ padEnd<T extends string = string, N extends number = number, P extends string = " ">(this: T, maxLength: N, fillString?: P): PadEnd<T, N, P>;
79
+
80
+ /**
81
+ * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
82
+ * The padding is applied from the start (left) of the current string.
83
+ * @param maxLength The length of the resulting string once the current string has been padded.
84
+ * @param fillString The string to pad the current string with. If this string is too long, it will be truncated and the left-most part will be applied.
85
+ */
86
+ padStart<T extends string = string, N extends number = number, P extends string = " ">(this: T, maxLength: N, fillString?: P): PadStart<T, N, P>;
87
+
88
+ /**
89
+ * Replace text in a string, using a regular expression or search string.
90
+ * @param searchValue A string to search for.
91
+ * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
92
+ */
93
+ replace<T extends string = string, S extends RegExp | string = string, R extends string = string>(this: T, searchValue: S, replaceValue: R): Replace<T, S, R>;
94
+
95
+ /**
96
+ * Replace all instances of a substring in a string, using a regular expression or search string.
97
+ * @param searchValue A string to search for.
98
+ * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
99
+ */
100
+ replaceAll<T extends string = string, S extends RegExp | string = string, R extends string = string>(this: T, searchValue: S, replaceValue: R): ReplaceAll<T, S, R>;
101
+
102
+ /**
103
+ * Returns a section of a string.
104
+ * @param start The index to the beginning of the specified portion of stringObj.
105
+ * @param end The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
106
+ */
107
+ slice<T extends string = string, S extends number = number, E extends number | undefined = undefined>(this: T, start?: S, end?: E): Slice<T, S, E>;
108
+
109
+ /**
110
+ * Split a string into substrings using the specified separator and return them as an array.
111
+ * @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
112
+ */
113
+ split<T extends string = string, S extends string = string>(this: T, separator: S): Split<T, S>;
114
+
115
+ /**
116
+ * Returns true if the sequence of elements of searchString converted to a String is the
117
+ * same as the corresponding elements of this object (converted to a String) starting at
118
+ * position. Otherwise returns false.
119
+ */
120
+ startsWith<T extends string = string, S extends string = string, P extends number = 0>(this: T, searchString: S, position?: P): StartsWith<T, S, P>;
121
+
122
+ /**
123
+ * Converts all alphabetic characters in a string to lowercase.
124
+ */
125
+ toLowerCase<T extends string = string>(this: T): ToLowerCase<T>;
126
+
127
+ /**
128
+ * Converts all alphabetic characters in a string to uppercase.
129
+ */
130
+ toUpperCase<T extends string = string>(this: T): ToUpperCase<T>;
131
+
132
+ /**
133
+ * Returns a string with all whitespace removed from both ends of a string.
134
+ */
135
+ trim<T extends string = string>(this: T): Trim<T>;
136
+
137
+ /**
138
+ * Returns a string with all whitespace removed from the end of a string.
139
+ */
140
+ trimEnd<T extends string = string>(this: T): TrimEnd<T>;
141
+
142
+ /**
143
+ * Returns a string with all whitespace removed from the start of a string.
144
+ */
145
+ trimStart<T extends string = string>(this: T): TrimStart<T>;
146
+ }
130
147
  }
package/dist/outdent.d.ts CHANGED
@@ -1,16 +1,14 @@
1
1
  declare const outdent: Outdent;
2
2
  interface Outdent {
3
- (strings: TemplateStringsArray, ...values: any[]): string;
4
- (options: Options): Outdent;
5
- string: (string_: string) => string;
3
+ (strings: TemplateStringsArray, ...values: any[]): string;
4
+ (options: Options): Outdent;
5
+ string: (string_: string) => string;
6
6
  }
7
7
  interface Options {
8
- cache?: boolean;
9
- cacheStore?: WeakMap<TemplateStringsArray, string[]>;
10
- newline?: string | null;
11
- trimLeadingNewline?: boolean;
12
- trimTrailingNewline?: boolean;
8
+ cache?: boolean;
9
+ cacheStore?: WeakMap<TemplateStringsArray, string[]>;
10
+ newline?: string | null;
11
+ trimLeadingNewline?: boolean;
12
+ trimTrailingNewline?: boolean;
13
13
  }
14
-
15
- export { outdent };
16
- export type { Options, Outdent };
14
+ export { Options, Outdent, outdent };
package/dist/outdent.js CHANGED
@@ -1,13 +1,7 @@
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_MATCH_NEWLINES, f as RE_DETECT_INDENTATION } from './packem_shared/constants-BsZS5f0z.js';
2
2
 
3
- const hop = Object.prototype.hasOwnProperty;
4
- const has = (object, property) => hop.call(object, property);
5
- const extend = (target, source) => {
6
- for (const property of Object.keys(source)) {
7
- target[property] = source[property];
8
- }
9
- return target;
10
- };
3
+ const has = (object, property) => Object.hasOwn(object, property);
4
+ const extend = (target, source) => Object.assign(target, source);
11
5
  const internalOutdentArray = (strings, firstInterpolatedValueSetsIndentationLevel, options) => {
12
6
  if (strings.length === 0) {
13
7
  return [];
@@ -19,15 +13,13 @@ const internalOutdentArray = (strings, firstInterpolatedValueSetsIndentationLeve
19
13
  }
20
14
  const reSource = String.raw`(\r\n|\r|\n).{0,${indentationLevel}}`;
21
15
  const reMatchIndent = new RegExp(reSource, "g");
22
- if (firstInterpolatedValueSetsIndentationLevel) {
23
- strings = strings.slice(1);
24
- }
16
+ const processedStrings = firstInterpolatedValueSetsIndentationLevel ? strings.slice(1) : strings;
25
17
  const { newline, trimLeadingNewline, trimTrailingNewline } = options;
26
18
  const normalizeNewlines = typeof newline === "string";
27
- const l = strings.length;
19
+ const l = processedStrings.length;
28
20
  const outdentedStrings = Array.from({ length: l });
29
21
  for (let index = 0; index < l; index++) {
30
- let v = strings[index];
22
+ let v = processedStrings[index];
31
23
  v = v.replace(reMatchIndent, "$1");
32
24
  if (index === 0 && trimLeadingNewline) {
33
25
  v = v.replace(RE_LEADING_NEWLINE, "");
@@ -57,7 +49,7 @@ const isTemplateStringsArray = (v) => has(v, "raw") && has(v, "length");
57
49
  const templateCache = /* @__PURE__ */ new WeakMap();
58
50
  const createInstance = (options) => {
59
51
  const enableCache = options.cache !== false;
60
- const cache = enableCache ? options.cacheStore ?? templateCache : null;
52
+ const cache = enableCache ? options.cacheStore ?? templateCache : void 0;
61
53
  const hasNewlineOption = options.newline !== void 0;
62
54
  function outdent2(stringsOrOptions, ...values) {
63
55
  if (isTemplateStringsArray(stringsOrOptions)) {
@@ -0,0 +1,25 @@
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 }).fill(Infinity);
6
+ const values = Array.from({ length: n }).fill(void 0);
7
+ for (const element of array) {
8
+ const candidateValue = element;
9
+ let currentDistance = distance(string_, candidateValue);
10
+ let currentValue = candidateValue;
11
+ for (let index = 0; index < n; index += 1) {
12
+ if (currentDistance < distances[index]) {
13
+ const temporaryDistance = distances[index];
14
+ const temporaryValue = values[index];
15
+ distances[index] = currentDistance;
16
+ values[index] = currentValue;
17
+ currentDistance = temporaryDistance;
18
+ currentValue = temporaryValue ?? "";
19
+ }
20
+ }
21
+ }
22
+ return values;
23
+ };
24
+
25
+ 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_GUJARATI as A, RE_GURMUKHI as B, RE_KANNADA as C, RE_TAMIL as D, RE_TELUGU as E, RE_MALAYALAM as F, RE_SINHALA as G, RE_THAI as H, RE_LAO as I, RE_TIBETAN as J, RE_MYANMAR as K, RE_ETHIOPIC as L, RE_KHMER as M, RE_ORIYA 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_MATCH_NEWLINES as e, RE_DETECT_INDENTATION as f, RE_ANSI as g, RE_CONTROL as h, RE_EMOJI as i, RE_VALID_ANSI_PAIRS as j, RE_VALID_HYPERLINKS 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_SEPARATORS as x, RE_DEVANAGARI as y, RE_BENGALI as z };
@@ -0,0 +1,22 @@
1
+ const countOccurrences = (value, substring) => {
2
+ const source = String(value);
3
+ if (typeof substring !== "string") {
4
+ throw new TypeError("Expected character");
5
+ }
6
+ if (substring.length === 0) {
7
+ throw new TypeError("Expected non-empty substring");
8
+ }
9
+ let count = 0;
10
+ let index = source.indexOf(substring);
11
+ while (index !== -1) {
12
+ count++;
13
+ const nextIndex = index + substring.length;
14
+ if (nextIndex <= index) {
15
+ break;
16
+ }
17
+ index = source.indexOf(substring, nextIndex);
18
+ }
19
+ return count;
20
+ };
21
+
22
+ export { countOccurrences };
@@ -0,0 +1,16 @@
1
+ const rtlRange = "֑-߿יִ-﷽ﹰ-ﻼ";
2
+ const ltrRange = "A-Za-zÀ-ÖØ-öø-ʸ̀-֐ࠀ-῿‎Ⰰ-﬜︀-﹯﻽-￿";
3
+ const rtl = new RegExp(`^[^${ltrRange}]*[${rtlRange}]`);
4
+ const ltr = new RegExp(`^[^${rtlRange}]*[${ltrRange}]`);
5
+ const direction = (value = "") => {
6
+ const source = value;
7
+ if (rtl.test(source)) {
8
+ return "rtl";
9
+ }
10
+ if (ltr.test(source)) {
11
+ return "ltr";
12
+ }
13
+ return "neutral";
14
+ };
15
+
16
+ export { direction };
@@ -0,0 +1,20 @@
1
+ import { i as isFullWidth, a as isWide, b as isAmbiguous, g as getCategory } from './lookup-BE8lEqy4.js';
2
+
3
+ function validate(codePoint) {
4
+ if (!Number.isSafeInteger(codePoint)) {
5
+ throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
6
+ }
7
+ }
8
+ function eastAsianWidthType(codePoint) {
9
+ validate(codePoint);
10
+ return getCategory(codePoint);
11
+ }
12
+ function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
13
+ validate(codePoint);
14
+ if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
15
+ return 2;
16
+ }
17
+ return 1;
18
+ }
19
+
20
+ export { isFullWidth as _isFullWidth, isWide as _isWide, eastAsianWidth, eastAsianWidthType };