@visulima/string 3.0.0-alpha.9 → 3.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.
Files changed (127) hide show
  1. package/CHANGELOG.md +298 -0
  2. package/LICENSE.md +68 -3
  3. package/README.md +80 -2
  4. package/dist/align-text.d.ts +35 -0
  5. package/dist/align-text.js +2 -34
  6. package/dist/case/camel-case.d.ts +17 -3
  7. package/dist/case/camel-case.js +1 -55
  8. package/dist/case/capital-case.d.ts +14 -3
  9. package/dist/case/capital-case.js +1 -47
  10. package/dist/case/constant-case.d.ts +14 -3
  11. package/dist/case/constant-case.js +1 -7
  12. package/dist/case/dot-case.d.ts +14 -3
  13. package/dist/case/dot-case.js +1 -7
  14. package/dist/case/flat-case.d.ts +12 -3
  15. package/dist/case/flat-case.js +1 -7
  16. package/dist/case/flip-case.d.ts +16 -3
  17. package/dist/case/flip-case.js +1 -82
  18. package/dist/case/identify-case.d.ts +15 -3
  19. package/dist/case/identify-case.js +1 -66
  20. package/dist/case/index.d.ts +8 -3
  21. package/dist/case/index.js +1 -20
  22. package/dist/case/kebab-case.d.ts +25 -3
  23. package/dist/case/kebab-case.js +1 -55
  24. package/dist/case/lower-first.d.ts +13 -3
  25. package/dist/case/lower-first.js +1 -9
  26. package/dist/case/no-case.d.ts +14 -3
  27. package/dist/case/no-case.js +1 -7
  28. package/dist/case/pascal-case.d.ts +17 -3
  29. package/dist/case/pascal-case.js +1 -48
  30. package/dist/case/pascal-snake-case.d.ts +14 -3
  31. package/dist/case/pascal-snake-case.js +1 -28
  32. package/dist/case/path-case.d.ts +14 -3
  33. package/dist/case/path-case.js +1 -7
  34. package/dist/case/sentence-case.d.ts +14 -3
  35. package/dist/case/sentence-case.js +1 -54
  36. package/dist/case/snake-case.d.ts +14 -3
  37. package/dist/case/snake-case.js +1 -7
  38. package/dist/case/split-by-case.d.ts +29 -3
  39. package/dist/case/split-by-case.js +1 -763
  40. package/dist/case/title-case.d.ts +12 -3
  41. package/dist/case/title-case.js +1 -40
  42. package/dist/case/train-case.d.ts +14 -3
  43. package/dist/case/train-case.js +1 -40
  44. package/dist/case/upper-first.d.ts +13 -3
  45. package/dist/case/upper-first.js +1 -9
  46. package/dist/closest-string.d.ts +32 -0
  47. package/dist/closest-string.js +1 -22
  48. package/dist/compare-similarity.d.ts +37 -0
  49. package/dist/compare-similarity.js +1 -12
  50. package/dist/count-occurrences.d.ts +9 -0
  51. package/dist/count-occurrences.js +1 -0
  52. package/dist/direction.d.ts +7 -0
  53. package/dist/direction.js +1 -0
  54. package/dist/east-asian-width.d.ts +52 -0
  55. package/dist/east-asian-width.js +1 -0
  56. package/dist/excerpt.d.ts +25 -0
  57. package/dist/excerpt.js +53 -0
  58. package/dist/get-string-truncated-width.d.ts +151 -0
  59. package/dist/get-string-truncated-width.js +1 -332
  60. package/dist/get-string-width.d.ts +58 -0
  61. package/dist/get-string-width.js +1 -5
  62. package/dist/indent.d.ts +87 -0
  63. package/dist/indent.js +1 -0
  64. package/dist/index.d.ts +12 -20
  65. package/dist/index.js +1 -44
  66. package/dist/is-fullwidth-code-point.d.ts +7 -0
  67. package/dist/is-fullwidth-code-point.js +1 -0
  68. package/dist/levenshtein.d.ts +25 -0
  69. package/dist/levenshtein.js +1 -0
  70. package/dist/native-string-types.d.ts +239 -0
  71. package/dist/outdent.d.ts +74 -0
  72. package/dist/outdent.js +1 -109
  73. package/dist/packem_shared/_isFullWidth-Dqc3MWgl.js +1 -0
  74. package/dist/packem_shared/closest-C6YDQs4m.js +1 -0
  75. package/dist/packem_shared/constants-aPzGW29R.js +1 -0
  76. package/dist/packem_shared/dedent-CPjAYUXh.js +1 -0
  77. package/dist/packem_shared/eastAsianWidth-DJV8Kqd-.js +1 -0
  78. package/dist/packem_shared/generate-cache-key-BqU1Cqwm.js +1 -0
  79. package/dist/packem_shared/indent-cz8WMI0e.js +1 -0
  80. package/dist/packem_shared/joinSegments-CaHT-45s.js +1 -0
  81. package/dist/packem_shared/lru-cache-BtMSrYQJ.js +1 -0
  82. package/dist/packem_shared/normalize-german-eszett-hNMwtGjd.js +1 -0
  83. package/dist/packem_shared/redent-ByOoJ6fN.js +1 -0
  84. package/dist/packem_shared/types.d-CmNvyl4l.d.ts +360 -0
  85. package/dist/packem_shared/types.d-fhe030jX.d.ts +402 -0
  86. package/dist/replace-string.d.ts +10 -0
  87. package/dist/replace-string.js +1 -0
  88. package/dist/slice.d.ts +42 -0
  89. package/dist/slice.js +1 -415
  90. package/dist/slugify.d.ts +10 -1
  91. package/dist/slugify.js +1 -46
  92. package/dist/test/utils.d.ts +17 -0
  93. package/dist/test/utils.js +13 -88
  94. package/dist/test/vitest.d.ts +3 -0
  95. package/dist/test/vitest.js +1 -5
  96. package/dist/transliterate.d.ts +10 -0
  97. package/dist/transliterate.js +5 -0
  98. package/dist/truncate.d.ts +43 -0
  99. package/dist/truncate.js +1 -112
  100. package/dist/utilities.d.ts +28 -2
  101. package/dist/utilities.js +1 -52
  102. package/dist/word-similarity-sort.d.ts +34 -0
  103. package/dist/word-similarity-sort.js +1 -22
  104. package/dist/word-wrap.d.ts +44 -0
  105. package/dist/word-wrap.js +8 -639
  106. package/package.json +70 -36
  107. package/dist/packem_shared/LRUCache-3r3SovvR.js +0 -46
  108. package/dist/packem_shared/closest-IHuSvnSn.js +0 -139
  109. package/dist/packem_shared/closestN-DUsjgiXb.js +0 -25
  110. package/dist/packem_shared/constants-BsZS5f0z.js +0 -95
  111. package/dist/packem_shared/countOccurrences-CS9XprQN.js +0 -22
  112. package/dist/packem_shared/direction-C9gfWWTK.js +0 -16
  113. package/dist/packem_shared/eastAsianWidthType-SD3YniiT.js +0 -20
  114. package/dist/packem_shared/excerpt-COsVNttN.js +0 -1502
  115. package/dist/packem_shared/generate-cache-key-DdayDfjV.js +0 -6
  116. package/dist/packem_shared/indent-D3DSCa6s.js +0 -33
  117. package/dist/packem_shared/isFullwidthCodePoint-IFXZxNjq.js +0 -10
  118. package/dist/packem_shared/joinSegments-CvxSgKz0.js +0 -44
  119. package/dist/packem_shared/lookup-BE8lEqy4.js +0 -104
  120. package/dist/packem_shared/lru-cache.d-BsP6kbVJ.d.ts +0 -13
  121. package/dist/packem_shared/normalize-german-eszett-4p3yKEzn.js +0 -8
  122. package/dist/packem_shared/redent-DSb1IJWn.js +0 -8
  123. package/dist/packem_shared/replaceString-Ce8X2ZQ-.js +0 -192
  124. package/dist/packem_shared/stripIndent-D_TRjxZ_.js +0 -20
  125. package/dist/packem_shared/transliterate-CKt9VK7D.js +0 -47756
  126. package/dist/packem_shared/types.d-BVNv675q.d.ts +0 -61
  127. package/dist/packem_shared/types.d-DfgbcNKh.d.ts +0 -57
