@visulima/string 3.0.0 → 3.1.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 (69) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/align-text.d.ts +29 -29
  3. package/dist/case/camel-case.d.ts +16 -16
  4. package/dist/case/camel-case.js +1 -1
  5. package/dist/case/capital-case.d.ts +13 -13
  6. package/dist/case/capital-case.js +1 -1
  7. package/dist/case/constant-case.d.ts +13 -13
  8. package/dist/case/dot-case.d.ts +13 -13
  9. package/dist/case/flat-case.d.ts +11 -11
  10. package/dist/case/flip-case.d.ts +14 -14
  11. package/dist/case/flip-case.js +1 -1
  12. package/dist/case/identify-case.d.ts +14 -14
  13. package/dist/case/index.d.ts +7 -7
  14. package/dist/case/kebab-case.d.ts +22 -22
  15. package/dist/case/kebab-case.js +1 -1
  16. package/dist/case/lower-first.d.ts +12 -12
  17. package/dist/case/no-case.d.ts +13 -13
  18. package/dist/case/pascal-case.d.ts +16 -16
  19. package/dist/case/pascal-case.js +1 -1
  20. package/dist/case/pascal-snake-case.d.ts +13 -13
  21. package/dist/case/pascal-snake-case.js +1 -1
  22. package/dist/case/path-case.d.ts +13 -13
  23. package/dist/case/sentence-case.d.ts +13 -13
  24. package/dist/case/sentence-case.js +1 -1
  25. package/dist/case/snake-case.d.ts +13 -13
  26. package/dist/case/split-by-case.d.ts +20 -20
  27. package/dist/case/split-by-case.js +1 -1
  28. package/dist/case/title-case.d.ts +11 -11
  29. package/dist/case/title-case.js +1 -1
  30. package/dist/case/train-case.d.ts +13 -13
  31. package/dist/case/train-case.js +1 -1
  32. package/dist/case/upper-first.d.ts +12 -12
  33. package/dist/closest-string.d.ts +28 -28
  34. package/dist/compare-similarity.d.ts +33 -33
  35. package/dist/count-occurrences.d.ts +6 -6
  36. package/dist/direction.d.ts +4 -4
  37. package/dist/east-asian-width.d.ts +20 -14
  38. package/dist/excerpt.d.ts +18 -18
  39. package/dist/get-string-truncated-width.d.ts +131 -131
  40. package/dist/get-string-truncated-width.js +1 -1
  41. package/dist/get-string-width.d.ts +56 -56
  42. package/dist/indent.d.ts +8 -7
  43. package/dist/index.d.ts +2 -2
  44. package/dist/is-fullwidth-code-point.d.ts +4 -4
  45. package/dist/levenshtein.d.ts +19 -19
  46. package/dist/native-string-types.d.ts +212 -228
  47. package/dist/outdent.d.ts +64 -64
  48. package/dist/packem_shared/generate-cache-key-B_0X7MKm.js +1 -0
  49. package/dist/packem_shared/strip-vt-control-characters-BW1RglLp.js +1 -0
  50. package/dist/packem_shared/types.d-CMNqA5bi.d.ts +402 -0
  51. package/dist/packem_shared/types.d-LgsTR37y.d.ts +360 -0
  52. package/dist/replace-string.d.ts +7 -7
  53. package/dist/slice.d.ts +38 -38
  54. package/dist/slice.js +1 -1
  55. package/dist/slugify.d.ts +9 -9
  56. package/dist/test/utils.d.ts +14 -14
  57. package/dist/test/utils.js +11 -11
  58. package/dist/test/vitest.d.ts +2 -2
  59. package/dist/transliterate.d.ts +7 -7
  60. package/dist/transliterate.js +2 -2
  61. package/dist/truncate.d.ts +37 -37
  62. package/dist/utilities.d.ts +23 -23
  63. package/dist/word-similarity-sort.d.ts +32 -32
  64. package/dist/word-wrap.d.ts +33 -33
  65. package/dist/word-wrap.js +7 -7
  66. package/package.json +1 -1
  67. package/dist/packem_shared/generate-cache-key-BqU1Cqwm.js +0 -1
  68. package/dist/packem_shared/types.d-CmNvyl4l.d.ts +0 -360
  69. package/dist/packem_shared/types.d-fhe030jX.d.ts +0 -402
package/dist/outdent.d.ts CHANGED
@@ -1,88 +1,88 @@
1
1
  declare const outdent: Outdent;
