caseparser 4.3.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -17
- package/dist/index.cjs +219 -62
- package/dist/index.d.cts +170 -44
- package/dist/index.d.ts +170 -44
- package/dist/index.js +213 -61
- package/package.json +5 -1
package/dist/index.d.ts
CHANGED
|
@@ -121,7 +121,7 @@ type Result<T, P> = T extends string ? string : T extends Array<unknown> ? { [K
|
|
|
121
121
|
* camelToDash({ firstName: 'John' }); // { 'first-name': 'John' }
|
|
122
122
|
* ```
|
|
123
123
|
*
|
|
124
|
-
* @deprecated Use `
|
|
124
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
125
125
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
126
126
|
*/
|
|
127
127
|
export declare function camelToDash<T extends object | string>(input: T): Result<T, "CamelToDash">;
|
|
@@ -173,7 +173,7 @@ export declare function camelToUpperSnake<T extends object | string>(input: T):
|
|
|
173
173
|
* camelToUpperDash({ firstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
174
174
|
* ```
|
|
175
175
|
*
|
|
176
|
-
* @deprecated Use `
|
|
176
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
177
177
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
178
178
|
*/
|
|
179
179
|
export declare function camelToUpperDash<T extends object | string>(input: T): Result<T, "CamelToUpperDash">;
|
|
@@ -292,7 +292,7 @@ export declare function dashToUpperSnake<T extends object | string>(input: T): R
|
|
|
292
292
|
* dashToUpperDash({ 'first-name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
293
293
|
* ```
|
|
294
294
|
*
|
|
295
|
-
* @deprecated Use `
|
|
295
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
296
296
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
297
297
|
*/
|
|
298
298
|
export declare function dashToUpperDash<T extends object | string>(input: T): Result<T, "DashToUpperDash">;
|
|
@@ -385,7 +385,7 @@ export declare function pascalToSnake<T extends object | string>(input: T): Resu
|
|
|
385
385
|
* pascalToDash({ FirstName: 'John' }); // { 'first-name': 'John' }
|
|
386
386
|
* ```
|
|
387
387
|
*
|
|
388
|
-
* @deprecated Use `
|
|
388
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
389
389
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
390
390
|
*/
|
|
391
391
|
export declare function pascalToDash<T extends object | string>(input: T): Result<T, "PascalToDash">;
|
|
@@ -411,7 +411,7 @@ export declare function pascalToUpperSnake<T extends object | string>(input: T):
|
|
|
411
411
|
* pascalToUpperDash({ FirstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
412
412
|
* ```
|
|
413
413
|
*
|
|
414
|
-
* @deprecated Use `
|
|
414
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
415
415
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
416
416
|
*/
|
|
417
417
|
export declare function pascalToUpperDash<T extends object | string>(input: T): Result<T, "PascalToUpperDash">;
|
|
@@ -491,7 +491,7 @@ export declare function snakeToCamel<T extends object | string>(input: T): Resul
|
|
|
491
491
|
* snakeToDash({ first_name: 'John' }); // { 'first-name': 'John' }
|
|
492
492
|
* ```
|
|
493
493
|
*
|
|
494
|
-
* @deprecated Use `
|
|
494
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
495
495
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
496
496
|
*/
|
|
497
497
|
export declare function snakeToDash<T extends object | string>(input: T): Result<T, "SnakeToDash">;
|
|
@@ -530,7 +530,7 @@ export declare function snakeToUpperSnake<T extends object | string>(input: T):
|
|
|
530
530
|
* snakeToUpperDash({ first_name: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
531
531
|
* ```
|
|
532
532
|
*
|
|
533
|
-
* @deprecated Use `
|
|
533
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
534
534
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
535
535
|
*/
|
|
536
536
|
export declare function snakeToUpperDash<T extends object | string>(input: T): Result<T, "SnakeToUpperDash">;
|
|
@@ -636,7 +636,7 @@ export declare function trainToSnake<T extends object | string>(input: T): Resul
|
|
|
636
636
|
* trainToDash({ 'First-Name': 'John' }); // { 'first-name': 'John' }
|
|
637
637
|
* ```
|
|
638
638
|
*
|
|
639
|
-
* @deprecated Use `
|
|
639
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
640
640
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
641
641
|
*/
|
|
642
642
|
export declare function trainToDash<T extends object | string>(input: T): Result<T, "TrainToDash">;
|
|
@@ -662,7 +662,7 @@ export declare function trainToUpperSnake<T extends object | string>(input: T):
|
|
|
662
662
|
* trainToUpperDash({ 'First-Name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
663
663
|
* ```
|
|
664
664
|
*
|
|
665
|
-
* @deprecated Use `
|
|
665
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
666
666
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
667
667
|
*/
|
|
668
668
|
export declare function trainToUpperDash<T extends object | string>(input: T): Result<T, "TrainToUpperDash">;
|
|
@@ -755,7 +755,7 @@ export declare function dotToSnake<T extends object | string>(input: T): Result<
|
|
|
755
755
|
* dotToDash({ 'first.name': 'John' }); // { 'first-name': 'John' }
|
|
756
756
|
* ```
|
|
757
757
|
*
|
|
758
|
-
* @deprecated Use `
|
|
758
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
759
759
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
760
760
|
*/
|
|
761
761
|
export declare function dotToDash<T extends object | string>(input: T): Result<T, "DotToDash">;
|
|
@@ -781,7 +781,7 @@ export declare function dotToUpperSnake<T extends object | string>(input: T): Re
|
|
|
781
781
|
* dotToUpperDash({ 'first.name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
782
782
|
* ```
|
|
783
783
|
*
|
|
784
|
-
* @deprecated Use `
|
|
784
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
785
785
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
786
786
|
*/
|
|
787
787
|
export declare function dotToUpperDash<T extends object | string>(input: T): Result<T, "DotToUpperDash">;
|
|
@@ -874,7 +874,7 @@ export declare function titleToSnake<T extends object | string>(input: T): Resul
|
|
|
874
874
|
* titleToDash({ 'First Name': 'John' }); // { 'first-name': 'John' }
|
|
875
875
|
* ```
|
|
876
876
|
*
|
|
877
|
-
* @deprecated Use `
|
|
877
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
878
878
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
879
879
|
*/
|
|
880
880
|
export declare function titleToDash<T extends object | string>(input: T): Result<T, "TitleToDash">;
|
|
@@ -900,7 +900,7 @@ export declare function titleToUpperSnake<T extends object | string>(input: T):
|
|
|
900
900
|
* titleToUpperDash({ 'First Name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
901
901
|
* ```
|
|
902
902
|
*
|
|
903
|
-
* @deprecated Use `
|
|
903
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
904
904
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
905
905
|
*/
|
|
906
906
|
export declare function titleToUpperDash<T extends object | string>(input: T): Result<T, "TitleToUpperDash">;
|
|
@@ -993,7 +993,7 @@ export declare function sentenceToSnake<T extends object | string>(input: T): Re
|
|
|
993
993
|
* sentenceToDash({ 'First name': 'John' }); // { 'first-name': 'John' }
|
|
994
994
|
* ```
|
|
995
995
|
*
|
|
996
|
-
* @deprecated Use `
|
|
996
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
997
997
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
998
998
|
*/
|
|
999
999
|
export declare function sentenceToDash<T extends object | string>(input: T): Result<T, "SentenceToDash">;
|
|
@@ -1019,7 +1019,7 @@ export declare function sentenceToUpperSnake<T extends object | string>(input: T
|
|
|
1019
1019
|
* sentenceToUpperDash({ 'First name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
1020
1020
|
* ```
|
|
1021
1021
|
*
|
|
1022
|
-
* @deprecated Use `
|
|
1022
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1023
1023
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1024
1024
|
*/
|
|
1025
1025
|
export declare function sentenceToUpperDash<T extends object | string>(input: T): Result<T, "SentenceToUpperDash">;
|
|
@@ -1099,7 +1099,7 @@ export declare function upperDashToSnake<T extends object | string>(input: T): R
|
|
|
1099
1099
|
* upperDashToDash({ 'FIRST-NAME': 'John' }); // { 'first-name': 'John' }
|
|
1100
1100
|
* ```
|
|
1101
1101
|
*
|
|
1102
|
-
* @deprecated Use `
|
|
1102
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1103
1103
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1104
1104
|
*/
|
|
1105
1105
|
export declare function upperDashToDash<T extends object | string>(input: T): Result<T, "UpperDashToDash">;
|
|
@@ -1218,7 +1218,7 @@ export declare function upperSnakeToSnake<T extends object | string>(input: T):
|
|
|
1218
1218
|
* upperSnakeToDash({ FIRST_NAME: 'John' }); // { 'first-name': 'John' }
|
|
1219
1219
|
* ```
|
|
1220
1220
|
*
|
|
1221
|
-
* @deprecated Use `
|
|
1221
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1222
1222
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1223
1223
|
*/
|
|
1224
1224
|
export declare function upperSnakeToDash<T extends object | string>(input: T): Result<T, "UpperSnakeToDash">;
|
|
@@ -1244,7 +1244,7 @@ export declare function upperSnakeToPascal<T extends object | string>(input: T):
|
|
|
1244
1244
|
* upperSnakeToUpperDash({ FIRST_NAME: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
1245
1245
|
* ```
|
|
1246
1246
|
*
|
|
1247
|
-
* @deprecated Use `
|
|
1247
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1248
1248
|
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1249
1249
|
*/
|
|
1250
1250
|
export declare function upperSnakeToUpperDash<T extends object | string>(input: T): Result<T, "UpperSnakeToUpperDash">;
|
|
@@ -1303,26 +1303,42 @@ export declare function upperSnakeToSentence<T extends object | string>(input: T
|
|
|
1303
1303
|
//#endregion
|
|
1304
1304
|
//#region src/anyCase/types.d.ts
|
|
1305
1305
|
type Separator = "_" | "-" | "." | " ";
|
|
1306
|
+
/** ASCII punctuation, except the separators `_`, `-` and `.`. */
|
|
1307
|
+
type SymbolChar = "!" | "\"" | "#" | "$" | "%" | "&" | "'" | "(" | ")" | "*" | "+" | "," | "/" | ":" | ";" | "<" | "=" | ">" | "?" | "@" | "[" | "\\" | "]" | "^" | "`" | "{" | "|" | "}" | "~";
|
|
1308
|
+
/**
|
|
1309
|
+
* Which symbols the `toX` functions keep: `true` keeps all of them, `false` (the default)
|
|
1310
|
+
* removes all of them, and an array keeps only the listed ones (e.g. `['$', '@']`).
|
|
1311
|
+
*/
|
|
1312
|
+
type KeepSymbols = boolean | readonly string[];
|
|
1306
1313
|
type IsUpper<C extends string> = C extends Lowercase<C> ? false : true;
|
|
1307
1314
|
type IsLower<C extends string> = C extends Uppercase<C> ? false : true;
|
|
1308
|
-
type Push<W extends string[], Word extends string> = Word extends "" ? W : [...W, Lowercase<Word>];
|
|
1315
|
+
type Push<L extends boolean, W extends string[], Word extends string> = Word extends "" ? W : [...W, L extends true ? Lowercase<Word> : Word];
|
|
1316
|
+
type RunText<Run> = Run extends string ? Run : "";
|
|
1309
1317
|
/**
|
|
1310
1318
|
* Splits a string into lowercase words, the same way `words()` does at runtime:
|
|
1311
1319
|
* on `_`, `-`, `.` and spaces, before an uppercase letter that follows a lowercase
|
|
1312
1320
|
* letter or a digit (`helloWorld`), and before the last letter of an acronym (`XMLHttp`).
|
|
1321
|
+
* Symbols also start a new word; the ones in `S` are kept (see `words()`). Words are lowercased
|
|
1322
|
+
* unless `L` is `false`. `Run` holds the kept symbols of the current run of symbols, or `false`
|
|
1323
|
+
* outside of one.
|
|
1313
1324
|
*/
|
|
1314
|
-
type Words<T extends string, W extends string[] = [], Word extends string = "", Prev extends string = ""> = T extends `${infer C}${infer Rest}` ? C extends Separator ? Words<Rest, Push<W, Word
|
|
1325
|
+
type Words<T extends string, S extends string, L extends boolean = true, W extends string[] = [], Word extends string = "", Prev extends string = "", Run extends string | false = false> = T extends `${infer C}${infer Rest}` ? C extends Separator | SymbolChar ? C extends Separator ? Words<Rest, S, L, Push<L, W, `${Word}${RunText<Run>}`>, "", "", false> : Words<Rest, S, L, W, Word, Prev, `${RunText<Run>}${C extends S ? C : ""}`> : Run extends string ? Words<Rest, S, L, Push<L, W, Word>, `${Run}${C}`, C, false> : IsUpper<C> extends true ? Prev extends "" ? Words<Rest, S, L, W, `${Word}${C}`, C> : IsUpper<Prev> extends false ? Words<Rest, S, L, Push<L, W, Word>, C, C> : Rest extends `${infer Next}${string}` ? IsLower<Next> extends true ? Words<Rest, S, L, Push<L, W, Word>, C, C> : Words<Rest, S, L, W, `${Word}${C}`, C> : Words<Rest, S, L, W, `${Word}${C}`, C> : Words<Rest, S, L, W, `${Word}${C}`, C> : Push<L, W, `${Word}${RunText<Run>}`>;
|
|
1326
|
+
/** Uppercases the first character that is not a symbol: `'$id'` → `'$Id'`. */
|
|
1327
|
+
type CapitalizeWord<W> = W extends `${infer C}${infer R}` ? C extends SymbolChar ? `${C}${CapitalizeWord<R>}` : `${Uppercase<C>}${R}` : W;
|
|
1315
1328
|
type Join<W, S extends string> = W extends [infer A] ? A & string : W extends [infer A, ...infer R] ? `${A & string}${S}${Join<R, S>}` : "";
|
|
1316
|
-
type CapitalizeAll<W> = { [K in keyof W]:
|
|
1329
|
+
type CapitalizeAll<W> = { [K in keyof W]: CapitalizeWord<W[K] & string>; };
|
|
1317
1330
|
type CamelWords<W> = W extends [infer F, ...infer R] ? `${F & string}${Join<CapitalizeAll<R>, "">}` : "";
|
|
1318
1331
|
/** A case that the `toX` functions (e.g. `toSnake`) convert to. */
|
|
1319
|
-
type Case = "Camel" | "Pascal" | "Snake" | "
|
|
1320
|
-
|
|
1332
|
+
type Case = "Camel" | "Pascal" | "Snake" | "Kebab" | "UpperSnake" | "UpperKebab" | "Train" | "Dot" | "Title" | "Sentence" | "PascalSnake" | "Path" | "Space" | "Lower" | "Upper";
|
|
1333
|
+
/** The symbols kept by a `keepSymbols` argument: `true` → all, `false` → none, `'$' | '@'` → those. */
|
|
1334
|
+
type KeptSymbols<S> = S extends true ? SymbolChar : S extends false ? never : S & string;
|
|
1335
|
+
type ConvertKey<K extends string, C extends Case, S extends string> = string extends K ? string : C extends "Camel" ? CamelWords<Words<K, S>> : C extends "Pascal" ? Join<CapitalizeAll<Words<K, S>>, ""> : C extends "Snake" ? Join<Words<K, S>, "_"> : C extends "Kebab" ? Join<Words<K, S>, "-"> : C extends "UpperSnake" ? Uppercase<Join<Words<K, S>, "_">> : C extends "UpperKebab" ? Uppercase<Join<Words<K, S>, "-">> : C extends "Train" ? Join<CapitalizeAll<Words<K, S>>, "-"> : C extends "Dot" ? Join<Words<K, S, false>, "."> : C extends "Title" ? Join<CapitalizeAll<Words<K, S>>, " "> : C extends "Sentence" ? CapitalizeWord<Join<Words<K, S>, " ">> : C extends "PascalSnake" ? Join<CapitalizeAll<Words<K, S>>, "_"> : C extends "Path" ? Join<Words<K, S, false>, "/"> : C extends "Space" ? Join<Words<K, S, false>, " "> : C extends "Lower" ? Join<Words<K, S>, " "> : C extends "Upper" ? Uppercase<Join<Words<K, S>, " ">> : never;
|
|
1321
1336
|
/**
|
|
1322
1337
|
* The type returned by a `toX` function: strings stay `string`, and object keys
|
|
1323
1338
|
* in any case (deeply, including inside arrays) are renamed to the case `C`.
|
|
1339
|
+
* `S` is the `keepSymbols` argument (`false` by default).
|
|
1324
1340
|
*/
|
|
1325
|
-
type CaseResult<T, C extends Case> = T extends string ? string : T extends Array<unknown> ? { [K in keyof T]: CaseResult<T[K], C>; } : T extends object ? Prettify<{ [K in keyof T as ConvertKey<K & string, C
|
|
1341
|
+
type CaseResult<T, C extends Case, S = false> = T extends string ? string : T extends Array<unknown> ? { [K in keyof T]: CaseResult<T[K], C, S>; } : T extends object ? Prettify<{ [K in keyof T as boolean extends S ? string : string extends KeptSymbols<S> ? string : ConvertKey<K & string, C, KeptSymbols<S>>]: CaseResult<T[K], C, S>; }> : T;
|
|
1326
1342
|
//#endregion
|
|
1327
1343
|
//#region src/anyCase/anyCase.d.ts
|
|
1328
1344
|
/**
|
|
@@ -1332,9 +1348,13 @@ type CaseResult<T, C extends Case> = T extends string ? string : T extends Array
|
|
|
1332
1348
|
* ```ts
|
|
1333
1349
|
* toCamel('hello_world'); // 'helloWorld'
|
|
1334
1350
|
* toCamel({ first_name: 'John', userID: 1 }); // { firstName: 'John', userId: 1 }
|
|
1351
|
+
* toCamel('$hello-world', true); // '$helloWorld'
|
|
1335
1352
|
* ```
|
|
1353
|
+
*
|
|
1354
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1355
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1336
1356
|
*/
|
|
1337
|
-
export declare function toCamel<T extends object | string>(input: T): CaseResult<T, "Camel">;
|
|
1357
|
+
export declare function toCamel<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Camel", S>;
|
|
1338
1358
|
/**
|
|
1339
1359
|
* Converts a string, or the keys of an object/array (deeply), from any case to PascalCase.
|
|
1340
1360
|
*
|
|
@@ -1342,9 +1362,13 @@ export declare function toCamel<T extends object | string>(input: T): CaseResult
|
|
|
1342
1362
|
* ```ts
|
|
1343
1363
|
* toPascal('hello-world'); // 'HelloWorld'
|
|
1344
1364
|
* toPascal({ 'first-name': 'John', userID: 1 }); // { FirstName: 'John', UserId: 1 }
|
|
1365
|
+
* toPascal('$hello-world', true); // '$HelloWorld'
|
|
1345
1366
|
* ```
|
|
1367
|
+
*
|
|
1368
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1369
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1346
1370
|
*/
|
|
1347
|
-
export declare function toPascal<T extends object | string>(input: T): CaseResult<T, "Pascal">;
|
|
1371
|
+
export declare function toPascal<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Pascal", S>;
|
|
1348
1372
|
/**
|
|
1349
1373
|
* Converts a string, or the keys of an object/array (deeply), from any case to snake_case.
|
|
1350
1374
|
*
|
|
@@ -1352,19 +1376,27 @@ export declare function toPascal<T extends object | string>(input: T): CaseResul
|
|
|
1352
1376
|
* ```ts
|
|
1353
1377
|
* toSnake('helloWorld'); // 'hello_world'
|
|
1354
1378
|
* toSnake({ firstName: 'John', userID: 1 }); // { first_name: 'John', user_id: 1 }
|
|
1379
|
+
* toSnake('$hello-world', true); // '$hello_world'
|
|
1355
1380
|
* ```
|
|
1381
|
+
*
|
|
1382
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1383
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1356
1384
|
*/
|
|
1357
|
-
export declare function toSnake<T extends object | string>(input: T): CaseResult<T, "Snake">;
|
|
1385
|
+
export declare function toSnake<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Snake", S>;
|
|
1358
1386
|
/**
|
|
1359
|
-
* Converts a string, or the keys of an object/array (deeply), from any case to
|
|
1387
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to kebab-case.
|
|
1360
1388
|
*
|
|
1361
1389
|
* @example
|
|
1362
1390
|
* ```ts
|
|
1363
|
-
*
|
|
1364
|
-
*
|
|
1391
|
+
* toKebab('HELLO_WORLD'); // 'hello-world'
|
|
1392
|
+
* toKebab({ FIRST_NAME: 'John', userID: 1 }); // { 'first-name': 'John', 'user-id': 1 }
|
|
1393
|
+
* toKebab('$hello-world', true); // '$hello-world'
|
|
1365
1394
|
* ```
|
|
1395
|
+
*
|
|
1396
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1397
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1366
1398
|
*/
|
|
1367
|
-
export declare function
|
|
1399
|
+
export declare function toKebab<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Kebab", S>;
|
|
1368
1400
|
/**
|
|
1369
1401
|
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER_SNAKE_CASE.
|
|
1370
1402
|
*
|
|
@@ -1372,19 +1404,27 @@ export declare function toDash<T extends object | string>(input: T): CaseResult<
|
|
|
1372
1404
|
* ```ts
|
|
1373
1405
|
* toUpperSnake('hello-world'); // 'HELLO_WORLD'
|
|
1374
1406
|
* toUpperSnake({ 'first-name': 'John', userID: 1 }); // { FIRST_NAME: 'John', USER_ID: 1 }
|
|
1407
|
+
* toUpperSnake('$hello-world', true); // '$HELLO_WORLD'
|
|
1375
1408
|
* ```
|
|
1409
|
+
*
|
|
1410
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1411
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1376
1412
|
*/
|
|
1377
|
-
export declare function toUpperSnake<T extends object | string>(input: T): CaseResult<T, "UpperSnake">;
|
|
1413
|
+
export declare function toUpperSnake<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "UpperSnake", S>;
|
|
1378
1414
|
/**
|
|
1379
|
-
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER-
|
|
1415
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER-KEBAB-CASE.
|
|
1380
1416
|
*
|
|
1381
1417
|
* @example
|
|
1382
1418
|
* ```ts
|
|
1383
|
-
*
|
|
1384
|
-
*
|
|
1419
|
+
* toUpperKebab('helloWorld'); // 'HELLO-WORLD'
|
|
1420
|
+
* toUpperKebab({ firstName: 'John', userID: 1 }); // { 'FIRST-NAME': 'John', 'USER-ID': 1 }
|
|
1421
|
+
* toUpperKebab('$hello-world', true); // '$HELLO-WORLD'
|
|
1385
1422
|
* ```
|
|
1423
|
+
*
|
|
1424
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1425
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1386
1426
|
*/
|
|
1387
|
-
export declare function
|
|
1427
|
+
export declare function toUpperKebab<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "UpperKebab", S>;
|
|
1388
1428
|
/**
|
|
1389
1429
|
* Converts a string, or the keys of an object/array (deeply), from any case to Train-Case.
|
|
1390
1430
|
*
|
|
@@ -1392,19 +1432,27 @@ export declare function toUpperDash<T extends object | string>(input: T): CaseRe
|
|
|
1392
1432
|
* ```ts
|
|
1393
1433
|
* toTrain('hello_world'); // 'Hello-World'
|
|
1394
1434
|
* toTrain({ first_name: 'John', userID: 1 }); // { 'First-Name': 'John', 'User-Id': 1 }
|
|
1435
|
+
* toTrain('$hello-world', true); // '$Hello-World'
|
|
1395
1436
|
* ```
|
|
1437
|
+
*
|
|
1438
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1439
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1396
1440
|
*/
|
|
1397
|
-
export declare function toTrain<T extends object | string>(input: T): CaseResult<T, "Train">;
|
|
1441
|
+
export declare function toTrain<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Train", S>;
|
|
1398
1442
|
/**
|
|
1399
|
-
* Converts a string, or the keys of an object/array (deeply), from any case to dot.case.
|
|
1443
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to dot.case, keeping the original case of each word.
|
|
1400
1444
|
*
|
|
1401
1445
|
* @example
|
|
1402
1446
|
* ```ts
|
|
1403
|
-
* toDot('HelloWorld'); // '
|
|
1404
|
-
* toDot({ FirstName: 'John', userID: 1 }); // { '
|
|
1447
|
+
* toDot('HelloWorld'); // 'Hello.World'
|
|
1448
|
+
* toDot({ FirstName: 'John', userID: 1 }); // { 'First.Name': 'John', 'user.ID': 1 }
|
|
1449
|
+
* toDot('$hello-world', true); // '$hello.world'
|
|
1405
1450
|
* ```
|
|
1451
|
+
*
|
|
1452
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1453
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1406
1454
|
*/
|
|
1407
|
-
export declare function toDot<T extends object | string>(input: T): CaseResult<T, "Dot">;
|
|
1455
|
+
export declare function toDot<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Dot", S>;
|
|
1408
1456
|
/**
|
|
1409
1457
|
* Converts a string, or the keys of an object/array (deeply), from any case to Title Case.
|
|
1410
1458
|
*
|
|
@@ -1412,9 +1460,13 @@ export declare function toDot<T extends object | string>(input: T): CaseResult<T
|
|
|
1412
1460
|
* ```ts
|
|
1413
1461
|
* toTitle('hello_world'); // 'Hello World'
|
|
1414
1462
|
* toTitle({ first_name: 'John', userID: 1 }); // { 'First Name': 'John', 'User Id': 1 }
|
|
1463
|
+
* toTitle('$hello-world', true); // '$Hello World'
|
|
1415
1464
|
* ```
|
|
1465
|
+
*
|
|
1466
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1467
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1416
1468
|
*/
|
|
1417
|
-
export declare function toTitle<T extends object | string>(input: T): CaseResult<T, "Title">;
|
|
1469
|
+
export declare function toTitle<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Title", S>;
|
|
1418
1470
|
/**
|
|
1419
1471
|
* Converts a string, or the keys of an object/array (deeply), from any case to Sentence case.
|
|
1420
1472
|
*
|
|
@@ -1422,8 +1474,82 @@ export declare function toTitle<T extends object | string>(input: T): CaseResult
|
|
|
1422
1474
|
* ```ts
|
|
1423
1475
|
* toSentence('helloWorld'); // 'Hello world'
|
|
1424
1476
|
* toSentence({ firstName: 'John', userID: 1 }); // { 'First name': 'John', 'User id': 1 }
|
|
1477
|
+
* toSentence('$hello-world', true); // '$Hello world'
|
|
1478
|
+
* ```
|
|
1479
|
+
*
|
|
1480
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1481
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1482
|
+
*/
|
|
1483
|
+
export declare function toSentence<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Sentence", S>;
|
|
1484
|
+
/**
|
|
1485
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Pascal_Snake_Case (also known as Ada_Case).
|
|
1486
|
+
*
|
|
1487
|
+
* @example
|
|
1488
|
+
* ```ts
|
|
1489
|
+
* toPascalSnake('helloWorld'); // 'Hello_World'
|
|
1490
|
+
* toPascalSnake({ first_name: 'John', userID: 1 }); // { First_Name: 'John', User_Id: 1 }
|
|
1491
|
+
* toPascalSnake('$hello-world', true); // '$Hello_World'
|
|
1425
1492
|
* ```
|
|
1493
|
+
*
|
|
1494
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1495
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1496
|
+
*/
|
|
1497
|
+
export declare function toPascalSnake<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "PascalSnake", S>;
|
|
1498
|
+
/**
|
|
1499
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to path/case, keeping the original case of each word.
|
|
1500
|
+
*
|
|
1501
|
+
* @example
|
|
1502
|
+
* ```ts
|
|
1503
|
+
* toPath('helloWorld'); // 'hello/World'
|
|
1504
|
+
* toPath({ first_name: 'John', userID: 1 }); // { 'first/name': 'John', 'user/ID': 1 }
|
|
1505
|
+
* toPath('$hello-world', true); // '$hello/world'
|
|
1506
|
+
* ```
|
|
1507
|
+
*
|
|
1508
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1509
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1510
|
+
*/
|
|
1511
|
+
export declare function toPath<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Path", S>;
|
|
1512
|
+
/**
|
|
1513
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to space case, keeping the original case of each word.
|
|
1514
|
+
*
|
|
1515
|
+
* @example
|
|
1516
|
+
* ```ts
|
|
1517
|
+
* toSpace('helloWorld'); // 'hello World'
|
|
1518
|
+
* toSpace({ first_name: 'John', userID: 1 }); // { 'first name': 'John', 'user ID': 1 }
|
|
1519
|
+
* toSpace('$hello-world', true); // '$hello world'
|
|
1520
|
+
* ```
|
|
1521
|
+
*
|
|
1522
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1523
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1524
|
+
*/
|
|
1525
|
+
export declare function toSpace<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Space", S>;
|
|
1526
|
+
/**
|
|
1527
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to lower case (space separated).
|
|
1528
|
+
*
|
|
1529
|
+
* @example
|
|
1530
|
+
* ```ts
|
|
1531
|
+
* toLower('helloWorld'); // 'hello world'
|
|
1532
|
+
* toLower({ first_name: 'John', userID: 1 }); // { 'first name': 'John', 'user id': 1 }
|
|
1533
|
+
* toLower('$hello-world', true); // '$hello world'
|
|
1534
|
+
* ```
|
|
1535
|
+
*
|
|
1536
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1537
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1538
|
+
*/
|
|
1539
|
+
export declare function toLower<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Lower", S>;
|
|
1540
|
+
/**
|
|
1541
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER CASE (space separated).
|
|
1542
|
+
*
|
|
1543
|
+
* @example
|
|
1544
|
+
* ```ts
|
|
1545
|
+
* toUpper('helloWorld'); // 'HELLO WORLD'
|
|
1546
|
+
* toUpper({ first_name: 'John', userID: 1 }); // { 'FIRST NAME': 'John', 'USER ID': 1 }
|
|
1547
|
+
* toUpper('$hello-world', true); // '$HELLO WORLD'
|
|
1548
|
+
* ```
|
|
1549
|
+
*
|
|
1550
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1551
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1426
1552
|
*/
|
|
1427
|
-
export declare function
|
|
1553
|
+
export declare function toUpper<T extends object | string, S extends boolean | string = false>(input: T, keepSymbols?: S | readonly S[]): CaseResult<T, "Upper", S>;
|
|
1428
1554
|
//#endregion
|
|
1429
|
-
export type { Case, CaseResult, ParserType, Prettify, Result };
|
|
1555
|
+
export type { Case, CaseResult, KeepSymbols, ParserType, Prettify, Result };
|