caseparser 5.0.0 → 5.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.
- package/README.md +184 -113
- package/dist/index.cjs +52 -227
- package/dist/index.d.cts +239 -36
- package/dist/index.d.ts +239 -36
- package/dist/index.js +52 -227
- package/package.json +11 -3
package/dist/index.d.ts
CHANGED
|
@@ -1309,7 +1309,30 @@ type SymbolChar = "!" | "\"" | "#" | "$" | "%" | "&" | "'" | "(" | ")" | "*" | "
|
|
|
1309
1309
|
* Which symbols the `toX` functions keep: `true` keeps all of them, `false` (the default)
|
|
1310
1310
|
* removes all of them, and an array keeps only the listed ones (e.g. `['$', '@']`).
|
|
1311
1311
|
*/
|
|
1312
|
-
type
|
|
1312
|
+
type AllowSymbols = boolean | readonly string[];
|
|
1313
|
+
/**
|
|
1314
|
+
* @deprecated Renamed to `AllowSymbols`. It will be removed in the next major version.
|
|
1315
|
+
*/
|
|
1316
|
+
type KeepSymbols = AllowSymbols;
|
|
1317
|
+
/** Changes the case of the whole result: `'lowercase'` or `'uppercase'`. */
|
|
1318
|
+
type Transform = "uppercase" | "lowercase";
|
|
1319
|
+
/** The options of the `toX` functions. `S` is inferred from `allowSymbols`. */
|
|
1320
|
+
interface CaseOptions<S = boolean | string> {
|
|
1321
|
+
/** Symbols are removed by default. `true` keeps all of them, and an array keeps only the listed ones (e.g. `['$']`). */
|
|
1322
|
+
allowSymbols?: S | readonly S[];
|
|
1323
|
+
}
|
|
1324
|
+
/** The options of `toDot` and `toPath`, which also take a `transform`. `X` is inferred from `transform`. */
|
|
1325
|
+
interface TransformCaseOptions<S = boolean | string, X extends Transform | undefined = Transform | undefined> extends CaseOptions<S> {
|
|
1326
|
+
/** The original case of each word is kept by default. `'lowercase'` or `'uppercase'` changes the case of the whole result. */
|
|
1327
|
+
transform?: X;
|
|
1328
|
+
}
|
|
1329
|
+
/** The separator that `toPath` joins the words with: `'/'` (the default) or `'\\'`. */
|
|
1330
|
+
type PathSeparator = "/" | "\\";
|
|
1331
|
+
/** The options of `toPath`, which also take a `separator`. `P` is inferred from `separator`. */
|
|
1332
|
+
interface PathCaseOptions<S = boolean | string, X extends Transform | undefined = Transform | undefined, P extends PathSeparator = PathSeparator> extends TransformCaseOptions<S, X> {
|
|
1333
|
+
/** Joins the words with `'/'` (the default) or `'\\'`. */
|
|
1334
|
+
separator?: P;
|
|
1335
|
+
}
|
|
1313
1336
|
type IsUpper<C extends string> = C extends Lowercase<C> ? false : true;
|
|
1314
1337
|
type IsLower<C extends string> = C extends Uppercase<C> ? false : true;
|
|
1315
1338
|
type Push<L extends boolean, W extends string[], Word extends string> = Word extends "" ? W : [...W, L extends true ? Lowercase<Word> : Word];
|
|
@@ -1327,18 +1350,23 @@ type Words<T extends string, S extends string, L extends boolean = true, W exten
|
|
|
1327
1350
|
type CapitalizeWord<W> = W extends `${infer C}${infer R}` ? C extends SymbolChar ? `${C}${CapitalizeWord<R>}` : `${Uppercase<C>}${R}` : W;
|
|
1328
1351
|
type Join<W, S extends string> = W extends [infer A] ? A & string : W extends [infer A, ...infer R] ? `${A & string}${S}${Join<R, S>}` : "";
|
|
1329
1352
|
type CapitalizeAll<W> = { [K in keyof W]: CapitalizeWord<W[K] & string>; };
|
|
1353
|
+
/** In a path, `/` and `\\` also separate words: they are replaced with a space before splitting, like `ToPath` does. */
|
|
1354
|
+
type PathSeparatorsToSpace<T extends string> = T extends `${infer A}/${infer B}` ? PathSeparatorsToSpace<`${A} ${B}`> : T extends `${infer A}\\${infer B}` ? PathSeparatorsToSpace<`${A} ${B}`> : T;
|
|
1330
1355
|
type CamelWords<W> = W extends [infer F, ...infer R] ? `${F & string}${Join<CapitalizeAll<R>, "">}` : "";
|
|
1331
1356
|
/** A case that the `toX` functions (e.g. `toSnake`) convert to. */
|
|
1332
1357
|
type Case = "Camel" | "Pascal" | "Snake" | "Kebab" | "UpperSnake" | "UpperKebab" | "Train" | "Dot" | "Title" | "Sentence" | "PascalSnake" | "Path" | "Space" | "Lower" | "Upper";
|
|
1333
|
-
/** The symbols kept by
|
|
1358
|
+
/** The symbols kept by an `allowSymbols` argument: `true` → all, `false` → none, `'$' | '@'` → those. */
|
|
1334
1359
|
type KeptSymbols<S> = S extends true ? SymbolChar : S extends false ? never : S & string;
|
|
1335
|
-
|
|
1360
|
+
/** Applies a `transform` to a converted key, or falls back to `string` when it is only known at runtime. */
|
|
1361
|
+
type ApplyTransform<K extends string, X> = [X] extends [undefined] ? K : [X] extends ["lowercase"] ? Lowercase<K> : [X] extends ["uppercase"] ? Uppercase<K> : string;
|
|
1362
|
+
type ConvertKey<K extends string, C extends Case, S extends string, P 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<PathSeparatorsToSpace<K>, S, false>, P> : C extends "Space" ? Join<Words<K, S, false>, " "> : C extends "Lower" ? Join<Words<K, S>, " "> : C extends "Upper" ? Uppercase<Join<Words<K, S>, " ">> : never;
|
|
1336
1363
|
/**
|
|
1337
1364
|
* The type returned by a `toX` function: strings stay `string`, and object keys
|
|
1338
1365
|
* in any case (deeply, including inside arrays) are renamed to the case `C`.
|
|
1339
|
-
* `S` is the `
|
|
1366
|
+
* `S` is the `allowSymbols` argument (`false` by default), `X` the `transform` option of `toDot` and `toPath`,
|
|
1367
|
+
* and `P` the `separator` option of `toPath`.
|
|
1340
1368
|
*/
|
|
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
|
|
1369
|
+
type CaseResult<T, C extends Case, S = false, X = undefined, P extends string = "/"> = T extends string ? string : T extends Array<unknown> ? { [K in keyof T]: CaseResult<T[K], C, S, X, P>; } : T extends object ? Prettify<{ [K in keyof T as boolean extends S ? string : string extends KeptSymbols<S> ? string : ApplyTransform<ConvertKey<K & string, C, KeptSymbols<S>, P>, X>]: CaseResult<T[K], C, S, X, P>; }> : T;
|
|
1342
1370
|
//#endregion
|
|
1343
1371
|
//#region src/anyCase/anyCase.d.ts
|
|
1344
1372
|
/**
|
|
@@ -1351,10 +1379,21 @@ type CaseResult<T, C extends Case, S = false> = T extends string ? string : T ex
|
|
|
1351
1379
|
* toCamel('$hello-world', true); // '$helloWorld'
|
|
1352
1380
|
* ```
|
|
1353
1381
|
*
|
|
1354
|
-
* @param
|
|
1382
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1355
1383
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1356
1384
|
*/
|
|
1357
|
-
export declare function toCamel<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1385
|
+
export declare function toCamel<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Camel", S>;
|
|
1386
|
+
/**
|
|
1387
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to camelCase.
|
|
1388
|
+
*
|
|
1389
|
+
* @example
|
|
1390
|
+
* ```ts
|
|
1391
|
+
* toCamel('$hello-world', { allowSymbols: ['$'] }); // '$helloWorld'
|
|
1392
|
+
* ```
|
|
1393
|
+
*
|
|
1394
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1395
|
+
*/
|
|
1396
|
+
export declare function toCamel<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "Camel", S>;
|
|
1358
1397
|
/**
|
|
1359
1398
|
* Converts a string, or the keys of an object/array (deeply), from any case to PascalCase.
|
|
1360
1399
|
*
|
|
@@ -1365,10 +1404,21 @@ export declare function toCamel<T extends object | string, S extends boolean | s
|
|
|
1365
1404
|
* toPascal('$hello-world', true); // '$HelloWorld'
|
|
1366
1405
|
* ```
|
|
1367
1406
|
*
|
|
1368
|
-
* @param
|
|
1407
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1369
1408
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1370
1409
|
*/
|
|
1371
|
-
export declare function toPascal<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1410
|
+
export declare function toPascal<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Pascal", S>;
|
|
1411
|
+
/**
|
|
1412
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to PascalCase.
|
|
1413
|
+
*
|
|
1414
|
+
* @example
|
|
1415
|
+
* ```ts
|
|
1416
|
+
* toPascal('$hello-world', { allowSymbols: ['$'] }); // '$HelloWorld'
|
|
1417
|
+
* ```
|
|
1418
|
+
*
|
|
1419
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1420
|
+
*/
|
|
1421
|
+
export declare function toPascal<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "Pascal", S>;
|
|
1372
1422
|
/**
|
|
1373
1423
|
* Converts a string, or the keys of an object/array (deeply), from any case to snake_case.
|
|
1374
1424
|
*
|
|
@@ -1379,10 +1429,21 @@ export declare function toPascal<T extends object | string, S extends boolean |
|
|
|
1379
1429
|
* toSnake('$hello-world', true); // '$hello_world'
|
|
1380
1430
|
* ```
|
|
1381
1431
|
*
|
|
1382
|
-
* @param
|
|
1432
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1383
1433
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1384
1434
|
*/
|
|
1385
|
-
export declare function toSnake<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1435
|
+
export declare function toSnake<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Snake", S>;
|
|
1436
|
+
/**
|
|
1437
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to snake_case.
|
|
1438
|
+
*
|
|
1439
|
+
* @example
|
|
1440
|
+
* ```ts
|
|
1441
|
+
* toSnake('$hello-world', { allowSymbols: ['$'] }); // '$hello_world'
|
|
1442
|
+
* ```
|
|
1443
|
+
*
|
|
1444
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1445
|
+
*/
|
|
1446
|
+
export declare function toSnake<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "Snake", S>;
|
|
1386
1447
|
/**
|
|
1387
1448
|
* Converts a string, or the keys of an object/array (deeply), from any case to kebab-case.
|
|
1388
1449
|
*
|
|
@@ -1393,10 +1454,21 @@ export declare function toSnake<T extends object | string, S extends boolean | s
|
|
|
1393
1454
|
* toKebab('$hello-world', true); // '$hello-world'
|
|
1394
1455
|
* ```
|
|
1395
1456
|
*
|
|
1396
|
-
* @param
|
|
1457
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1397
1458
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1398
1459
|
*/
|
|
1399
|
-
export declare function toKebab<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1460
|
+
export declare function toKebab<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Kebab", S>;
|
|
1461
|
+
/**
|
|
1462
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to kebab-case.
|
|
1463
|
+
*
|
|
1464
|
+
* @example
|
|
1465
|
+
* ```ts
|
|
1466
|
+
* toKebab('$hello-world', { allowSymbols: ['$'] }); // '$hello-world'
|
|
1467
|
+
* ```
|
|
1468
|
+
*
|
|
1469
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1470
|
+
*/
|
|
1471
|
+
export declare function toKebab<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "Kebab", S>;
|
|
1400
1472
|
/**
|
|
1401
1473
|
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER_SNAKE_CASE.
|
|
1402
1474
|
*
|
|
@@ -1407,10 +1479,21 @@ export declare function toKebab<T extends object | string, S extends boolean | s
|
|
|
1407
1479
|
* toUpperSnake('$hello-world', true); // '$HELLO_WORLD'
|
|
1408
1480
|
* ```
|
|
1409
1481
|
*
|
|
1410
|
-
* @param
|
|
1482
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1411
1483
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1412
1484
|
*/
|
|
1413
|
-
export declare function toUpperSnake<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1485
|
+
export declare function toUpperSnake<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "UpperSnake", S>;
|
|
1486
|
+
/**
|
|
1487
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER_SNAKE_CASE.
|
|
1488
|
+
*
|
|
1489
|
+
* @example
|
|
1490
|
+
* ```ts
|
|
1491
|
+
* toUpperSnake('$hello-world', { allowSymbols: ['$'] }); // '$HELLO_WORLD'
|
|
1492
|
+
* ```
|
|
1493
|
+
*
|
|
1494
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1495
|
+
*/
|
|
1496
|
+
export declare function toUpperSnake<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "UpperSnake", S>;
|
|
1414
1497
|
/**
|
|
1415
1498
|
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER-KEBAB-CASE.
|
|
1416
1499
|
*
|
|
@@ -1421,10 +1504,21 @@ export declare function toUpperSnake<T extends object | string, S extends boolea
|
|
|
1421
1504
|
* toUpperKebab('$hello-world', true); // '$HELLO-WORLD'
|
|
1422
1505
|
* ```
|
|
1423
1506
|
*
|
|
1424
|
-
* @param
|
|
1507
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1425
1508
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1426
1509
|
*/
|
|
1427
|
-
export declare function toUpperKebab<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1510
|
+
export declare function toUpperKebab<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "UpperKebab", S>;
|
|
1511
|
+
/**
|
|
1512
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER-KEBAB-CASE.
|
|
1513
|
+
*
|
|
1514
|
+
* @example
|
|
1515
|
+
* ```ts
|
|
1516
|
+
* toUpperKebab('$hello-world', { allowSymbols: ['$'] }); // '$HELLO-WORLD'
|
|
1517
|
+
* ```
|
|
1518
|
+
*
|
|
1519
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1520
|
+
*/
|
|
1521
|
+
export declare function toUpperKebab<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "UpperKebab", S>;
|
|
1428
1522
|
/**
|
|
1429
1523
|
* Converts a string, or the keys of an object/array (deeply), from any case to Train-Case.
|
|
1430
1524
|
*
|
|
@@ -1435,10 +1529,35 @@ export declare function toUpperKebab<T extends object | string, S extends boolea
|
|
|
1435
1529
|
* toTrain('$hello-world', true); // '$Hello-World'
|
|
1436
1530
|
* ```
|
|
1437
1531
|
*
|
|
1438
|
-
* @param
|
|
1532
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1439
1533
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1440
1534
|
*/
|
|
1441
|
-
export declare function toTrain<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1535
|
+
export declare function toTrain<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Train", S>;
|
|
1536
|
+
/**
|
|
1537
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Train-Case.
|
|
1538
|
+
*
|
|
1539
|
+
* @example
|
|
1540
|
+
* ```ts
|
|
1541
|
+
* toTrain('$hello-world', { allowSymbols: ['$'] }); // '$Hello-World'
|
|
1542
|
+
* ```
|
|
1543
|
+
*
|
|
1544
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1545
|
+
*/
|
|
1546
|
+
export declare function toTrain<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "Train", S>;
|
|
1547
|
+
/**
|
|
1548
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to dot.case, keeping the original case of each word.
|
|
1549
|
+
*
|
|
1550
|
+
* @example
|
|
1551
|
+
* ```ts
|
|
1552
|
+
* toDot('$hello-World', { allowSymbols: ['$'] }); // '$hello.World'
|
|
1553
|
+
* toDot('helloWorld', { transform: 'lowercase' }); // 'hello.world'
|
|
1554
|
+
* toDot('helloWorld', { transform: 'uppercase' }); // 'HELLO.WORLD'
|
|
1555
|
+
* ```
|
|
1556
|
+
*
|
|
1557
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1558
|
+
* `transform`: the original case of each word is kept by default; `'lowercase'` or `'uppercase'` changes the case of the whole result.
|
|
1559
|
+
*/
|
|
1560
|
+
export declare function toDot<T extends object | string, S extends boolean | string = false, X extends Transform | undefined = undefined>(input: T, options: TransformCaseOptions<S, X>): CaseResult<T, "Dot", S, X>;
|
|
1442
1561
|
/**
|
|
1443
1562
|
* Converts a string, or the keys of an object/array (deeply), from any case to dot.case, keeping the original case of each word.
|
|
1444
1563
|
*
|
|
@@ -1449,10 +1568,10 @@ export declare function toTrain<T extends object | string, S extends boolean | s
|
|
|
1449
1568
|
* toDot('$hello-world', true); // '$hello.world'
|
|
1450
1569
|
* ```
|
|
1451
1570
|
*
|
|
1452
|
-
* @param
|
|
1571
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1453
1572
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1454
1573
|
*/
|
|
1455
|
-
export declare function toDot<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1574
|
+
export declare function toDot<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Dot", S>;
|
|
1456
1575
|
/**
|
|
1457
1576
|
* Converts a string, or the keys of an object/array (deeply), from any case to Title Case.
|
|
1458
1577
|
*
|
|
@@ -1463,10 +1582,21 @@ export declare function toDot<T extends object | string, S extends boolean | str
|
|
|
1463
1582
|
* toTitle('$hello-world', true); // '$Hello World'
|
|
1464
1583
|
* ```
|
|
1465
1584
|
*
|
|
1466
|
-
* @param
|
|
1585
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1467
1586
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1468
1587
|
*/
|
|
1469
|
-
export declare function toTitle<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1588
|
+
export declare function toTitle<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Title", S>;
|
|
1589
|
+
/**
|
|
1590
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Title Case.
|
|
1591
|
+
*
|
|
1592
|
+
* @example
|
|
1593
|
+
* ```ts
|
|
1594
|
+
* toTitle('$hello-world', { allowSymbols: ['$'] }); // '$Hello World'
|
|
1595
|
+
* ```
|
|
1596
|
+
*
|
|
1597
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1598
|
+
*/
|
|
1599
|
+
export declare function toTitle<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "Title", S>;
|
|
1470
1600
|
/**
|
|
1471
1601
|
* Converts a string, or the keys of an object/array (deeply), from any case to Sentence case.
|
|
1472
1602
|
*
|
|
@@ -1477,10 +1607,21 @@ export declare function toTitle<T extends object | string, S extends boolean | s
|
|
|
1477
1607
|
* toSentence('$hello-world', true); // '$Hello world'
|
|
1478
1608
|
* ```
|
|
1479
1609
|
*
|
|
1480
|
-
* @param
|
|
1610
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1481
1611
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1482
1612
|
*/
|
|
1483
|
-
export declare function toSentence<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1613
|
+
export declare function toSentence<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Sentence", S>;
|
|
1614
|
+
/**
|
|
1615
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Sentence case.
|
|
1616
|
+
*
|
|
1617
|
+
* @example
|
|
1618
|
+
* ```ts
|
|
1619
|
+
* toSentence('$hello-world', { allowSymbols: ['$'] }); // '$Hello world'
|
|
1620
|
+
* ```
|
|
1621
|
+
*
|
|
1622
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1623
|
+
*/
|
|
1624
|
+
export declare function toSentence<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "Sentence", S>;
|
|
1484
1625
|
/**
|
|
1485
1626
|
* Converts a string, or the keys of an object/array (deeply), from any case to Pascal_Snake_Case (also known as Ada_Case).
|
|
1486
1627
|
*
|
|
@@ -1491,12 +1632,41 @@ export declare function toSentence<T extends object | string, S extends boolean
|
|
|
1491
1632
|
* toPascalSnake('$hello-world', true); // '$Hello_World'
|
|
1492
1633
|
* ```
|
|
1493
1634
|
*
|
|
1494
|
-
* @param
|
|
1635
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1495
1636
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1496
1637
|
*/
|
|
1497
|
-
export declare function toPascalSnake<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1638
|
+
export declare function toPascalSnake<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "PascalSnake", S>;
|
|
1639
|
+
/**
|
|
1640
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Pascal_Snake_Case (also known as Ada_Case).
|
|
1641
|
+
*
|
|
1642
|
+
* @example
|
|
1643
|
+
* ```ts
|
|
1644
|
+
* toPascalSnake('$hello-world', { allowSymbols: ['$'] }); // '$Hello_World'
|
|
1645
|
+
* ```
|
|
1646
|
+
*
|
|
1647
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1648
|
+
*/
|
|
1649
|
+
export declare function toPascalSnake<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "PascalSnake", S>;
|
|
1650
|
+
/**
|
|
1651
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to path/case, keeping the original case of each word.
|
|
1652
|
+
* `/` and `\\` in the input also separate words.
|
|
1653
|
+
*
|
|
1654
|
+
* @example
|
|
1655
|
+
* ```ts
|
|
1656
|
+
* toPath('$hello-World', { allowSymbols: ['$'] }); // '$hello/World'
|
|
1657
|
+
* toPath('helloWorld', { transform: 'lowercase' }); // 'hello/world'
|
|
1658
|
+
* toPath('helloWorld', { transform: 'uppercase' }); // 'HELLO/WORLD'
|
|
1659
|
+
* toPath('users/profilePicture', { separator: '\\' }); // 'users\\profile\\Picture'
|
|
1660
|
+
* ```
|
|
1661
|
+
*
|
|
1662
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1663
|
+
* `transform`: the original case of each word is kept by default; `'lowercase'` or `'uppercase'` changes the case of the whole result.
|
|
1664
|
+
* `separator`: `'/'` (the default) or `'\\'`.
|
|
1665
|
+
*/
|
|
1666
|
+
export declare function toPath<T extends object | string, S extends boolean | string = false, X extends Transform | undefined = undefined, P extends PathSeparator = "/">(input: T, options: PathCaseOptions<S, X, P>): CaseResult<T, "Path", S, X, P>;
|
|
1498
1667
|
/**
|
|
1499
1668
|
* Converts a string, or the keys of an object/array (deeply), from any case to path/case, keeping the original case of each word.
|
|
1669
|
+
* `/` and `\\` in the input also separate words.
|
|
1500
1670
|
*
|
|
1501
1671
|
* @example
|
|
1502
1672
|
* ```ts
|
|
@@ -1505,10 +1675,10 @@ export declare function toPascalSnake<T extends object | string, S extends boole
|
|
|
1505
1675
|
* toPath('$hello-world', true); // '$hello/world'
|
|
1506
1676
|
* ```
|
|
1507
1677
|
*
|
|
1508
|
-
* @param
|
|
1678
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1509
1679
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1510
1680
|
*/
|
|
1511
|
-
export declare function toPath<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1681
|
+
export declare function toPath<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Path", S>;
|
|
1512
1682
|
/**
|
|
1513
1683
|
* 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
1684
|
*
|
|
@@ -1519,10 +1689,21 @@ export declare function toPath<T extends object | string, S extends boolean | st
|
|
|
1519
1689
|
* toSpace('$hello-world', true); // '$hello world'
|
|
1520
1690
|
* ```
|
|
1521
1691
|
*
|
|
1522
|
-
* @param
|
|
1692
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1523
1693
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1524
1694
|
*/
|
|
1525
|
-
export declare function toSpace<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1695
|
+
export declare function toSpace<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Space", S>;
|
|
1696
|
+
/**
|
|
1697
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to space case, keeping the original case of each word.
|
|
1698
|
+
*
|
|
1699
|
+
* @example
|
|
1700
|
+
* ```ts
|
|
1701
|
+
* toSpace('$hello-world', { allowSymbols: ['$'] }); // '$hello world'
|
|
1702
|
+
* ```
|
|
1703
|
+
*
|
|
1704
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1705
|
+
*/
|
|
1706
|
+
export declare function toSpace<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "Space", S>;
|
|
1526
1707
|
/**
|
|
1527
1708
|
* Converts a string, or the keys of an object/array (deeply), from any case to lower case (space separated).
|
|
1528
1709
|
*
|
|
@@ -1533,10 +1714,21 @@ export declare function toSpace<T extends object | string, S extends boolean | s
|
|
|
1533
1714
|
* toLower('$hello-world', true); // '$hello world'
|
|
1534
1715
|
* ```
|
|
1535
1716
|
*
|
|
1536
|
-
* @param
|
|
1717
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1537
1718
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1538
1719
|
*/
|
|
1539
|
-
export declare function toLower<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1720
|
+
export declare function toLower<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Lower", S>;
|
|
1721
|
+
/**
|
|
1722
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to lower case (space separated).
|
|
1723
|
+
*
|
|
1724
|
+
* @example
|
|
1725
|
+
* ```ts
|
|
1726
|
+
* toLower('$hello-world', { allowSymbols: ['$'] }); // '$hello world'
|
|
1727
|
+
* ```
|
|
1728
|
+
*
|
|
1729
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1730
|
+
*/
|
|
1731
|
+
export declare function toLower<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "Lower", S>;
|
|
1540
1732
|
/**
|
|
1541
1733
|
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER CASE (space separated).
|
|
1542
1734
|
*
|
|
@@ -1547,9 +1739,20 @@ export declare function toLower<T extends object | string, S extends boolean | s
|
|
|
1547
1739
|
* toUpper('$hello-world', true); // '$HELLO WORLD'
|
|
1548
1740
|
* ```
|
|
1549
1741
|
*
|
|
1550
|
-
* @param
|
|
1742
|
+
* @param allowSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1551
1743
|
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1552
1744
|
*/
|
|
1553
|
-
export declare function toUpper<T extends object | string, S extends boolean | string = false>(input: T,
|
|
1745
|
+
export declare function toUpper<T extends object | string, S extends boolean | string = false>(input: T, allowSymbols?: S | readonly S[]): CaseResult<T, "Upper", S>;
|
|
1746
|
+
/**
|
|
1747
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER CASE (space separated).
|
|
1748
|
+
*
|
|
1749
|
+
* @example
|
|
1750
|
+
* ```ts
|
|
1751
|
+
* toUpper('$hello-world', { allowSymbols: ['$'] }); // '$HELLO WORLD'
|
|
1752
|
+
* ```
|
|
1753
|
+
*
|
|
1754
|
+
* @param options `allowSymbols`: symbols are removed by default; `true` keeps all of them, and an array keeps only some.
|
|
1755
|
+
*/
|
|
1756
|
+
export declare function toUpper<T extends object | string, S extends boolean | string = false>(input: T, options: CaseOptions<S>): CaseResult<T, "Upper", S>;
|
|
1554
1757
|
//#endregion
|
|
1555
|
-
export type { Case, CaseResult, KeepSymbols, ParserType, Prettify, Result };
|
|
1758
|
+
export type { AllowSymbols, Case, CaseOptions, CaseResult, KeepSymbols, ParserType, PathCaseOptions, PathSeparator, Prettify, Result, Transform, TransformCaseOptions };
|