caseparser 4.2.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 +103 -13
- package/dist/index.cjs +638 -34
- package/dist/index.d.cts +522 -1
- package/dist/index.d.ts +522 -1
- package/dist/index.js +624 -35
- package/package.json +5 -1
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,35 @@ function Uncapitalize(str) {
|
|
|
22
22
|
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
23
23
|
}
|
|
24
24
|
//#endregion
|
|
25
|
+
//#region src/parser/objectParser.ts
|
|
26
|
+
function objectParser(input, convertKey) {
|
|
27
|
+
const result = {};
|
|
28
|
+
for (const property of Object.keys(input)) {
|
|
29
|
+
const parsedKey = convertKey(property);
|
|
30
|
+
const value = input[property];
|
|
31
|
+
let parsedValue;
|
|
32
|
+
if (isArray(value)) parsedValue = arrayParser(value, convertKey);
|
|
33
|
+
else if (isObject(value)) parsedValue = objectParser(value, convertKey);
|
|
34
|
+
else parsedValue = value;
|
|
35
|
+
Object.defineProperty(result, parsedKey, {
|
|
36
|
+
value: parsedValue,
|
|
37
|
+
enumerable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
configurable: true
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/parser/arrayParser.ts
|
|
46
|
+
function arrayParser(input, convertKey) {
|
|
47
|
+
return input.map((item) => {
|
|
48
|
+
if (isArray(item)) return arrayParser(item, convertKey);
|
|
49
|
+
if (isObject(item)) return objectParser(item, convertKey);
|
|
50
|
+
return item;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
25
54
|
//#region src/parser/stringParser.ts
|
|
26
55
|
const CamelToDash = (str) => str.replace(/([A-Z])/g, (g) => "-" + g[0].toLowerCase());
|
|
27
56
|
const CamelToPascal = (str) => Capitalize(str);
|
|
@@ -208,42 +237,15 @@ function parse(input, type) {
|
|
|
208
237
|
}[type](input);
|
|
209
238
|
}
|
|
210
239
|
//#endregion
|
|
211
|
-
//#region src/parser/objectParser.ts
|
|
212
|
-
function objectParser(input, type) {
|
|
213
|
-
const result = {};
|
|
214
|
-
for (const property of Object.keys(input)) {
|
|
215
|
-
const parsedKey = parse(property, type);
|
|
216
|
-
const value = input[property];
|
|
217
|
-
let parsedValue;
|
|
218
|
-
if (isArray(value)) parsedValue = arrayParser(value, type);
|
|
219
|
-
else if (isObject(value)) parsedValue = objectParser(value, type);
|
|
220
|
-
else parsedValue = value;
|
|
221
|
-
Object.defineProperty(result, parsedKey, {
|
|
222
|
-
value: parsedValue,
|
|
223
|
-
enumerable: true,
|
|
224
|
-
writable: true,
|
|
225
|
-
configurable: true
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
//#endregion
|
|
231
|
-
//#region src/parser/arrayParser.ts
|
|
232
|
-
function arrayParser(input, type) {
|
|
233
|
-
return input.map((item) => {
|
|
234
|
-
if (isArray(item)) return arrayParser(item, type);
|
|
235
|
-
if (isObject(item)) return objectParser(item, type);
|
|
236
|
-
return item;
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
//#endregion
|
|
240
240
|
//#region src/parser/parser.ts
|
|
241
|
+
/** Converts a string, or the keys of an object/array (deeply), with `convertKey`. */
|
|
242
|
+
function convert(input, convertKey) {
|
|
243
|
+
if (isString(input)) return convertKey(input);
|
|
244
|
+
if (isArray(input)) return arrayParser(input, convertKey);
|
|
245
|
+
if (isObject(input)) return objectParser(input, convertKey);
|
|
246
|
+
}
|
|
241
247
|
function converter(input, type) {
|
|
242
|
-
|
|
243
|
-
if (isString(input)) result = parse(input, type);
|
|
244
|
-
if (isArray(input)) result = arrayParser(input, type);
|
|
245
|
-
if (isObject(input)) result = objectParser(input, type);
|
|
246
|
-
return result;
|
|
248
|
+
return convert(input, (key) => parse(key, type));
|
|
247
249
|
}
|
|
248
250
|
//#endregion
|
|
249
251
|
//#region src/camelCase/camelCase.ts
|
|
@@ -255,6 +257,9 @@ function converter(input, type) {
|
|
|
255
257
|
* camelToDash('helloWorld'); // 'hello-world'
|
|
256
258
|
* camelToDash({ firstName: 'John' }); // { 'first-name': 'John' }
|
|
257
259
|
* ```
|
|
260
|
+
*
|
|
261
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
262
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
258
263
|
*/
|
|
259
264
|
function camelToDash(input) {
|
|
260
265
|
return converter(input, "CamelToDash");
|
|
@@ -267,6 +272,9 @@ function camelToDash(input) {
|
|
|
267
272
|
* camelToSnake('helloWorld'); // 'hello_world'
|
|
268
273
|
* camelToSnake({ firstName: 'John' }); // { first_name: 'John' }
|
|
269
274
|
* ```
|
|
275
|
+
*
|
|
276
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
277
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
270
278
|
*/
|
|
271
279
|
function camelToSnake(input) {
|
|
272
280
|
return converter(input, "CamelToSnake");
|
|
@@ -279,6 +287,9 @@ function camelToSnake(input) {
|
|
|
279
287
|
* camelToPascal('helloWorld'); // 'HelloWorld'
|
|
280
288
|
* camelToPascal({ firstName: 'John' }); // { FirstName: 'John' }
|
|
281
289
|
* ```
|
|
290
|
+
*
|
|
291
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
292
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
282
293
|
*/
|
|
283
294
|
function camelToPascal(input) {
|
|
284
295
|
return converter(input, "CamelToPascal");
|
|
@@ -291,6 +302,9 @@ function camelToPascal(input) {
|
|
|
291
302
|
* camelToUpperSnake('helloWorld'); // 'HELLO_WORLD'
|
|
292
303
|
* camelToUpperSnake({ firstName: 'John' }); // { FIRST_NAME: 'John' }
|
|
293
304
|
* ```
|
|
305
|
+
*
|
|
306
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
307
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
294
308
|
*/
|
|
295
309
|
function camelToUpperSnake(input) {
|
|
296
310
|
return converter(input, "CamelToUpperSnake");
|
|
@@ -303,6 +317,9 @@ function camelToUpperSnake(input) {
|
|
|
303
317
|
* camelToUpperDash('helloWorld'); // 'HELLO-WORLD'
|
|
304
318
|
* camelToUpperDash({ firstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
305
319
|
* ```
|
|
320
|
+
*
|
|
321
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
322
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
306
323
|
*/
|
|
307
324
|
function camelToUpperDash(input) {
|
|
308
325
|
return converter(input, "CamelToUpperDash");
|
|
@@ -315,6 +332,9 @@ function camelToUpperDash(input) {
|
|
|
315
332
|
* camelToTrain('helloWorld'); // 'Hello-World'
|
|
316
333
|
* camelToTrain({ firstName: 'John' }); // { 'First-Name': 'John' }
|
|
317
334
|
* ```
|
|
335
|
+
*
|
|
336
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
337
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
318
338
|
*/
|
|
319
339
|
function camelToTrain(input) {
|
|
320
340
|
return converter(input, "CamelToTrain");
|
|
@@ -327,6 +347,9 @@ function camelToTrain(input) {
|
|
|
327
347
|
* camelToDot('helloWorld'); // 'hello.world'
|
|
328
348
|
* camelToDot({ firstName: 'John' }); // { 'first.name': 'John' }
|
|
329
349
|
* ```
|
|
350
|
+
*
|
|
351
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
352
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
330
353
|
*/
|
|
331
354
|
function camelToDot(input) {
|
|
332
355
|
return converter(input, "CamelToDot");
|
|
@@ -339,6 +362,9 @@ function camelToDot(input) {
|
|
|
339
362
|
* camelToTitle('helloWorld'); // 'Hello World'
|
|
340
363
|
* camelToTitle({ firstName: 'John' }); // { 'First Name': 'John' }
|
|
341
364
|
* ```
|
|
365
|
+
*
|
|
366
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
367
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
342
368
|
*/
|
|
343
369
|
function camelToTitle(input) {
|
|
344
370
|
return converter(input, "CamelToTitle");
|
|
@@ -351,6 +377,9 @@ function camelToTitle(input) {
|
|
|
351
377
|
* camelToSentence('helloWorld'); // 'Hello world'
|
|
352
378
|
* camelToSentence({ firstName: 'John' }); // { 'First name': 'John' }
|
|
353
379
|
* ```
|
|
380
|
+
*
|
|
381
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
382
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
354
383
|
*/
|
|
355
384
|
function camelToSentence(input) {
|
|
356
385
|
return converter(input, "CamelToSentence");
|
|
@@ -365,6 +394,9 @@ function camelToSentence(input) {
|
|
|
365
394
|
* dashToSnake('hello-world'); // 'hello_world'
|
|
366
395
|
* dashToSnake({ 'first-name': 'John' }); // { first_name: 'John' }
|
|
367
396
|
* ```
|
|
397
|
+
*
|
|
398
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
399
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
368
400
|
*/
|
|
369
401
|
function dashToSnake(input) {
|
|
370
402
|
return converter(input, "DashToSnake");
|
|
@@ -377,6 +409,9 @@ function dashToSnake(input) {
|
|
|
377
409
|
* dashToCamel('hello-world'); // 'helloWorld'
|
|
378
410
|
* dashToCamel({ 'first-name': 'John' }); // { firstName: 'John' }
|
|
379
411
|
* ```
|
|
412
|
+
*
|
|
413
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
414
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
380
415
|
*/
|
|
381
416
|
function dashToCamel(input) {
|
|
382
417
|
return converter(input, "DashToCamel");
|
|
@@ -389,6 +424,9 @@ function dashToCamel(input) {
|
|
|
389
424
|
* dashToPascal('hello-world'); // 'HelloWorld'
|
|
390
425
|
* dashToPascal({ 'first-name': 'John' }); // { FirstName: 'John' }
|
|
391
426
|
* ```
|
|
427
|
+
*
|
|
428
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
429
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
392
430
|
*/
|
|
393
431
|
function dashToPascal(input) {
|
|
394
432
|
return converter(input, "DashToPascal");
|
|
@@ -401,6 +439,9 @@ function dashToPascal(input) {
|
|
|
401
439
|
* dashToUpperSnake('hello-world'); // 'HELLO_WORLD'
|
|
402
440
|
* dashToUpperSnake({ 'first-name': 'John' }); // { FIRST_NAME: 'John' }
|
|
403
441
|
* ```
|
|
442
|
+
*
|
|
443
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
444
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
404
445
|
*/
|
|
405
446
|
function dashToUpperSnake(input) {
|
|
406
447
|
return converter(input, "DashToUpperSnake");
|
|
@@ -413,6 +454,9 @@ function dashToUpperSnake(input) {
|
|
|
413
454
|
* dashToUpperDash('hello-world'); // 'HELLO-WORLD'
|
|
414
455
|
* dashToUpperDash({ 'first-name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
415
456
|
* ```
|
|
457
|
+
*
|
|
458
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
459
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
416
460
|
*/
|
|
417
461
|
function dashToUpperDash(input) {
|
|
418
462
|
return converter(input, "DashToUpperDash");
|
|
@@ -425,6 +469,9 @@ function dashToUpperDash(input) {
|
|
|
425
469
|
* dashToTrain('hello-world'); // 'Hello-World'
|
|
426
470
|
* dashToTrain({ 'first-name': 'John' }); // { 'First-Name': 'John' }
|
|
427
471
|
* ```
|
|
472
|
+
*
|
|
473
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
474
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
428
475
|
*/
|
|
429
476
|
function dashToTrain(input) {
|
|
430
477
|
return converter(input, "DashToTrain");
|
|
@@ -437,6 +484,9 @@ function dashToTrain(input) {
|
|
|
437
484
|
* dashToDot('hello-world'); // 'hello.world'
|
|
438
485
|
* dashToDot({ 'first-name': 'John' }); // { 'first.name': 'John' }
|
|
439
486
|
* ```
|
|
487
|
+
*
|
|
488
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
489
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
440
490
|
*/
|
|
441
491
|
function dashToDot(input) {
|
|
442
492
|
return converter(input, "DashToDot");
|
|
@@ -449,6 +499,9 @@ function dashToDot(input) {
|
|
|
449
499
|
* dashToTitle('hello-world'); // 'Hello World'
|
|
450
500
|
* dashToTitle({ 'first-name': 'John' }); // { 'First Name': 'John' }
|
|
451
501
|
* ```
|
|
502
|
+
*
|
|
503
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
504
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
452
505
|
*/
|
|
453
506
|
function dashToTitle(input) {
|
|
454
507
|
return converter(input, "DashToTitle");
|
|
@@ -461,6 +514,9 @@ function dashToTitle(input) {
|
|
|
461
514
|
* dashToSentence('hello-world'); // 'Hello world'
|
|
462
515
|
* dashToSentence({ 'first-name': 'John' }); // { 'First name': 'John' }
|
|
463
516
|
* ```
|
|
517
|
+
*
|
|
518
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
519
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
464
520
|
*/
|
|
465
521
|
function dashToSentence(input) {
|
|
466
522
|
return converter(input, "DashToSentence");
|
|
@@ -475,6 +531,9 @@ function dashToSentence(input) {
|
|
|
475
531
|
* pascalToCamel('HelloWorld'); // 'helloWorld'
|
|
476
532
|
* pascalToCamel({ FirstName: 'John' }); // { firstName: 'John' }
|
|
477
533
|
* ```
|
|
534
|
+
*
|
|
535
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
536
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
478
537
|
*/
|
|
479
538
|
function pascalToCamel(input) {
|
|
480
539
|
return converter(input, "PascalToCamel");
|
|
@@ -487,6 +546,9 @@ function pascalToCamel(input) {
|
|
|
487
546
|
* pascalToSnake('HelloWorld'); // 'hello_world'
|
|
488
547
|
* pascalToSnake({ FirstName: 'John' }); // { first_name: 'John' }
|
|
489
548
|
* ```
|
|
549
|
+
*
|
|
550
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
551
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
490
552
|
*/
|
|
491
553
|
function pascalToSnake(input) {
|
|
492
554
|
return converter(input, "PascalToSnake");
|
|
@@ -499,6 +561,9 @@ function pascalToSnake(input) {
|
|
|
499
561
|
* pascalToDash('HelloWorld'); // 'hello-world'
|
|
500
562
|
* pascalToDash({ FirstName: 'John' }); // { 'first-name': 'John' }
|
|
501
563
|
* ```
|
|
564
|
+
*
|
|
565
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
566
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
502
567
|
*/
|
|
503
568
|
function pascalToDash(input) {
|
|
504
569
|
return converter(input, "PascalToDash");
|
|
@@ -511,6 +576,9 @@ function pascalToDash(input) {
|
|
|
511
576
|
* pascalToUpperSnake('HelloWorld'); // 'HELLO_WORLD'
|
|
512
577
|
* pascalToUpperSnake({ FirstName: 'John' }); // { FIRST_NAME: 'John' }
|
|
513
578
|
* ```
|
|
579
|
+
*
|
|
580
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
581
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
514
582
|
*/
|
|
515
583
|
function pascalToUpperSnake(input) {
|
|
516
584
|
return converter(input, "PascalToUpperSnake");
|
|
@@ -523,6 +591,9 @@ function pascalToUpperSnake(input) {
|
|
|
523
591
|
* pascalToUpperDash('HelloWorld'); // 'HELLO-WORLD'
|
|
524
592
|
* pascalToUpperDash({ FirstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
525
593
|
* ```
|
|
594
|
+
*
|
|
595
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
596
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
526
597
|
*/
|
|
527
598
|
function pascalToUpperDash(input) {
|
|
528
599
|
return converter(input, "PascalToUpperDash");
|
|
@@ -535,6 +606,9 @@ function pascalToUpperDash(input) {
|
|
|
535
606
|
* pascalToTrain('HelloWorld'); // 'Hello-World'
|
|
536
607
|
* pascalToTrain({ FirstName: 'John' }); // { 'First-Name': 'John' }
|
|
537
608
|
* ```
|
|
609
|
+
*
|
|
610
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
611
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
538
612
|
*/
|
|
539
613
|
function pascalToTrain(input) {
|
|
540
614
|
return converter(input, "PascalToTrain");
|
|
@@ -547,6 +621,9 @@ function pascalToTrain(input) {
|
|
|
547
621
|
* pascalToDot('HelloWorld'); // 'hello.world'
|
|
548
622
|
* pascalToDot({ FirstName: 'John' }); // { 'first.name': 'John' }
|
|
549
623
|
* ```
|
|
624
|
+
*
|
|
625
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
626
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
550
627
|
*/
|
|
551
628
|
function pascalToDot(input) {
|
|
552
629
|
return converter(input, "PascalToDot");
|
|
@@ -559,6 +636,9 @@ function pascalToDot(input) {
|
|
|
559
636
|
* pascalToTitle('HelloWorld'); // 'Hello World'
|
|
560
637
|
* pascalToTitle({ FirstName: 'John' }); // { 'First Name': 'John' }
|
|
561
638
|
* ```
|
|
639
|
+
*
|
|
640
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
641
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
562
642
|
*/
|
|
563
643
|
function pascalToTitle(input) {
|
|
564
644
|
return converter(input, "PascalToTitle");
|
|
@@ -571,6 +651,9 @@ function pascalToTitle(input) {
|
|
|
571
651
|
* pascalToSentence('HelloWorld'); // 'Hello world'
|
|
572
652
|
* pascalToSentence({ FirstName: 'John' }); // { 'First name': 'John' }
|
|
573
653
|
* ```
|
|
654
|
+
*
|
|
655
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
656
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
574
657
|
*/
|
|
575
658
|
function pascalToSentence(input) {
|
|
576
659
|
return converter(input, "PascalToSentence");
|
|
@@ -585,6 +668,9 @@ function pascalToSentence(input) {
|
|
|
585
668
|
* snakeToCamel('hello_world'); // 'helloWorld'
|
|
586
669
|
* snakeToCamel({ first_name: 'John' }); // { firstName: 'John' }
|
|
587
670
|
* ```
|
|
671
|
+
*
|
|
672
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
673
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
588
674
|
*/
|
|
589
675
|
function snakeToCamel(input) {
|
|
590
676
|
return converter(input, "SnakeToCamel");
|
|
@@ -597,6 +683,9 @@ function snakeToCamel(input) {
|
|
|
597
683
|
* snakeToDash('hello_world'); // 'hello-world'
|
|
598
684
|
* snakeToDash({ first_name: 'John' }); // { 'first-name': 'John' }
|
|
599
685
|
* ```
|
|
686
|
+
*
|
|
687
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
688
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
600
689
|
*/
|
|
601
690
|
function snakeToDash(input) {
|
|
602
691
|
return converter(input, "SnakeToDash");
|
|
@@ -609,6 +698,9 @@ function snakeToDash(input) {
|
|
|
609
698
|
* snakeToPascal('hello_world'); // 'HelloWorld'
|
|
610
699
|
* snakeToPascal({ first_name: 'John' }); // { FirstName: 'John' }
|
|
611
700
|
* ```
|
|
701
|
+
*
|
|
702
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
703
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
612
704
|
*/
|
|
613
705
|
function snakeToPascal(input) {
|
|
614
706
|
return converter(input, "SnakeToPascal");
|
|
@@ -621,6 +713,9 @@ function snakeToPascal(input) {
|
|
|
621
713
|
* snakeToUpperSnake('hello_world'); // 'HELLO_WORLD'
|
|
622
714
|
* snakeToUpperSnake({ first_name: 'John' }); // { FIRST_NAME: 'John' }
|
|
623
715
|
* ```
|
|
716
|
+
*
|
|
717
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
718
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
624
719
|
*/
|
|
625
720
|
function snakeToUpperSnake(input) {
|
|
626
721
|
return converter(input, "SnakeToUpperSnake");
|
|
@@ -633,6 +728,9 @@ function snakeToUpperSnake(input) {
|
|
|
633
728
|
* snakeToUpperDash('hello_world'); // 'HELLO-WORLD'
|
|
634
729
|
* snakeToUpperDash({ first_name: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
635
730
|
* ```
|
|
731
|
+
*
|
|
732
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
733
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
636
734
|
*/
|
|
637
735
|
function snakeToUpperDash(input) {
|
|
638
736
|
return converter(input, "SnakeToUpperDash");
|
|
@@ -645,6 +743,9 @@ function snakeToUpperDash(input) {
|
|
|
645
743
|
* snakeToTrain('hello_world'); // 'Hello-World'
|
|
646
744
|
* snakeToTrain({ first_name: 'John' }); // { 'First-Name': 'John' }
|
|
647
745
|
* ```
|
|
746
|
+
*
|
|
747
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
748
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
648
749
|
*/
|
|
649
750
|
function snakeToTrain(input) {
|
|
650
751
|
return converter(input, "SnakeToTrain");
|
|
@@ -657,6 +758,9 @@ function snakeToTrain(input) {
|
|
|
657
758
|
* snakeToDot('hello_world'); // 'hello.world'
|
|
658
759
|
* snakeToDot({ first_name: 'John' }); // { 'first.name': 'John' }
|
|
659
760
|
* ```
|
|
761
|
+
*
|
|
762
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
763
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
660
764
|
*/
|
|
661
765
|
function snakeToDot(input) {
|
|
662
766
|
return converter(input, "SnakeToDot");
|
|
@@ -669,6 +773,9 @@ function snakeToDot(input) {
|
|
|
669
773
|
* snakeToTitle('hello_world'); // 'Hello World'
|
|
670
774
|
* snakeToTitle({ first_name: 'John' }); // { 'First Name': 'John' }
|
|
671
775
|
* ```
|
|
776
|
+
*
|
|
777
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
778
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
672
779
|
*/
|
|
673
780
|
function snakeToTitle(input) {
|
|
674
781
|
return converter(input, "SnakeToTitle");
|
|
@@ -681,6 +788,9 @@ function snakeToTitle(input) {
|
|
|
681
788
|
* snakeToSentence('hello_world'); // 'Hello world'
|
|
682
789
|
* snakeToSentence({ first_name: 'John' }); // { 'First name': 'John' }
|
|
683
790
|
* ```
|
|
791
|
+
*
|
|
792
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
793
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
684
794
|
*/
|
|
685
795
|
function snakeToSentence(input) {
|
|
686
796
|
return converter(input, "SnakeToSentence");
|
|
@@ -695,6 +805,9 @@ function snakeToSentence(input) {
|
|
|
695
805
|
* trainToCamel('Hello-World'); // 'helloWorld'
|
|
696
806
|
* trainToCamel({ 'First-Name': 'John' }); // { firstName: 'John' }
|
|
697
807
|
* ```
|
|
808
|
+
*
|
|
809
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
810
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
698
811
|
*/
|
|
699
812
|
function trainToCamel(input) {
|
|
700
813
|
return converter(input, "TrainToCamel");
|
|
@@ -707,6 +820,9 @@ function trainToCamel(input) {
|
|
|
707
820
|
* trainToPascal('Hello-World'); // 'HelloWorld'
|
|
708
821
|
* trainToPascal({ 'First-Name': 'John' }); // { FirstName: 'John' }
|
|
709
822
|
* ```
|
|
823
|
+
*
|
|
824
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
825
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
710
826
|
*/
|
|
711
827
|
function trainToPascal(input) {
|
|
712
828
|
return converter(input, "TrainToPascal");
|
|
@@ -719,6 +835,9 @@ function trainToPascal(input) {
|
|
|
719
835
|
* trainToSnake('Hello-World'); // 'hello_world'
|
|
720
836
|
* trainToSnake({ 'First-Name': 'John' }); // { first_name: 'John' }
|
|
721
837
|
* ```
|
|
838
|
+
*
|
|
839
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
840
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
722
841
|
*/
|
|
723
842
|
function trainToSnake(input) {
|
|
724
843
|
return converter(input, "TrainToSnake");
|
|
@@ -731,6 +850,9 @@ function trainToSnake(input) {
|
|
|
731
850
|
* trainToDash('Hello-World'); // 'hello-world'
|
|
732
851
|
* trainToDash({ 'First-Name': 'John' }); // { 'first-name': 'John' }
|
|
733
852
|
* ```
|
|
853
|
+
*
|
|
854
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
855
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
734
856
|
*/
|
|
735
857
|
function trainToDash(input) {
|
|
736
858
|
return converter(input, "TrainToDash");
|
|
@@ -743,6 +865,9 @@ function trainToDash(input) {
|
|
|
743
865
|
* trainToUpperSnake('Hello-World'); // 'HELLO_WORLD'
|
|
744
866
|
* trainToUpperSnake({ 'First-Name': 'John' }); // { FIRST_NAME: 'John' }
|
|
745
867
|
* ```
|
|
868
|
+
*
|
|
869
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
870
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
746
871
|
*/
|
|
747
872
|
function trainToUpperSnake(input) {
|
|
748
873
|
return converter(input, "TrainToUpperSnake");
|
|
@@ -755,6 +880,9 @@ function trainToUpperSnake(input) {
|
|
|
755
880
|
* trainToUpperDash('Hello-World'); // 'HELLO-WORLD'
|
|
756
881
|
* trainToUpperDash({ 'First-Name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
757
882
|
* ```
|
|
883
|
+
*
|
|
884
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
885
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
758
886
|
*/
|
|
759
887
|
function trainToUpperDash(input) {
|
|
760
888
|
return converter(input, "TrainToUpperDash");
|
|
@@ -767,6 +895,9 @@ function trainToUpperDash(input) {
|
|
|
767
895
|
* trainToDot('Hello-World'); // 'hello.world'
|
|
768
896
|
* trainToDot({ 'First-Name': 'John' }); // { 'first.name': 'John' }
|
|
769
897
|
* ```
|
|
898
|
+
*
|
|
899
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
900
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
770
901
|
*/
|
|
771
902
|
function trainToDot(input) {
|
|
772
903
|
return converter(input, "TrainToDot");
|
|
@@ -779,6 +910,9 @@ function trainToDot(input) {
|
|
|
779
910
|
* trainToTitle('Hello-World'); // 'Hello World'
|
|
780
911
|
* trainToTitle({ 'First-Name': 'John' }); // { 'First Name': 'John' }
|
|
781
912
|
* ```
|
|
913
|
+
*
|
|
914
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
915
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
782
916
|
*/
|
|
783
917
|
function trainToTitle(input) {
|
|
784
918
|
return converter(input, "TrainToTitle");
|
|
@@ -791,6 +925,9 @@ function trainToTitle(input) {
|
|
|
791
925
|
* trainToSentence('Hello-World'); // 'Hello world'
|
|
792
926
|
* trainToSentence({ 'First-Name': 'John' }); // { 'First name': 'John' }
|
|
793
927
|
* ```
|
|
928
|
+
*
|
|
929
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
930
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
794
931
|
*/
|
|
795
932
|
function trainToSentence(input) {
|
|
796
933
|
return converter(input, "TrainToSentence");
|
|
@@ -805,6 +942,9 @@ function trainToSentence(input) {
|
|
|
805
942
|
* dotToCamel('hello.world'); // 'helloWorld'
|
|
806
943
|
* dotToCamel({ 'first.name': 'John' }); // { firstName: 'John' }
|
|
807
944
|
* ```
|
|
945
|
+
*
|
|
946
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
947
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
808
948
|
*/
|
|
809
949
|
function dotToCamel(input) {
|
|
810
950
|
return converter(input, "DotToCamel");
|
|
@@ -817,6 +957,9 @@ function dotToCamel(input) {
|
|
|
817
957
|
* dotToPascal('hello.world'); // 'HelloWorld'
|
|
818
958
|
* dotToPascal({ 'first.name': 'John' }); // { FirstName: 'John' }
|
|
819
959
|
* ```
|
|
960
|
+
*
|
|
961
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
962
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
820
963
|
*/
|
|
821
964
|
function dotToPascal(input) {
|
|
822
965
|
return converter(input, "DotToPascal");
|
|
@@ -829,6 +972,9 @@ function dotToPascal(input) {
|
|
|
829
972
|
* dotToSnake('hello.world'); // 'hello_world'
|
|
830
973
|
* dotToSnake({ 'first.name': 'John' }); // { first_name: 'John' }
|
|
831
974
|
* ```
|
|
975
|
+
*
|
|
976
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
977
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
832
978
|
*/
|
|
833
979
|
function dotToSnake(input) {
|
|
834
980
|
return converter(input, "DotToSnake");
|
|
@@ -841,6 +987,9 @@ function dotToSnake(input) {
|
|
|
841
987
|
* dotToDash('hello.world'); // 'hello-world'
|
|
842
988
|
* dotToDash({ 'first.name': 'John' }); // { 'first-name': 'John' }
|
|
843
989
|
* ```
|
|
990
|
+
*
|
|
991
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
992
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
844
993
|
*/
|
|
845
994
|
function dotToDash(input) {
|
|
846
995
|
return converter(input, "DotToDash");
|
|
@@ -853,6 +1002,9 @@ function dotToDash(input) {
|
|
|
853
1002
|
* dotToUpperSnake('hello.world'); // 'HELLO_WORLD'
|
|
854
1003
|
* dotToUpperSnake({ 'first.name': 'John' }); // { FIRST_NAME: 'John' }
|
|
855
1004
|
* ```
|
|
1005
|
+
*
|
|
1006
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1007
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
856
1008
|
*/
|
|
857
1009
|
function dotToUpperSnake(input) {
|
|
858
1010
|
return converter(input, "DotToUpperSnake");
|
|
@@ -865,6 +1017,9 @@ function dotToUpperSnake(input) {
|
|
|
865
1017
|
* dotToUpperDash('hello.world'); // 'HELLO-WORLD'
|
|
866
1018
|
* dotToUpperDash({ 'first.name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
867
1019
|
* ```
|
|
1020
|
+
*
|
|
1021
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1022
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
868
1023
|
*/
|
|
869
1024
|
function dotToUpperDash(input) {
|
|
870
1025
|
return converter(input, "DotToUpperDash");
|
|
@@ -877,6 +1032,9 @@ function dotToUpperDash(input) {
|
|
|
877
1032
|
* dotToTrain('hello.world'); // 'Hello-World'
|
|
878
1033
|
* dotToTrain({ 'first.name': 'John' }); // { 'First-Name': 'John' }
|
|
879
1034
|
* ```
|
|
1035
|
+
*
|
|
1036
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
1037
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
880
1038
|
*/
|
|
881
1039
|
function dotToTrain(input) {
|
|
882
1040
|
return converter(input, "DotToTrain");
|
|
@@ -889,6 +1047,9 @@ function dotToTrain(input) {
|
|
|
889
1047
|
* dotToTitle('hello.world'); // 'Hello World'
|
|
890
1048
|
* dotToTitle({ 'first.name': 'John' }); // { 'First Name': 'John' }
|
|
891
1049
|
* ```
|
|
1050
|
+
*
|
|
1051
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
1052
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
892
1053
|
*/
|
|
893
1054
|
function dotToTitle(input) {
|
|
894
1055
|
return converter(input, "DotToTitle");
|
|
@@ -901,6 +1062,9 @@ function dotToTitle(input) {
|
|
|
901
1062
|
* dotToSentence('hello.world'); // 'Hello world'
|
|
902
1063
|
* dotToSentence({ 'first.name': 'John' }); // { 'First name': 'John' }
|
|
903
1064
|
* ```
|
|
1065
|
+
*
|
|
1066
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
1067
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
904
1068
|
*/
|
|
905
1069
|
function dotToSentence(input) {
|
|
906
1070
|
return converter(input, "DotToSentence");
|
|
@@ -915,6 +1079,9 @@ function dotToSentence(input) {
|
|
|
915
1079
|
* titleToCamel('Hello World'); // 'helloWorld'
|
|
916
1080
|
* titleToCamel({ 'First Name': 'John' }); // { firstName: 'John' }
|
|
917
1081
|
* ```
|
|
1082
|
+
*
|
|
1083
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
1084
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
918
1085
|
*/
|
|
919
1086
|
function titleToCamel(input) {
|
|
920
1087
|
return converter(input, "TitleToCamel");
|
|
@@ -927,6 +1094,9 @@ function titleToCamel(input) {
|
|
|
927
1094
|
* titleToPascal('Hello World'); // 'HelloWorld'
|
|
928
1095
|
* titleToPascal({ 'First Name': 'John' }); // { FirstName: 'John' }
|
|
929
1096
|
* ```
|
|
1097
|
+
*
|
|
1098
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
1099
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
930
1100
|
*/
|
|
931
1101
|
function titleToPascal(input) {
|
|
932
1102
|
return converter(input, "TitleToPascal");
|
|
@@ -939,6 +1109,9 @@ function titleToPascal(input) {
|
|
|
939
1109
|
* titleToSnake('Hello World'); // 'hello_world'
|
|
940
1110
|
* titleToSnake({ 'First Name': 'John' }); // { first_name: 'John' }
|
|
941
1111
|
* ```
|
|
1112
|
+
*
|
|
1113
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1114
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
942
1115
|
*/
|
|
943
1116
|
function titleToSnake(input) {
|
|
944
1117
|
return converter(input, "TitleToSnake");
|
|
@@ -951,6 +1124,9 @@ function titleToSnake(input) {
|
|
|
951
1124
|
* titleToDash('Hello World'); // 'hello-world'
|
|
952
1125
|
* titleToDash({ 'First Name': 'John' }); // { 'first-name': 'John' }
|
|
953
1126
|
* ```
|
|
1127
|
+
*
|
|
1128
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1129
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
954
1130
|
*/
|
|
955
1131
|
function titleToDash(input) {
|
|
956
1132
|
return converter(input, "TitleToDash");
|
|
@@ -963,6 +1139,9 @@ function titleToDash(input) {
|
|
|
963
1139
|
* titleToUpperSnake('Hello World'); // 'HELLO_WORLD'
|
|
964
1140
|
* titleToUpperSnake({ 'First Name': 'John' }); // { FIRST_NAME: 'John' }
|
|
965
1141
|
* ```
|
|
1142
|
+
*
|
|
1143
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1144
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
966
1145
|
*/
|
|
967
1146
|
function titleToUpperSnake(input) {
|
|
968
1147
|
return converter(input, "TitleToUpperSnake");
|
|
@@ -975,6 +1154,9 @@ function titleToUpperSnake(input) {
|
|
|
975
1154
|
* titleToUpperDash('Hello World'); // 'HELLO-WORLD'
|
|
976
1155
|
* titleToUpperDash({ 'First Name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
977
1156
|
* ```
|
|
1157
|
+
*
|
|
1158
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1159
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
978
1160
|
*/
|
|
979
1161
|
function titleToUpperDash(input) {
|
|
980
1162
|
return converter(input, "TitleToUpperDash");
|
|
@@ -987,6 +1169,9 @@ function titleToUpperDash(input) {
|
|
|
987
1169
|
* titleToTrain('Hello World'); // 'Hello-World'
|
|
988
1170
|
* titleToTrain({ 'First Name': 'John' }); // { 'First-Name': 'John' }
|
|
989
1171
|
* ```
|
|
1172
|
+
*
|
|
1173
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
1174
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
990
1175
|
*/
|
|
991
1176
|
function titleToTrain(input) {
|
|
992
1177
|
return converter(input, "TitleToTrain");
|
|
@@ -999,6 +1184,9 @@ function titleToTrain(input) {
|
|
|
999
1184
|
* titleToDot('Hello World'); // 'hello.world'
|
|
1000
1185
|
* titleToDot({ 'First Name': 'John' }); // { 'first.name': 'John' }
|
|
1001
1186
|
* ```
|
|
1187
|
+
*
|
|
1188
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
1189
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1002
1190
|
*/
|
|
1003
1191
|
function titleToDot(input) {
|
|
1004
1192
|
return converter(input, "TitleToDot");
|
|
@@ -1011,6 +1199,9 @@ function titleToDot(input) {
|
|
|
1011
1199
|
* titleToSentence('Hello World'); // 'Hello world'
|
|
1012
1200
|
* titleToSentence({ 'First Name': 'John' }); // { 'First name': 'John' }
|
|
1013
1201
|
* ```
|
|
1202
|
+
*
|
|
1203
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
1204
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1014
1205
|
*/
|
|
1015
1206
|
function titleToSentence(input) {
|
|
1016
1207
|
return converter(input, "TitleToSentence");
|
|
@@ -1025,6 +1216,9 @@ function titleToSentence(input) {
|
|
|
1025
1216
|
* sentenceToCamel('Hello world'); // 'helloWorld'
|
|
1026
1217
|
* sentenceToCamel({ 'First name': 'John' }); // { firstName: 'John' }
|
|
1027
1218
|
* ```
|
|
1219
|
+
*
|
|
1220
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
1221
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1028
1222
|
*/
|
|
1029
1223
|
function sentenceToCamel(input) {
|
|
1030
1224
|
return converter(input, "SentenceToCamel");
|
|
@@ -1037,6 +1231,9 @@ function sentenceToCamel(input) {
|
|
|
1037
1231
|
* sentenceToPascal('Hello world'); // 'HelloWorld'
|
|
1038
1232
|
* sentenceToPascal({ 'First name': 'John' }); // { FirstName: 'John' }
|
|
1039
1233
|
* ```
|
|
1234
|
+
*
|
|
1235
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
1236
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1040
1237
|
*/
|
|
1041
1238
|
function sentenceToPascal(input) {
|
|
1042
1239
|
return converter(input, "SentenceToPascal");
|
|
@@ -1049,6 +1246,9 @@ function sentenceToPascal(input) {
|
|
|
1049
1246
|
* sentenceToSnake('Hello world'); // 'hello_world'
|
|
1050
1247
|
* sentenceToSnake({ 'First name': 'John' }); // { first_name: 'John' }
|
|
1051
1248
|
* ```
|
|
1249
|
+
*
|
|
1250
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1251
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1052
1252
|
*/
|
|
1053
1253
|
function sentenceToSnake(input) {
|
|
1054
1254
|
return converter(input, "SentenceToSnake");
|
|
@@ -1061,6 +1261,9 @@ function sentenceToSnake(input) {
|
|
|
1061
1261
|
* sentenceToDash('Hello world'); // 'hello-world'
|
|
1062
1262
|
* sentenceToDash({ 'First name': 'John' }); // { 'first-name': 'John' }
|
|
1063
1263
|
* ```
|
|
1264
|
+
*
|
|
1265
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1266
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1064
1267
|
*/
|
|
1065
1268
|
function sentenceToDash(input) {
|
|
1066
1269
|
return converter(input, "SentenceToDash");
|
|
@@ -1073,6 +1276,9 @@ function sentenceToDash(input) {
|
|
|
1073
1276
|
* sentenceToUpperSnake('Hello world'); // 'HELLO_WORLD'
|
|
1074
1277
|
* sentenceToUpperSnake({ 'First name': 'John' }); // { FIRST_NAME: 'John' }
|
|
1075
1278
|
* ```
|
|
1279
|
+
*
|
|
1280
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1281
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1076
1282
|
*/
|
|
1077
1283
|
function sentenceToUpperSnake(input) {
|
|
1078
1284
|
return converter(input, "SentenceToUpperSnake");
|
|
@@ -1085,6 +1291,9 @@ function sentenceToUpperSnake(input) {
|
|
|
1085
1291
|
* sentenceToUpperDash('Hello world'); // 'HELLO-WORLD'
|
|
1086
1292
|
* sentenceToUpperDash({ 'First name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
1087
1293
|
* ```
|
|
1294
|
+
*
|
|
1295
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1296
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1088
1297
|
*/
|
|
1089
1298
|
function sentenceToUpperDash(input) {
|
|
1090
1299
|
return converter(input, "SentenceToUpperDash");
|
|
@@ -1097,6 +1306,9 @@ function sentenceToUpperDash(input) {
|
|
|
1097
1306
|
* sentenceToTrain('Hello world'); // 'Hello-World'
|
|
1098
1307
|
* sentenceToTrain({ 'First name': 'John' }); // { 'First-Name': 'John' }
|
|
1099
1308
|
* ```
|
|
1309
|
+
*
|
|
1310
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
1311
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1100
1312
|
*/
|
|
1101
1313
|
function sentenceToTrain(input) {
|
|
1102
1314
|
return converter(input, "SentenceToTrain");
|
|
@@ -1109,6 +1321,9 @@ function sentenceToTrain(input) {
|
|
|
1109
1321
|
* sentenceToDot('Hello world'); // 'hello.world'
|
|
1110
1322
|
* sentenceToDot({ 'First name': 'John' }); // { 'first.name': 'John' }
|
|
1111
1323
|
* ```
|
|
1324
|
+
*
|
|
1325
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
1326
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1112
1327
|
*/
|
|
1113
1328
|
function sentenceToDot(input) {
|
|
1114
1329
|
return converter(input, "SentenceToDot");
|
|
@@ -1121,6 +1336,9 @@ function sentenceToDot(input) {
|
|
|
1121
1336
|
* sentenceToTitle('Hello world'); // 'Hello World'
|
|
1122
1337
|
* sentenceToTitle({ 'First name': 'John' }); // { 'First Name': 'John' }
|
|
1123
1338
|
* ```
|
|
1339
|
+
*
|
|
1340
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
1341
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1124
1342
|
*/
|
|
1125
1343
|
function sentenceToTitle(input) {
|
|
1126
1344
|
return converter(input, "SentenceToTitle");
|
|
@@ -1135,6 +1353,9 @@ function sentenceToTitle(input) {
|
|
|
1135
1353
|
* upperDashToCamel('HELLO-WORLD'); // 'helloWorld'
|
|
1136
1354
|
* upperDashToCamel({ 'FIRST-NAME': 'John' }); // { firstName: 'John' }
|
|
1137
1355
|
* ```
|
|
1356
|
+
*
|
|
1357
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
1358
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1138
1359
|
*/
|
|
1139
1360
|
function upperDashToCamel(input) {
|
|
1140
1361
|
return converter(input, "UpperDashToCamel");
|
|
@@ -1147,6 +1368,9 @@ function upperDashToCamel(input) {
|
|
|
1147
1368
|
* upperDashToSnake('HELLO-WORLD'); // 'hello_world'
|
|
1148
1369
|
* upperDashToSnake({ 'FIRST-NAME': 'John' }); // { first_name: 'John' }
|
|
1149
1370
|
* ```
|
|
1371
|
+
*
|
|
1372
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1373
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1150
1374
|
*/
|
|
1151
1375
|
function upperDashToSnake(input) {
|
|
1152
1376
|
return converter(input, "UpperDashToSnake");
|
|
@@ -1159,6 +1383,9 @@ function upperDashToSnake(input) {
|
|
|
1159
1383
|
* upperDashToDash('HELLO-WORLD'); // 'hello-world'
|
|
1160
1384
|
* upperDashToDash({ 'FIRST-NAME': 'John' }); // { 'first-name': 'John' }
|
|
1161
1385
|
* ```
|
|
1386
|
+
*
|
|
1387
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1388
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1162
1389
|
*/
|
|
1163
1390
|
function upperDashToDash(input) {
|
|
1164
1391
|
return converter(input, "UpperDashToDash");
|
|
@@ -1171,6 +1398,9 @@ function upperDashToDash(input) {
|
|
|
1171
1398
|
* upperDashToPascal('HELLO-WORLD'); // 'HelloWorld'
|
|
1172
1399
|
* upperDashToPascal({ 'FIRST-NAME': 'John' }); // { FirstName: 'John' }
|
|
1173
1400
|
* ```
|
|
1401
|
+
*
|
|
1402
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
1403
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1174
1404
|
*/
|
|
1175
1405
|
function upperDashToPascal(input) {
|
|
1176
1406
|
return converter(input, "UpperDashToPascal");
|
|
@@ -1183,6 +1413,9 @@ function upperDashToPascal(input) {
|
|
|
1183
1413
|
* upperDashToUpperSnake('HELLO-WORLD'); // 'HELLO_WORLD'
|
|
1184
1414
|
* upperDashToUpperSnake({ 'FIRST-NAME': 'John' }); // { FIRST_NAME: 'John' }
|
|
1185
1415
|
* ```
|
|
1416
|
+
*
|
|
1417
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1418
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1186
1419
|
*/
|
|
1187
1420
|
function upperDashToUpperSnake(input) {
|
|
1188
1421
|
return converter(input, "UpperDashToUpperSnake");
|
|
@@ -1195,6 +1428,9 @@ function upperDashToUpperSnake(input) {
|
|
|
1195
1428
|
* upperDashToTrain('HELLO-WORLD'); // 'Hello-World'
|
|
1196
1429
|
* upperDashToTrain({ 'FIRST-NAME': 'John' }); // { 'First-Name': 'John' }
|
|
1197
1430
|
* ```
|
|
1431
|
+
*
|
|
1432
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
1433
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1198
1434
|
*/
|
|
1199
1435
|
function upperDashToTrain(input) {
|
|
1200
1436
|
return converter(input, "UpperDashToTrain");
|
|
@@ -1207,6 +1443,9 @@ function upperDashToTrain(input) {
|
|
|
1207
1443
|
* upperDashToDot('HELLO-WORLD'); // 'hello.world'
|
|
1208
1444
|
* upperDashToDot({ 'FIRST-NAME': 'John' }); // { 'first.name': 'John' }
|
|
1209
1445
|
* ```
|
|
1446
|
+
*
|
|
1447
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
1448
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1210
1449
|
*/
|
|
1211
1450
|
function upperDashToDot(input) {
|
|
1212
1451
|
return converter(input, "UpperDashToDot");
|
|
@@ -1219,6 +1458,9 @@ function upperDashToDot(input) {
|
|
|
1219
1458
|
* upperDashToTitle('HELLO-WORLD'); // 'Hello World'
|
|
1220
1459
|
* upperDashToTitle({ 'FIRST-NAME': 'John' }); // { 'First Name': 'John' }
|
|
1221
1460
|
* ```
|
|
1461
|
+
*
|
|
1462
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
1463
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1222
1464
|
*/
|
|
1223
1465
|
function upperDashToTitle(input) {
|
|
1224
1466
|
return converter(input, "UpperDashToTitle");
|
|
@@ -1231,6 +1473,9 @@ function upperDashToTitle(input) {
|
|
|
1231
1473
|
* upperDashToSentence('HELLO-WORLD'); // 'Hello world'
|
|
1232
1474
|
* upperDashToSentence({ 'FIRST-NAME': 'John' }); // { 'First name': 'John' }
|
|
1233
1475
|
* ```
|
|
1476
|
+
*
|
|
1477
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
1478
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1234
1479
|
*/
|
|
1235
1480
|
function upperDashToSentence(input) {
|
|
1236
1481
|
return converter(input, "UpperDashToSentence");
|
|
@@ -1245,6 +1490,9 @@ function upperDashToSentence(input) {
|
|
|
1245
1490
|
* upperSnakeToCamel('HELLO_WORLD'); // 'helloWorld'
|
|
1246
1491
|
* upperSnakeToCamel({ FIRST_NAME: 'John' }); // { firstName: 'John' }
|
|
1247
1492
|
* ```
|
|
1493
|
+
*
|
|
1494
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
1495
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1248
1496
|
*/
|
|
1249
1497
|
function upperSnakeToCamel(input) {
|
|
1250
1498
|
return converter(input, "UpperSnakeToCamel");
|
|
@@ -1257,6 +1505,9 @@ function upperSnakeToCamel(input) {
|
|
|
1257
1505
|
* upperSnakeToSnake('HELLO_WORLD'); // 'hello_world'
|
|
1258
1506
|
* upperSnakeToSnake({ FIRST_NAME: 'John' }); // { first_name: 'John' }
|
|
1259
1507
|
* ```
|
|
1508
|
+
*
|
|
1509
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1510
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1260
1511
|
*/
|
|
1261
1512
|
function upperSnakeToSnake(input) {
|
|
1262
1513
|
return converter(input, "UpperSnakeToSnake");
|
|
@@ -1269,6 +1520,9 @@ function upperSnakeToSnake(input) {
|
|
|
1269
1520
|
* upperSnakeToDash('HELLO_WORLD'); // 'hello-world'
|
|
1270
1521
|
* upperSnakeToDash({ FIRST_NAME: 'John' }); // { 'first-name': 'John' }
|
|
1271
1522
|
* ```
|
|
1523
|
+
*
|
|
1524
|
+
* @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1525
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1272
1526
|
*/
|
|
1273
1527
|
function upperSnakeToDash(input) {
|
|
1274
1528
|
return converter(input, "UpperSnakeToDash");
|
|
@@ -1281,6 +1535,9 @@ function upperSnakeToDash(input) {
|
|
|
1281
1535
|
* upperSnakeToPascal('HELLO_WORLD'); // 'HelloWorld'
|
|
1282
1536
|
* upperSnakeToPascal({ FIRST_NAME: 'John' }); // { FirstName: 'John' }
|
|
1283
1537
|
* ```
|
|
1538
|
+
*
|
|
1539
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
1540
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1284
1541
|
*/
|
|
1285
1542
|
function upperSnakeToPascal(input) {
|
|
1286
1543
|
return converter(input, "UpperSnakeToPascal");
|
|
@@ -1293,6 +1550,9 @@ function upperSnakeToPascal(input) {
|
|
|
1293
1550
|
* upperSnakeToUpperDash('HELLO_WORLD'); // 'HELLO-WORLD'
|
|
1294
1551
|
* upperSnakeToUpperDash({ FIRST_NAME: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
1295
1552
|
* ```
|
|
1553
|
+
*
|
|
1554
|
+
* @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
|
|
1555
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1296
1556
|
*/
|
|
1297
1557
|
function upperSnakeToUpperDash(input) {
|
|
1298
1558
|
return converter(input, "UpperSnakeToUpperDash");
|
|
@@ -1305,6 +1565,9 @@ function upperSnakeToUpperDash(input) {
|
|
|
1305
1565
|
* upperSnakeToTrain('HELLO_WORLD'); // 'Hello-World'
|
|
1306
1566
|
* upperSnakeToTrain({ FIRST_NAME: 'John' }); // { 'First-Name': 'John' }
|
|
1307
1567
|
* ```
|
|
1568
|
+
*
|
|
1569
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
1570
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1308
1571
|
*/
|
|
1309
1572
|
function upperSnakeToTrain(input) {
|
|
1310
1573
|
return converter(input, "UpperSnakeToTrain");
|
|
@@ -1317,6 +1580,9 @@ function upperSnakeToTrain(input) {
|
|
|
1317
1580
|
* upperSnakeToDot('HELLO_WORLD'); // 'hello.world'
|
|
1318
1581
|
* upperSnakeToDot({ FIRST_NAME: 'John' }); // { 'first.name': 'John' }
|
|
1319
1582
|
* ```
|
|
1583
|
+
*
|
|
1584
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
1585
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1320
1586
|
*/
|
|
1321
1587
|
function upperSnakeToDot(input) {
|
|
1322
1588
|
return converter(input, "UpperSnakeToDot");
|
|
@@ -1329,6 +1595,9 @@ function upperSnakeToDot(input) {
|
|
|
1329
1595
|
* upperSnakeToTitle('HELLO_WORLD'); // 'Hello World'
|
|
1330
1596
|
* upperSnakeToTitle({ FIRST_NAME: 'John' }); // { 'First Name': 'John' }
|
|
1331
1597
|
* ```
|
|
1598
|
+
*
|
|
1599
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
1600
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1332
1601
|
*/
|
|
1333
1602
|
function upperSnakeToTitle(input) {
|
|
1334
1603
|
return converter(input, "UpperSnakeToTitle");
|
|
@@ -1341,11 +1610,331 @@ function upperSnakeToTitle(input) {
|
|
|
1341
1610
|
* upperSnakeToSentence('HELLO_WORLD'); // 'Hello world'
|
|
1342
1611
|
* upperSnakeToSentence({ FIRST_NAME: 'John' }); // { 'First name': 'John' }
|
|
1343
1612
|
* ```
|
|
1613
|
+
*
|
|
1614
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
1615
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1344
1616
|
*/
|
|
1345
1617
|
function upperSnakeToSentence(input) {
|
|
1346
1618
|
return converter(input, "UpperSnakeToSentence");
|
|
1347
1619
|
}
|
|
1348
1620
|
//#endregion
|
|
1621
|
+
//#region src/anyCase/words.ts
|
|
1622
|
+
const SYMBOLS = "!\"#$%&'()*+,/:;<=>?@[\\]^`{|}~";
|
|
1623
|
+
const isSeparator = (c) => c === "_" || c === "-" || c === "." || c === " ";
|
|
1624
|
+
const isSymbol = (c) => SYMBOLS.indexOf(c) !== -1;
|
|
1625
|
+
const isUpper = (c) => c !== c.toLowerCase();
|
|
1626
|
+
const isLower = (c) => c !== c.toUpperCase();
|
|
1627
|
+
const isKept = (c, keep) => keep === true || typeof keep !== "boolean" && keep !== void 0 && keep !== null && keep.indexOf(c) !== -1;
|
|
1628
|
+
/**
|
|
1629
|
+
* Splits a string in any case into lowercase words: on `_`, `-`, `.` and spaces,
|
|
1630
|
+
* before an uppercase letter that follows a lowercase letter or a digit (`helloWorld`),
|
|
1631
|
+
* and before the last letter of an acronym (`XMLHttp`). Mirrors the `Words` type.
|
|
1632
|
+
*
|
|
1633
|
+
* Symbols (ASCII punctuation) also start a new word. They are removed, unless `keep` is
|
|
1634
|
+
* `true` or lists them: a kept symbol sticks to the start of the next word (`hello$World`
|
|
1635
|
+
* → `hello`, `$world`), or to the end of the previous one when no word follows (`total%`).
|
|
1636
|
+
* Words keep their original case when `lowercase` is `false`.
|
|
1637
|
+
*/
|
|
1638
|
+
function words(str, keep = false, lowercase = true) {
|
|
1639
|
+
const result = [];
|
|
1640
|
+
let word = "";
|
|
1641
|
+
let prev = "";
|
|
1642
|
+
const push = () => {
|
|
1643
|
+
if (word) result.push(lowercase ? word.toLowerCase() : word);
|
|
1644
|
+
word = "";
|
|
1645
|
+
};
|
|
1646
|
+
for (let i = 0; i < str.length; i++) {
|
|
1647
|
+
const c = str[i];
|
|
1648
|
+
if (isSeparator(c)) {
|
|
1649
|
+
push();
|
|
1650
|
+
prev = "";
|
|
1651
|
+
continue;
|
|
1652
|
+
}
|
|
1653
|
+
if (isSymbol(c)) {
|
|
1654
|
+
let kept = "";
|
|
1655
|
+
let j = i;
|
|
1656
|
+
for (; j < str.length && isSymbol(str[j]); j++) if (isKept(str[j], keep)) kept += str[j];
|
|
1657
|
+
const next = str.charAt(j);
|
|
1658
|
+
if (next && !isSeparator(next)) {
|
|
1659
|
+
push();
|
|
1660
|
+
prev = "";
|
|
1661
|
+
}
|
|
1662
|
+
word += kept;
|
|
1663
|
+
i = j - 1;
|
|
1664
|
+
continue;
|
|
1665
|
+
}
|
|
1666
|
+
const next = str.charAt(i + 1);
|
|
1667
|
+
if (isUpper(c) && prev && (!isUpper(prev) || next && isLower(next))) push();
|
|
1668
|
+
word += c;
|
|
1669
|
+
prev = c;
|
|
1670
|
+
}
|
|
1671
|
+
push();
|
|
1672
|
+
return result;
|
|
1673
|
+
}
|
|
1674
|
+
/** Uppercases the first character that is not a symbol: `'$id'` → `'$Id'`. */
|
|
1675
|
+
function capitalize(word) {
|
|
1676
|
+
let i = 0;
|
|
1677
|
+
while (i < word.length && isSymbol(word[i])) i++;
|
|
1678
|
+
return word.slice(0, i) + word.charAt(i).toUpperCase() + word.slice(i + 1);
|
|
1679
|
+
}
|
|
1680
|
+
const ToCamel = (str, keep) => words(str, keep).map((w, i) => i ? capitalize(w) : w).join("");
|
|
1681
|
+
const ToPascal = (str, keep) => words(str, keep).map(capitalize).join("");
|
|
1682
|
+
const ToSnake = (str, keep) => words(str, keep).join("_");
|
|
1683
|
+
const ToKebab = (str, keep) => words(str, keep).join("-");
|
|
1684
|
+
const ToUpperSnake = (str, keep) => words(str, keep).join("_").toUpperCase();
|
|
1685
|
+
const ToUpperKebab = (str, keep) => words(str, keep).join("-").toUpperCase();
|
|
1686
|
+
const ToTrain = (str, keep) => words(str, keep).map(capitalize).join("-");
|
|
1687
|
+
const ToDot = (str, keep) => words(str, keep, false).join(".");
|
|
1688
|
+
const ToTitle = (str, keep) => words(str, keep).map(capitalize).join(" ");
|
|
1689
|
+
const ToSentence = (str, keep) => capitalize(words(str, keep).join(" "));
|
|
1690
|
+
const ToPascalSnake = (str, keep) => words(str, keep).map(capitalize).join("_");
|
|
1691
|
+
const ToPath = (str, keep) => words(str, keep, false).join("/");
|
|
1692
|
+
const ToSpace = (str, keep) => words(str, keep, false).join(" ");
|
|
1693
|
+
const ToLower = (str, keep) => words(str, keep).join(" ");
|
|
1694
|
+
const ToUpper = (str, keep) => words(str, keep).join(" ").toUpperCase();
|
|
1695
|
+
//#endregion
|
|
1696
|
+
//#region src/anyCase/anyCase.ts
|
|
1697
|
+
/**
|
|
1698
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to camelCase.
|
|
1699
|
+
*
|
|
1700
|
+
* @example
|
|
1701
|
+
* ```ts
|
|
1702
|
+
* toCamel('hello_world'); // 'helloWorld'
|
|
1703
|
+
* toCamel({ first_name: 'John', userID: 1 }); // { firstName: 'John', userId: 1 }
|
|
1704
|
+
* toCamel('$hello-world', true); // '$helloWorld'
|
|
1705
|
+
* ```
|
|
1706
|
+
*
|
|
1707
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1708
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1709
|
+
*/
|
|
1710
|
+
function toCamel(input, keepSymbols) {
|
|
1711
|
+
return convert(input, (key) => ToCamel(key, keepSymbols));
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to PascalCase.
|
|
1715
|
+
*
|
|
1716
|
+
* @example
|
|
1717
|
+
* ```ts
|
|
1718
|
+
* toPascal('hello-world'); // 'HelloWorld'
|
|
1719
|
+
* toPascal({ 'first-name': 'John', userID: 1 }); // { FirstName: 'John', UserId: 1 }
|
|
1720
|
+
* toPascal('$hello-world', true); // '$HelloWorld'
|
|
1721
|
+
* ```
|
|
1722
|
+
*
|
|
1723
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1724
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1725
|
+
*/
|
|
1726
|
+
function toPascal(input, keepSymbols) {
|
|
1727
|
+
return convert(input, (key) => ToPascal(key, keepSymbols));
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to snake_case.
|
|
1731
|
+
*
|
|
1732
|
+
* @example
|
|
1733
|
+
* ```ts
|
|
1734
|
+
* toSnake('helloWorld'); // 'hello_world'
|
|
1735
|
+
* toSnake({ firstName: 'John', userID: 1 }); // { first_name: 'John', user_id: 1 }
|
|
1736
|
+
* toSnake('$hello-world', true); // '$hello_world'
|
|
1737
|
+
* ```
|
|
1738
|
+
*
|
|
1739
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1740
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1741
|
+
*/
|
|
1742
|
+
function toSnake(input, keepSymbols) {
|
|
1743
|
+
return convert(input, (key) => ToSnake(key, keepSymbols));
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to kebab-case.
|
|
1747
|
+
*
|
|
1748
|
+
* @example
|
|
1749
|
+
* ```ts
|
|
1750
|
+
* toKebab('HELLO_WORLD'); // 'hello-world'
|
|
1751
|
+
* toKebab({ FIRST_NAME: 'John', userID: 1 }); // { 'first-name': 'John', 'user-id': 1 }
|
|
1752
|
+
* toKebab('$hello-world', true); // '$hello-world'
|
|
1753
|
+
* ```
|
|
1754
|
+
*
|
|
1755
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1756
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1757
|
+
*/
|
|
1758
|
+
function toKebab(input, keepSymbols) {
|
|
1759
|
+
return convert(input, (key) => ToKebab(key, keepSymbols));
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER_SNAKE_CASE.
|
|
1763
|
+
*
|
|
1764
|
+
* @example
|
|
1765
|
+
* ```ts
|
|
1766
|
+
* toUpperSnake('hello-world'); // 'HELLO_WORLD'
|
|
1767
|
+
* toUpperSnake({ 'first-name': 'John', userID: 1 }); // { FIRST_NAME: 'John', USER_ID: 1 }
|
|
1768
|
+
* toUpperSnake('$hello-world', true); // '$HELLO_WORLD'
|
|
1769
|
+
* ```
|
|
1770
|
+
*
|
|
1771
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1772
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1773
|
+
*/
|
|
1774
|
+
function toUpperSnake(input, keepSymbols) {
|
|
1775
|
+
return convert(input, (key) => ToUpperSnake(key, keepSymbols));
|
|
1776
|
+
}
|
|
1777
|
+
/**
|
|
1778
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER-KEBAB-CASE.
|
|
1779
|
+
*
|
|
1780
|
+
* @example
|
|
1781
|
+
* ```ts
|
|
1782
|
+
* toUpperKebab('helloWorld'); // 'HELLO-WORLD'
|
|
1783
|
+
* toUpperKebab({ firstName: 'John', userID: 1 }); // { 'FIRST-NAME': 'John', 'USER-ID': 1 }
|
|
1784
|
+
* toUpperKebab('$hello-world', true); // '$HELLO-WORLD'
|
|
1785
|
+
* ```
|
|
1786
|
+
*
|
|
1787
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1788
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1789
|
+
*/
|
|
1790
|
+
function toUpperKebab(input, keepSymbols) {
|
|
1791
|
+
return convert(input, (key) => ToUpperKebab(key, keepSymbols));
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Train-Case.
|
|
1795
|
+
*
|
|
1796
|
+
* @example
|
|
1797
|
+
* ```ts
|
|
1798
|
+
* toTrain('hello_world'); // 'Hello-World'
|
|
1799
|
+
* toTrain({ first_name: 'John', userID: 1 }); // { 'First-Name': 'John', 'User-Id': 1 }
|
|
1800
|
+
* toTrain('$hello-world', true); // '$Hello-World'
|
|
1801
|
+
* ```
|
|
1802
|
+
*
|
|
1803
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1804
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1805
|
+
*/
|
|
1806
|
+
function toTrain(input, keepSymbols) {
|
|
1807
|
+
return convert(input, (key) => ToTrain(key, keepSymbols));
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to dot.case, keeping the original case of each word.
|
|
1811
|
+
*
|
|
1812
|
+
* @example
|
|
1813
|
+
* ```ts
|
|
1814
|
+
* toDot('HelloWorld'); // 'Hello.World'
|
|
1815
|
+
* toDot({ FirstName: 'John', userID: 1 }); // { 'First.Name': 'John', 'user.ID': 1 }
|
|
1816
|
+
* toDot('$hello-world', true); // '$hello.world'
|
|
1817
|
+
* ```
|
|
1818
|
+
*
|
|
1819
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1820
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1821
|
+
*/
|
|
1822
|
+
function toDot(input, keepSymbols) {
|
|
1823
|
+
return convert(input, (key) => ToDot(key, keepSymbols));
|
|
1824
|
+
}
|
|
1825
|
+
/**
|
|
1826
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Title Case.
|
|
1827
|
+
*
|
|
1828
|
+
* @example
|
|
1829
|
+
* ```ts
|
|
1830
|
+
* toTitle('hello_world'); // 'Hello World'
|
|
1831
|
+
* toTitle({ first_name: 'John', userID: 1 }); // { 'First Name': 'John', 'User Id': 1 }
|
|
1832
|
+
* toTitle('$hello-world', true); // '$Hello World'
|
|
1833
|
+
* ```
|
|
1834
|
+
*
|
|
1835
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1836
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1837
|
+
*/
|
|
1838
|
+
function toTitle(input, keepSymbols) {
|
|
1839
|
+
return convert(input, (key) => ToTitle(key, keepSymbols));
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Sentence case.
|
|
1843
|
+
*
|
|
1844
|
+
* @example
|
|
1845
|
+
* ```ts
|
|
1846
|
+
* toSentence('helloWorld'); // 'Hello world'
|
|
1847
|
+
* toSentence({ firstName: 'John', userID: 1 }); // { 'First name': 'John', 'User id': 1 }
|
|
1848
|
+
* toSentence('$hello-world', true); // '$Hello world'
|
|
1849
|
+
* ```
|
|
1850
|
+
*
|
|
1851
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1852
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1853
|
+
*/
|
|
1854
|
+
function toSentence(input, keepSymbols) {
|
|
1855
|
+
return convert(input, (key) => ToSentence(key, keepSymbols));
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Pascal_Snake_Case (also known as Ada_Case).
|
|
1859
|
+
*
|
|
1860
|
+
* @example
|
|
1861
|
+
* ```ts
|
|
1862
|
+
* toPascalSnake('helloWorld'); // 'Hello_World'
|
|
1863
|
+
* toPascalSnake({ first_name: 'John', userID: 1 }); // { First_Name: 'John', User_Id: 1 }
|
|
1864
|
+
* toPascalSnake('$hello-world', true); // '$Hello_World'
|
|
1865
|
+
* ```
|
|
1866
|
+
*
|
|
1867
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1868
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1869
|
+
*/
|
|
1870
|
+
function toPascalSnake(input, keepSymbols) {
|
|
1871
|
+
return convert(input, (key) => ToPascalSnake(key, keepSymbols));
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to path/case, keeping the original case of each word.
|
|
1875
|
+
*
|
|
1876
|
+
* @example
|
|
1877
|
+
* ```ts
|
|
1878
|
+
* toPath('helloWorld'); // 'hello/World'
|
|
1879
|
+
* toPath({ first_name: 'John', userID: 1 }); // { 'first/name': 'John', 'user/ID': 1 }
|
|
1880
|
+
* toPath('$hello-world', true); // '$hello/world'
|
|
1881
|
+
* ```
|
|
1882
|
+
*
|
|
1883
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1884
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1885
|
+
*/
|
|
1886
|
+
function toPath(input, keepSymbols) {
|
|
1887
|
+
return convert(input, (key) => ToPath(key, keepSymbols));
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to space case, keeping the original case of each word.
|
|
1891
|
+
*
|
|
1892
|
+
* @example
|
|
1893
|
+
* ```ts
|
|
1894
|
+
* toSpace('helloWorld'); // 'hello World'
|
|
1895
|
+
* toSpace({ first_name: 'John', userID: 1 }); // { 'first name': 'John', 'user ID': 1 }
|
|
1896
|
+
* toSpace('$hello-world', true); // '$hello world'
|
|
1897
|
+
* ```
|
|
1898
|
+
*
|
|
1899
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1900
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1901
|
+
*/
|
|
1902
|
+
function toSpace(input, keepSymbols) {
|
|
1903
|
+
return convert(input, (key) => ToSpace(key, keepSymbols));
|
|
1904
|
+
}
|
|
1905
|
+
/**
|
|
1906
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to lower case (space separated).
|
|
1907
|
+
*
|
|
1908
|
+
* @example
|
|
1909
|
+
* ```ts
|
|
1910
|
+
* toLower('helloWorld'); // 'hello world'
|
|
1911
|
+
* toLower({ first_name: 'John', userID: 1 }); // { 'first name': 'John', 'user id': 1 }
|
|
1912
|
+
* toLower('$hello-world', true); // '$hello world'
|
|
1913
|
+
* ```
|
|
1914
|
+
*
|
|
1915
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1916
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1917
|
+
*/
|
|
1918
|
+
function toLower(input, keepSymbols) {
|
|
1919
|
+
return convert(input, (key) => ToLower(key, keepSymbols));
|
|
1920
|
+
}
|
|
1921
|
+
/**
|
|
1922
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER CASE (space separated).
|
|
1923
|
+
*
|
|
1924
|
+
* @example
|
|
1925
|
+
* ```ts
|
|
1926
|
+
* toUpper('helloWorld'); // 'HELLO WORLD'
|
|
1927
|
+
* toUpper({ first_name: 'John', userID: 1 }); // { 'FIRST NAME': 'John', 'USER ID': 1 }
|
|
1928
|
+
* toUpper('$hello-world', true); // '$HELLO WORLD'
|
|
1929
|
+
* ```
|
|
1930
|
+
*
|
|
1931
|
+
* @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
|
|
1932
|
+
* Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
|
|
1933
|
+
*/
|
|
1934
|
+
function toUpper(input, keepSymbols) {
|
|
1935
|
+
return convert(input, (key) => ToUpper(key, keepSymbols));
|
|
1936
|
+
}
|
|
1937
|
+
//#endregion
|
|
1349
1938
|
exports.camelToDash = camelToDash;
|
|
1350
1939
|
exports.camelToDot = camelToDot;
|
|
1351
1940
|
exports.camelToPascal = camelToPascal;
|
|
@@ -1409,6 +1998,21 @@ exports.titleToSnake = titleToSnake;
|
|
|
1409
1998
|
exports.titleToTrain = titleToTrain;
|
|
1410
1999
|
exports.titleToUpperDash = titleToUpperDash;
|
|
1411
2000
|
exports.titleToUpperSnake = titleToUpperSnake;
|
|
2001
|
+
exports.toCamel = toCamel;
|
|
2002
|
+
exports.toDot = toDot;
|
|
2003
|
+
exports.toKebab = toKebab;
|
|
2004
|
+
exports.toLower = toLower;
|
|
2005
|
+
exports.toPascal = toPascal;
|
|
2006
|
+
exports.toPascalSnake = toPascalSnake;
|
|
2007
|
+
exports.toPath = toPath;
|
|
2008
|
+
exports.toSentence = toSentence;
|
|
2009
|
+
exports.toSnake = toSnake;
|
|
2010
|
+
exports.toSpace = toSpace;
|
|
2011
|
+
exports.toTitle = toTitle;
|
|
2012
|
+
exports.toTrain = toTrain;
|
|
2013
|
+
exports.toUpper = toUpper;
|
|
2014
|
+
exports.toUpperKebab = toUpperKebab;
|
|
2015
|
+
exports.toUpperSnake = toUpperSnake;
|
|
1412
2016
|
exports.trainToCamel = trainToCamel;
|
|
1413
2017
|
exports.trainToDash = trainToDash;
|
|
1414
2018
|
exports.trainToDot = trainToDot;
|