@@ -0,0 +1,360 @@
1
+
2
+ /**
3
+ * Creates a tuple type of specified length filled with a given type.
4
+ * @template L - The desired length of the tuple
5
+ * @template T - The type to fill the tuple with (defaults to unknown)
6
+ * @template Result - Internal accumulator for recursive type building
7
+ * @returns A tuple type of length L filled with type T
8
+ */
9
+ type TupleOf<L extends number, T = unknown, Result extends any[] = []> = Result["length"] extends L ? Result : TupleOf<L, T, [...Result, T]>;
10
+ /**
11
+ * Internal type for implementing string slicing with both start and end indices.
12
+ * Handles edge cases and type safety for string literal types.
13
+ * @template T - The input string type
14
+ * @template StartIndex - The starting index for the slice
15
+ * @template EndIndex - The ending index for the slice
16
+ * @template Result - Internal accumulator for building the result string
17
+ */
18
+ 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;
19
+ /**
20
+ * Internal type for implementing string slicing with only a start index.
21
+ * Provides type-safe string slicing functionality for string literal types.
22
+ * @template T - The input string type
23
+ * @template StartIndex - The starting index for the slice
24
+ * @template Result - Internal accumulator for building the result string
25
+ */
26
+ 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;
27
+ 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;
28
+ /**
29
+ * Internal type for implementing EndsWith functionality without a position parameter.
30
+ * Uses string reversal to check if a string ends with another string.
31
+ * @template T - The string to check
32
+ * @template S - The suffix to check for
33
+ */
34
+ type EndsWithNoPositionType<T extends string, S extends string> = StartsWith<Reverse<T>, Reverse<S>>;
35
+ /**
36
+ * Namespace containing type-level mathematical operations.
37
+ * These utilities provide type-safe arithmetic and number manipulation.
38
+ */
39
+ declare namespace Math {
40
+ type Subtract<A extends number, B extends number> = number extends A | B ? number : TupleOf<A> extends [...infer U, ...TupleOf<B>] ? U["length"] : 0;
41
+ type IsNegative<T extends number> = number extends T ? boolean : `${T}` extends `-${number}` ? true : false;
42
+ type Abs<T extends number> = `${T}` extends `-${infer U extends number}` ? U : T;
43
+ type GetPositiveIndex<T extends string, I extends number> = IsNegative<I> extends false ? I : Subtract<Length<T>, Abs<I>>;
44
+ }
45
+ /**
46
+ * Type predicate that determines if a number type is a literal type rather than the general 'number' type.
47
+ * For example: IsNumberLiteral&lt;42> is true, but IsNumberLiteral&lt;number> is false.
48
+ * @template T - The number type to check
49
+ * @returns true if T is a number literal type, false otherwise
50
+ */
51
+ type IsNumberLiteral<T extends number> = [T] extends [number] ? ([number] extends [T] ? false : true) : false;
52
+ type IsBooleanLiteral<T extends boolean> = [T] extends [boolean] ? ([boolean] extends [T] ? false : true) : false;
53
+ /**
54
+ * Type-level string reversal utility.
55
+ * Recursively builds the reversed string using template literal types.
56
+ * @template T - The string type to reverse
57
+ * @template Accumulator - Internal accumulator for building the reversed string
58
+ * @returns A type representing the reversed string
59
+ * @example
60
+ * type ReversedHello = Reverse<'hello'> // type ReversedHello = 'olleh'
61
+ */
62
+ type Reverse<T extends string, Accumulator extends string = ""> = T extends `${infer Head}${infer Tail}` ? Reverse<Tail, `${Head}${Accumulator}`> : Accumulator extends "" ? T : `${T}${Accumulator}`;
63
+ /**
64
+ * Type predicate that checks if any element in a boolean array type is the literal 'true'.
65
+ * Distinguishes between literal true/false and the general boolean type.
66
+ * @template T - Array of boolean types to check
67
+ * @returns true if any element is the literal true, false otherwise
68
+ * @example
69
+ * type HasTrue = Any<[true, false, boolean]> // type HasTrue = true
70
+ */
71
+ type Any<BoolArray extends boolean[]> = BoolArray extends [infer Head extends boolean, ...infer Rest extends boolean[]] ? IsBooleanLiteral<Head> extends true ? Head extends true ? true : Any<Rest> : Any<Rest> : false;
72
+ /**
73
+ * Type predicate that checks if all elements in a boolean array type are the literal 'true'.
74
+ * Distinguishes between literal true/false and the general boolean type.
75
+ * @template T - Array of boolean types to check
76
+ * @returns true if all elements are the literal true, false otherwise
77
+ * @example
78
+ * type AllTrue = All<[true, true]> // type AllTrue = true
79
+ * type NotAllTrue = All<[true, false]> // type NotAllTrue = false
80
+ */
81
+ 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;
82
+ /**
83
+ * Type predicate that determines if a string type is a literal type rather than the general 'string' type.
84
+ * @template T - The string type to check
85
+ * @returns true if T is a string literal type, false if it's the general string type
86
+ * @example
87
+ * type IsLiteral = IsStringLiteral<'hello'> // type IsLiteral = true
88
+ * type NotLiteral = IsStringLiteral<string> // type NotLiteral = false
89
+ */
90
+ 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;
91
+ type IsStringLiteralArray<StringArray extends ReadonlyArray<string>> = IsStringLiteral<StringArray[number]> extends true ? true : false;
92
+ /**
93
+ * Type-safe utility to get the character at a specific index in a string literal type.
94
+ * @template T - The string type to extract a character from
95
+ * @template Index - The numeric index of the desired character
96
+ * @returns The character type at the specified index, or never if the index is invalid
97
+ * @example
98
+ * type FirstChar = CharAt<'hello', 0> // type FirstChar = 'h'
99
+ */
100
+ type CharAt<T extends string, Index extends number> = All<[IsStringLiteral<T>, IsNumberLiteral<Index>]> extends true ? Split<T>[Index] : string;
101
+ /**
102
+ * Type-level string concatenation for tuples of string literals.
103
+ * Joins all strings in the tuple into a single string type.
104
+ * @template T - Tuple of string types to concatenate
105
+ * @returns A single string type representing the concatenated result
106
+ * @example
107
+ * type Combined = Concat<['hello', ' ', 'world']> // type Combined = 'hello world'
108
+ */
109
+ type Concat<T extends string[]> = Join<T>;
110
+ /**
111
+ * Type-level implementation of string.endsWith() functionality.
112
+ * Checks if a string type ends with another string type at a given position.
113
+ * @template T - The string type to check
114
+ * @template S - The suffix to check for
115
+ * @template P - Optional position at which to end the search
116
+ * @returns A boolean type indicating if T ends with S at position P
117
+ * @example
118
+ * type EndsWithWorld = EndsWith<'hello world', 'world'> // type EndsWithWorld = true
119
+ * type DoesNotEnd = EndsWith<'hello world', 'hello'> // type DoesNotEnd = false
120
+ */
121
+ type EndsWith<T extends string, S extends string, P extends number | undefined = undefined> = P extends number ? InternalEndsWithType<T, S, P> : EndsWithNoPositionType<T, S>;
122
+ /**
123
+ * Type-level implementation of string.includes() functionality.
124
+ * Determines if one string type contains another string type starting at an optional position.
125
+ * @template T - The string type to search within
126
+ * @template S - The string type to search for
127
+ * @template P - Optional position to start the search from
128
+ * @returns A boolean type indicating if S is found within T starting at P
129
+ * @example
130
+ * type HasWorld = Includes<'hello world', 'world'> // type HasWorld = true
131
+ * type NoWorld = Includes<'hello', 'world'> // type NoWorld = false
132
+ */
133
+ 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>;
134
+ /**
135
+ * Type-level implementation of Array.join() functionality for string tuples.
136
+ * Combines string literal types in a tuple using a delimiter.
137
+ * @template T - Tuple of string types to join
138
+ * @template Delimiter - The delimiter to insert between elements
139
+ * @returns A string type representing the joined result
140
+ * @example
141
+ * type Joined = Join<['a', 'b', 'c'], '.'> // type Joined = 'a.b.c'
142
+ */
143
+ 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;
144
+ /**
145
+ * Type-level utility to compute the length of a string literal type.
146
+ * @template T - The string type to measure
147
+ * @returns A number literal type representing the string's length
148
+ * @example
149
+ * type Len = Length<'hello'> // type Len = 5
150
+ */
151
+ type Length<T extends string> = IsStringLiteral<T> extends true ? Split<T>["length"] : number;
152
+ /**
153
+ * Type-level implementation of string.padEnd() functionality.
154
+ * Adds padding to the end of a string type until it reaches a specified length.
155
+ * @template T - The string type to pad
156
+ * @template Times - Target total length of the padded string
157
+ * @template Pad - The string to use as padding (defaults to space)
158
+ * @returns A string type with the padding added to the end
159
+ * @example
160
+ * type Padded = PadEnd<'hello', 7, '_'> // type Padded = 'hello__'
161
+ */
162
+ 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;
163
+ /**
164
+ * Type-level implementation of string.padStart() functionality.
165
+ * Adds padding to the beginning of a string type until it reaches a specified length.
166
+ * @template T - The string type to pad
167
+ * @template Times - Target total length of the padded string
168
+ * @template Pad - The string to use as padding (defaults to space)
169
+ * @returns A string type with the padding added to the start
170
+ * @example
171
+ * type Padded = PadStart<'hello', 7, '_'> // type Padded = '__hello'
172
+ */
173
+ 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;
174
+ /**
175
+ * Type-level implementation of string.repeat() functionality.
176
+ * Creates a new string type by repeating the input string a specified number of times.
177
+ * @template T - The string type to repeat
178
+ * @template Times - The number of times to repeat the string
179
+ * @returns A string type containing T repeated Times times
180
+ * @example
181
+ * type Repeated = Repeat<'abc', 2> // type Repeated = 'abcabc'
182
+ */
183
+ 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;
184
+ /**
185
+ * Type-level implementation of string.replaceAll() functionality.
186
+ * Replaces all occurrences of a substring with another string.
187
+ * @template Sentence - The string type to perform replacements on
188
+ * @template Lookup - The string or RegExp pattern to search for. When a RegExp is used, the result type widens to string.
189
+ * @template Replacement - The string type to replace matches with
190
+ * @returns A string type with all occurrences of Lookup replaced with Replacement. When Lookup is a RegExp, returns string.
191
+ * @example
192
+ * type Replaced = ReplaceAll<'hello hello', 'hello', 'hi'> // type Replaced = 'hi hi'
193
+ */
194
+ 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;
195
+ /**
196
+ * Type-level implementation of string.replace() functionality.
197
+ * Replaces the first occurrence of a substring with another string.
198
+ * @template Sentence - The string type to perform replacement on
199
+ * @template Lookup - The string or RegExp pattern to search for. When a RegExp is used, the result type widens to string.
200
+ * @template Replacement - The string type to replace the match with
201
+ * @returns A string type with the first occurrence of Lookup replaced with Replacement. When Lookup is a RegExp, returns string.
202
+ * @example
203
+ * type Replaced = Replace<'hello hello', 'hello', 'hi'> // type Replaced = 'hi hello'
204
+ */
205
+ 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;
206
+ /**
207
+ * Type-level implementation of string.slice() functionality.
208
+ * Extracts a portion of a string type between start and end indices.
209
+ * @template T - The string type to slice
210
+ * @template StartIndex - The starting index of the slice
211
+ * @template EndIndex - The ending index of the slice (optional)
212
+ * @returns A string type containing the characters between the indices
213
+ * @example
214
+ * type Sliced = Slice<'hello world', 0, 5> // type Sliced = 'hello'
215
+ * type ToEnd = Slice<'hello world', 6> // type ToEnd = 'world'
216
+ */
217
+ type Slice<T extends string, StartIndex extends number = 0, EndIndex extends number | undefined = undefined> = EndIndex extends number ? InternalSliceType<T, StartIndex, EndIndex> : SliceStartType<T, StartIndex>;
218
+ /**
219
+ * Type-level implementation of string.split() functionality.
220
+ * Splits a string type into a tuple of string types based on a delimiter.
221
+ * @template T - The string type to split
222
+ * @template Delimiter - The string type to use as a separator
223
+ * @returns A tuple type containing the split string parts
224
+ * @example
225
+ * type Parts = Split<'a,b,c', ','> // type Parts = ['a', 'b', 'c']
226
+ */
227
+ 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[];
228
+ /**
229
+ * Type-level implementation of string.startsWith() functionality.
230
+ * Checks if a string type begins with another string type at a given position.
231
+ * @template T - The string type to check
232
+ * @template S - The prefix to check for
233
+ * @template P - Optional position at which to start the search
234
+ * @returns A boolean type indicating if T starts with S at position P
235
+ * @example
236
+ * type StartsWithHello = StartsWith<'hello world', 'hello'> // type StartsWithHello = true
237
+ * type DoesNotStart = StartsWith<'hello world', 'world'> // type DoesNotStart = false
238
+ */
239
+ 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;
240
+ /**
241
+ * Type-level implementation of string.trimEnd() functionality.
242
+ * Removes whitespace characters from the end of a string type.
243
+ * @template T - The string type to trim
244
+ * @returns A string type with trailing whitespace removed
245
+ * @example
246
+ * type Trimmed = TrimEnd<'hello '> // type Trimmed = 'hello'
247
+ */
248
+ type TrimEnd<T extends string> = T extends `${infer Rest} ` ? TrimEnd<Rest> : T;
249
+ /**
250
+ * Type-level implementation of string.trimStart() functionality.
251
+ * Removes whitespace characters from the beginning of a string type.
252
+ * @template T - The string type to trim
253
+ * @returns A string type with leading whitespace removed
254
+ * @example
255
+ * type Trimmed = TrimStart<' hello'> // type Trimmed = 'hello'
256
+ */
257
+ type TrimStart<T extends string> = T extends ` ${infer Rest}` ? TrimStart<Rest> : T;
258
+ /**
259
+ * Type-level implementation of string.trim() functionality.
260
+ * Removes whitespace characters from both ends of a string type.
261
+ * @template T - The string type to trim
262
+ * @returns A string type with both leading and trailing whitespace removed
263
+ * @example
264
+ * type Trimmed = Trim<' hello '> // type Trimmed = 'hello'
265
+ */
266
+ type Trim<T extends string> = TrimEnd<TrimStart<T>>;
267
+ type NodeLocale = "af" | "am" | "ar" | "az" | "be" | "bg" | "bn" | "bs" | "ca" | "cs" | "cy" | "da" | "de" | "el" | "en" | "en-AU" | "en-CA" | "en-GB" | "en-US" | "es" | "es-ES" | "et" | "fa" | "fi" | "fil" | "fr" | "ga" | "gl" | "gu" | "he" | "hi" | "hr" | "hu" | "hy" | "id" | "is" | "it" | "ja" | "ka" | "kk" | "km" | "kn" | "ko" | "ky" | "lo" | "lt" | "lv" | "mk" | "ml" | "mn" | "mr" | "ms" | "mt" | "ne" | "nl" | "no" | "pa" | "pl" | "pt" | "pt-BR" | "pt-PT" | "ro" | "ru" | "si" | "sk" | "sl" | "sq" | "sr" | "sv" | "ta" | "te" | "th" | "tr" | "uk" | "ur" | "uz" | "vi" | "zh" | "zh-CN" | "zh-HK" | "zh-TW";
268
+ /**
269
+ * Type-level implementation of string.toLowerCase() functionality.
270
+ * Converts all alphabetic characters in a string type to lowercase.
271
+ * @template T - The string type to convert
272
+ * @returns A string type with all characters converted to lowercase
273
+ * @example
274
+ * type Lower = ToLowerCase<'HELLO'> // type Lower = 'hello'
275
+ */
276
+ type ToLowerCase<T extends string> = IsStringLiteral<T> extends true ? Lowercase<T> : string;
277
+ /**
278
+ * Type-level implementation of string.toUpperCase() functionality.
279
+ * Converts all alphabetic characters in a string type to uppercase.
280
+ * @template T - The string type to convert
281
+ * @returns A string type with all characters converted to uppercase
282
+ * @example
283
+ * type Upper = ToUpperCase<'hello'> // type Upper = 'HELLO'
284
+ */
285
+ type ToUpperCase<T extends string> = IsStringLiteral<T> extends true ? Uppercase<T> : string;
286
+ type Interval = [number, number];
287
+ /** Array of intervals representing ranges */
288
+ type IntervalArray = Interval[];
289
+ /** Array of replacement options as tuples */
290
+ type OptionReplaceArray = [RegExp | string, string | undefined][];
291
+ /** OptionReplace object type */
292
+ type OptionReplaceObject = Record<string, string>;
293
+ /** Combined OptionReplace type (object or array) */
294
+ type OptionReplaceCombined = OptionReplaceArray | OptionReplaceObject;
295
+ /** Options for transliteration */
296
+ interface OptionsTransliterate {
297
+ /** Fix spacing for Chinese characters */
298
+ fixChineseSpacing?: boolean;
299
+ /** Characters/strings to ignore */
300
+ ignore?: string[];
301
+ /** Search/replace pairs after charmap */
302
+ replaceAfter?: OptionReplaceCombined;
303
+ /** Search/replace pairs before charmap */
304
+ replaceBefore?: OptionReplaceCombined;
305
+ /** Trim leading/trailing whitespace */
306
+ trim?: boolean;
307
+ /** Character to use for unknown characters */
308
+ unknown?: string;
309
+ }
310
+ /** Character map type used by Transliterate */
311
+ type Charmap = Record<string, string | undefined>;
312
+ interface SlugifyOptions extends OptionsTransliterate {
313
+ /**
314
+ * Allowed characters. Other characters will be converted to `separator`.
315
+ * @default "a-zA-Z0-9-_.~"
316
+ */
317
+ allowedChars?: string;
318
+ /**
319
+ * Fix Chinese spacing passed to transliterate. If you don't need to transliterate Chinese characters, set it to false to improve performance.
320
+ * @default true // Matches transliterate's default
321
+ */
322
+ fixChineseSpacing?: boolean;
323
+ /**
324
+ * Locale to use for locale-aware transliteration. When set, locale-specific
325
+ * character replacements are applied *before* the global charmap, so e.g.
326
+ * German `ö` becomes `oe` instead of `o`, and Turkish `ı` becomes `i`.
327
+ *
328
+ * Only the primary subtag is considered (case-insensitively), so `"de-DE"`
329
+ * resolves to `"de"`. Unknown locales fall back to the global charmap.
330
+ *
331
+ * Supported locales: `de`, `da`, `nb`, `sr`, `tr`, `vi`. Use `replaceBefore`
332
+ * for any additional custom mappings.
333
+ * @default undefined
334
+ */
335
+ locale?: string;
336
+ /**
337
+ * Whether the result should be converted into lowercase.
338
+ * Cannot be true if `uppercase` is true. Passing both `lowercase: true` and
339
+ * `uppercase: true` throws a `TypeError`.
340
+ * @default true
341
+ */
342
+ lowercase?: boolean;
343
+ /**
344
+ * Custom separator string used to join words in the slug.
345
+ * @default "-"
346
+ */
347
+ separator?: string;
348
+ /**
349
+ * Whether to transliterate the input string.
350
+ * @default true
351
+ */
352
+ transliterate?: boolean;
353
+ /**
354
+ * Whether the result should be converted into uppercase.
355
+ * Cannot be true if `lowercase` is true.
356
+ * @default false
357
+ */
358
+ uppercase?: boolean;
359
+ }
360
+ export { All as A, CharAt as C, EndsWith as E, Includes as I, Join as J, Length as L, Math as M, NodeLocale as N, OptionReplaceArray as O, PadEnd as P, Repeat as R, Slice as S, ToLowerCase as T, Any as a, Charmap as b, Concat as c, Interval as d, IntervalArray as e, IsBooleanLiteral as f, IsNumberLiteral as g, IsStringLiteral as h, IsStringLiteralArray as i, OptionReplaceCombined as j, OptionReplaceObject as k, OptionsTransliterate as l, PadStart as m, Replace as n, ReplaceAll as o, Reverse as p, SlugifyOptions as q, Split as r, StartsWith as s, ToUpperCase as t, Trim as u, TrimEnd as v, TrimStart as w };