2
2
  /**
3
- * Represents the outdent function, which can be called as a template tag
4
- * or as a function to create a new instance with specific options.
5
- * It also includes a `.string()` method for processing regular strings.
6
- */
3
+ * Represents the outdent function, which can be called as a template tag
4
+ * or as a function to create a new instance with specific options.
5
+ * It also includes a `.string()` method for processing regular strings.
6
+ */
7
7
  interface Outdent {
8
8
  /**
9
- * Remove indentation from a template literal.
10
- * Tag function for template literals.
11
- * @param strings The static string parts of the template literal.
12
- * @param values The interpolated values.
13
- * @returns The processed string with indentation removed.
14
- */
9
+ * Remove indentation from a template literal.
10
+ * Tag function for template literals.
11
+ * @param strings The static string parts of the template literal.
12
+ * @param values The interpolated values.
13
+ * @returns The processed string with indentation removed.
14
+ */
15
15
  (strings: TemplateStringsArray, ...values: any[]): string;
16
16
  /**
17
- * Create and return a new Outdent instance with the given options.
18
- * @param options Configuration options for the new instance.
19
- * @returns A new Outdent function instance.
20
- */
17
+ * Create and return a new Outdent instance with the given options.
18
+ * @param options Configuration options for the new instance.
19
+ * @returns A new Outdent function instance.
20
+ */
21
21
  (options: Options): Outdent;
22
22
  /**
23
- * Remove indentation from a string
24
- * @param string_ The raw string to process.
25
- * @returns The processed string with indentation removed.
26
- */
23
+ * Remove indentation from a string
24
+ * @param string_ The raw string to process.
25
+ * @returns The processed string with indentation removed.
26
+ */
27
27
  string: (string_: string) => string;
28
28
  }
29
29
  /**
30
- * Configuration options for the outdent function.
31
- */
30
+ * Configuration options for the outdent function.
31
+ */
32
32
  interface Options {
33
33
  /**
34
- * Whether to cache processed template literals for better performance when
35
- * using the same template multiple times.
36
- *
37
- * Enabling caching can significantly improve performance when the same template
38
- * is used repeatedly, such as in loops or frequently called functions.
39
- * @example
40
- * // Create an outdent function with caching enabled (default)
41
- * const dedent = outdent();
42
- *
43
- * // Create an outdent function with caching disabled
44
- * const noCacheDedent = outdent({ cache: false });
45
- * @default true
46
- */
34
+ * Whether to cache processed template literals for better performance when
35
+ * using the same template multiple times.
36
+ *
37
+ * Enabling caching can significantly improve performance when the same template
38
+ * is used repeatedly, such as in loops or frequently called functions.
39
+ * @example
40
+ * // Create an outdent function with caching enabled (default)
41
+ * const dedent = outdent();
42
+ *
43
+ * // Create an outdent function with caching disabled
44
+ * const noCacheDedent = outdent({ cache: false });
45
+ * @default true
46
+ */
47
47
  cache?: boolean;
48
48
  /**
49
- * Custom cache store to use instead of the default WeakMap.
50
- * Must be a WeakMap instance.
51
- *
52
- * This allows you to provide your own WeakMap instance for caching,
53
- * which can be useful for advanced use cases or for sharing cache
54
- * between multiple outdent instances.
55
- * @example
56
- * // Create a custom cache
57
- * const customCache = new WeakMap();
58
- *
59
- * // Create an outdent function with a custom cache
60
- * const customCacheDedent = outdent({ cacheStore: customCache });
61
- */
49
+ * Custom cache store to use instead of the default WeakMap.
50
+ * Must be a WeakMap instance.
51
+ *
52
+ * This allows you to provide your own WeakMap instance for caching,
53
+ * which can be useful for advanced use cases or for sharing cache
54
+ * between multiple outdent instances.
55
+ * @example
56
+ * // Create a custom cache
57
+ * const customCache = new WeakMap();
58
+ *
59
+ * // Create an outdent function with a custom cache
60
+ * const customCacheDedent = outdent({ cacheStore: customCache });
61
+ */
62
62
  cacheStore?: WeakMap<TemplateStringsArray, string[]>;
63
63
  /**
64
- * Normalize all newlines in the template literal to this value.
65
- *
66
- * If `null`, newlines are left untouched.
67
- *
68
- * Newlines that get normalized are '\r\n', '\r', and '\n'.
69
- *
70
- * Newlines within interpolated values are *never* normalized.
71
- *
72
- * Although intended for normalizing to '\n' or '\r\n',
73
- * you can also set to any string; for example ' '.
74
- * @default null
75
- */
64
+ * Normalize all newlines in the template literal to this value.
65
+ *
66
+ * If `null`, newlines are left untouched.
67
+ *
68
+ * Newlines that get normalized are '\r\n', '\r', and '\n'.
69
+ *
70
+ * Newlines within interpolated values are *never* normalized.
71
+ *
72
+ * Although intended for normalizing to '\n' or '\r\n',
73
+ * you can also set to any string; for example ' '.
74
+ * @default null
75
+ */
76
76
  newline?: string | null;
77
77
  /**
78
- * Whether to trim the leading newline in the template literal.
79
- * @default true
80
- */
78
+ * Whether to trim the leading newline in the template literal.
79
+ * @default true
80
+ */
81
81
  trimLeadingNewline?: boolean;
82
82
  /**
83
- * Whether to trim the trailing newline in the template literal.
84
- * @default true
85
- */
83
+ * Whether to trim the trailing newline in the template literal.
84
+ * @default true
85
+ */
86
86
  trimTrailingNewline?: boolean;
87
87
  }
