caseparser 4.1.0 → 4.3.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 +76 -21
- package/dist/index.cjs +996 -35
- package/dist/index.d.cts +788 -11
- package/dist/index.d.ts +788 -11
- package/dist/index.js +953 -36
- package/package.json +6 -2
package/dist/index.js
CHANGED
|
@@ -21,6 +21,35 @@ function Uncapitalize(str) {
|
|
|
21
21
|
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
22
22
|
}
|
|
23
23
|
//#endregion
|
|
24
|
+
//#region src/parser/objectParser.ts
|
|
25
|
+
function objectParser(input, convertKey) {
|
|
26
|
+
const result = {};
|
|
27
|
+
for (const property of Object.keys(input)) {
|
|
28
|
+
const parsedKey = convertKey(property);
|
|
29
|
+
const value = input[property];
|
|
30
|
+
let parsedValue;
|
|
31
|
+
if (isArray(value)) parsedValue = arrayParser(value, convertKey);
|
|
32
|
+
else if (isObject(value)) parsedValue = objectParser(value, convertKey);
|
|
33
|
+
else parsedValue = value;
|
|
34
|
+
Object.defineProperty(result, parsedKey, {
|
|
35
|
+
value: parsedValue,
|
|
36
|
+
enumerable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
configurable: true
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/parser/arrayParser.ts
|
|
45
|
+
function arrayParser(input, convertKey) {
|
|
46
|
+
return input.map((item) => {
|
|
47
|
+
if (isArray(item)) return arrayParser(item, convertKey);
|
|
48
|
+
if (isObject(item)) return objectParser(item, convertKey);
|
|
49
|
+
return item;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
24
53
|
//#region src/parser/stringParser.ts
|
|
25
54
|
const CamelToDash = (str) => str.replace(/([A-Z])/g, (g) => "-" + g[0].toLowerCase());
|
|
26
55
|
const CamelToPascal = (str) => Capitalize(str);
|
|
@@ -78,6 +107,40 @@ const DotToSnake = (str) => DashToSnake(DotToDash(str));
|
|
|
78
107
|
const DotToTrain = (str) => DashToTrain(DotToDash(str));
|
|
79
108
|
const DotToUpperDash = (str) => Uppercase(DotToDash(str));
|
|
80
109
|
const DotToUpperSnake = (str) => DashToUpperSnake(DotToDash(str));
|
|
110
|
+
const DashToTitle = (str) => str.split("-").map(Capitalize).join(" ");
|
|
111
|
+
const DashToSentence = (str) => Capitalize(str.replace(/(\-)/g, " "));
|
|
112
|
+
const CamelToTitle = (str) => DashToTitle(CamelToDash(str));
|
|
113
|
+
const CamelToSentence = (str) => DashToSentence(CamelToDash(str));
|
|
114
|
+
const PascalToTitle = (str) => DashToTitle(PascalToDash(str));
|
|
115
|
+
const PascalToSentence = (str) => DashToSentence(PascalToDash(str));
|
|
116
|
+
const SnakeToTitle = (str) => DashToTitle(SnakeToDash(str));
|
|
117
|
+
const SnakeToSentence = (str) => DashToSentence(SnakeToDash(str));
|
|
118
|
+
const UpperSnakeToTitle = (str) => DashToTitle(UpperSnakeToDash(str));
|
|
119
|
+
const UpperSnakeToSentence = (str) => DashToSentence(UpperSnakeToDash(str));
|
|
120
|
+
const UpperDashToTitle = (str) => DashToTitle(UpperDashToDash(str));
|
|
121
|
+
const UpperDashToSentence = (str) => DashToSentence(UpperDashToDash(str));
|
|
122
|
+
const TrainToTitle = (str) => DashToTitle(TrainToDash(str));
|
|
123
|
+
const TrainToSentence = (str) => DashToSentence(TrainToDash(str));
|
|
124
|
+
const DotToTitle = (str) => DashToTitle(DotToDash(str));
|
|
125
|
+
const DotToSentence = (str) => DashToSentence(DotToDash(str));
|
|
126
|
+
const TitleToDash = (str) => Lowercase(str).replace(/( )/g, "-");
|
|
127
|
+
const TitleToCamel = (str) => DashToCamel(TitleToDash(str));
|
|
128
|
+
const TitleToPascal = (str) => DashToPascal(TitleToDash(str));
|
|
129
|
+
const TitleToSnake = (str) => DashToSnake(TitleToDash(str));
|
|
130
|
+
const TitleToUpperSnake = (str) => DashToUpperSnake(TitleToDash(str));
|
|
131
|
+
const TitleToUpperDash = (str) => DashToUpperDash(TitleToDash(str));
|
|
132
|
+
const TitleToTrain = (str) => DashToTrain(TitleToDash(str));
|
|
133
|
+
const TitleToDot = (str) => DashToDot(TitleToDash(str));
|
|
134
|
+
const TitleToSentence = (str) => DashToSentence(TitleToDash(str));
|
|
135
|
+
const SentenceToDash = (str) => Lowercase(str).replace(/( )/g, "-");
|
|
136
|
+
const SentenceToCamel = (str) => DashToCamel(SentenceToDash(str));
|
|
137
|
+
const SentenceToPascal = (str) => DashToPascal(SentenceToDash(str));
|
|
138
|
+
const SentenceToSnake = (str) => DashToSnake(SentenceToDash(str));
|
|
139
|
+
const SentenceToUpperSnake = (str) => DashToUpperSnake(SentenceToDash(str));
|
|
140
|
+
const SentenceToUpperDash = (str) => DashToUpperDash(SentenceToDash(str));
|
|
141
|
+
const SentenceToTrain = (str) => DashToTrain(SentenceToDash(str));
|
|
142
|
+
const SentenceToDot = (str) => DashToDot(SentenceToDash(str));
|
|
143
|
+
const SentenceToTitle = (str) => DashToTitle(SentenceToDash(str));
|
|
81
144
|
function parse(input, type) {
|
|
82
145
|
return {
|
|
83
146
|
CamelToDash,
|
|
@@ -135,46 +198,53 @@ function parse(input, type) {
|
|
|
135
198
|
DotToDash,
|
|
136
199
|
DotToUpperSnake,
|
|
137
200
|
DotToUpperDash,
|
|
138
|
-
DotToTrain
|
|
201
|
+
DotToTrain,
|
|
202
|
+
CamelToTitle,
|
|
203
|
+
CamelToSentence,
|
|
204
|
+
PascalToTitle,
|
|
205
|
+
PascalToSentence,
|
|
206
|
+
SnakeToTitle,
|
|
207
|
+
SnakeToSentence,
|
|
208
|
+
DashToTitle,
|
|
209
|
+
DashToSentence,
|
|
210
|
+
UpperSnakeToTitle,
|
|
211
|
+
UpperSnakeToSentence,
|
|
212
|
+
UpperDashToTitle,
|
|
213
|
+
UpperDashToSentence,
|
|
214
|
+
TrainToTitle,
|
|
215
|
+
TrainToSentence,
|
|
216
|
+
DotToTitle,
|
|
217
|
+
DotToSentence,
|
|
218
|
+
TitleToCamel,
|
|
219
|
+
TitleToPascal,
|
|
220
|
+
TitleToSnake,
|
|
221
|
+
TitleToDash,
|
|
222
|
+
TitleToUpperSnake,
|
|
223
|
+
TitleToUpperDash,
|
|
224
|
+
TitleToTrain,
|
|
225
|
+
TitleToDot,
|
|
226
|
+
TitleToSentence,
|
|
227
|
+
SentenceToCamel,
|
|
228
|
+
SentenceToPascal,
|
|
229
|
+
SentenceToSnake,
|
|
230
|
+
SentenceToDash,
|
|
231
|
+
SentenceToUpperSnake,
|
|
232
|
+
SentenceToUpperDash,
|
|
233
|
+
SentenceToTrain,
|
|
234
|
+
SentenceToDot,
|
|
235
|
+
SentenceToTitle
|
|
139
236
|
}[type](input);
|
|
140
237
|
}
|
|
141
238
|
//#endregion
|
|
142
|
-
//#region src/parser/objectParser.ts
|
|
143
|
-
function objectParser(input, type) {
|
|
144
|
-
const result = {};
|
|
145
|
-
for (const property of Object.keys(input)) {
|
|
146
|
-
const parsedKey = parse(property, type);
|
|
147
|
-
const value = input[property];
|
|
148
|
-
let parsedValue;
|
|
149
|
-
if (isArray(value)) parsedValue = arrayParser(value, type);
|
|
150
|
-
else if (isObject(value)) parsedValue = objectParser(value, type);
|
|
151
|
-
else parsedValue = value;
|
|
152
|
-
Object.defineProperty(result, parsedKey, {
|
|
153
|
-
value: parsedValue,
|
|
154
|
-
enumerable: true,
|
|
155
|
-
writable: true,
|
|
156
|
-
configurable: true
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
//#endregion
|
|
162
|
-
//#region src/parser/arrayParser.ts
|
|
163
|
-
function arrayParser(input, type) {
|
|
164
|
-
return input.map((item) => {
|
|
165
|
-
if (isArray(item)) return arrayParser(item, type);
|
|
166
|
-
if (isObject(item)) return objectParser(item, type);
|
|
167
|
-
return item;
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
//#endregion
|
|
171
239
|
//#region src/parser/parser.ts
|
|
240
|
+
/** Converts a string, or the keys of an object/array (deeply), with `convertKey`. */
|
|
241
|
+
function convert(input, convertKey) {
|
|
242
|
+
if (isString(input)) return convertKey(input);
|
|
243
|
+
if (isArray(input)) return arrayParser(input, convertKey);
|
|
244
|
+
if (isObject(input)) return objectParser(input, convertKey);
|
|
245
|
+
}
|
|
172
246
|
function converter(input, type) {
|
|
173
|
-
|
|
174
|
-
if (isString(input)) result = parse(input, type);
|
|
175
|
-
if (isArray(input)) result = arrayParser(input, type);
|
|
176
|
-
if (isObject(input)) result = objectParser(input, type);
|
|
177
|
-
return result;
|
|
247
|
+
return convert(input, (key) => parse(key, type));
|
|
178
248
|
}
|
|
179
249
|
//#endregion
|
|
180
250
|
//#region src/camelCase/camelCase.ts
|
|
@@ -186,6 +256,9 @@ function converter(input, type) {
|
|
|
186
256
|
* camelToDash('helloWorld'); // 'hello-world'
|
|
187
257
|
* camelToDash({ firstName: 'John' }); // { 'first-name': 'John' }
|
|
188
258
|
* ```
|
|
259
|
+
*
|
|
260
|
+
* @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
|
|
261
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
189
262
|
*/
|
|
190
263
|
function camelToDash(input) {
|
|
191
264
|
return converter(input, "CamelToDash");
|
|
@@ -198,6 +271,9 @@ function camelToDash(input) {
|
|
|
198
271
|
* camelToSnake('helloWorld'); // 'hello_world'
|
|
199
272
|
* camelToSnake({ firstName: 'John' }); // { first_name: 'John' }
|
|
200
273
|
* ```
|
|
274
|
+
*
|
|
275
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
276
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
201
277
|
*/
|
|
202
278
|
function camelToSnake(input) {
|
|
203
279
|
return converter(input, "CamelToSnake");
|
|
@@ -210,6 +286,9 @@ function camelToSnake(input) {
|
|
|
210
286
|
* camelToPascal('helloWorld'); // 'HelloWorld'
|
|
211
287
|
* camelToPascal({ firstName: 'John' }); // { FirstName: 'John' }
|
|
212
288
|
* ```
|
|
289
|
+
*
|
|
290
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
291
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
213
292
|
*/
|
|
214
293
|
function camelToPascal(input) {
|
|
215
294
|
return converter(input, "CamelToPascal");
|
|
@@ -222,6 +301,9 @@ function camelToPascal(input) {
|
|
|
222
301
|
* camelToUpperSnake('helloWorld'); // 'HELLO_WORLD'
|
|
223
302
|
* camelToUpperSnake({ firstName: 'John' }); // { FIRST_NAME: 'John' }
|
|
224
303
|
* ```
|
|
304
|
+
*
|
|
305
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
306
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
225
307
|
*/
|
|
226
308
|
function camelToUpperSnake(input) {
|
|
227
309
|
return converter(input, "CamelToUpperSnake");
|
|
@@ -234,6 +316,9 @@ function camelToUpperSnake(input) {
|
|
|
234
316
|
* camelToUpperDash('helloWorld'); // 'HELLO-WORLD'
|
|
235
317
|
* camelToUpperDash({ firstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
236
318
|
* ```
|
|
319
|
+
*
|
|
320
|
+
* @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
|
|
321
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
237
322
|
*/
|
|
238
323
|
function camelToUpperDash(input) {
|
|
239
324
|
return converter(input, "CamelToUpperDash");
|
|
@@ -246,6 +331,9 @@ function camelToUpperDash(input) {
|
|
|
246
331
|
* camelToTrain('helloWorld'); // 'Hello-World'
|
|
247
332
|
* camelToTrain({ firstName: 'John' }); // { 'First-Name': 'John' }
|
|
248
333
|
* ```
|
|
334
|
+
*
|
|
335
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
336
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
249
337
|
*/
|
|
250
338
|
function camelToTrain(input) {
|
|
251
339
|
return converter(input, "CamelToTrain");
|
|
@@ -258,10 +346,43 @@ function camelToTrain(input) {
|
|
|
258
346
|
* camelToDot('helloWorld'); // 'hello.world'
|
|
259
347
|
* camelToDot({ firstName: 'John' }); // { 'first.name': 'John' }
|
|
260
348
|
* ```
|
|
349
|
+
*
|
|
350
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
351
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
261
352
|
*/
|
|
262
353
|
function camelToDot(input) {
|
|
263
354
|
return converter(input, "CamelToDot");
|
|
264
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to Title Case.
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* ```ts
|
|
361
|
+
* camelToTitle('helloWorld'); // 'Hello World'
|
|
362
|
+
* camelToTitle({ firstName: 'John' }); // { 'First Name': 'John' }
|
|
363
|
+
* ```
|
|
364
|
+
*
|
|
365
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
366
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
367
|
+
*/
|
|
368
|
+
function camelToTitle(input) {
|
|
369
|
+
return converter(input, "CamelToTitle");
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to Sentence case.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```ts
|
|
376
|
+
* camelToSentence('helloWorld'); // 'Hello world'
|
|
377
|
+
* camelToSentence({ firstName: 'John' }); // { 'First name': 'John' }
|
|
378
|
+
* ```
|
|
379
|
+
*
|
|
380
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
381
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
382
|
+
*/
|
|
383
|
+
function camelToSentence(input) {
|
|
384
|
+
return converter(input, "CamelToSentence");
|
|
385
|
+
}
|
|
265
386
|
//#endregion
|
|
266
387
|
//#region src/dashCase/dashCase.ts
|
|
267
388
|
/**
|
|
@@ -272,6 +393,9 @@ function camelToDot(input) {
|
|
|
272
393
|
* dashToSnake('hello-world'); // 'hello_world'
|
|
273
394
|
* dashToSnake({ 'first-name': 'John' }); // { first_name: 'John' }
|
|
274
395
|
* ```
|
|
396
|
+
*
|
|
397
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
398
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
275
399
|
*/
|
|
276
400
|
function dashToSnake(input) {
|
|
277
401
|
return converter(input, "DashToSnake");
|
|
@@ -284,6 +408,9 @@ function dashToSnake(input) {
|
|
|
284
408
|
* dashToCamel('hello-world'); // 'helloWorld'
|
|
285
409
|
* dashToCamel({ 'first-name': 'John' }); // { firstName: 'John' }
|
|
286
410
|
* ```
|
|
411
|
+
*
|
|
412
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
413
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
287
414
|
*/
|
|
288
415
|
function dashToCamel(input) {
|
|
289
416
|
return converter(input, "DashToCamel");
|
|
@@ -296,6 +423,9 @@ function dashToCamel(input) {
|
|
|
296
423
|
* dashToPascal('hello-world'); // 'HelloWorld'
|
|
297
424
|
* dashToPascal({ 'first-name': 'John' }); // { FirstName: 'John' }
|
|
298
425
|
* ```
|
|
426
|
+
*
|
|
427
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
428
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
299
429
|
*/
|
|
300
430
|
function dashToPascal(input) {
|
|
301
431
|
return converter(input, "DashToPascal");
|
|
@@ -308,6 +438,9 @@ function dashToPascal(input) {
|
|
|
308
438
|
* dashToUpperSnake('hello-world'); // 'HELLO_WORLD'
|
|
309
439
|
* dashToUpperSnake({ 'first-name': 'John' }); // { FIRST_NAME: 'John' }
|
|
310
440
|
* ```
|
|
441
|
+
*
|
|
442
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
443
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
311
444
|
*/
|
|
312
445
|
function dashToUpperSnake(input) {
|
|
313
446
|
return converter(input, "DashToUpperSnake");
|
|
@@ -320,6 +453,9 @@ function dashToUpperSnake(input) {
|
|
|
320
453
|
* dashToUpperDash('hello-world'); // 'HELLO-WORLD'
|
|
321
454
|
* dashToUpperDash({ 'first-name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
322
455
|
* ```
|
|
456
|
+
*
|
|
457
|
+
* @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
|
|
458
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
323
459
|
*/
|
|
324
460
|
function dashToUpperDash(input) {
|
|
325
461
|
return converter(input, "DashToUpperDash");
|
|
@@ -332,6 +468,9 @@ function dashToUpperDash(input) {
|
|
|
332
468
|
* dashToTrain('hello-world'); // 'Hello-World'
|
|
333
469
|
* dashToTrain({ 'first-name': 'John' }); // { 'First-Name': 'John' }
|
|
334
470
|
* ```
|
|
471
|
+
*
|
|
472
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
473
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
335
474
|
*/
|
|
336
475
|
function dashToTrain(input) {
|
|
337
476
|
return converter(input, "DashToTrain");
|
|
@@ -344,10 +483,43 @@ function dashToTrain(input) {
|
|
|
344
483
|
* dashToDot('hello-world'); // 'hello.world'
|
|
345
484
|
* dashToDot({ 'first-name': 'John' }); // { 'first.name': 'John' }
|
|
346
485
|
* ```
|
|
486
|
+
*
|
|
487
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
488
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
347
489
|
*/
|
|
348
490
|
function dashToDot(input) {
|
|
349
491
|
return converter(input, "DashToDot");
|
|
350
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to Title Case.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```ts
|
|
498
|
+
* dashToTitle('hello-world'); // 'Hello World'
|
|
499
|
+
* dashToTitle({ 'first-name': 'John' }); // { 'First Name': 'John' }
|
|
500
|
+
* ```
|
|
501
|
+
*
|
|
502
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
503
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
504
|
+
*/
|
|
505
|
+
function dashToTitle(input) {
|
|
506
|
+
return converter(input, "DashToTitle");
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to Sentence case.
|
|
510
|
+
*
|
|
511
|
+
* @example
|
|
512
|
+
* ```ts
|
|
513
|
+
* dashToSentence('hello-world'); // 'Hello world'
|
|
514
|
+
* dashToSentence({ 'first-name': 'John' }); // { 'First name': 'John' }
|
|
515
|
+
* ```
|
|
516
|
+
*
|
|
517
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
518
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
519
|
+
*/
|
|
520
|
+
function dashToSentence(input) {
|
|
521
|
+
return converter(input, "DashToSentence");
|
|
522
|
+
}
|
|
351
523
|
//#endregion
|
|
352
524
|
//#region src/pascalCase/pascalCase.ts
|
|
353
525
|
/**
|
|
@@ -358,6 +530,9 @@ function dashToDot(input) {
|
|
|
358
530
|
* pascalToCamel('HelloWorld'); // 'helloWorld'
|
|
359
531
|
* pascalToCamel({ FirstName: 'John' }); // { firstName: 'John' }
|
|
360
532
|
* ```
|
|
533
|
+
*
|
|
534
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
535
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
361
536
|
*/
|
|
362
537
|
function pascalToCamel(input) {
|
|
363
538
|
return converter(input, "PascalToCamel");
|
|
@@ -370,6 +545,9 @@ function pascalToCamel(input) {
|
|
|
370
545
|
* pascalToSnake('HelloWorld'); // 'hello_world'
|
|
371
546
|
* pascalToSnake({ FirstName: 'John' }); // { first_name: 'John' }
|
|
372
547
|
* ```
|
|
548
|
+
*
|
|
549
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
550
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
373
551
|
*/
|
|
374
552
|
function pascalToSnake(input) {
|
|
375
553
|
return converter(input, "PascalToSnake");
|
|
@@ -382,6 +560,9 @@ function pascalToSnake(input) {
|
|
|
382
560
|
* pascalToDash('HelloWorld'); // 'hello-world'
|
|
383
561
|
* pascalToDash({ FirstName: 'John' }); // { 'first-name': 'John' }
|
|
384
562
|
* ```
|
|
563
|
+
*
|
|
564
|
+
* @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
|
|
565
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
385
566
|
*/
|
|
386
567
|
function pascalToDash(input) {
|
|
387
568
|
return converter(input, "PascalToDash");
|
|
@@ -394,6 +575,9 @@ function pascalToDash(input) {
|
|
|
394
575
|
* pascalToUpperSnake('HelloWorld'); // 'HELLO_WORLD'
|
|
395
576
|
* pascalToUpperSnake({ FirstName: 'John' }); // { FIRST_NAME: 'John' }
|
|
396
577
|
* ```
|
|
578
|
+
*
|
|
579
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
580
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
397
581
|
*/
|
|
398
582
|
function pascalToUpperSnake(input) {
|
|
399
583
|
return converter(input, "PascalToUpperSnake");
|
|
@@ -406,6 +590,9 @@ function pascalToUpperSnake(input) {
|
|
|
406
590
|
* pascalToUpperDash('HelloWorld'); // 'HELLO-WORLD'
|
|
407
591
|
* pascalToUpperDash({ FirstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
408
592
|
* ```
|
|
593
|
+
*
|
|
594
|
+
* @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
|
|
595
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
409
596
|
*/
|
|
410
597
|
function pascalToUpperDash(input) {
|
|
411
598
|
return converter(input, "PascalToUpperDash");
|
|
@@ -418,6 +605,9 @@ function pascalToUpperDash(input) {
|
|
|
418
605
|
* pascalToTrain('HelloWorld'); // 'Hello-World'
|
|
419
606
|
* pascalToTrain({ FirstName: 'John' }); // { 'First-Name': 'John' }
|
|
420
607
|
* ```
|
|
608
|
+
*
|
|
609
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
610
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
421
611
|
*/
|
|
422
612
|
function pascalToTrain(input) {
|
|
423
613
|
return converter(input, "PascalToTrain");
|
|
@@ -430,10 +620,43 @@ function pascalToTrain(input) {
|
|
|
430
620
|
* pascalToDot('HelloWorld'); // 'hello.world'
|
|
431
621
|
* pascalToDot({ FirstName: 'John' }); // { 'first.name': 'John' }
|
|
432
622
|
* ```
|
|
623
|
+
*
|
|
624
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
625
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
433
626
|
*/
|
|
434
627
|
function pascalToDot(input) {
|
|
435
628
|
return converter(input, "PascalToDot");
|
|
436
629
|
}
|
|
630
|
+
/**
|
|
631
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to Title Case.
|
|
632
|
+
*
|
|
633
|
+
* @example
|
|
634
|
+
* ```ts
|
|
635
|
+
* pascalToTitle('HelloWorld'); // 'Hello World'
|
|
636
|
+
* pascalToTitle({ FirstName: 'John' }); // { 'First Name': 'John' }
|
|
637
|
+
* ```
|
|
638
|
+
*
|
|
639
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
640
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
641
|
+
*/
|
|
642
|
+
function pascalToTitle(input) {
|
|
643
|
+
return converter(input, "PascalToTitle");
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to Sentence case.
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* ```ts
|
|
650
|
+
* pascalToSentence('HelloWorld'); // 'Hello world'
|
|
651
|
+
* pascalToSentence({ FirstName: 'John' }); // { 'First name': 'John' }
|
|
652
|
+
* ```
|
|
653
|
+
*
|
|
654
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
655
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
656
|
+
*/
|
|
657
|
+
function pascalToSentence(input) {
|
|
658
|
+
return converter(input, "PascalToSentence");
|
|
659
|
+
}
|
|
437
660
|
//#endregion
|
|
438
661
|
//#region src/snakeCase/snakeCase.ts
|
|
439
662
|
/**
|
|
@@ -444,6 +667,9 @@ function pascalToDot(input) {
|
|
|
444
667
|
* snakeToCamel('hello_world'); // 'helloWorld'
|
|
445
668
|
* snakeToCamel({ first_name: 'John' }); // { firstName: 'John' }
|
|
446
669
|
* ```
|
|
670
|
+
*
|
|
671
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
672
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
447
673
|
*/
|
|
448
674
|
function snakeToCamel(input) {
|
|
449
675
|
return converter(input, "SnakeToCamel");
|
|
@@ -456,6 +682,9 @@ function snakeToCamel(input) {
|
|
|
456
682
|
* snakeToDash('hello_world'); // 'hello-world'
|
|
457
683
|
* snakeToDash({ first_name: 'John' }); // { 'first-name': 'John' }
|
|
458
684
|
* ```
|
|
685
|
+
*
|
|
686
|
+
* @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
|
|
687
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
459
688
|
*/
|
|
460
689
|
function snakeToDash(input) {
|
|
461
690
|
return converter(input, "SnakeToDash");
|
|
@@ -468,6 +697,9 @@ function snakeToDash(input) {
|
|
|
468
697
|
* snakeToPascal('hello_world'); // 'HelloWorld'
|
|
469
698
|
* snakeToPascal({ first_name: 'John' }); // { FirstName: 'John' }
|
|
470
699
|
* ```
|
|
700
|
+
*
|
|
701
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
702
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
471
703
|
*/
|
|
472
704
|
function snakeToPascal(input) {
|
|
473
705
|
return converter(input, "SnakeToPascal");
|
|
@@ -480,6 +712,9 @@ function snakeToPascal(input) {
|
|
|
480
712
|
* snakeToUpperSnake('hello_world'); // 'HELLO_WORLD'
|
|
481
713
|
* snakeToUpperSnake({ first_name: 'John' }); // { FIRST_NAME: 'John' }
|
|
482
714
|
* ```
|
|
715
|
+
*
|
|
716
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
717
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
483
718
|
*/
|
|
484
719
|
function snakeToUpperSnake(input) {
|
|
485
720
|
return converter(input, "SnakeToUpperSnake");
|
|
@@ -492,6 +727,9 @@ function snakeToUpperSnake(input) {
|
|
|
492
727
|
* snakeToUpperDash('hello_world'); // 'HELLO-WORLD'
|
|
493
728
|
* snakeToUpperDash({ first_name: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
494
729
|
* ```
|
|
730
|
+
*
|
|
731
|
+
* @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
|
|
732
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
495
733
|
*/
|
|
496
734
|
function snakeToUpperDash(input) {
|
|
497
735
|
return converter(input, "SnakeToUpperDash");
|
|
@@ -504,6 +742,9 @@ function snakeToUpperDash(input) {
|
|
|
504
742
|
* snakeToTrain('hello_world'); // 'Hello-World'
|
|
505
743
|
* snakeToTrain({ first_name: 'John' }); // { 'First-Name': 'John' }
|
|
506
744
|
* ```
|
|
745
|
+
*
|
|
746
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
747
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
507
748
|
*/
|
|
508
749
|
function snakeToTrain(input) {
|
|
509
750
|
return converter(input, "SnakeToTrain");
|
|
@@ -516,10 +757,43 @@ function snakeToTrain(input) {
|
|
|
516
757
|
* snakeToDot('hello_world'); // 'hello.world'
|
|
517
758
|
* snakeToDot({ first_name: 'John' }); // { 'first.name': 'John' }
|
|
518
759
|
* ```
|
|
760
|
+
*
|
|
761
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
762
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
519
763
|
*/
|
|
520
764
|
function snakeToDot(input) {
|
|
521
765
|
return converter(input, "SnakeToDot");
|
|
522
766
|
}
|
|
767
|
+
/**
|
|
768
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to Title Case.
|
|
769
|
+
*
|
|
770
|
+
* @example
|
|
771
|
+
* ```ts
|
|
772
|
+
* snakeToTitle('hello_world'); // 'Hello World'
|
|
773
|
+
* snakeToTitle({ first_name: 'John' }); // { 'First Name': 'John' }
|
|
774
|
+
* ```
|
|
775
|
+
*
|
|
776
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
777
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
778
|
+
*/
|
|
779
|
+
function snakeToTitle(input) {
|
|
780
|
+
return converter(input, "SnakeToTitle");
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to Sentence case.
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* ```ts
|
|
787
|
+
* snakeToSentence('hello_world'); // 'Hello world'
|
|
788
|
+
* snakeToSentence({ first_name: 'John' }); // { 'First name': 'John' }
|
|
789
|
+
* ```
|
|
790
|
+
*
|
|
791
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
792
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
793
|
+
*/
|
|
794
|
+
function snakeToSentence(input) {
|
|
795
|
+
return converter(input, "SnakeToSentence");
|
|
796
|
+
}
|
|
523
797
|
//#endregion
|
|
524
798
|
//#region src/trainCase/trainCase.ts
|
|
525
799
|
/**
|
|
@@ -530,6 +804,9 @@ function snakeToDot(input) {
|
|
|
530
804
|
* trainToCamel('Hello-World'); // 'helloWorld'
|
|
531
805
|
* trainToCamel({ 'First-Name': 'John' }); // { firstName: 'John' }
|
|
532
806
|
* ```
|
|
807
|
+
*
|
|
808
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
809
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
533
810
|
*/
|
|
534
811
|
function trainToCamel(input) {
|
|
535
812
|
return converter(input, "TrainToCamel");
|
|
@@ -542,6 +819,9 @@ function trainToCamel(input) {
|
|
|
542
819
|
* trainToPascal('Hello-World'); // 'HelloWorld'
|
|
543
820
|
* trainToPascal({ 'First-Name': 'John' }); // { FirstName: 'John' }
|
|
544
821
|
* ```
|
|
822
|
+
*
|
|
823
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
824
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
545
825
|
*/
|
|
546
826
|
function trainToPascal(input) {
|
|
547
827
|
return converter(input, "TrainToPascal");
|
|
@@ -554,6 +834,9 @@ function trainToPascal(input) {
|
|
|
554
834
|
* trainToSnake('Hello-World'); // 'hello_world'
|
|
555
835
|
* trainToSnake({ 'First-Name': 'John' }); // { first_name: 'John' }
|
|
556
836
|
* ```
|
|
837
|
+
*
|
|
838
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
839
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
557
840
|
*/
|
|
558
841
|
function trainToSnake(input) {
|
|
559
842
|
return converter(input, "TrainToSnake");
|
|
@@ -566,6 +849,9 @@ function trainToSnake(input) {
|
|
|
566
849
|
* trainToDash('Hello-World'); // 'hello-world'
|
|
567
850
|
* trainToDash({ 'First-Name': 'John' }); // { 'first-name': 'John' }
|
|
568
851
|
* ```
|
|
852
|
+
*
|
|
853
|
+
* @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
|
|
854
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
569
855
|
*/
|
|
570
856
|
function trainToDash(input) {
|
|
571
857
|
return converter(input, "TrainToDash");
|
|
@@ -578,6 +864,9 @@ function trainToDash(input) {
|
|
|
578
864
|
* trainToUpperSnake('Hello-World'); // 'HELLO_WORLD'
|
|
579
865
|
* trainToUpperSnake({ 'First-Name': 'John' }); // { FIRST_NAME: 'John' }
|
|
580
866
|
* ```
|
|
867
|
+
*
|
|
868
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
869
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
581
870
|
*/
|
|
582
871
|
function trainToUpperSnake(input) {
|
|
583
872
|
return converter(input, "TrainToUpperSnake");
|
|
@@ -590,6 +879,9 @@ function trainToUpperSnake(input) {
|
|
|
590
879
|
* trainToUpperDash('Hello-World'); // 'HELLO-WORLD'
|
|
591
880
|
* trainToUpperDash({ 'First-Name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
592
881
|
* ```
|
|
882
|
+
*
|
|
883
|
+
* @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
|
|
884
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
593
885
|
*/
|
|
594
886
|
function trainToUpperDash(input) {
|
|
595
887
|
return converter(input, "TrainToUpperDash");
|
|
@@ -602,10 +894,43 @@ function trainToUpperDash(input) {
|
|
|
602
894
|
* trainToDot('Hello-World'); // 'hello.world'
|
|
603
895
|
* trainToDot({ 'First-Name': 'John' }); // { 'first.name': 'John' }
|
|
604
896
|
* ```
|
|
897
|
+
*
|
|
898
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
899
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
605
900
|
*/
|
|
606
901
|
function trainToDot(input) {
|
|
607
902
|
return converter(input, "TrainToDot");
|
|
608
903
|
}
|
|
904
|
+
/**
|
|
905
|
+
* Converts a string, or the keys of an object/array (deeply), from Train-Case to Title Case.
|
|
906
|
+
*
|
|
907
|
+
* @example
|
|
908
|
+
* ```ts
|
|
909
|
+
* trainToTitle('Hello-World'); // 'Hello World'
|
|
910
|
+
* trainToTitle({ 'First-Name': 'John' }); // { 'First Name': 'John' }
|
|
911
|
+
* ```
|
|
912
|
+
*
|
|
913
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
914
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
915
|
+
*/
|
|
916
|
+
function trainToTitle(input) {
|
|
917
|
+
return converter(input, "TrainToTitle");
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Converts a string, or the keys of an object/array (deeply), from Train-Case to Sentence case.
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* ```ts
|
|
924
|
+
* trainToSentence('Hello-World'); // 'Hello world'
|
|
925
|
+
* trainToSentence({ 'First-Name': 'John' }); // { 'First name': 'John' }
|
|
926
|
+
* ```
|
|
927
|
+
*
|
|
928
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
929
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
930
|
+
*/
|
|
931
|
+
function trainToSentence(input) {
|
|
932
|
+
return converter(input, "TrainToSentence");
|
|
933
|
+
}
|
|
609
934
|
//#endregion
|
|
610
935
|
//#region src/dotCase/dotCase.ts
|
|
611
936
|
/**
|
|
@@ -616,6 +941,9 @@ function trainToDot(input) {
|
|
|
616
941
|
* dotToCamel('hello.world'); // 'helloWorld'
|
|
617
942
|
* dotToCamel({ 'first.name': 'John' }); // { firstName: 'John' }
|
|
618
943
|
* ```
|
|
944
|
+
*
|
|
945
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
946
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
619
947
|
*/
|
|
620
948
|
function dotToCamel(input) {
|
|
621
949
|
return converter(input, "DotToCamel");
|
|
@@ -628,6 +956,9 @@ function dotToCamel(input) {
|
|
|
628
956
|
* dotToPascal('hello.world'); // 'HelloWorld'
|
|
629
957
|
* dotToPascal({ 'first.name': 'John' }); // { FirstName: 'John' }
|
|
630
958
|
* ```
|
|
959
|
+
*
|
|
960
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
961
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
631
962
|
*/
|
|
632
963
|
function dotToPascal(input) {
|
|
633
964
|
return converter(input, "DotToPascal");
|
|
@@ -640,6 +971,9 @@ function dotToPascal(input) {
|
|
|
640
971
|
* dotToSnake('hello.world'); // 'hello_world'
|
|
641
972
|
* dotToSnake({ 'first.name': 'John' }); // { first_name: 'John' }
|
|
642
973
|
* ```
|
|
974
|
+
*
|
|
975
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
976
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
643
977
|
*/
|
|
644
978
|
function dotToSnake(input) {
|
|
645
979
|
return converter(input, "DotToSnake");
|
|
@@ -652,6 +986,9 @@ function dotToSnake(input) {
|
|
|
652
986
|
* dotToDash('hello.world'); // 'hello-world'
|
|
653
987
|
* dotToDash({ 'first.name': 'John' }); // { 'first-name': 'John' }
|
|
654
988
|
* ```
|
|
989
|
+
*
|
|
990
|
+
* @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
|
|
991
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
655
992
|
*/
|
|
656
993
|
function dotToDash(input) {
|
|
657
994
|
return converter(input, "DotToDash");
|
|
@@ -664,6 +1001,9 @@ function dotToDash(input) {
|
|
|
664
1001
|
* dotToUpperSnake('hello.world'); // 'HELLO_WORLD'
|
|
665
1002
|
* dotToUpperSnake({ 'first.name': 'John' }); // { FIRST_NAME: 'John' }
|
|
666
1003
|
* ```
|
|
1004
|
+
*
|
|
1005
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1006
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
667
1007
|
*/
|
|
668
1008
|
function dotToUpperSnake(input) {
|
|
669
1009
|
return converter(input, "DotToUpperSnake");
|
|
@@ -676,6 +1016,9 @@ function dotToUpperSnake(input) {
|
|
|
676
1016
|
* dotToUpperDash('hello.world'); // 'HELLO-WORLD'
|
|
677
1017
|
* dotToUpperDash({ 'first.name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
678
1018
|
* ```
|
|
1019
|
+
*
|
|
1020
|
+
* @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
|
|
1021
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
679
1022
|
*/
|
|
680
1023
|
function dotToUpperDash(input) {
|
|
681
1024
|
return converter(input, "DotToUpperDash");
|
|
@@ -688,10 +1031,317 @@ function dotToUpperDash(input) {
|
|
|
688
1031
|
* dotToTrain('hello.world'); // 'Hello-World'
|
|
689
1032
|
* dotToTrain({ 'first.name': 'John' }); // { 'First-Name': 'John' }
|
|
690
1033
|
* ```
|
|
1034
|
+
*
|
|
1035
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
1036
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
691
1037
|
*/
|
|
692
1038
|
function dotToTrain(input) {
|
|
693
1039
|
return converter(input, "DotToTrain");
|
|
694
1040
|
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Converts a string, or the keys of an object/array (deeply), from dot.case to Title Case.
|
|
1043
|
+
*
|
|
1044
|
+
* @example
|
|
1045
|
+
* ```ts
|
|
1046
|
+
* dotToTitle('hello.world'); // 'Hello World'
|
|
1047
|
+
* dotToTitle({ 'first.name': 'John' }); // { 'First Name': 'John' }
|
|
1048
|
+
* ```
|
|
1049
|
+
*
|
|
1050
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
1051
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1052
|
+
*/
|
|
1053
|
+
function dotToTitle(input) {
|
|
1054
|
+
return converter(input, "DotToTitle");
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Converts a string, or the keys of an object/array (deeply), from dot.case to Sentence case.
|
|
1058
|
+
*
|
|
1059
|
+
* @example
|
|
1060
|
+
* ```ts
|
|
1061
|
+
* dotToSentence('hello.world'); // 'Hello world'
|
|
1062
|
+
* dotToSentence({ 'first.name': 'John' }); // { 'First name': 'John' }
|
|
1063
|
+
* ```
|
|
1064
|
+
*
|
|
1065
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
1066
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1067
|
+
*/
|
|
1068
|
+
function dotToSentence(input) {
|
|
1069
|
+
return converter(input, "DotToSentence");
|
|
1070
|
+
}
|
|
1071
|
+
//#endregion
|
|
1072
|
+
//#region src/titleCase/titleCase.ts
|
|
1073
|
+
/**
|
|
1074
|
+
* Converts a string, or the keys of an object/array (deeply), from Title Case to camelCase.
|
|
1075
|
+
*
|
|
1076
|
+
* @example
|
|
1077
|
+
* ```ts
|
|
1078
|
+
* titleToCamel('Hello World'); // 'helloWorld'
|
|
1079
|
+
* titleToCamel({ 'First Name': 'John' }); // { firstName: 'John' }
|
|
1080
|
+
* ```
|
|
1081
|
+
*
|
|
1082
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
1083
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1084
|
+
*/
|
|
1085
|
+
function titleToCamel(input) {
|
|
1086
|
+
return converter(input, "TitleToCamel");
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Converts a string, or the keys of an object/array (deeply), from Title Case to PascalCase.
|
|
1090
|
+
*
|
|
1091
|
+
* @example
|
|
1092
|
+
* ```ts
|
|
1093
|
+
* titleToPascal('Hello World'); // 'HelloWorld'
|
|
1094
|
+
* titleToPascal({ 'First Name': 'John' }); // { FirstName: 'John' }
|
|
1095
|
+
* ```
|
|
1096
|
+
*
|
|
1097
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
1098
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1099
|
+
*/
|
|
1100
|
+
function titleToPascal(input) {
|
|
1101
|
+
return converter(input, "TitleToPascal");
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Converts a string, or the keys of an object/array (deeply), from Title Case to snake_case.
|
|
1105
|
+
*
|
|
1106
|
+
* @example
|
|
1107
|
+
* ```ts
|
|
1108
|
+
* titleToSnake('Hello World'); // 'hello_world'
|
|
1109
|
+
* titleToSnake({ 'First Name': 'John' }); // { first_name: 'John' }
|
|
1110
|
+
* ```
|
|
1111
|
+
*
|
|
1112
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1113
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1114
|
+
*/
|
|
1115
|
+
function titleToSnake(input) {
|
|
1116
|
+
return converter(input, "TitleToSnake");
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Converts a string, or the keys of an object/array (deeply), from Title Case to dash-case.
|
|
1120
|
+
*
|
|
1121
|
+
* @example
|
|
1122
|
+
* ```ts
|
|
1123
|
+
* titleToDash('Hello World'); // 'hello-world'
|
|
1124
|
+
* titleToDash({ 'First Name': 'John' }); // { 'first-name': 'John' }
|
|
1125
|
+
* ```
|
|
1126
|
+
*
|
|
1127
|
+
* @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
|
|
1128
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1129
|
+
*/
|
|
1130
|
+
function titleToDash(input) {
|
|
1131
|
+
return converter(input, "TitleToDash");
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Converts a string, or the keys of an object/array (deeply), from Title Case to UPPER_SNAKE_CASE.
|
|
1135
|
+
*
|
|
1136
|
+
* @example
|
|
1137
|
+
* ```ts
|
|
1138
|
+
* titleToUpperSnake('Hello World'); // 'HELLO_WORLD'
|
|
1139
|
+
* titleToUpperSnake({ 'First Name': 'John' }); // { FIRST_NAME: 'John' }
|
|
1140
|
+
* ```
|
|
1141
|
+
*
|
|
1142
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1143
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1144
|
+
*/
|
|
1145
|
+
function titleToUpperSnake(input) {
|
|
1146
|
+
return converter(input, "TitleToUpperSnake");
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Converts a string, or the keys of an object/array (deeply), from Title Case to UPPER-DASH-CASE.
|
|
1150
|
+
*
|
|
1151
|
+
* @example
|
|
1152
|
+
* ```ts
|
|
1153
|
+
* titleToUpperDash('Hello World'); // 'HELLO-WORLD'
|
|
1154
|
+
* titleToUpperDash({ 'First Name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
1155
|
+
* ```
|
|
1156
|
+
*
|
|
1157
|
+
* @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
|
|
1158
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1159
|
+
*/
|
|
1160
|
+
function titleToUpperDash(input) {
|
|
1161
|
+
return converter(input, "TitleToUpperDash");
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Converts a string, or the keys of an object/array (deeply), from Title Case to Train-Case.
|
|
1165
|
+
*
|
|
1166
|
+
* @example
|
|
1167
|
+
* ```ts
|
|
1168
|
+
* titleToTrain('Hello World'); // 'Hello-World'
|
|
1169
|
+
* titleToTrain({ 'First Name': 'John' }); // { 'First-Name': 'John' }
|
|
1170
|
+
* ```
|
|
1171
|
+
*
|
|
1172
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
1173
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1174
|
+
*/
|
|
1175
|
+
function titleToTrain(input) {
|
|
1176
|
+
return converter(input, "TitleToTrain");
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Converts a string, or the keys of an object/array (deeply), from Title Case to dot.case.
|
|
1180
|
+
*
|
|
1181
|
+
* @example
|
|
1182
|
+
* ```ts
|
|
1183
|
+
* titleToDot('Hello World'); // 'hello.world'
|
|
1184
|
+
* titleToDot({ 'First Name': 'John' }); // { 'first.name': 'John' }
|
|
1185
|
+
* ```
|
|
1186
|
+
*
|
|
1187
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
1188
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1189
|
+
*/
|
|
1190
|
+
function titleToDot(input) {
|
|
1191
|
+
return converter(input, "TitleToDot");
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Converts a string, or the keys of an object/array (deeply), from Title Case to Sentence case.
|
|
1195
|
+
*
|
|
1196
|
+
* @example
|
|
1197
|
+
* ```ts
|
|
1198
|
+
* titleToSentence('Hello World'); // 'Hello world'
|
|
1199
|
+
* titleToSentence({ 'First Name': 'John' }); // { 'First name': 'John' }
|
|
1200
|
+
* ```
|
|
1201
|
+
*
|
|
1202
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
1203
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1204
|
+
*/
|
|
1205
|
+
function titleToSentence(input) {
|
|
1206
|
+
return converter(input, "TitleToSentence");
|
|
1207
|
+
}
|
|
1208
|
+
//#endregion
|
|
1209
|
+
//#region src/sentenceCase/sentenceCase.ts
|
|
1210
|
+
/**
|
|
1211
|
+
* Converts a string, or the keys of an object/array (deeply), from Sentence case to camelCase.
|
|
1212
|
+
*
|
|
1213
|
+
* @example
|
|
1214
|
+
* ```ts
|
|
1215
|
+
* sentenceToCamel('Hello world'); // 'helloWorld'
|
|
1216
|
+
* sentenceToCamel({ 'First name': 'John' }); // { firstName: 'John' }
|
|
1217
|
+
* ```
|
|
1218
|
+
*
|
|
1219
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
1220
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1221
|
+
*/
|
|
1222
|
+
function sentenceToCamel(input) {
|
|
1223
|
+
return converter(input, "SentenceToCamel");
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Converts a string, or the keys of an object/array (deeply), from Sentence case to PascalCase.
|
|
1227
|
+
*
|
|
1228
|
+
* @example
|
|
1229
|
+
* ```ts
|
|
1230
|
+
* sentenceToPascal('Hello world'); // 'HelloWorld'
|
|
1231
|
+
* sentenceToPascal({ 'First name': 'John' }); // { FirstName: 'John' }
|
|
1232
|
+
* ```
|
|
1233
|
+
*
|
|
1234
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
1235
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1236
|
+
*/
|
|
1237
|
+
function sentenceToPascal(input) {
|
|
1238
|
+
return converter(input, "SentenceToPascal");
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Converts a string, or the keys of an object/array (deeply), from Sentence case to snake_case.
|
|
1242
|
+
*
|
|
1243
|
+
* @example
|
|
1244
|
+
* ```ts
|
|
1245
|
+
* sentenceToSnake('Hello world'); // 'hello_world'
|
|
1246
|
+
* sentenceToSnake({ 'First name': 'John' }); // { first_name: 'John' }
|
|
1247
|
+
* ```
|
|
1248
|
+
*
|
|
1249
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1250
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1251
|
+
*/
|
|
1252
|
+
function sentenceToSnake(input) {
|
|
1253
|
+
return converter(input, "SentenceToSnake");
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Converts a string, or the keys of an object/array (deeply), from Sentence case to dash-case.
|
|
1257
|
+
*
|
|
1258
|
+
* @example
|
|
1259
|
+
* ```ts
|
|
1260
|
+
* sentenceToDash('Hello world'); // 'hello-world'
|
|
1261
|
+
* sentenceToDash({ 'First name': 'John' }); // { 'first-name': 'John' }
|
|
1262
|
+
* ```
|
|
1263
|
+
*
|
|
1264
|
+
* @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
|
|
1265
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1266
|
+
*/
|
|
1267
|
+
function sentenceToDash(input) {
|
|
1268
|
+
return converter(input, "SentenceToDash");
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Converts a string, or the keys of an object/array (deeply), from Sentence case to UPPER_SNAKE_CASE.
|
|
1272
|
+
*
|
|
1273
|
+
* @example
|
|
1274
|
+
* ```ts
|
|
1275
|
+
* sentenceToUpperSnake('Hello world'); // 'HELLO_WORLD'
|
|
1276
|
+
* sentenceToUpperSnake({ 'First name': 'John' }); // { FIRST_NAME: 'John' }
|
|
1277
|
+
* ```
|
|
1278
|
+
*
|
|
1279
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1280
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1281
|
+
*/
|
|
1282
|
+
function sentenceToUpperSnake(input) {
|
|
1283
|
+
return converter(input, "SentenceToUpperSnake");
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Converts a string, or the keys of an object/array (deeply), from Sentence case to UPPER-DASH-CASE.
|
|
1287
|
+
*
|
|
1288
|
+
* @example
|
|
1289
|
+
* ```ts
|
|
1290
|
+
* sentenceToUpperDash('Hello world'); // 'HELLO-WORLD'
|
|
1291
|
+
* sentenceToUpperDash({ 'First name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
1292
|
+
* ```
|
|
1293
|
+
*
|
|
1294
|
+
* @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
|
|
1295
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1296
|
+
*/
|
|
1297
|
+
function sentenceToUpperDash(input) {
|
|
1298
|
+
return converter(input, "SentenceToUpperDash");
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Converts a string, or the keys of an object/array (deeply), from Sentence case to Train-Case.
|
|
1302
|
+
*
|
|
1303
|
+
* @example
|
|
1304
|
+
* ```ts
|
|
1305
|
+
* sentenceToTrain('Hello world'); // 'Hello-World'
|
|
1306
|
+
* sentenceToTrain({ 'First name': 'John' }); // { 'First-Name': 'John' }
|
|
1307
|
+
* ```
|
|
1308
|
+
*
|
|
1309
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
1310
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1311
|
+
*/
|
|
1312
|
+
function sentenceToTrain(input) {
|
|
1313
|
+
return converter(input, "SentenceToTrain");
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* Converts a string, or the keys of an object/array (deeply), from Sentence case to dot.case.
|
|
1317
|
+
*
|
|
1318
|
+
* @example
|
|
1319
|
+
* ```ts
|
|
1320
|
+
* sentenceToDot('Hello world'); // 'hello.world'
|
|
1321
|
+
* sentenceToDot({ 'First name': 'John' }); // { 'first.name': 'John' }
|
|
1322
|
+
* ```
|
|
1323
|
+
*
|
|
1324
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
1325
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1326
|
+
*/
|
|
1327
|
+
function sentenceToDot(input) {
|
|
1328
|
+
return converter(input, "SentenceToDot");
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Converts a string, or the keys of an object/array (deeply), from Sentence case to Title Case.
|
|
1332
|
+
*
|
|
1333
|
+
* @example
|
|
1334
|
+
* ```ts
|
|
1335
|
+
* sentenceToTitle('Hello world'); // 'Hello World'
|
|
1336
|
+
* sentenceToTitle({ 'First name': 'John' }); // { 'First Name': 'John' }
|
|
1337
|
+
* ```
|
|
1338
|
+
*
|
|
1339
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
1340
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1341
|
+
*/
|
|
1342
|
+
function sentenceToTitle(input) {
|
|
1343
|
+
return converter(input, "SentenceToTitle");
|
|
1344
|
+
}
|
|
695
1345
|
//#endregion
|
|
696
1346
|
//#region src/upperDashCase/upperDashCase.ts
|
|
697
1347
|
/**
|
|
@@ -702,6 +1352,9 @@ function dotToTrain(input) {
|
|
|
702
1352
|
* upperDashToCamel('HELLO-WORLD'); // 'helloWorld'
|
|
703
1353
|
* upperDashToCamel({ 'FIRST-NAME': 'John' }); // { firstName: 'John' }
|
|
704
1354
|
* ```
|
|
1355
|
+
*
|
|
1356
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
1357
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
705
1358
|
*/
|
|
706
1359
|
function upperDashToCamel(input) {
|
|
707
1360
|
return converter(input, "UpperDashToCamel");
|
|
@@ -714,6 +1367,9 @@ function upperDashToCamel(input) {
|
|
|
714
1367
|
* upperDashToSnake('HELLO-WORLD'); // 'hello_world'
|
|
715
1368
|
* upperDashToSnake({ 'FIRST-NAME': 'John' }); // { first_name: 'John' }
|
|
716
1369
|
* ```
|
|
1370
|
+
*
|
|
1371
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1372
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
717
1373
|
*/
|
|
718
1374
|
function upperDashToSnake(input) {
|
|
719
1375
|
return converter(input, "UpperDashToSnake");
|
|
@@ -726,6 +1382,9 @@ function upperDashToSnake(input) {
|
|
|
726
1382
|
* upperDashToDash('HELLO-WORLD'); // 'hello-world'
|
|
727
1383
|
* upperDashToDash({ 'FIRST-NAME': 'John' }); // { 'first-name': 'John' }
|
|
728
1384
|
* ```
|
|
1385
|
+
*
|
|
1386
|
+
* @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
|
|
1387
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
729
1388
|
*/
|
|
730
1389
|
function upperDashToDash(input) {
|
|
731
1390
|
return converter(input, "UpperDashToDash");
|
|
@@ -738,6 +1397,9 @@ function upperDashToDash(input) {
|
|
|
738
1397
|
* upperDashToPascal('HELLO-WORLD'); // 'HelloWorld'
|
|
739
1398
|
* upperDashToPascal({ 'FIRST-NAME': 'John' }); // { FirstName: 'John' }
|
|
740
1399
|
* ```
|
|
1400
|
+
*
|
|
1401
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
1402
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
741
1403
|
*/
|
|
742
1404
|
function upperDashToPascal(input) {
|
|
743
1405
|
return converter(input, "UpperDashToPascal");
|
|
@@ -750,6 +1412,9 @@ function upperDashToPascal(input) {
|
|
|
750
1412
|
* upperDashToUpperSnake('HELLO-WORLD'); // 'HELLO_WORLD'
|
|
751
1413
|
* upperDashToUpperSnake({ 'FIRST-NAME': 'John' }); // { FIRST_NAME: 'John' }
|
|
752
1414
|
* ```
|
|
1415
|
+
*
|
|
1416
|
+
* @deprecated Use `toUpperSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1417
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
753
1418
|
*/
|
|
754
1419
|
function upperDashToUpperSnake(input) {
|
|
755
1420
|
return converter(input, "UpperDashToUpperSnake");
|
|
@@ -762,6 +1427,9 @@ function upperDashToUpperSnake(input) {
|
|
|
762
1427
|
* upperDashToTrain('HELLO-WORLD'); // 'Hello-World'
|
|
763
1428
|
* upperDashToTrain({ 'FIRST-NAME': 'John' }); // { 'First-Name': 'John' }
|
|
764
1429
|
* ```
|
|
1430
|
+
*
|
|
1431
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
1432
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
765
1433
|
*/
|
|
766
1434
|
function upperDashToTrain(input) {
|
|
767
1435
|
return converter(input, "UpperDashToTrain");
|
|
@@ -774,10 +1442,43 @@ function upperDashToTrain(input) {
|
|
|
774
1442
|
* upperDashToDot('HELLO-WORLD'); // 'hello.world'
|
|
775
1443
|
* upperDashToDot({ 'FIRST-NAME': 'John' }); // { 'first.name': 'John' }
|
|
776
1444
|
* ```
|
|
1445
|
+
*
|
|
1446
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
1447
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
777
1448
|
*/
|
|
778
1449
|
function upperDashToDot(input) {
|
|
779
1450
|
return converter(input, "UpperDashToDot");
|
|
780
1451
|
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to Title Case.
|
|
1454
|
+
*
|
|
1455
|
+
* @example
|
|
1456
|
+
* ```ts
|
|
1457
|
+
* upperDashToTitle('HELLO-WORLD'); // 'Hello World'
|
|
1458
|
+
* upperDashToTitle({ 'FIRST-NAME': 'John' }); // { 'First Name': 'John' }
|
|
1459
|
+
* ```
|
|
1460
|
+
*
|
|
1461
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
1462
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1463
|
+
*/
|
|
1464
|
+
function upperDashToTitle(input) {
|
|
1465
|
+
return converter(input, "UpperDashToTitle");
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to Sentence case.
|
|
1469
|
+
*
|
|
1470
|
+
* @example
|
|
1471
|
+
* ```ts
|
|
1472
|
+
* upperDashToSentence('HELLO-WORLD'); // 'Hello world'
|
|
1473
|
+
* upperDashToSentence({ 'FIRST-NAME': 'John' }); // { 'First name': 'John' }
|
|
1474
|
+
* ```
|
|
1475
|
+
*
|
|
1476
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
1477
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1478
|
+
*/
|
|
1479
|
+
function upperDashToSentence(input) {
|
|
1480
|
+
return converter(input, "UpperDashToSentence");
|
|
1481
|
+
}
|
|
781
1482
|
//#endregion
|
|
782
1483
|
//#region src/upperSnakeCase/upperSnakeCase.ts
|
|
783
1484
|
/**
|
|
@@ -788,6 +1489,9 @@ function upperDashToDot(input) {
|
|
|
788
1489
|
* upperSnakeToCamel('HELLO_WORLD'); // 'helloWorld'
|
|
789
1490
|
* upperSnakeToCamel({ FIRST_NAME: 'John' }); // { firstName: 'John' }
|
|
790
1491
|
* ```
|
|
1492
|
+
*
|
|
1493
|
+
* @deprecated Use `toCamel` instead, which converts from any case. It keeps acronyms together,
|
|
1494
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
791
1495
|
*/
|
|
792
1496
|
function upperSnakeToCamel(input) {
|
|
793
1497
|
return converter(input, "UpperSnakeToCamel");
|
|
@@ -800,6 +1504,9 @@ function upperSnakeToCamel(input) {
|
|
|
800
1504
|
* upperSnakeToSnake('HELLO_WORLD'); // 'hello_world'
|
|
801
1505
|
* upperSnakeToSnake({ FIRST_NAME: 'John' }); // { first_name: 'John' }
|
|
802
1506
|
* ```
|
|
1507
|
+
*
|
|
1508
|
+
* @deprecated Use `toSnake` instead, which converts from any case. It keeps acronyms together,
|
|
1509
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
803
1510
|
*/
|
|
804
1511
|
function upperSnakeToSnake(input) {
|
|
805
1512
|
return converter(input, "UpperSnakeToSnake");
|
|
@@ -812,6 +1519,9 @@ function upperSnakeToSnake(input) {
|
|
|
812
1519
|
* upperSnakeToDash('HELLO_WORLD'); // 'hello-world'
|
|
813
1520
|
* upperSnakeToDash({ FIRST_NAME: 'John' }); // { 'first-name': 'John' }
|
|
814
1521
|
* ```
|
|
1522
|
+
*
|
|
1523
|
+
* @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
|
|
1524
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
815
1525
|
*/
|
|
816
1526
|
function upperSnakeToDash(input) {
|
|
817
1527
|
return converter(input, "UpperSnakeToDash");
|
|
@@ -824,6 +1534,9 @@ function upperSnakeToDash(input) {
|
|
|
824
1534
|
* upperSnakeToPascal('HELLO_WORLD'); // 'HelloWorld'
|
|
825
1535
|
* upperSnakeToPascal({ FIRST_NAME: 'John' }); // { FirstName: 'John' }
|
|
826
1536
|
* ```
|
|
1537
|
+
*
|
|
1538
|
+
* @deprecated Use `toPascal` instead, which converts from any case. It keeps acronyms together,
|
|
1539
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
827
1540
|
*/
|
|
828
1541
|
function upperSnakeToPascal(input) {
|
|
829
1542
|
return converter(input, "UpperSnakeToPascal");
|
|
@@ -836,6 +1549,9 @@ function upperSnakeToPascal(input) {
|
|
|
836
1549
|
* upperSnakeToUpperDash('HELLO_WORLD'); // 'HELLO-WORLD'
|
|
837
1550
|
* upperSnakeToUpperDash({ FIRST_NAME: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
838
1551
|
* ```
|
|
1552
|
+
*
|
|
1553
|
+
* @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
|
|
1554
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
839
1555
|
*/
|
|
840
1556
|
function upperSnakeToUpperDash(input) {
|
|
841
1557
|
return converter(input, "UpperSnakeToUpperDash");
|
|
@@ -848,6 +1564,9 @@ function upperSnakeToUpperDash(input) {
|
|
|
848
1564
|
* upperSnakeToTrain('HELLO_WORLD'); // 'Hello-World'
|
|
849
1565
|
* upperSnakeToTrain({ FIRST_NAME: 'John' }); // { 'First-Name': 'John' }
|
|
850
1566
|
* ```
|
|
1567
|
+
*
|
|
1568
|
+
* @deprecated Use `toTrain` instead, which converts from any case. It keeps acronyms together,
|
|
1569
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
851
1570
|
*/
|
|
852
1571
|
function upperSnakeToTrain(input) {
|
|
853
1572
|
return converter(input, "UpperSnakeToTrain");
|
|
@@ -860,9 +1579,207 @@ function upperSnakeToTrain(input) {
|
|
|
860
1579
|
* upperSnakeToDot('HELLO_WORLD'); // 'hello.world'
|
|
861
1580
|
* upperSnakeToDot({ FIRST_NAME: 'John' }); // { 'first.name': 'John' }
|
|
862
1581
|
* ```
|
|
1582
|
+
*
|
|
1583
|
+
* @deprecated Use `toDot` instead, which converts from any case. It keeps acronyms together,
|
|
1584
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
863
1585
|
*/
|
|
864
1586
|
function upperSnakeToDot(input) {
|
|
865
1587
|
return converter(input, "UpperSnakeToDot");
|
|
866
1588
|
}
|
|
1589
|
+
/**
|
|
1590
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to Title Case.
|
|
1591
|
+
*
|
|
1592
|
+
* @example
|
|
1593
|
+
* ```ts
|
|
1594
|
+
* upperSnakeToTitle('HELLO_WORLD'); // 'Hello World'
|
|
1595
|
+
* upperSnakeToTitle({ FIRST_NAME: 'John' }); // { 'First Name': 'John' }
|
|
1596
|
+
* ```
|
|
1597
|
+
*
|
|
1598
|
+
* @deprecated Use `toTitle` instead, which converts from any case. It keeps acronyms together,
|
|
1599
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1600
|
+
*/
|
|
1601
|
+
function upperSnakeToTitle(input) {
|
|
1602
|
+
return converter(input, "UpperSnakeToTitle");
|
|
1603
|
+
}
|
|
1604
|
+
/**
|
|
1605
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to Sentence case.
|
|
1606
|
+
*
|
|
1607
|
+
* @example
|
|
1608
|
+
* ```ts
|
|
1609
|
+
* upperSnakeToSentence('HELLO_WORLD'); // 'Hello world'
|
|
1610
|
+
* upperSnakeToSentence({ FIRST_NAME: 'John' }); // { 'First name': 'John' }
|
|
1611
|
+
* ```
|
|
1612
|
+
*
|
|
1613
|
+
* @deprecated Use `toSentence` instead, which converts from any case. It keeps acronyms together,
|
|
1614
|
+
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1615
|
+
*/
|
|
1616
|
+
function upperSnakeToSentence(input) {
|
|
1617
|
+
return converter(input, "UpperSnakeToSentence");
|
|
1618
|
+
}
|
|
1619
|
+
//#endregion
|
|
1620
|
+
//#region src/anyCase/words.ts
|
|
1621
|
+
const isSeparator = (c) => c === "_" || c === "-" || c === "." || c === " ";
|
|
1622
|
+
const isUpper = (c) => c !== c.toLowerCase();
|
|
1623
|
+
const isLower = (c) => c !== c.toUpperCase();
|
|
1624
|
+
/**
|
|
1625
|
+
* Splits a string in any case into lowercase words: on `_`, `-`, `.` and spaces,
|
|
1626
|
+
* before an uppercase letter that follows a lowercase letter or a digit (`helloWorld`),
|
|
1627
|
+
* and before the last letter of an acronym (`XMLHttp`). Mirrors the `Words` type.
|
|
1628
|
+
*/
|
|
1629
|
+
function words(str) {
|
|
1630
|
+
const result = [];
|
|
1631
|
+
let word = "";
|
|
1632
|
+
let prev = "";
|
|
1633
|
+
const push = () => {
|
|
1634
|
+
if (word) result.push(word.toLowerCase());
|
|
1635
|
+
word = "";
|
|
1636
|
+
};
|
|
1637
|
+
for (let i = 0; i < str.length; i++) {
|
|
1638
|
+
const c = str[i];
|
|
1639
|
+
if (isSeparator(c)) {
|
|
1640
|
+
push();
|
|
1641
|
+
prev = "";
|
|
1642
|
+
continue;
|
|
1643
|
+
}
|
|
1644
|
+
const next = str.charAt(i + 1);
|
|
1645
|
+
if (isUpper(c) && word && (!isUpper(prev) || next && isLower(next))) push();
|
|
1646
|
+
word += c;
|
|
1647
|
+
prev = c;
|
|
1648
|
+
}
|
|
1649
|
+
push();
|
|
1650
|
+
return result;
|
|
1651
|
+
}
|
|
1652
|
+
const ToCamel = (str) => words(str).map((w, i) => i ? Capitalize(w) : w).join("");
|
|
1653
|
+
const ToPascal = (str) => words(str).map(Capitalize).join("");
|
|
1654
|
+
const ToSnake = (str) => words(str).join("_");
|
|
1655
|
+
const ToDash = (str) => words(str).join("-");
|
|
1656
|
+
const ToUpperSnake = (str) => words(str).join("_").toUpperCase();
|
|
1657
|
+
const ToUpperDash = (str) => words(str).join("-").toUpperCase();
|
|
1658
|
+
const ToTrain = (str) => words(str).map(Capitalize).join("-");
|
|
1659
|
+
const ToDot = (str) => words(str).join(".");
|
|
1660
|
+
const ToTitle = (str) => words(str).map(Capitalize).join(" ");
|
|
1661
|
+
const ToSentence = (str) => Capitalize(words(str).join(" "));
|
|
1662
|
+
//#endregion
|
|
1663
|
+
//#region src/anyCase/anyCase.ts
|
|
1664
|
+
/**
|
|
1665
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to camelCase.
|
|
1666
|
+
*
|
|
1667
|
+
* @example
|
|
1668
|
+
* ```ts
|
|
1669
|
+
* toCamel('hello_world'); // 'helloWorld'
|
|
1670
|
+
* toCamel({ first_name: 'John', userID: 1 }); // { firstName: 'John', userId: 1 }
|
|
1671
|
+
* ```
|
|
1672
|
+
*/
|
|
1673
|
+
function toCamel(input) {
|
|
1674
|
+
return convert(input, ToCamel);
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to PascalCase.
|
|
1678
|
+
*
|
|
1679
|
+
* @example
|
|
1680
|
+
* ```ts
|
|
1681
|
+
* toPascal('hello-world'); // 'HelloWorld'
|
|
1682
|
+
* toPascal({ 'first-name': 'John', userID: 1 }); // { FirstName: 'John', UserId: 1 }
|
|
1683
|
+
* ```
|
|
1684
|
+
*/
|
|
1685
|
+
function toPascal(input) {
|
|
1686
|
+
return convert(input, ToPascal);
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to snake_case.
|
|
1690
|
+
*
|
|
1691
|
+
* @example
|
|
1692
|
+
* ```ts
|
|
1693
|
+
* toSnake('helloWorld'); // 'hello_world'
|
|
1694
|
+
* toSnake({ firstName: 'John', userID: 1 }); // { first_name: 'John', user_id: 1 }
|
|
1695
|
+
* ```
|
|
1696
|
+
*/
|
|
1697
|
+
function toSnake(input) {
|
|
1698
|
+
return convert(input, ToSnake);
|
|
1699
|
+
}
|
|
1700
|
+
/**
|
|
1701
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to dash-case.
|
|
1702
|
+
*
|
|
1703
|
+
* @example
|
|
1704
|
+
* ```ts
|
|
1705
|
+
* toDash('HELLO_WORLD'); // 'hello-world'
|
|
1706
|
+
* toDash({ FIRST_NAME: 'John', userID: 1 }); // { 'first-name': 'John', 'user-id': 1 }
|
|
1707
|
+
* ```
|
|
1708
|
+
*/
|
|
1709
|
+
function toDash(input) {
|
|
1710
|
+
return convert(input, ToDash);
|
|
1711
|
+
}
|
|
1712
|
+
/**
|
|
1713
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER_SNAKE_CASE.
|
|
1714
|
+
*
|
|
1715
|
+
* @example
|
|
1716
|
+
* ```ts
|
|
1717
|
+
* toUpperSnake('hello-world'); // 'HELLO_WORLD'
|
|
1718
|
+
* toUpperSnake({ 'first-name': 'John', userID: 1 }); // { FIRST_NAME: 'John', USER_ID: 1 }
|
|
1719
|
+
* ```
|
|
1720
|
+
*/
|
|
1721
|
+
function toUpperSnake(input) {
|
|
1722
|
+
return convert(input, ToUpperSnake);
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to UPPER-DASH-CASE.
|
|
1726
|
+
*
|
|
1727
|
+
* @example
|
|
1728
|
+
* ```ts
|
|
1729
|
+
* toUpperDash('helloWorld'); // 'HELLO-WORLD'
|
|
1730
|
+
* toUpperDash({ firstName: 'John', userID: 1 }); // { 'FIRST-NAME': 'John', 'USER-ID': 1 }
|
|
1731
|
+
* ```
|
|
1732
|
+
*/
|
|
1733
|
+
function toUpperDash(input) {
|
|
1734
|
+
return convert(input, ToUpperDash);
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Train-Case.
|
|
1738
|
+
*
|
|
1739
|
+
* @example
|
|
1740
|
+
* ```ts
|
|
1741
|
+
* toTrain('hello_world'); // 'Hello-World'
|
|
1742
|
+
* toTrain({ first_name: 'John', userID: 1 }); // { 'First-Name': 'John', 'User-Id': 1 }
|
|
1743
|
+
* ```
|
|
1744
|
+
*/
|
|
1745
|
+
function toTrain(input) {
|
|
1746
|
+
return convert(input, ToTrain);
|
|
1747
|
+
}
|
|
1748
|
+
/**
|
|
1749
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to dot.case.
|
|
1750
|
+
*
|
|
1751
|
+
* @example
|
|
1752
|
+
* ```ts
|
|
1753
|
+
* toDot('HelloWorld'); // 'hello.world'
|
|
1754
|
+
* toDot({ FirstName: 'John', userID: 1 }); // { 'first.name': 'John', 'user.id': 1 }
|
|
1755
|
+
* ```
|
|
1756
|
+
*/
|
|
1757
|
+
function toDot(input) {
|
|
1758
|
+
return convert(input, ToDot);
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Title Case.
|
|
1762
|
+
*
|
|
1763
|
+
* @example
|
|
1764
|
+
* ```ts
|
|
1765
|
+
* toTitle('hello_world'); // 'Hello World'
|
|
1766
|
+
* toTitle({ first_name: 'John', userID: 1 }); // { 'First Name': 'John', 'User Id': 1 }
|
|
1767
|
+
* ```
|
|
1768
|
+
*/
|
|
1769
|
+
function toTitle(input) {
|
|
1770
|
+
return convert(input, ToTitle);
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Converts a string, or the keys of an object/array (deeply), from any case to Sentence case.
|
|
1774
|
+
*
|
|
1775
|
+
* @example
|
|
1776
|
+
* ```ts
|
|
1777
|
+
* toSentence('helloWorld'); // 'Hello world'
|
|
1778
|
+
* toSentence({ firstName: 'John', userID: 1 }); // { 'First name': 'John', 'User id': 1 }
|
|
1779
|
+
* ```
|
|
1780
|
+
*/
|
|
1781
|
+
function toSentence(input) {
|
|
1782
|
+
return convert(input, ToSentence);
|
|
1783
|
+
}
|
|
867
1784
|
//#endregion
|
|
868
|
-
export { camelToDash, camelToDot, camelToPascal, camelToSnake, camelToTrain, camelToUpperDash, camelToUpperSnake, dashToCamel, dashToDot, dashToPascal, dashToSnake, dashToTrain, dashToUpperDash, dashToUpperSnake, dotToCamel, dotToDash, dotToPascal, dotToSnake, dotToTrain, dotToUpperDash, dotToUpperSnake, pascalToCamel, pascalToDash, pascalToDot, pascalToSnake, pascalToTrain, pascalToUpperDash, pascalToUpperSnake, snakeToCamel, snakeToDash, snakeToDot, snakeToPascal, snakeToTrain, snakeToUpperDash, snakeToUpperSnake, trainToCamel, trainToDash, trainToDot, trainToPascal, trainToSnake, trainToUpperDash, trainToUpperSnake, upperDashToCamel, upperDashToDash, upperDashToDot, upperDashToPascal, upperDashToSnake, upperDashToTrain, upperDashToUpperSnake, upperSnakeToCamel, upperSnakeToDash, upperSnakeToDot, upperSnakeToPascal, upperSnakeToSnake, upperSnakeToTrain, upperSnakeToUpperDash };
|
|
1785
|
+
export { camelToDash, camelToDot, camelToPascal, camelToSentence, camelToSnake, camelToTitle, camelToTrain, camelToUpperDash, camelToUpperSnake, dashToCamel, dashToDot, dashToPascal, dashToSentence, dashToSnake, dashToTitle, dashToTrain, dashToUpperDash, dashToUpperSnake, dotToCamel, dotToDash, dotToPascal, dotToSentence, dotToSnake, dotToTitle, dotToTrain, dotToUpperDash, dotToUpperSnake, pascalToCamel, pascalToDash, pascalToDot, pascalToSentence, pascalToSnake, pascalToTitle, pascalToTrain, pascalToUpperDash, pascalToUpperSnake, sentenceToCamel, sentenceToDash, sentenceToDot, sentenceToPascal, sentenceToSnake, sentenceToTitle, sentenceToTrain, sentenceToUpperDash, sentenceToUpperSnake, snakeToCamel, snakeToDash, snakeToDot, snakeToPascal, snakeToSentence, snakeToTitle, snakeToTrain, snakeToUpperDash, snakeToUpperSnake, titleToCamel, titleToDash, titleToDot, titleToPascal, titleToSentence, titleToSnake, titleToTrain, titleToUpperDash, titleToUpperSnake, toCamel, toDash, toDot, toPascal, toSentence, toSnake, toTitle, toTrain, toUpperDash, toUpperSnake, trainToCamel, trainToDash, trainToDot, trainToPascal, trainToSentence, trainToSnake, trainToTitle, trainToUpperDash, trainToUpperSnake, upperDashToCamel, upperDashToDash, upperDashToDot, upperDashToPascal, upperDashToSentence, upperDashToSnake, upperDashToTitle, upperDashToTrain, upperDashToUpperSnake, upperSnakeToCamel, upperSnakeToDash, upperSnakeToDot, upperSnakeToPascal, upperSnakeToSentence, upperSnakeToSnake, upperSnakeToTitle, upperSnakeToTrain, upperSnakeToUpperDash };
|