88
88
  export { Options, Outdent, outdent };
@@ -0,0 +1 @@
1
+ const s=(r,n)=>`${r}::${n?.joiner??""}::${n?.locale??""}::${n?.knownAcronyms?.join(",")??""}::${n?.normalize?"true":"false"}::${n?.stripAnsi?"true":"false"}::${n?.stripEmoji?"true":"false"}::${n?.handleAnsi?"true":"false"}::${n?.handleEmoji?"true":"false"}`;export{s as a};
@@ -0,0 +1 @@
1
+ const r=new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))","g"),t=e=>{if(typeof e!="string")throw new TypeError(`The "value" argument must be of type string. Received ${typeof e}`);return e.replaceAll(r,"")};export{t as r};
@@ -0,0 +1,402 @@
1
+ import { N as NodeLocale, h as IsStringLiteral } from "./types.d-LgsTR37y.js";
2
+ declare class LRUCache<K, V> {
3
+ private readonly capacity;
4
+ private readonly cache;
5
+ constructor(capacity: number);
6
+ get(key: K): V | undefined;
7
+ has(key: K): boolean;
8
+ set(key: K, value: V): void;
9
+ delete(key: K): void;
10
+ clear(): void;
11
+ size(): number;
12
+ }
13
+ /**
14
+ * Valid characters used to split strings into words.
15
+ * Used by various case conversion functions to identify word boundaries.
16
+ * @type {string}
17
+ */
18
+ type SplitterCharacter = " " | "_" | "-" | "." | "/";
19
+ /**
20
+ * Gets the type of the last element in an array type.
21
+ * @template T - The array type to extract from
22
+ * @returns The type of the last element, or never if array is empty
23
+ */
24
+ type LastOfArray<T extends any[]> = T extends [...any, infer R] ? R : never;
25
+ /**
26
+ * Creates a new array type with the last element removed.
27
+ * @template T - The array type to modify
28
+ * @returns A new array type without the last element, or never if array is empty
29
+ */
30
+ type RemoveLastOfArray<T extends any[]> = T extends [...infer F, any] ? F : never;
31
+ /**
32
+ * Type predicate that checks if a string type contains only uppercase characters.
33
+ * @template S - The string type to check
34
+ * @returns true if string is all uppercase, false otherwise
35
+ * @example
36
+ * type IsUpper = IsUpperCase<'ABC'> // type IsUpper = true
37
+ * type NotUpper = IsUpperCase<'aBc'> // type NotUpper = false
38
+ */
39
+ type IsUpperCase<S extends string> = S extends Uppercase<S> ? true : false;
40
+ /**
41
+ * Type predicate that checks if a string type contains only lowercase characters.
42
+ * @template S - The string type to check
43
+ * @returns true if string is all lowercase, false otherwise
44
+ * @example
45
+ * type IsLower = IsLowerCase<'abc'> // type IsLower = true
46
+ * type NotLower = IsLowerCase<'aBc'> // type NotLower = false
47
+ */
48
+ type IsLowerCase<S extends string> = S extends Lowercase<S> ? true : false;
49
+ /**
50
+ * Type predicate that checks if two string types have the same case pattern.
51
+ * Both strings must be either all uppercase or all lowercase to be considered the same case.
52
+ * @template X - First string type to compare
53
+ * @template Y - Second string type to compare
54
+ * @returns true if both strings have the same case pattern, false otherwise
55
+ * @example
56
+ * type Same = SameLetterCase<'ABC', 'XYZ'> // type Same = true
57
+ * type Different = SameLetterCase<'abc', 'XYZ'> // type Different = false
58
+ */
59
+ type SameLetterCase<X extends string, Y extends string> = IsUpperCase<X> extends IsUpperCase<Y> ? true : IsLowerCase<X> extends IsLowerCase<Y> ? true : false;
60
+ /**
61
+ * Gets the first character of a string type.
62
+ * @template S - The string type to extract from
63
+ * @returns The first character as a string type, or never if string is empty
64
+ * @example
65
+ * type First = FirstOfString<'hello'> // type First = 'h'
66
+ */
67
+ type FirstOfString<S extends string> = S extends `${infer F}${string}` ? F : never;
68
+ /**
69
+ * Creates a new string type with the first character removed.
70
+ * @template S - The string type to modify
71
+ * @returns A new string type without the first character, or never if string is empty
72
+ * @example
73
+ * type Rest = RemoveFirstOfString<'hello'> // type Rest = 'ello'
74
+ */
75
+ type RemoveFirstOfString<S extends string> = S extends `${string}${infer R}` ? R : never;
76
+ /**
77
+ * Options for locale support.
78
+ */
79
+ interface LocaleOptions {
80
+ /**
81
+ * The locale to use for case conversion.
82
+ * If not provided, the system default locale will be used.
83
+ */
84
+ locale?: NodeLocale;
85
+ }
86
+ /**
87
+ * Options for case conversion with locale support.
88
+ */
89
+ interface CaseOptions extends LocaleOptions {
90
+ /**
91
+ * Uses a shared LRU cache with a fixed size.
92
+ * @default false
93
+ */
94
+ cache?: boolean;
95
+ /**
96
+ * A custom cache store for this specific case function.
97
+ * Each case function (camelCase, pascalCase, etc.) should have its own dedicated cache store
98
+ * to avoid conflicts and ensure optimal performance.
99
+ * @example
100
+ * ```typescript
101
+ * // Create separate caches for each case function
102
+ * const camelCaseStore = new LRUCache<string, string>(1000);
103
+ * const pascalCaseStore = new LRUCache<string, string>(1000);
104
+ *
105
+ * camelCase("some-string", { cache: true, cacheStore: camelCaseStore });
106
+ * pascalCase("some-string", { cache: true, cacheStore: pascalCaseStore });
107
+ * ```
108
+ */
109
+ cacheStore?: LRUCache<string, string>;
110
+ /**
111
+ * Whether to handle ANSI escape sequences.
112
+ * @default false
113
+ */
114
+ handleAnsi?: boolean;
115
+ /**
116
+ * Whether to handle emoji sequences.
117
+ * @default false
118
+ */
119
+ handleEmoji?: boolean;
120
+ /**
121
+ * A list of known acronyms to preserve casing for.
122
+ */
123
+ knownAcronyms?: ReadonlyArray<string>;
124
+ /**
125
+ * Whether to normalize case (e.g., convert uppercase tokens not in knownAcronyms to title case).
126
+ */
127
+ normalize?: boolean;
128
+ /**
129
+ * Whether to strip ANSI escape sequences. (default: false)
130
+ */
131
+ stripAnsi?: boolean;
132
+ /**
133
+ * Whether to strip emoji sequences. (default: false)
134
+ */
135
+ stripEmoji?: boolean;
136
+ }
137
+ /**
138
+ * Type-level implementation of camelCase conversion.
139
+ * Converts a string type to camelCase format where words are joined together
140
+ * with the first word in lowercase and subsequent words capitalized.
141
+ * @template T - The string type to convert
142
+ * @returns A string type in camelCase format
143
+ * @example
144
+ * type Result1 = CamelCase<'foo bar'> // type Result1 = 'fooBar'
145
+ * type Result2 = CamelCase<'foo-bar'> // type Result2 = 'fooBar'
146
+ * type Result3 = CamelCase<'foo_bar'> // type Result3 = 'fooBar'
147
+ */
148
+ type CamelCase<T extends string> = IsStringLiteral<T> extends true ? T extends `${infer F}_${infer R}` ? `${Lowercase<F>}${Capitalize<CamelCase<R>>}` : T extends `${infer F}-${infer R}` ? `${Lowercase<F>}${Capitalize<CamelCase<R>>}` : T extends `${infer F} ${infer R}` ? `${Lowercase<F>}${Capitalize<CamelCase<R>>}` : Lowercase<T> : string;
149
+ /**
150
+ * Type-level implementation of PascalCase conversion.
151
+ * Converts a string type to PascalCase format where words are joined together
152
+ * with each word capitalized.
153
+ * @template T - The string type to convert
154
+ * @returns A string type in PascalCase format
155
+ * @example
156
+ * type Result1 = PascalCase<'foo bar'> // type Result1 = 'FooBar'
157
+ * type Result2 = PascalCase<'foo-bar'> // type Result2 = 'FooBar'
158
+ * type Result3 = PascalCase<'foo_bar'> // type Result3 = 'FooBar'
159
+ */
160
+ type PascalCase<T extends string> = IsStringLiteral<T> extends true ? Capitalize<CamelCase<T>> : string;
161
+ /**
162
+ * Type-level implementation of snake_case conversion.
163
+ * Converts a string type to snake_case format where words are in lowercase
164
+ * and separated by underscores.
165
+ * @template T - The string type to convert
166
+ * @returns A string type in snake_case format
167
+ * @example
168
+ * type Result1 = SnakeCase<'fooBar'> // type Result1 = 'foo_bar'
169
+ * type Result2 = SnakeCase<'foo bar'> // type Result2 = 'foo_bar'
170
+ * type Result3 = SnakeCase<'foo-bar'> // type Result3 = 'foo_bar'
171
+ */
172
+ type SnakeCase<T extends string> = IsStringLiteral<T> extends true ? T extends `${infer C}${infer Rest}` ? C extends Uppercase<C> ? `_${Lowercase<C>}${SnakeCase<Rest>}` : `${C}${SnakeCase<Rest>}` : T : string;
173
+ /**
174
+ * Type-level implementation of kebab-case conversion.
175
+ * Converts a string type to kebab-case format where words are in lowercase
176
+ * and separated by hyphens.
177
+ * @template T - The string type to convert
178
+ * @returns A string type in kebab-case format
179
+ * @example
180
+ * type Result1 = KebabCase<'fooBar'> // type Result1 = 'foo-bar'
181
+ * type Result2 = KebabCase<'foo bar'> // type Result2 = 'foo-bar'
182
+ * type Result3 = KebabCase<'foo_bar'> // type Result3 = 'foo-bar'
183
+ */
184
+ type KebabCase<T extends string> = IsStringLiteral<T> extends true ? T extends `${infer C}${infer Rest}` ? C extends Uppercase<C> ? `-${Lowercase<C>}${KebabCase<Rest>}` : `${C}${KebabCase<Rest>}` : T : string;
185
+ /**
186
+ * Type-level implementation of flat case conversion.
187
+ * Converts a string type to flat case format where all words are joined together
188
+ * in lowercase with no separators.
189
+ * @template T - The string type to convert
190
+ * @returns A string type in flat case format
191
+ * @example
192
+ * type Result1 = FlatCase<'foo-barBaz'> // type Result1 = 'foobarbaz'
193
+ * type Result2 = FlatCase<'foo bar'> // type Result2 = 'foobar'
194
+ * type Result3 = FlatCase<'FOO_BAR'> // type Result3 = 'foobar'
195
+ */
196
+ type FlatCase<T extends string> = IsStringLiteral<T> extends true ? Lowercase<T extends `${infer F}${infer R}` ? `${F}${FlatCase<R>}` : T> : string;
197
+ /**
198
+ * Type-level implementation of Train-Case conversion.
199
+ * Converts a string type to Train-Case format where words are capitalized
200
+ * and separated by hyphens. This case style is similar to PascalCase but with
201
+ * hyphens between words.
202
+ * @template T - The string type to convert
203
+ * @returns A string type in Train-Case format
204
+ * @example
205
+ * type Result1 = TrainCase<'FooBARb'> // type Result1 = 'Foo-Ba-Rb'
206
+ * type Result2 = TrainCase<'foo bar'> // type Result2 = 'Foo-Bar'
207
+ * type Result3 = TrainCase<'foo_bar'> // type Result3 = 'Foo-Bar'
208
+ */
209
+ type TrainCase<T extends string, N extends boolean = false> = IsStringLiteral<T> extends true ? T extends `${infer F}${infer R}` ? F extends Uppercase<F> ? R extends `${infer Next}${infer Rest}` ? Next extends Uppercase<Next> ? N extends true ? `${Capitalize<F>}-${Lowercase<Next>}${TrainCase<Rest, N>}` : `${F}${Next}${TrainCase<Rest, N>}` : `${Capitalize<F>}${TrainCase<R, N>}` : `${Capitalize<F>}${Lowercase<R>}` : `${Lowercase<F>}${TrainCase<R, N>}` : T : string;
210
+ /**
211
+ * Type-level implementation of Title Case conversion.
212
+ * Converts a string type to Title Case format where the first letter of each
213
+ * significant word is capitalized. Articles, conjunctions, and prepositions
214
+ * typically remain in lowercase unless they are the first word.
215
+ * @template T - The string type to convert
216
+ * @returns A string type in Title Case format
217
+ * @example
218
+ * type Result1 = TitleCase<'this-IS-aTitle'> // type Result1 = 'This Is A Title'
219
+ * type Result2 = TitleCase<'hello_world'> // type Result2 = 'Hello World'
220
+ * type Result3 = TitleCase<'theFox'> // type Result3 = 'The Fox'
221
+ */
222
+ type TitleCase<T extends string> = IsStringLiteral<T> extends true ? (T extends `${infer F}${infer R}` ? `${Capitalize<F>}${Lowercase<R>}` : T) : string;
223
+ /**
224
+ * Type-level implementation of first character capitalization.
225
+ * Converts the first character of a string type to uppercase while leaving
226
+ * the rest of the string unchanged.
227
+ * @template T - The string type to modify
228
+ * @returns A string type with its first character in uppercase
229
+ * @example
230
+ * type Result1 = UpperFirst<'hello world!'> // type Result1 = 'Hello world!'
231
+ * type Result2 = UpperFirst<'fooBar'> // type Result2 = 'FooBar'
232
+ * type Result3 = UpperFirst<'123abc'> // type Result3 = '123abc'
233
+ */
234
+ type UpperFirst<T extends string> = IsStringLiteral<T> extends true ? (T extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : T) : string;
235
+ /**
236
+ * Type-level implementation of first character lowercasing.
237
+ * Converts the first character of a string type to lowercase while leaving
238
+ * the rest of the string unchanged.
239
+ * @template T - The string type to modify
240
+ * @returns A string type with its first character in lowercase
241
+ * @example
242
+ * type Result1 = LowerFirst<'Hello world!'> // type Result1 = 'hello world!'
243
+ * type Result2 = LowerFirst<'FooBar'> // type Result2 = 'fooBar'
244
+ * type Result3 = LowerFirst<'123ABC'> // type Result3 = '123ABC'
245
+ */
246
+ type LowerFirst<T extends string> = IsStringLiteral<T> extends true ? (T extends `${infer F}${infer R}` ? `${Lowercase<F>}${R}` : T) : string;
247
+ /**
248
+ * Type-level implementation of case flipping.
249
+ * Inverts the case of each character in a string type - uppercase becomes
250
+ * lowercase and vice versa.
251
+ * @template T - The string type to modify
252
+ * @returns A string type with inverted character cases
253
+ * @example
254
+ * type Result1 = FlipCase<'FooBar'> // type Result1 = 'fOObAR'
255
+ * type Result2 = FlipCase<'Hello World'> // type Result2 = 'hELLO wORLD'
256
+ * type Result3 = FlipCase<'123'> // type Result3 = '123'
257
+ */
258
+ type FlipCase<T extends string> = IsStringLiteral<T> extends true ? T extends `${infer C}${infer Rest}` ? `${C extends Uppercase<C> ? Lowercase<C> : Uppercase<C>}${FlipCase<Rest>}` : T : string;
259
+ /**
260
+ * Type-level implementation of dot.case conversion.
261
+ * Converts a string type to dot.case format where words are in lowercase
262
+ * and separated by dots.
263
+ * @template T - The string type to convert
264
+ * @returns A string type in dot.case format
265
+ * @example
266
+ * type Result1 = DotCase<'fooBar'> // type Result1 = 'foo.bar'
267
+ * type Result2 = DotCase<'foo_bar'> // type Result2 = 'foo.bar'
268
+ * type Result3 = DotCase<'foo-bar'> // type Result3 = 'foo.bar'
269
+ */
270
+ type DotCase<T extends string> = T & {
271
+ __dot_case__: never;
272
+ };
273
+ /**
274
+ * Type-level implementation of path/case conversion.
275
+ * Converts a string type to path/case format where words are in lowercase
276
+ * and separated by forward slashes, making it suitable for file paths.
277
+ * @template T - The string type to convert
278
+ * @returns A string type in path/case format
279
+ * @example
280
+ * type Result1 = PathCase<'fooBar'> // type Result1 = 'foo/bar'
281
+ * type Result2 = PathCase<'foo_bar'> // type Result2 = 'foo/bar'
282
+ * type Result3 = PathCase<'foo-bar'> // type Result3 = 'foo/bar'
283
+ */
284
+ type PathCase<T extends string> = T & {
285
+ __path_case__: never;
286
+ };
287
+ /**
288
+ * Type-level implementation of no case conversion.
289
+ * Converts a string type to space-separated lowercase words, removing all
290
+ * special case formatting.
291
+ * @template T - The string type to convert
292
+ * @returns A string type in space-separated lowercase format
293
+ * @example
294
+ * type Result1 = NoCase<'fooBar'> // type Result1 = 'foo bar'
295
+ * type Result2 = NoCase<'foo_bar'> // type Result2 = 'foo bar'
296
+ * type Result3 = NoCase<'FOO-BAR'> // type Result3 = 'foo bar'
297
+ */
298
+ type NoCase<T extends string> = T & {
299
+ __no_case__: never;
300
+ };
301
+ /**
302
+ * Type-level implementation of CONSTANT_CASE conversion.
303
+ * Converts a string type to CONSTANT_CASE format where words are in uppercase
304
+ * and separated by underscores. Commonly used for constant/enum values.
305
+ * @template T - The string type to convert
306
+ * @returns A string type in CONSTANT_CASE format
307
+ * @example
308
+ * type Result1 = ConstantCase<'fooBar'> // type Result1 = 'FOO_BAR'
309
+ * type Result2 = ConstantCase<'foo-bar'> // type Result2 = 'FOO_BAR'
310
+ * type Result3 = ConstantCase<'foo bar'> // type Result3 = 'FOO_BAR'
311
+ */
312
+ type ConstantCase<T extends string> = T & {
313
+ __constant_case__: never;
314
+ };
315
+ /**
316
+ * Type-level implementation of Capital Case conversion.
317
+ * Converts a string type to Capital Case format where each word starts with
318
+ * a capital letter and words are separated by spaces.
319
+ * @template T - The string type to convert
320
+ * @returns A string type in Capital Case format
321
+ * @example
322
+ * type Result1 = CapitalCase<'fooBar'> // type Result1 = 'Foo Bar'
323
+ * type Result2 = CapitalCase<'foo_bar'> // type Result2 = 'Foo Bar'
324
+ * type Result3 = CapitalCase<'foo-bar'> // type Result3 = 'Foo Bar'
325
+ */
326
+ type CapitalCase<T extends string> = T & {
327
+ __capital_case__: never;
328
+ };
329
+ /**
330
+ * Type-level implementation of Sentence case conversion.
331
+ * Converts a string type to Sentence case format where only the first word
332
+ * starts with a capital letter and all other words are lowercase.
333
+ * @template T - The string type to convert
334
+ * @returns A string type in Sentence case format
335
+ * @example
336
+ * type Result1 = SentenceCase<'fooBar'> // type Result1 = 'Foo bar'
337
+ * type Result2 = SentenceCase<'FOO_BAR'> // type Result2 = 'Foo bar'
338
+ * type Result3 = SentenceCase<'foo-bar'> // type Result3 = 'Foo bar'
339
+ */
340
+ type SentenceCase<T extends string> = T & {
341
+ __sentence_case__: never;
342
+ };
343
+ /**
344
+ * Type-level implementation of Pascal_Snake_Case conversion.
345
+ * Converts a string type to Pascal_Snake_Case format where words are capitalized
346
+ * and separated by underscores. This is a hybrid between PascalCase and snake_case.
347
+ * @template T - The string type to convert
348
+ * @returns A string type in Pascal_Snake_Case format
349
+ * @example
350
+ * type Result1 = PascalSnakeCase<'fooBar'> // type Result1 = 'Foo_Bar'
351
+ * type Result2 = PascalSnakeCase<'foo bar'> // type Result2 = 'Foo_Bar'
352
+ * type Result3 = PascalSnakeCase<'foo-bar'> // type Result3 = 'Foo_Bar'
353
+ */
354
+ type PascalSnakeCase<T extends string> = T & {
355
+ __pascal_snake_case__: never;
356
+ };
357
+ /**
358
+ * Type-level utility that identifies the case pattern of a string type.
359
+ * Analyzes the string to determine if it follows a specific case convention
360
+ * such as camelCase, PascalCase, snake_case, etc.
361
+ * @template T - The string type to analyze
362
+ * @returns A string literal type indicating the detected case pattern:
363
+ * - 'snake' for snake_case
364
+ * - 'kebab' for kebab-case
365
+ * - 'flat' for flatcase
366
+ * - 'lower' for lowercase
367
+ * - 'upper' for UPPERCASE
368
+ * - 'train' for Train-Case
369
+ * - 'pascal' for PascalCase
370
+ * - 'camel' for camelCase
371
+ * - 'title' for Title Case
372
+ * - 'mixed' for mixed case patterns
373
+ * - string type for non-literal strings
374
+ * @example
375
+ * type Case1 = IdentifyCase<'foo_bar'> // type Case1 = 'snake'
376
+ * type Case2 = IdentifyCase<'foo-bar'> // type Case2 = 'kebab'
377
+ * type Case3 = IdentifyCase<'fooBar'> // type Case3 = 'camel'
378
+ * type Case4 = IdentifyCase<'FooBar'> // type Case4 = 'pascal'
379
+ * type Case5 = IdentifyCase<'FOO_BAR'> // type Case5 = 'upper'
380
+ */
381
+ type IdentifyCase<T extends string> = IsStringLiteral<T> extends true ? T extends Lowercase<T> ? T extends `${string}_${string}` ? "snake" : T extends `${string}-${string}` ? "kebab" : T extends `${string}${string}` ? "flat" : "lower" : T extends Uppercase<T> ? "upper" : T extends Capitalize<string> ? T extends `${Uppercase<string>}${string}` ? T extends `${string}-${string}` ? "train" : "pascal" : T extends `${Lowercase<string>}${Capitalize<string>}` ? "camel" : T extends `${Capitalize<string>} ${Lowercase<string>}` ? "title" : "mixed" : "mixed" : string;
382
+ /**
383
+ * Type-level utility that splits a string type into an array of substrings based on case boundaries
384
+ * and separator characters. This is particularly useful for breaking down strings in various case
385
+ * formats into their constituent words.
386
+ *
387
+ * The utility handles multiple scenarios:
388
+ * - Case boundaries (e.g., camelCase -> ['camel', 'Case'])
389
+ * - Separator characters (e.g., snake_case -> ['snake', 'case'])
390
+ * - Mixed patterns (e.g., FOO-Bar -> ['FOO', 'Bar'])
391
+ * @template T - The string type to split
392
+ * @template Separator - The separator character(s) to split on (defaults to SplitterCharacter)
393
+ * @template Accumulator - Internal accumulator for building the result array
394
+ * @returns A tuple type containing the split string parts, or string[] for non-literal strings
395
+ * @example
396
+ * type Split1 = SplitByCase<'camelCase'> // type Split1 = ['camel', 'Case']
397
+ * type Split2 = SplitByCase<'foo_bar'> // type Split2 = ['foo', 'bar']
398
+ * type Split3 = SplitByCase<'FOO-Bar'> // type Split3 = ['FOO', 'Bar']
399
+ * type Split4 = SplitByCase<'simpletext'> // type Split4 = ['simpletext']
400
+ */
401
+ type SplitByCase<T, Separator extends string = SplitterCharacter, Accumulator extends unknown[] = []> = string extends Separator ? string[] : T extends `${infer F}${infer R}` ? [LastOfArray<Accumulator>] extends [never] ? SplitByCase<R, Separator, [F]> : LastOfArray<Accumulator> extends string ? R extends "" ? SplitByCase<R, Separator, [...RemoveLastOfArray<Accumulator>, `${LastOfArray<Accumulator>}${F}`]> : SameLetterCase<F, FirstOfString<R>> extends true ? F extends Separator ? FirstOfString<R> extends Separator ? SplitByCase<R, Separator, [...Accumulator, ""]> : IsUpperCase<FirstOfString<R>> extends true ? SplitByCase<RemoveFirstOfString<R>, Separator, [...Accumulator, FirstOfString<R>]> : SplitByCase<R, Separator, [...Accumulator, ""]> : SplitByCase<R, Separator, [...RemoveLastOfArray<Accumulator>, `${LastOfArray<Accumulator>}${F}`]> : IsLowerCase<F> extends true ? SplitByCase<RemoveFirstOfString<R>, Separator, [...RemoveLastOfArray<Accumulator>, `${LastOfArray<Accumulator>}${F}`, FirstOfString<R>]> : SplitByCase<R, Separator, [...Accumulator, F]> : never : Accumulator extends [] ? T extends "" ? [] : string[] : Accumulator;
402
+ export { CamelCase as C, DotCase as D, FlatCase as F, IdentifyCase as I, KebabCase as K, LocaleOptions as L, NoCase as N, PascalCase as P, SentenceCase as S, TitleCase as T, UpperFirst as U, CapitalCase as a, CaseOptions as b, ConstantCase as c, FlipCase as d, LowerFirst as e, PascalSnakeCase as f, PathCase as g, SnakeCase as h, SplitByCase as i, TrainCase as j };