caseparser 5.0.0 → 6.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 +258 -138
- package/dist/index.cjs +235 -1964
- package/dist/index.d.cts +230 -1328
- package/dist/index.d.ts +230 -1328
- package/dist/index.js +236 -1875
- package/package.json +16 -3
package/dist/index.cjs
CHANGED
|
@@ -4,1627 +4,117 @@ function isString(input) {
|
|
|
4
4
|
return typeof input === "string";
|
|
5
5
|
}
|
|
6
6
|
function isObject(input) {
|
|
7
|
-
|
|
7
|
+
if (typeof input !== "object" || input === null) return false;
|
|
8
|
+
const proto = Object.getPrototypeOf(input);
|
|
9
|
+
return proto !== null && proto.constructor === Object;
|
|
8
10
|
}
|
|
9
11
|
function isArray(input) {
|
|
10
12
|
return Array.isArray(input);
|
|
11
13
|
}
|
|
12
|
-
function Lowercase(str) {
|
|
13
|
-
return str.toLowerCase();
|
|
14
|
-
}
|
|
15
|
-
function Uppercase(str) {
|
|
16
|
-
return str.toUpperCase();
|
|
17
|
-
}
|
|
18
|
-
function Capitalize(str) {
|
|
19
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
20
|
-
}
|
|
21
|
-
function Uncapitalize(str) {
|
|
22
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
23
|
-
}
|
|
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
|
|
54
|
-
//#region src/parser/stringParser.ts
|
|
55
|
-
const CamelToDash = (str) => str.replace(/([A-Z])/g, (g) => "-" + g[0].toLowerCase());
|
|
56
|
-
const CamelToPascal = (str) => Capitalize(str);
|
|
57
|
-
const CamelToSnake = (str) => str.replace(/([A-Z])/g, (g) => "_" + g[0].toLowerCase());
|
|
58
|
-
const CamelToUpperDash = (str) => Uppercase(CamelToDash(str));
|
|
59
|
-
const CamelToUpperSnake = (str) => Uppercase(CamelToSnake(str));
|
|
60
|
-
const CamelToTrain = (str) => DashToTrain(CamelToDash(str));
|
|
61
|
-
const CamelToDot = (str) => DashToDot(CamelToDash(str));
|
|
62
|
-
const DashToCamel = (str) => str.replace(/(\-\w)/g, (g) => g[1].toUpperCase());
|
|
63
|
-
const DashToPascal = (str) => Capitalize(DashToCamel(str));
|
|
64
|
-
const DashToSnake = (str) => str.replace(/(\-)/g, "_");
|
|
65
|
-
const DashToUpperDash = (str) => Uppercase(str);
|
|
66
|
-
const DashToUpperSnake = (str) => Uppercase(DashToSnake(str));
|
|
67
|
-
const DashToTrain = (str) => str.split("-").map(Capitalize).join("-");
|
|
68
|
-
const DashToDot = (str) => str.replace(/(\-)/g, ".");
|
|
69
|
-
const PascalToCamel = (str) => Uncapitalize(str);
|
|
70
|
-
const PascalToDash = (str) => CamelToDash(Uncapitalize(str));
|
|
71
|
-
const PascalToSnake = (str) => CamelToSnake(Uncapitalize(str));
|
|
72
|
-
const PascalToUpperDash = (str) => Uppercase(PascalToDash(str));
|
|
73
|
-
const PascalToUpperSnake = (str) => Uppercase(PascalToSnake(str));
|
|
74
|
-
const PascalToTrain = (str) => DashToTrain(PascalToDash(str));
|
|
75
|
-
const PascalToDot = (str) => DashToDot(PascalToDash(str));
|
|
76
|
-
const SnakeToCamel = (str) => str.replace(/(\_\w)/g, (g) => g[1].toUpperCase());
|
|
77
|
-
const SnakeToDash = (str) => str.replace(/(\_)/g, "-");
|
|
78
|
-
const SnakeToPascal = (str) => Capitalize(SnakeToCamel(str));
|
|
79
|
-
const SnakeToUpperDash = (str) => Uppercase(SnakeToDash(str));
|
|
80
|
-
const SnakeToTrain = (str) => DashToTrain(SnakeToDash(str));
|
|
81
|
-
const SnakeToDot = (str) => DashToDot(SnakeToDash(str));
|
|
82
|
-
const SnakeToUpperSnake = (str) => Uppercase(str);
|
|
83
|
-
const UpperDashToCamel = (str) => DashToCamel(Lowercase(str));
|
|
84
|
-
const UpperDashToDash = (str) => Lowercase(str);
|
|
85
|
-
const UpperDashToPascal = (str) => Capitalize(UpperDashToCamel(str));
|
|
86
|
-
const UpperDashToSnake = (str) => DashToSnake(UpperDashToDash(str));
|
|
87
|
-
const UpperDashToUpperSnake = (str) => Uppercase(UpperDashToSnake(str));
|
|
88
|
-
const UpperDashToTrain = (str) => DashToTrain(UpperDashToDash(str));
|
|
89
|
-
const UpperDashToDot = (str) => DashToDot(UpperDashToDash(str));
|
|
90
|
-
const UpperSnakeToCamel = (str) => SnakeToCamel(Lowercase(str));
|
|
91
|
-
const UpperSnakeToDash = (str) => str.replace(/(\_)/g, "-").toLowerCase();
|
|
92
|
-
const UpperSnakeToPascal = (str) => SnakeToPascal(Lowercase(str));
|
|
93
|
-
const UpperSnakeToSnake = (str) => Lowercase(str);
|
|
94
|
-
const UpperSnakeToUpperDash = (str) => Uppercase(UpperSnakeToDash(str));
|
|
95
|
-
const UpperSnakeToTrain = (str) => DashToTrain(UpperSnakeToDash(str));
|
|
96
|
-
const UpperSnakeToDot = (str) => DashToDot(UpperSnakeToDash(str));
|
|
97
|
-
const TrainToCamel = (str) => DashToCamel(TrainToDash(str));
|
|
98
|
-
const TrainToDash = (str) => Lowercase(str);
|
|
99
|
-
const TrainToDot = (str) => DashToDot(TrainToDash(str));
|
|
100
|
-
const TrainToPascal = (str) => DashToPascal(TrainToDash(str));
|
|
101
|
-
const TrainToSnake = (str) => DashToSnake(TrainToDash(str));
|
|
102
|
-
const TrainToUpperDash = (str) => Uppercase(str);
|
|
103
|
-
const TrainToUpperSnake = (str) => DashToUpperSnake(TrainToDash(str));
|
|
104
|
-
const DotToCamel = (str) => DashToCamel(DotToDash(str));
|
|
105
|
-
const DotToDash = (str) => str.replace(/(\.)/g, "-");
|
|
106
|
-
const DotToPascal = (str) => DashToPascal(DotToDash(str));
|
|
107
|
-
const DotToSnake = (str) => DashToSnake(DotToDash(str));
|
|
108
|
-
const DotToTrain = (str) => DashToTrain(DotToDash(str));
|
|
109
|
-
const DotToUpperDash = (str) => Uppercase(DotToDash(str));
|
|
110
|
-
const DotToUpperSnake = (str) => DashToUpperSnake(DotToDash(str));
|
|
111
|
-
const DashToTitle = (str) => str.split("-").map(Capitalize).join(" ");
|
|
112
|
-
const DashToSentence = (str) => Capitalize(str.replace(/(\-)/g, " "));
|
|
113
|
-
const CamelToTitle = (str) => DashToTitle(CamelToDash(str));
|
|
114
|
-
const CamelToSentence = (str) => DashToSentence(CamelToDash(str));
|
|
115
|
-
const PascalToTitle = (str) => DashToTitle(PascalToDash(str));
|
|
116
|
-
const PascalToSentence = (str) => DashToSentence(PascalToDash(str));
|
|
117
|
-
const SnakeToTitle = (str) => DashToTitle(SnakeToDash(str));
|
|
118
|
-
const SnakeToSentence = (str) => DashToSentence(SnakeToDash(str));
|
|
119
|
-
const UpperSnakeToTitle = (str) => DashToTitle(UpperSnakeToDash(str));
|
|
120
|
-
const UpperSnakeToSentence = (str) => DashToSentence(UpperSnakeToDash(str));
|
|
121
|
-
const UpperDashToTitle = (str) => DashToTitle(UpperDashToDash(str));
|
|
122
|
-
const UpperDashToSentence = (str) => DashToSentence(UpperDashToDash(str));
|
|
123
|
-
const TrainToTitle = (str) => DashToTitle(TrainToDash(str));
|
|
124
|
-
const TrainToSentence = (str) => DashToSentence(TrainToDash(str));
|
|
125
|
-
const DotToTitle = (str) => DashToTitle(DotToDash(str));
|
|
126
|
-
const DotToSentence = (str) => DashToSentence(DotToDash(str));
|
|
127
|
-
const TitleToDash = (str) => Lowercase(str).replace(/( )/g, "-");
|
|
128
|
-
const TitleToCamel = (str) => DashToCamel(TitleToDash(str));
|
|
129
|
-
const TitleToPascal = (str) => DashToPascal(TitleToDash(str));
|
|
130
|
-
const TitleToSnake = (str) => DashToSnake(TitleToDash(str));
|
|
131
|
-
const TitleToUpperSnake = (str) => DashToUpperSnake(TitleToDash(str));
|
|
132
|
-
const TitleToUpperDash = (str) => DashToUpperDash(TitleToDash(str));
|
|
133
|
-
const TitleToTrain = (str) => DashToTrain(TitleToDash(str));
|
|
134
|
-
const TitleToDot = (str) => DashToDot(TitleToDash(str));
|
|
135
|
-
const TitleToSentence = (str) => DashToSentence(TitleToDash(str));
|
|
136
|
-
const SentenceToDash = (str) => Lowercase(str).replace(/( )/g, "-");
|
|
137
|
-
const SentenceToCamel = (str) => DashToCamel(SentenceToDash(str));
|
|
138
|
-
const SentenceToPascal = (str) => DashToPascal(SentenceToDash(str));
|
|
139
|
-
const SentenceToSnake = (str) => DashToSnake(SentenceToDash(str));
|
|
140
|
-
const SentenceToUpperSnake = (str) => DashToUpperSnake(SentenceToDash(str));
|
|
141
|
-
const SentenceToUpperDash = (str) => DashToUpperDash(SentenceToDash(str));
|
|
142
|
-
const SentenceToTrain = (str) => DashToTrain(SentenceToDash(str));
|
|
143
|
-
const SentenceToDot = (str) => DashToDot(SentenceToDash(str));
|
|
144
|
-
const SentenceToTitle = (str) => DashToTitle(SentenceToDash(str));
|
|
145
|
-
function parse(input, type) {
|
|
146
|
-
return {
|
|
147
|
-
CamelToDash,
|
|
148
|
-
CamelToPascal,
|
|
149
|
-
CamelToSnake,
|
|
150
|
-
CamelToUpperDash,
|
|
151
|
-
CamelToUpperSnake,
|
|
152
|
-
DashToCamel,
|
|
153
|
-
DashToSnake,
|
|
154
|
-
DashToPascal,
|
|
155
|
-
DashToUpperSnake,
|
|
156
|
-
DashToUpperDash,
|
|
157
|
-
PascalToCamel,
|
|
158
|
-
PascalToSnake,
|
|
159
|
-
PascalToDash,
|
|
160
|
-
PascalToUpperSnake,
|
|
161
|
-
PascalToUpperDash,
|
|
162
|
-
SnakeToCamel,
|
|
163
|
-
SnakeToDash,
|
|
164
|
-
SnakeToPascal,
|
|
165
|
-
SnakeToUpperSnake,
|
|
166
|
-
SnakeToUpperDash,
|
|
167
|
-
UpperSnakeToCamel,
|
|
168
|
-
UpperSnakeToSnake,
|
|
169
|
-
UpperSnakeToDash,
|
|
170
|
-
UpperSnakeToPascal,
|
|
171
|
-
UpperSnakeToUpperDash,
|
|
172
|
-
UpperDashToCamel,
|
|
173
|
-
UpperDashToSnake,
|
|
174
|
-
UpperDashToDash,
|
|
175
|
-
UpperDashToPascal,
|
|
176
|
-
UpperDashToUpperSnake,
|
|
177
|
-
CamelToTrain,
|
|
178
|
-
CamelToDot,
|
|
179
|
-
PascalToTrain,
|
|
180
|
-
PascalToDot,
|
|
181
|
-
SnakeToTrain,
|
|
182
|
-
SnakeToDot,
|
|
183
|
-
DashToTrain,
|
|
184
|
-
DashToDot,
|
|
185
|
-
UpperSnakeToTrain,
|
|
186
|
-
UpperSnakeToDot,
|
|
187
|
-
UpperDashToTrain,
|
|
188
|
-
UpperDashToDot,
|
|
189
|
-
TrainToCamel,
|
|
190
|
-
TrainToPascal,
|
|
191
|
-
TrainToSnake,
|
|
192
|
-
TrainToDash,
|
|
193
|
-
TrainToUpperSnake,
|
|
194
|
-
TrainToUpperDash,
|
|
195
|
-
TrainToDot,
|
|
196
|
-
DotToCamel,
|
|
197
|
-
DotToPascal,
|
|
198
|
-
DotToSnake,
|
|
199
|
-
DotToDash,
|
|
200
|
-
DotToUpperSnake,
|
|
201
|
-
DotToUpperDash,
|
|
202
|
-
DotToTrain,
|
|
203
|
-
CamelToTitle,
|
|
204
|
-
CamelToSentence,
|
|
205
|
-
PascalToTitle,
|
|
206
|
-
PascalToSentence,
|
|
207
|
-
SnakeToTitle,
|
|
208
|
-
SnakeToSentence,
|
|
209
|
-
DashToTitle,
|
|
210
|
-
DashToSentence,
|
|
211
|
-
UpperSnakeToTitle,
|
|
212
|
-
UpperSnakeToSentence,
|
|
213
|
-
UpperDashToTitle,
|
|
214
|
-
UpperDashToSentence,
|
|
215
|
-
TrainToTitle,
|
|
216
|
-
TrainToSentence,
|
|
217
|
-
DotToTitle,
|
|
218
|
-
DotToSentence,
|
|
219
|
-
TitleToCamel,
|
|
220
|
-
TitleToPascal,
|
|
221
|
-
TitleToSnake,
|
|
222
|
-
TitleToDash,
|
|
223
|
-
TitleToUpperSnake,
|
|
224
|
-
TitleToUpperDash,
|
|
225
|
-
TitleToTrain,
|
|
226
|
-
TitleToDot,
|
|
227
|
-
TitleToSentence,
|
|
228
|
-
SentenceToCamel,
|
|
229
|
-
SentenceToPascal,
|
|
230
|
-
SentenceToSnake,
|
|
231
|
-
SentenceToDash,
|
|
232
|
-
SentenceToUpperSnake,
|
|
233
|
-
SentenceToUpperDash,
|
|
234
|
-
SentenceToTrain,
|
|
235
|
-
SentenceToDot,
|
|
236
|
-
SentenceToTitle
|
|
237
|
-
}[type](input);
|
|
238
|
-
}
|
|
239
|
-
//#endregion
|
|
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
|
-
}
|
|
247
|
-
function converter(input, type) {
|
|
248
|
-
return convert(input, (key) => parse(key, type));
|
|
249
|
-
}
|
|
250
|
-
//#endregion
|
|
251
|
-
//#region src/camelCase/camelCase.ts
|
|
252
|
-
/**
|
|
253
|
-
* Converts a string, or the keys of an object/array (deeply), from camelCase to dash-case.
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* ```ts
|
|
257
|
-
* camelToDash('helloWorld'); // 'hello-world'
|
|
258
|
-
* camelToDash({ firstName: 'John' }); // { 'first-name': 'John' }
|
|
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).
|
|
263
|
-
*/
|
|
264
|
-
function camelToDash(input) {
|
|
265
|
-
return converter(input, "CamelToDash");
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Converts a string, or the keys of an object/array (deeply), from camelCase to snake_case.
|
|
269
|
-
*
|
|
270
|
-
* @example
|
|
271
|
-
* ```ts
|
|
272
|
-
* camelToSnake('helloWorld'); // 'hello_world'
|
|
273
|
-
* camelToSnake({ firstName: 'John' }); // { first_name: 'John' }
|
|
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).
|
|
278
|
-
*/
|
|
279
|
-
function camelToSnake(input) {
|
|
280
|
-
return converter(input, "CamelToSnake");
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Converts a string, or the keys of an object/array (deeply), from camelCase to PascalCase.
|
|
284
|
-
*
|
|
285
|
-
* @example
|
|
286
|
-
* ```ts
|
|
287
|
-
* camelToPascal('helloWorld'); // 'HelloWorld'
|
|
288
|
-
* camelToPascal({ firstName: 'John' }); // { FirstName: 'John' }
|
|
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).
|
|
293
|
-
*/
|
|
294
|
-
function camelToPascal(input) {
|
|
295
|
-
return converter(input, "CamelToPascal");
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Converts a string, or the keys of an object/array (deeply), from camelCase to UPPER_SNAKE_CASE.
|
|
299
|
-
*
|
|
300
|
-
* @example
|
|
301
|
-
* ```ts
|
|
302
|
-
* camelToUpperSnake('helloWorld'); // 'HELLO_WORLD'
|
|
303
|
-
* camelToUpperSnake({ firstName: 'John' }); // { FIRST_NAME: 'John' }
|
|
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).
|
|
308
|
-
*/
|
|
309
|
-
function camelToUpperSnake(input) {
|
|
310
|
-
return converter(input, "CamelToUpperSnake");
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Converts a string, or the keys of an object/array (deeply), from camelCase to UPPER-DASH-CASE.
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* ```ts
|
|
317
|
-
* camelToUpperDash('helloWorld'); // 'HELLO-WORLD'
|
|
318
|
-
* camelToUpperDash({ firstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
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).
|
|
323
|
-
*/
|
|
324
|
-
function camelToUpperDash(input) {
|
|
325
|
-
return converter(input, "CamelToUpperDash");
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Converts a string, or the keys of an object/array (deeply), from camelCase to Train-Case.
|
|
329
|
-
*
|
|
330
|
-
* @example
|
|
331
|
-
* ```ts
|
|
332
|
-
* camelToTrain('helloWorld'); // 'Hello-World'
|
|
333
|
-
* camelToTrain({ firstName: 'John' }); // { 'First-Name': 'John' }
|
|
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).
|
|
338
|
-
*/
|
|
339
|
-
function camelToTrain(input) {
|
|
340
|
-
return converter(input, "CamelToTrain");
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Converts a string, or the keys of an object/array (deeply), from camelCase to dot.case.
|
|
344
|
-
*
|
|
345
|
-
* @example
|
|
346
|
-
* ```ts
|
|
347
|
-
* camelToDot('helloWorld'); // 'hello.world'
|
|
348
|
-
* camelToDot({ firstName: 'John' }); // { 'first.name': 'John' }
|
|
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).
|
|
353
|
-
*/
|
|
354
|
-
function camelToDot(input) {
|
|
355
|
-
return converter(input, "CamelToDot");
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Converts a string, or the keys of an object/array (deeply), from camelCase to Title Case.
|
|
359
|
-
*
|
|
360
|
-
* @example
|
|
361
|
-
* ```ts
|
|
362
|
-
* camelToTitle('helloWorld'); // 'Hello World'
|
|
363
|
-
* camelToTitle({ firstName: 'John' }); // { 'First Name': 'John' }
|
|
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).
|
|
368
|
-
*/
|
|
369
|
-
function camelToTitle(input) {
|
|
370
|
-
return converter(input, "CamelToTitle");
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Converts a string, or the keys of an object/array (deeply), from camelCase to Sentence case.
|
|
374
|
-
*
|
|
375
|
-
* @example
|
|
376
|
-
* ```ts
|
|
377
|
-
* camelToSentence('helloWorld'); // 'Hello world'
|
|
378
|
-
* camelToSentence({ firstName: 'John' }); // { 'First name': 'John' }
|
|
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).
|
|
383
|
-
*/
|
|
384
|
-
function camelToSentence(input) {
|
|
385
|
-
return converter(input, "CamelToSentence");
|
|
386
|
-
}
|
|
387
|
-
//#endregion
|
|
388
|
-
//#region src/dashCase/dashCase.ts
|
|
389
|
-
/**
|
|
390
|
-
* Converts a string, or the keys of an object/array (deeply), from dash-case to snake_case.
|
|
391
|
-
*
|
|
392
|
-
* @example
|
|
393
|
-
* ```ts
|
|
394
|
-
* dashToSnake('hello-world'); // 'hello_world'
|
|
395
|
-
* dashToSnake({ 'first-name': 'John' }); // { first_name: 'John' }
|
|
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).
|
|
400
|
-
*/
|
|
401
|
-
function dashToSnake(input) {
|
|
402
|
-
return converter(input, "DashToSnake");
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Converts a string, or the keys of an object/array (deeply), from dash-case to camelCase.
|
|
406
|
-
*
|
|
407
|
-
* @example
|
|
408
|
-
* ```ts
|
|
409
|
-
* dashToCamel('hello-world'); // 'helloWorld'
|
|
410
|
-
* dashToCamel({ 'first-name': 'John' }); // { firstName: 'John' }
|
|
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).
|
|
415
|
-
*/
|
|
416
|
-
function dashToCamel(input) {
|
|
417
|
-
return converter(input, "DashToCamel");
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Converts a string, or the keys of an object/array (deeply), from dash-case to PascalCase.
|
|
421
|
-
*
|
|
422
|
-
* @example
|
|
423
|
-
* ```ts
|
|
424
|
-
* dashToPascal('hello-world'); // 'HelloWorld'
|
|
425
|
-
* dashToPascal({ 'first-name': 'John' }); // { FirstName: 'John' }
|
|
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).
|
|
430
|
-
*/
|
|
431
|
-
function dashToPascal(input) {
|
|
432
|
-
return converter(input, "DashToPascal");
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Converts a string, or the keys of an object/array (deeply), from dash-case to UPPER_SNAKE_CASE.
|
|
436
|
-
*
|
|
437
|
-
* @example
|
|
438
|
-
* ```ts
|
|
439
|
-
* dashToUpperSnake('hello-world'); // 'HELLO_WORLD'
|
|
440
|
-
* dashToUpperSnake({ 'first-name': 'John' }); // { FIRST_NAME: 'John' }
|
|
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).
|
|
445
|
-
*/
|
|
446
|
-
function dashToUpperSnake(input) {
|
|
447
|
-
return converter(input, "DashToUpperSnake");
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Converts a string, or the keys of an object/array (deeply), from dash-case to UPPER-DASH-CASE.
|
|
451
|
-
*
|
|
452
|
-
* @example
|
|
453
|
-
* ```ts
|
|
454
|
-
* dashToUpperDash('hello-world'); // 'HELLO-WORLD'
|
|
455
|
-
* dashToUpperDash({ 'first-name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
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).
|
|
460
|
-
*/
|
|
461
|
-
function dashToUpperDash(input) {
|
|
462
|
-
return converter(input, "DashToUpperDash");
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* Converts a string, or the keys of an object/array (deeply), from dash-case to Train-Case.
|
|
466
|
-
*
|
|
467
|
-
* @example
|
|
468
|
-
* ```ts
|
|
469
|
-
* dashToTrain('hello-world'); // 'Hello-World'
|
|
470
|
-
* dashToTrain({ 'first-name': 'John' }); // { 'First-Name': 'John' }
|
|
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).
|
|
475
|
-
*/
|
|
476
|
-
function dashToTrain(input) {
|
|
477
|
-
return converter(input, "DashToTrain");
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Converts a string, or the keys of an object/array (deeply), from dash-case to dot.case.
|
|
481
|
-
*
|
|
482
|
-
* @example
|
|
483
|
-
* ```ts
|
|
484
|
-
* dashToDot('hello-world'); // 'hello.world'
|
|
485
|
-
* dashToDot({ 'first-name': 'John' }); // { 'first.name': 'John' }
|
|
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).
|
|
490
|
-
*/
|
|
491
|
-
function dashToDot(input) {
|
|
492
|
-
return converter(input, "DashToDot");
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* Converts a string, or the keys of an object/array (deeply), from dash-case to Title Case.
|
|
496
|
-
*
|
|
497
|
-
* @example
|
|
498
|
-
* ```ts
|
|
499
|
-
* dashToTitle('hello-world'); // 'Hello World'
|
|
500
|
-
* dashToTitle({ 'first-name': 'John' }); // { 'First Name': 'John' }
|
|
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).
|
|
505
|
-
*/
|
|
506
|
-
function dashToTitle(input) {
|
|
507
|
-
return converter(input, "DashToTitle");
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Converts a string, or the keys of an object/array (deeply), from dash-case to Sentence case.
|
|
511
|
-
*
|
|
512
|
-
* @example
|
|
513
|
-
* ```ts
|
|
514
|
-
* dashToSentence('hello-world'); // 'Hello world'
|
|
515
|
-
* dashToSentence({ 'first-name': 'John' }); // { 'First name': 'John' }
|
|
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).
|
|
520
|
-
*/
|
|
521
|
-
function dashToSentence(input) {
|
|
522
|
-
return converter(input, "DashToSentence");
|
|
523
|
-
}
|
|
524
|
-
//#endregion
|
|
525
|
-
//#region src/pascalCase/pascalCase.ts
|
|
526
|
-
/**
|
|
527
|
-
* Converts a string, or the keys of an object/array (deeply), from PascalCase to camelCase.
|
|
528
|
-
*
|
|
529
|
-
* @example
|
|
530
|
-
* ```ts
|
|
531
|
-
* pascalToCamel('HelloWorld'); // 'helloWorld'
|
|
532
|
-
* pascalToCamel({ FirstName: 'John' }); // { firstName: 'John' }
|
|
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).
|
|
537
|
-
*/
|
|
538
|
-
function pascalToCamel(input) {
|
|
539
|
-
return converter(input, "PascalToCamel");
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* Converts a string, or the keys of an object/array (deeply), from PascalCase to snake_case.
|
|
543
|
-
*
|
|
544
|
-
* @example
|
|
545
|
-
* ```ts
|
|
546
|
-
* pascalToSnake('HelloWorld'); // 'hello_world'
|
|
547
|
-
* pascalToSnake({ FirstName: 'John' }); // { first_name: 'John' }
|
|
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).
|
|
552
|
-
*/
|
|
553
|
-
function pascalToSnake(input) {
|
|
554
|
-
return converter(input, "PascalToSnake");
|
|
555
|
-
}
|
|
556
|
-
/**
|
|
557
|
-
* Converts a string, or the keys of an object/array (deeply), from PascalCase to dash-case.
|
|
558
|
-
*
|
|
559
|
-
* @example
|
|
560
|
-
* ```ts
|
|
561
|
-
* pascalToDash('HelloWorld'); // 'hello-world'
|
|
562
|
-
* pascalToDash({ FirstName: 'John' }); // { 'first-name': 'John' }
|
|
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).
|
|
567
|
-
*/
|
|
568
|
-
function pascalToDash(input) {
|
|
569
|
-
return converter(input, "PascalToDash");
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* Converts a string, or the keys of an object/array (deeply), from PascalCase to UPPER_SNAKE_CASE.
|
|
573
|
-
*
|
|
574
|
-
* @example
|
|
575
|
-
* ```ts
|
|
576
|
-
* pascalToUpperSnake('HelloWorld'); // 'HELLO_WORLD'
|
|
577
|
-
* pascalToUpperSnake({ FirstName: 'John' }); // { FIRST_NAME: 'John' }
|
|
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).
|
|
582
|
-
*/
|
|
583
|
-
function pascalToUpperSnake(input) {
|
|
584
|
-
return converter(input, "PascalToUpperSnake");
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* Converts a string, or the keys of an object/array (deeply), from PascalCase to UPPER-DASH-CASE.
|
|
588
|
-
*
|
|
589
|
-
* @example
|
|
590
|
-
* ```ts
|
|
591
|
-
* pascalToUpperDash('HelloWorld'); // 'HELLO-WORLD'
|
|
592
|
-
* pascalToUpperDash({ FirstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
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).
|
|
597
|
-
*/
|
|
598
|
-
function pascalToUpperDash(input) {
|
|
599
|
-
return converter(input, "PascalToUpperDash");
|
|
600
|
-
}
|
|
601
|
-
/**
|
|
602
|
-
* Converts a string, or the keys of an object/array (deeply), from PascalCase to Train-Case.
|
|
603
|
-
*
|
|
604
|
-
* @example
|
|
605
|
-
* ```ts
|
|
606
|
-
* pascalToTrain('HelloWorld'); // 'Hello-World'
|
|
607
|
-
* pascalToTrain({ FirstName: 'John' }); // { 'First-Name': 'John' }
|
|
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).
|
|
612
|
-
*/
|
|
613
|
-
function pascalToTrain(input) {
|
|
614
|
-
return converter(input, "PascalToTrain");
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* Converts a string, or the keys of an object/array (deeply), from PascalCase to dot.case.
|
|
618
|
-
*
|
|
619
|
-
* @example
|
|
620
|
-
* ```ts
|
|
621
|
-
* pascalToDot('HelloWorld'); // 'hello.world'
|
|
622
|
-
* pascalToDot({ FirstName: 'John' }); // { 'first.name': 'John' }
|
|
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).
|
|
627
|
-
*/
|
|
628
|
-
function pascalToDot(input) {
|
|
629
|
-
return converter(input, "PascalToDot");
|
|
630
|
-
}
|
|
631
|
-
/**
|
|
632
|
-
* Converts a string, or the keys of an object/array (deeply), from PascalCase to Title Case.
|
|
633
|
-
*
|
|
634
|
-
* @example
|
|
635
|
-
* ```ts
|
|
636
|
-
* pascalToTitle('HelloWorld'); // 'Hello World'
|
|
637
|
-
* pascalToTitle({ FirstName: 'John' }); // { 'First Name': 'John' }
|
|
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).
|
|
642
|
-
*/
|
|
643
|
-
function pascalToTitle(input) {
|
|
644
|
-
return converter(input, "PascalToTitle");
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* Converts a string, or the keys of an object/array (deeply), from PascalCase to Sentence case.
|
|
648
|
-
*
|
|
649
|
-
* @example
|
|
650
|
-
* ```ts
|
|
651
|
-
* pascalToSentence('HelloWorld'); // 'Hello world'
|
|
652
|
-
* pascalToSentence({ FirstName: 'John' }); // { 'First name': 'John' }
|
|
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).
|
|
657
|
-
*/
|
|
658
|
-
function pascalToSentence(input) {
|
|
659
|
-
return converter(input, "PascalToSentence");
|
|
660
|
-
}
|
|
661
|
-
//#endregion
|
|
662
|
-
//#region src/snakeCase/snakeCase.ts
|
|
663
|
-
/**
|
|
664
|
-
* Converts a string, or the keys of an object/array (deeply), from snake_case to camelCase.
|
|
665
|
-
*
|
|
666
|
-
* @example
|
|
667
|
-
* ```ts
|
|
668
|
-
* snakeToCamel('hello_world'); // 'helloWorld'
|
|
669
|
-
* snakeToCamel({ first_name: 'John' }); // { firstName: 'John' }
|
|
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).
|
|
674
|
-
*/
|
|
675
|
-
function snakeToCamel(input) {
|
|
676
|
-
return converter(input, "SnakeToCamel");
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* Converts a string, or the keys of an object/array (deeply), from snake_case to dash-case.
|
|
680
|
-
*
|
|
681
|
-
* @example
|
|
682
|
-
* ```ts
|
|
683
|
-
* snakeToDash('hello_world'); // 'hello-world'
|
|
684
|
-
* snakeToDash({ first_name: 'John' }); // { 'first-name': 'John' }
|
|
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).
|
|
689
|
-
*/
|
|
690
|
-
function snakeToDash(input) {
|
|
691
|
-
return converter(input, "SnakeToDash");
|
|
692
|
-
}
|
|
693
|
-
/**
|
|
694
|
-
* Converts a string, or the keys of an object/array (deeply), from snake_case to PascalCase.
|
|
695
|
-
*
|
|
696
|
-
* @example
|
|
697
|
-
* ```ts
|
|
698
|
-
* snakeToPascal('hello_world'); // 'HelloWorld'
|
|
699
|
-
* snakeToPascal({ first_name: 'John' }); // { FirstName: 'John' }
|
|
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).
|
|
704
|
-
*/
|
|
705
|
-
function snakeToPascal(input) {
|
|
706
|
-
return converter(input, "SnakeToPascal");
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* Converts a string, or the keys of an object/array (deeply), from snake_case to UPPER_SNAKE_CASE.
|
|
710
|
-
*
|
|
711
|
-
* @example
|
|
712
|
-
* ```ts
|
|
713
|
-
* snakeToUpperSnake('hello_world'); // 'HELLO_WORLD'
|
|
714
|
-
* snakeToUpperSnake({ first_name: 'John' }); // { FIRST_NAME: 'John' }
|
|
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).
|
|
719
|
-
*/
|
|
720
|
-
function snakeToUpperSnake(input) {
|
|
721
|
-
return converter(input, "SnakeToUpperSnake");
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* Converts a string, or the keys of an object/array (deeply), from snake_case to UPPER-DASH-CASE.
|
|
725
|
-
*
|
|
726
|
-
* @example
|
|
727
|
-
* ```ts
|
|
728
|
-
* snakeToUpperDash('hello_world'); // 'HELLO-WORLD'
|
|
729
|
-
* snakeToUpperDash({ first_name: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
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).
|
|
734
|
-
*/
|
|
735
|
-
function snakeToUpperDash(input) {
|
|
736
|
-
return converter(input, "SnakeToUpperDash");
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* Converts a string, or the keys of an object/array (deeply), from snake_case to Train-Case.
|
|
740
|
-
*
|
|
741
|
-
* @example
|
|
742
|
-
* ```ts
|
|
743
|
-
* snakeToTrain('hello_world'); // 'Hello-World'
|
|
744
|
-
* snakeToTrain({ first_name: 'John' }); // { 'First-Name': 'John' }
|
|
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).
|
|
749
|
-
*/
|
|
750
|
-
function snakeToTrain(input) {
|
|
751
|
-
return converter(input, "SnakeToTrain");
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* Converts a string, or the keys of an object/array (deeply), from snake_case to dot.case.
|
|
755
|
-
*
|
|
756
|
-
* @example
|
|
757
|
-
* ```ts
|
|
758
|
-
* snakeToDot('hello_world'); // 'hello.world'
|
|
759
|
-
* snakeToDot({ first_name: 'John' }); // { 'first.name': 'John' }
|
|
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).
|
|
764
|
-
*/
|
|
765
|
-
function snakeToDot(input) {
|
|
766
|
-
return converter(input, "SnakeToDot");
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* Converts a string, or the keys of an object/array (deeply), from snake_case to Title Case.
|
|
770
|
-
*
|
|
771
|
-
* @example
|
|
772
|
-
* ```ts
|
|
773
|
-
* snakeToTitle('hello_world'); // 'Hello World'
|
|
774
|
-
* snakeToTitle({ first_name: 'John' }); // { 'First Name': 'John' }
|
|
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).
|
|
779
|
-
*/
|
|
780
|
-
function snakeToTitle(input) {
|
|
781
|
-
return converter(input, "SnakeToTitle");
|
|
782
|
-
}
|
|
783
|
-
/**
|
|
784
|
-
* Converts a string, or the keys of an object/array (deeply), from snake_case to Sentence case.
|
|
785
|
-
*
|
|
786
|
-
* @example
|
|
787
|
-
* ```ts
|
|
788
|
-
* snakeToSentence('hello_world'); // 'Hello world'
|
|
789
|
-
* snakeToSentence({ first_name: 'John' }); // { 'First name': 'John' }
|
|
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).
|
|
794
|
-
*/
|
|
795
|
-
function snakeToSentence(input) {
|
|
796
|
-
return converter(input, "SnakeToSentence");
|
|
797
|
-
}
|
|
798
|
-
//#endregion
|
|
799
|
-
//#region src/trainCase/trainCase.ts
|
|
800
|
-
/**
|
|
801
|
-
* Converts a string, or the keys of an object/array (deeply), from Train-Case to camelCase.
|
|
802
|
-
*
|
|
803
|
-
* @example
|
|
804
|
-
* ```ts
|
|
805
|
-
* trainToCamel('Hello-World'); // 'helloWorld'
|
|
806
|
-
* trainToCamel({ 'First-Name': 'John' }); // { firstName: 'John' }
|
|
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).
|
|
811
|
-
*/
|
|
812
|
-
function trainToCamel(input) {
|
|
813
|
-
return converter(input, "TrainToCamel");
|
|
814
|
-
}
|
|
815
|
-
/**
|
|
816
|
-
* Converts a string, or the keys of an object/array (deeply), from Train-Case to PascalCase.
|
|
817
|
-
*
|
|
818
|
-
* @example
|
|
819
|
-
* ```ts
|
|
820
|
-
* trainToPascal('Hello-World'); // 'HelloWorld'
|
|
821
|
-
* trainToPascal({ 'First-Name': 'John' }); // { FirstName: 'John' }
|
|
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).
|
|
826
|
-
*/
|
|
827
|
-
function trainToPascal(input) {
|
|
828
|
-
return converter(input, "TrainToPascal");
|
|
829
|
-
}
|
|
830
|
-
/**
|
|
831
|
-
* Converts a string, or the keys of an object/array (deeply), from Train-Case to snake_case.
|
|
832
|
-
*
|
|
833
|
-
* @example
|
|
834
|
-
* ```ts
|
|
835
|
-
* trainToSnake('Hello-World'); // 'hello_world'
|
|
836
|
-
* trainToSnake({ 'First-Name': 'John' }); // { first_name: 'John' }
|
|
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).
|
|
841
|
-
*/
|
|
842
|
-
function trainToSnake(input) {
|
|
843
|
-
return converter(input, "TrainToSnake");
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Converts a string, or the keys of an object/array (deeply), from Train-Case to dash-case.
|
|
847
|
-
*
|
|
848
|
-
* @example
|
|
849
|
-
* ```ts
|
|
850
|
-
* trainToDash('Hello-World'); // 'hello-world'
|
|
851
|
-
* trainToDash({ 'First-Name': 'John' }); // { 'first-name': 'John' }
|
|
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).
|
|
856
|
-
*/
|
|
857
|
-
function trainToDash(input) {
|
|
858
|
-
return converter(input, "TrainToDash");
|
|
859
|
-
}
|
|
860
|
-
/**
|
|
861
|
-
* Converts a string, or the keys of an object/array (deeply), from Train-Case to UPPER_SNAKE_CASE.
|
|
862
|
-
*
|
|
863
|
-
* @example
|
|
864
|
-
* ```ts
|
|
865
|
-
* trainToUpperSnake('Hello-World'); // 'HELLO_WORLD'
|
|
866
|
-
* trainToUpperSnake({ 'First-Name': 'John' }); // { FIRST_NAME: 'John' }
|
|
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).
|
|
871
|
-
*/
|
|
872
|
-
function trainToUpperSnake(input) {
|
|
873
|
-
return converter(input, "TrainToUpperSnake");
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* Converts a string, or the keys of an object/array (deeply), from Train-Case to UPPER-DASH-CASE.
|
|
877
|
-
*
|
|
878
|
-
* @example
|
|
879
|
-
* ```ts
|
|
880
|
-
* trainToUpperDash('Hello-World'); // 'HELLO-WORLD'
|
|
881
|
-
* trainToUpperDash({ 'First-Name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
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).
|
|
886
|
-
*/
|
|
887
|
-
function trainToUpperDash(input) {
|
|
888
|
-
return converter(input, "TrainToUpperDash");
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* Converts a string, or the keys of an object/array (deeply), from Train-Case to dot.case.
|
|
892
|
-
*
|
|
893
|
-
* @example
|
|
894
|
-
* ```ts
|
|
895
|
-
* trainToDot('Hello-World'); // 'hello.world'
|
|
896
|
-
* trainToDot({ 'First-Name': 'John' }); // { 'first.name': 'John' }
|
|
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).
|
|
901
|
-
*/
|
|
902
|
-
function trainToDot(input) {
|
|
903
|
-
return converter(input, "TrainToDot");
|
|
904
|
-
}
|
|
905
|
-
/**
|
|
906
|
-
* Converts a string, or the keys of an object/array (deeply), from Train-Case to Title Case.
|
|
907
|
-
*
|
|
908
|
-
* @example
|
|
909
|
-
* ```ts
|
|
910
|
-
* trainToTitle('Hello-World'); // 'Hello World'
|
|
911
|
-
* trainToTitle({ 'First-Name': 'John' }); // { 'First Name': 'John' }
|
|
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).
|
|
916
|
-
*/
|
|
917
|
-
function trainToTitle(input) {
|
|
918
|
-
return converter(input, "TrainToTitle");
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* Converts a string, or the keys of an object/array (deeply), from Train-Case to Sentence case.
|
|
922
|
-
*
|
|
923
|
-
* @example
|
|
924
|
-
* ```ts
|
|
925
|
-
* trainToSentence('Hello-World'); // 'Hello world'
|
|
926
|
-
* trainToSentence({ 'First-Name': 'John' }); // { 'First name': 'John' }
|
|
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).
|
|
931
|
-
*/
|
|
932
|
-
function trainToSentence(input) {
|
|
933
|
-
return converter(input, "TrainToSentence");
|
|
934
|
-
}
|
|
935
|
-
//#endregion
|
|
936
|
-
//#region src/dotCase/dotCase.ts
|
|
937
|
-
/**
|
|
938
|
-
* Converts a string, or the keys of an object/array (deeply), from dot.case to camelCase.
|
|
939
|
-
*
|
|
940
|
-
* @example
|
|
941
|
-
* ```ts
|
|
942
|
-
* dotToCamel('hello.world'); // 'helloWorld'
|
|
943
|
-
* dotToCamel({ 'first.name': 'John' }); // { firstName: 'John' }
|
|
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).
|
|
948
|
-
*/
|
|
949
|
-
function dotToCamel(input) {
|
|
950
|
-
return converter(input, "DotToCamel");
|
|
951
|
-
}
|
|
952
|
-
/**
|
|
953
|
-
* Converts a string, or the keys of an object/array (deeply), from dot.case to PascalCase.
|
|
954
|
-
*
|
|
955
|
-
* @example
|
|
956
|
-
* ```ts
|
|
957
|
-
* dotToPascal('hello.world'); // 'HelloWorld'
|
|
958
|
-
* dotToPascal({ 'first.name': 'John' }); // { FirstName: 'John' }
|
|
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).
|
|
963
|
-
*/
|
|
964
|
-
function dotToPascal(input) {
|
|
965
|
-
return converter(input, "DotToPascal");
|
|
966
|
-
}
|
|
967
|
-
/**
|
|
968
|
-
* Converts a string, or the keys of an object/array (deeply), from dot.case to snake_case.
|
|
969
|
-
*
|
|
970
|
-
* @example
|
|
971
|
-
* ```ts
|
|
972
|
-
* dotToSnake('hello.world'); // 'hello_world'
|
|
973
|
-
* dotToSnake({ 'first.name': 'John' }); // { first_name: 'John' }
|
|
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).
|
|
978
|
-
*/
|
|
979
|
-
function dotToSnake(input) {
|
|
980
|
-
return converter(input, "DotToSnake");
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
* Converts a string, or the keys of an object/array (deeply), from dot.case to dash-case.
|
|
984
|
-
*
|
|
985
|
-
* @example
|
|
986
|
-
* ```ts
|
|
987
|
-
* dotToDash('hello.world'); // 'hello-world'
|
|
988
|
-
* dotToDash({ 'first.name': 'John' }); // { 'first-name': 'John' }
|
|
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).
|
|
993
|
-
*/
|
|
994
|
-
function dotToDash(input) {
|
|
995
|
-
return converter(input, "DotToDash");
|
|
996
|
-
}
|
|
997
|
-
/**
|
|
998
|
-
* Converts a string, or the keys of an object/array (deeply), from dot.case to UPPER_SNAKE_CASE.
|
|
999
|
-
*
|
|
1000
|
-
* @example
|
|
1001
|
-
* ```ts
|
|
1002
|
-
* dotToUpperSnake('hello.world'); // 'HELLO_WORLD'
|
|
1003
|
-
* dotToUpperSnake({ 'first.name': 'John' }); // { FIRST_NAME: 'John' }
|
|
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).
|
|
1008
|
-
*/
|
|
1009
|
-
function dotToUpperSnake(input) {
|
|
1010
|
-
return converter(input, "DotToUpperSnake");
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Converts a string, or the keys of an object/array (deeply), from dot.case to UPPER-DASH-CASE.
|
|
1014
|
-
*
|
|
1015
|
-
* @example
|
|
1016
|
-
* ```ts
|
|
1017
|
-
* dotToUpperDash('hello.world'); // 'HELLO-WORLD'
|
|
1018
|
-
* dotToUpperDash({ 'first.name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
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).
|
|
1023
|
-
*/
|
|
1024
|
-
function dotToUpperDash(input) {
|
|
1025
|
-
return converter(input, "DotToUpperDash");
|
|
1026
|
-
}
|
|
1027
|
-
/**
|
|
1028
|
-
* Converts a string, or the keys of an object/array (deeply), from dot.case to Train-Case.
|
|
1029
|
-
*
|
|
1030
|
-
* @example
|
|
1031
|
-
* ```ts
|
|
1032
|
-
* dotToTrain('hello.world'); // 'Hello-World'
|
|
1033
|
-
* dotToTrain({ 'first.name': 'John' }); // { 'First-Name': 'John' }
|
|
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).
|
|
1038
|
-
*/
|
|
1039
|
-
function dotToTrain(input) {
|
|
1040
|
-
return converter(input, "DotToTrain");
|
|
1041
|
-
}
|
|
1042
|
-
/**
|
|
1043
|
-
* Converts a string, or the keys of an object/array (deeply), from dot.case to Title Case.
|
|
1044
|
-
*
|
|
1045
|
-
* @example
|
|
1046
|
-
* ```ts
|
|
1047
|
-
* dotToTitle('hello.world'); // 'Hello World'
|
|
1048
|
-
* dotToTitle({ 'first.name': 'John' }); // { 'First Name': 'John' }
|
|
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).
|
|
1053
|
-
*/
|
|
1054
|
-
function dotToTitle(input) {
|
|
1055
|
-
return converter(input, "DotToTitle");
|
|
1056
|
-
}
|
|
1057
|
-
/**
|
|
1058
|
-
* Converts a string, or the keys of an object/array (deeply), from dot.case to Sentence case.
|
|
1059
|
-
*
|
|
1060
|
-
* @example
|
|
1061
|
-
* ```ts
|
|
1062
|
-
* dotToSentence('hello.world'); // 'Hello world'
|
|
1063
|
-
* dotToSentence({ 'first.name': 'John' }); // { 'First name': 'John' }
|
|
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).
|
|
1068
|
-
*/
|
|
1069
|
-
function dotToSentence(input) {
|
|
1070
|
-
return converter(input, "DotToSentence");
|
|
1071
|
-
}
|
|
1072
|
-
//#endregion
|
|
1073
|
-
//#region src/titleCase/titleCase.ts
|
|
1074
|
-
/**
|
|
1075
|
-
* Converts a string, or the keys of an object/array (deeply), from Title Case to camelCase.
|
|
1076
|
-
*
|
|
1077
|
-
* @example
|
|
1078
|
-
* ```ts
|
|
1079
|
-
* titleToCamel('Hello World'); // 'helloWorld'
|
|
1080
|
-
* titleToCamel({ 'First Name': 'John' }); // { firstName: 'John' }
|
|
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).
|
|
1085
|
-
*/
|
|
1086
|
-
function titleToCamel(input) {
|
|
1087
|
-
return converter(input, "TitleToCamel");
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* Converts a string, or the keys of an object/array (deeply), from Title Case to PascalCase.
|
|
1091
|
-
*
|
|
1092
|
-
* @example
|
|
1093
|
-
* ```ts
|
|
1094
|
-
* titleToPascal('Hello World'); // 'HelloWorld'
|
|
1095
|
-
* titleToPascal({ 'First Name': 'John' }); // { FirstName: 'John' }
|
|
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).
|
|
1100
|
-
*/
|
|
1101
|
-
function titleToPascal(input) {
|
|
1102
|
-
return converter(input, "TitleToPascal");
|
|
1103
|
-
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Converts a string, or the keys of an object/array (deeply), from Title Case to snake_case.
|
|
1106
|
-
*
|
|
1107
|
-
* @example
|
|
1108
|
-
* ```ts
|
|
1109
|
-
* titleToSnake('Hello World'); // 'hello_world'
|
|
1110
|
-
* titleToSnake({ 'First Name': 'John' }); // { first_name: 'John' }
|
|
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).
|
|
1115
|
-
*/
|
|
1116
|
-
function titleToSnake(input) {
|
|
1117
|
-
return converter(input, "TitleToSnake");
|
|
1118
|
-
}
|
|
1119
|
-
/**
|
|
1120
|
-
* Converts a string, or the keys of an object/array (deeply), from Title Case to dash-case.
|
|
1121
|
-
*
|
|
1122
|
-
* @example
|
|
1123
|
-
* ```ts
|
|
1124
|
-
* titleToDash('Hello World'); // 'hello-world'
|
|
1125
|
-
* titleToDash({ 'First Name': 'John' }); // { 'first-name': 'John' }
|
|
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).
|
|
1130
|
-
*/
|
|
1131
|
-
function titleToDash(input) {
|
|
1132
|
-
return converter(input, "TitleToDash");
|
|
1133
|
-
}
|
|
1134
|
-
/**
|
|
1135
|
-
* Converts a string, or the keys of an object/array (deeply), from Title Case to UPPER_SNAKE_CASE.
|
|
1136
|
-
*
|
|
1137
|
-
* @example
|
|
1138
|
-
* ```ts
|
|
1139
|
-
* titleToUpperSnake('Hello World'); // 'HELLO_WORLD'
|
|
1140
|
-
* titleToUpperSnake({ 'First Name': 'John' }); // { FIRST_NAME: 'John' }
|
|
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).
|
|
1145
|
-
*/
|
|
1146
|
-
function titleToUpperSnake(input) {
|
|
1147
|
-
return converter(input, "TitleToUpperSnake");
|
|
1148
|
-
}
|
|
1149
|
-
/**
|
|
1150
|
-
* Converts a string, or the keys of an object/array (deeply), from Title Case to UPPER-DASH-CASE.
|
|
1151
|
-
*
|
|
1152
|
-
* @example
|
|
1153
|
-
* ```ts
|
|
1154
|
-
* titleToUpperDash('Hello World'); // 'HELLO-WORLD'
|
|
1155
|
-
* titleToUpperDash({ 'First Name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
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).
|
|
1160
|
-
*/
|
|
1161
|
-
function titleToUpperDash(input) {
|
|
1162
|
-
return converter(input, "TitleToUpperDash");
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* Converts a string, or the keys of an object/array (deeply), from Title Case to Train-Case.
|
|
1166
|
-
*
|
|
1167
|
-
* @example
|
|
1168
|
-
* ```ts
|
|
1169
|
-
* titleToTrain('Hello World'); // 'Hello-World'
|
|
1170
|
-
* titleToTrain({ 'First Name': 'John' }); // { 'First-Name': 'John' }
|
|
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).
|
|
1175
|
-
*/
|
|
1176
|
-
function titleToTrain(input) {
|
|
1177
|
-
return converter(input, "TitleToTrain");
|
|
1178
|
-
}
|
|
1179
|
-
/**
|
|
1180
|
-
* Converts a string, or the keys of an object/array (deeply), from Title Case to dot.case.
|
|
1181
|
-
*
|
|
1182
|
-
* @example
|
|
1183
|
-
* ```ts
|
|
1184
|
-
* titleToDot('Hello World'); // 'hello.world'
|
|
1185
|
-
* titleToDot({ 'First Name': 'John' }); // { 'first.name': 'John' }
|
|
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).
|
|
1190
|
-
*/
|
|
1191
|
-
function titleToDot(input) {
|
|
1192
|
-
return converter(input, "TitleToDot");
|
|
1193
|
-
}
|
|
1194
|
-
/**
|
|
1195
|
-
* Converts a string, or the keys of an object/array (deeply), from Title Case to Sentence case.
|
|
1196
|
-
*
|
|
1197
|
-
* @example
|
|
1198
|
-
* ```ts
|
|
1199
|
-
* titleToSentence('Hello World'); // 'Hello world'
|
|
1200
|
-
* titleToSentence({ 'First Name': 'John' }); // { 'First name': 'John' }
|
|
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).
|
|
1205
|
-
*/
|
|
1206
|
-
function titleToSentence(input) {
|
|
1207
|
-
return converter(input, "TitleToSentence");
|
|
1208
|
-
}
|
|
1209
14
|
//#endregion
|
|
1210
|
-
//#region src/
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
* so results differ for keys like `userID` (see the migration notes in the README).
|
|
1237
|
-
*/
|
|
1238
|
-
function sentenceToPascal(input) {
|
|
1239
|
-
return converter(input, "SentenceToPascal");
|
|
1240
|
-
}
|
|
1241
|
-
/**
|
|
1242
|
-
* Converts a string, or the keys of an object/array (deeply), from Sentence case to snake_case.
|
|
1243
|
-
*
|
|
1244
|
-
* @example
|
|
1245
|
-
* ```ts
|
|
1246
|
-
* sentenceToSnake('Hello world'); // 'hello_world'
|
|
1247
|
-
* sentenceToSnake({ 'First name': 'John' }); // { first_name: 'John' }
|
|
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).
|
|
1252
|
-
*/
|
|
1253
|
-
function sentenceToSnake(input) {
|
|
1254
|
-
return converter(input, "SentenceToSnake");
|
|
1255
|
-
}
|
|
1256
|
-
/**
|
|
1257
|
-
* Converts a string, or the keys of an object/array (deeply), from Sentence case to dash-case.
|
|
1258
|
-
*
|
|
1259
|
-
* @example
|
|
1260
|
-
* ```ts
|
|
1261
|
-
* sentenceToDash('Hello world'); // 'hello-world'
|
|
1262
|
-
* sentenceToDash({ 'First name': 'John' }); // { 'first-name': 'John' }
|
|
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).
|
|
1267
|
-
*/
|
|
1268
|
-
function sentenceToDash(input) {
|
|
1269
|
-
return converter(input, "SentenceToDash");
|
|
1270
|
-
}
|
|
1271
|
-
/**
|
|
1272
|
-
* Converts a string, or the keys of an object/array (deeply), from Sentence case to UPPER_SNAKE_CASE.
|
|
1273
|
-
*
|
|
1274
|
-
* @example
|
|
1275
|
-
* ```ts
|
|
1276
|
-
* sentenceToUpperSnake('Hello world'); // 'HELLO_WORLD'
|
|
1277
|
-
* sentenceToUpperSnake({ 'First name': 'John' }); // { FIRST_NAME: 'John' }
|
|
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).
|
|
1282
|
-
*/
|
|
1283
|
-
function sentenceToUpperSnake(input) {
|
|
1284
|
-
return converter(input, "SentenceToUpperSnake");
|
|
1285
|
-
}
|
|
1286
|
-
/**
|
|
1287
|
-
* Converts a string, or the keys of an object/array (deeply), from Sentence case to UPPER-DASH-CASE.
|
|
1288
|
-
*
|
|
1289
|
-
* @example
|
|
1290
|
-
* ```ts
|
|
1291
|
-
* sentenceToUpperDash('Hello world'); // 'HELLO-WORLD'
|
|
1292
|
-
* sentenceToUpperDash({ 'First name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
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).
|
|
1297
|
-
*/
|
|
1298
|
-
function sentenceToUpperDash(input) {
|
|
1299
|
-
return converter(input, "SentenceToUpperDash");
|
|
1300
|
-
}
|
|
1301
|
-
/**
|
|
1302
|
-
* Converts a string, or the keys of an object/array (deeply), from Sentence case to Train-Case.
|
|
1303
|
-
*
|
|
1304
|
-
* @example
|
|
1305
|
-
* ```ts
|
|
1306
|
-
* sentenceToTrain('Hello world'); // 'Hello-World'
|
|
1307
|
-
* sentenceToTrain({ 'First name': 'John' }); // { 'First-Name': 'John' }
|
|
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).
|
|
1312
|
-
*/
|
|
1313
|
-
function sentenceToTrain(input) {
|
|
1314
|
-
return converter(input, "SentenceToTrain");
|
|
1315
|
-
}
|
|
1316
|
-
/**
|
|
1317
|
-
* Converts a string, or the keys of an object/array (deeply), from Sentence case to dot.case.
|
|
1318
|
-
*
|
|
1319
|
-
* @example
|
|
1320
|
-
* ```ts
|
|
1321
|
-
* sentenceToDot('Hello world'); // 'hello.world'
|
|
1322
|
-
* sentenceToDot({ 'First name': 'John' }); // { 'first.name': 'John' }
|
|
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).
|
|
1327
|
-
*/
|
|
1328
|
-
function sentenceToDot(input) {
|
|
1329
|
-
return converter(input, "SentenceToDot");
|
|
1330
|
-
}
|
|
1331
|
-
/**
|
|
1332
|
-
* Converts a string, or the keys of an object/array (deeply), from Sentence case to Title Case.
|
|
1333
|
-
*
|
|
1334
|
-
* @example
|
|
1335
|
-
* ```ts
|
|
1336
|
-
* sentenceToTitle('Hello world'); // 'Hello World'
|
|
1337
|
-
* sentenceToTitle({ 'First name': 'John' }); // { 'First Name': 'John' }
|
|
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).
|
|
1342
|
-
*/
|
|
1343
|
-
function sentenceToTitle(input) {
|
|
1344
|
-
return converter(input, "SentenceToTitle");
|
|
15
|
+
//#region src/parser/objectParser.ts
|
|
16
|
+
function objectParser(input, context) {
|
|
17
|
+
const result = {};
|
|
18
|
+
const keys = Object.keys(input);
|
|
19
|
+
for (let i = 0; i < keys.length; i++) {
|
|
20
|
+
const key = keys[i];
|
|
21
|
+
const { cache } = context;
|
|
22
|
+
let parsedKey = cache === null || cache === void 0 ? void 0 : cache.get(key);
|
|
23
|
+
if (parsedKey === void 0) {
|
|
24
|
+
parsedKey = context.convertKey(key);
|
|
25
|
+
cache === null || cache === void 0 || cache.set(key, parsedKey);
|
|
26
|
+
}
|
|
27
|
+
let value = input[key];
|
|
28
|
+
if (typeof value === "object" && value !== null) {
|
|
29
|
+
if (Array.isArray(value)) value = arrayParser(value, context);
|
|
30
|
+
else if (isObject(value)) value = objectParser(value, context);
|
|
31
|
+
}
|
|
32
|
+
if (parsedKey === "__proto__") Object.defineProperty(result, parsedKey, {
|
|
33
|
+
value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
configurable: true
|
|
37
|
+
});
|
|
38
|
+
else result[parsedKey] = value;
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
1345
41
|
}
|
|
1346
42
|
//#endregion
|
|
1347
|
-
//#region src/
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
function upperDashToCamel(input) {
|
|
1361
|
-
return converter(input, "UpperDashToCamel");
|
|
1362
|
-
}
|
|
1363
|
-
/**
|
|
1364
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to snake_case.
|
|
1365
|
-
*
|
|
1366
|
-
* @example
|
|
1367
|
-
* ```ts
|
|
1368
|
-
* upperDashToSnake('HELLO-WORLD'); // 'hello_world'
|
|
1369
|
-
* upperDashToSnake({ 'FIRST-NAME': 'John' }); // { first_name: 'John' }
|
|
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).
|
|
1374
|
-
*/
|
|
1375
|
-
function upperDashToSnake(input) {
|
|
1376
|
-
return converter(input, "UpperDashToSnake");
|
|
1377
|
-
}
|
|
1378
|
-
/**
|
|
1379
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to dash-case.
|
|
1380
|
-
*
|
|
1381
|
-
* @example
|
|
1382
|
-
* ```ts
|
|
1383
|
-
* upperDashToDash('HELLO-WORLD'); // 'hello-world'
|
|
1384
|
-
* upperDashToDash({ 'FIRST-NAME': 'John' }); // { 'first-name': 'John' }
|
|
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).
|
|
1389
|
-
*/
|
|
1390
|
-
function upperDashToDash(input) {
|
|
1391
|
-
return converter(input, "UpperDashToDash");
|
|
1392
|
-
}
|
|
1393
|
-
/**
|
|
1394
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to PascalCase.
|
|
1395
|
-
*
|
|
1396
|
-
* @example
|
|
1397
|
-
* ```ts
|
|
1398
|
-
* upperDashToPascal('HELLO-WORLD'); // 'HelloWorld'
|
|
1399
|
-
* upperDashToPascal({ 'FIRST-NAME': 'John' }); // { FirstName: 'John' }
|
|
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).
|
|
1404
|
-
*/
|
|
1405
|
-
function upperDashToPascal(input) {
|
|
1406
|
-
return converter(input, "UpperDashToPascal");
|
|
1407
|
-
}
|
|
1408
|
-
/**
|
|
1409
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to UPPER_SNAKE_CASE.
|
|
1410
|
-
*
|
|
1411
|
-
* @example
|
|
1412
|
-
* ```ts
|
|
1413
|
-
* upperDashToUpperSnake('HELLO-WORLD'); // 'HELLO_WORLD'
|
|
1414
|
-
* upperDashToUpperSnake({ 'FIRST-NAME': 'John' }); // { FIRST_NAME: 'John' }
|
|
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).
|
|
1419
|
-
*/
|
|
1420
|
-
function upperDashToUpperSnake(input) {
|
|
1421
|
-
return converter(input, "UpperDashToUpperSnake");
|
|
1422
|
-
}
|
|
1423
|
-
/**
|
|
1424
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to Train-Case.
|
|
1425
|
-
*
|
|
1426
|
-
* @example
|
|
1427
|
-
* ```ts
|
|
1428
|
-
* upperDashToTrain('HELLO-WORLD'); // 'Hello-World'
|
|
1429
|
-
* upperDashToTrain({ 'FIRST-NAME': 'John' }); // { 'First-Name': 'John' }
|
|
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).
|
|
1434
|
-
*/
|
|
1435
|
-
function upperDashToTrain(input) {
|
|
1436
|
-
return converter(input, "UpperDashToTrain");
|
|
1437
|
-
}
|
|
1438
|
-
/**
|
|
1439
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to dot.case.
|
|
1440
|
-
*
|
|
1441
|
-
* @example
|
|
1442
|
-
* ```ts
|
|
1443
|
-
* upperDashToDot('HELLO-WORLD'); // 'hello.world'
|
|
1444
|
-
* upperDashToDot({ 'FIRST-NAME': 'John' }); // { 'first.name': 'John' }
|
|
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).
|
|
1449
|
-
*/
|
|
1450
|
-
function upperDashToDot(input) {
|
|
1451
|
-
return converter(input, "UpperDashToDot");
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to Title Case.
|
|
1455
|
-
*
|
|
1456
|
-
* @example
|
|
1457
|
-
* ```ts
|
|
1458
|
-
* upperDashToTitle('HELLO-WORLD'); // 'Hello World'
|
|
1459
|
-
* upperDashToTitle({ 'FIRST-NAME': 'John' }); // { 'First Name': 'John' }
|
|
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).
|
|
1464
|
-
*/
|
|
1465
|
-
function upperDashToTitle(input) {
|
|
1466
|
-
return converter(input, "UpperDashToTitle");
|
|
1467
|
-
}
|
|
1468
|
-
/**
|
|
1469
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to Sentence case.
|
|
1470
|
-
*
|
|
1471
|
-
* @example
|
|
1472
|
-
* ```ts
|
|
1473
|
-
* upperDashToSentence('HELLO-WORLD'); // 'Hello world'
|
|
1474
|
-
* upperDashToSentence({ 'FIRST-NAME': 'John' }); // { 'First name': 'John' }
|
|
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).
|
|
1479
|
-
*/
|
|
1480
|
-
function upperDashToSentence(input) {
|
|
1481
|
-
return converter(input, "UpperDashToSentence");
|
|
43
|
+
//#region src/parser/arrayParser.ts
|
|
44
|
+
function arrayParser(input, context) {
|
|
45
|
+
if (!context.cache) context.cache = /* @__PURE__ */ new Map();
|
|
46
|
+
const length = input.length;
|
|
47
|
+
const result = new Array(length);
|
|
48
|
+
for (let i = 0; i < length; i++) {
|
|
49
|
+
const item = input[i];
|
|
50
|
+
if (typeof item === "object" && item !== null) {
|
|
51
|
+
if (Array.isArray(item)) result[i] = arrayParser(item, context);
|
|
52
|
+
else result[i] = isObject(item) ? objectParser(item, context) : item;
|
|
53
|
+
} else result[i] = item;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
1482
56
|
}
|
|
1483
57
|
//#endregion
|
|
1484
|
-
//#region src/
|
|
1485
|
-
/**
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
*/
|
|
1497
|
-
function upperSnakeToCamel(input) {
|
|
1498
|
-
return converter(input, "UpperSnakeToCamel");
|
|
1499
|
-
}
|
|
1500
|
-
/**
|
|
1501
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to snake_case.
|
|
1502
|
-
*
|
|
1503
|
-
* @example
|
|
1504
|
-
* ```ts
|
|
1505
|
-
* upperSnakeToSnake('HELLO_WORLD'); // 'hello_world'
|
|
1506
|
-
* upperSnakeToSnake({ FIRST_NAME: 'John' }); // { first_name: 'John' }
|
|
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).
|
|
1511
|
-
*/
|
|
1512
|
-
function upperSnakeToSnake(input) {
|
|
1513
|
-
return converter(input, "UpperSnakeToSnake");
|
|
1514
|
-
}
|
|
1515
|
-
/**
|
|
1516
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to dash-case.
|
|
1517
|
-
*
|
|
1518
|
-
* @example
|
|
1519
|
-
* ```ts
|
|
1520
|
-
* upperSnakeToDash('HELLO_WORLD'); // 'hello-world'
|
|
1521
|
-
* upperSnakeToDash({ FIRST_NAME: 'John' }); // { 'first-name': 'John' }
|
|
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).
|
|
1526
|
-
*/
|
|
1527
|
-
function upperSnakeToDash(input) {
|
|
1528
|
-
return converter(input, "UpperSnakeToDash");
|
|
1529
|
-
}
|
|
1530
|
-
/**
|
|
1531
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to PascalCase.
|
|
1532
|
-
*
|
|
1533
|
-
* @example
|
|
1534
|
-
* ```ts
|
|
1535
|
-
* upperSnakeToPascal('HELLO_WORLD'); // 'HelloWorld'
|
|
1536
|
-
* upperSnakeToPascal({ FIRST_NAME: 'John' }); // { FirstName: 'John' }
|
|
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).
|
|
1541
|
-
*/
|
|
1542
|
-
function upperSnakeToPascal(input) {
|
|
1543
|
-
return converter(input, "UpperSnakeToPascal");
|
|
1544
|
-
}
|
|
1545
|
-
/**
|
|
1546
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to UPPER-DASH-CASE.
|
|
1547
|
-
*
|
|
1548
|
-
* @example
|
|
1549
|
-
* ```ts
|
|
1550
|
-
* upperSnakeToUpperDash('HELLO_WORLD'); // 'HELLO-WORLD'
|
|
1551
|
-
* upperSnakeToUpperDash({ FIRST_NAME: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
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).
|
|
1556
|
-
*/
|
|
1557
|
-
function upperSnakeToUpperDash(input) {
|
|
1558
|
-
return converter(input, "UpperSnakeToUpperDash");
|
|
1559
|
-
}
|
|
1560
|
-
/**
|
|
1561
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to Train-Case.
|
|
1562
|
-
*
|
|
1563
|
-
* @example
|
|
1564
|
-
* ```ts
|
|
1565
|
-
* upperSnakeToTrain('HELLO_WORLD'); // 'Hello-World'
|
|
1566
|
-
* upperSnakeToTrain({ FIRST_NAME: 'John' }); // { 'First-Name': 'John' }
|
|
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).
|
|
1571
|
-
*/
|
|
1572
|
-
function upperSnakeToTrain(input) {
|
|
1573
|
-
return converter(input, "UpperSnakeToTrain");
|
|
1574
|
-
}
|
|
1575
|
-
/**
|
|
1576
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to dot.case.
|
|
1577
|
-
*
|
|
1578
|
-
* @example
|
|
1579
|
-
* ```ts
|
|
1580
|
-
* upperSnakeToDot('HELLO_WORLD'); // 'hello.world'
|
|
1581
|
-
* upperSnakeToDot({ FIRST_NAME: 'John' }); // { 'first.name': 'John' }
|
|
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).
|
|
1586
|
-
*/
|
|
1587
|
-
function upperSnakeToDot(input) {
|
|
1588
|
-
return converter(input, "UpperSnakeToDot");
|
|
1589
|
-
}
|
|
1590
|
-
/**
|
|
1591
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to Title Case.
|
|
1592
|
-
*
|
|
1593
|
-
* @example
|
|
1594
|
-
* ```ts
|
|
1595
|
-
* upperSnakeToTitle('HELLO_WORLD'); // 'Hello World'
|
|
1596
|
-
* upperSnakeToTitle({ FIRST_NAME: 'John' }); // { 'First Name': 'John' }
|
|
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).
|
|
1601
|
-
*/
|
|
1602
|
-
function upperSnakeToTitle(input) {
|
|
1603
|
-
return converter(input, "UpperSnakeToTitle");
|
|
1604
|
-
}
|
|
1605
|
-
/**
|
|
1606
|
-
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to Sentence case.
|
|
1607
|
-
*
|
|
1608
|
-
* @example
|
|
1609
|
-
* ```ts
|
|
1610
|
-
* upperSnakeToSentence('HELLO_WORLD'); // 'Hello world'
|
|
1611
|
-
* upperSnakeToSentence({ FIRST_NAME: 'John' }); // { 'First name': 'John' }
|
|
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).
|
|
1616
|
-
*/
|
|
1617
|
-
function upperSnakeToSentence(input) {
|
|
1618
|
-
return converter(input, "UpperSnakeToSentence");
|
|
58
|
+
//#region src/parser/parser.ts
|
|
59
|
+
/** Converts a string, or the keys of an object/array (deeply), with `convertKey`. Keys in `ignore` are kept as they are. */
|
|
60
|
+
function convert(input, convertKey, ignore) {
|
|
61
|
+
if (isString(input)) return convertKey(input);
|
|
62
|
+
const array = isArray(input);
|
|
63
|
+
if (!array && !isObject(input)) return void 0;
|
|
64
|
+
const context = { convertKey };
|
|
65
|
+
if (ignore) {
|
|
66
|
+
context.cache = /* @__PURE__ */ new Map();
|
|
67
|
+
for (const key of ignore) context.cache.set(key, key);
|
|
68
|
+
}
|
|
69
|
+
return array ? arrayParser(input, context) : objectParser(input, context);
|
|
1619
70
|
}
|
|
1620
71
|
//#endregion
|
|
1621
72
|
//#region src/anyCase/words.ts
|
|
1622
73
|
const SYMBOLS = "!\"#$%&'()*+,/:;<=>?@[\\]^`{|}~";
|
|
1623
|
-
const
|
|
1624
|
-
const
|
|
1625
|
-
const
|
|
1626
|
-
const
|
|
1627
|
-
const
|
|
74
|
+
const OTHER = 0;
|
|
75
|
+
const SEPARATOR = 1;
|
|
76
|
+
const SYMBOL = 2;
|
|
77
|
+
const UPPER = 3;
|
|
78
|
+
const LOWER = 4;
|
|
79
|
+
const KINDS = /* @__PURE__ */ new Uint8Array(128);
|
|
80
|
+
for (let code = 65; code <= 90; code++) KINDS[code] = UPPER;
|
|
81
|
+
for (let code = 97; code <= 122; code++) KINDS[code] = LOWER;
|
|
82
|
+
for (let i = 0; i < 29; i++) KINDS[SYMBOLS.charCodeAt(i)] = SYMBOL;
|
|
83
|
+
for (const separator of "_-. ") KINDS[separator.charCodeAt(0)] = SEPARATOR;
|
|
84
|
+
const PATH_KINDS = KINDS.slice();
|
|
85
|
+
PATH_KINDS[47] = SEPARATOR;
|
|
86
|
+
PATH_KINDS[92] = SEPARATOR;
|
|
87
|
+
function kindAt(str, i, kinds) {
|
|
88
|
+
const code = str.charCodeAt(i);
|
|
89
|
+
if (code < 128) return kinds[code];
|
|
90
|
+
const c = str[i];
|
|
91
|
+
if (c !== c.toLowerCase()) return UPPER;
|
|
92
|
+
return c !== c.toUpperCase() ? LOWER : OTHER;
|
|
93
|
+
}
|
|
94
|
+
function isLowerAt(str, i) {
|
|
95
|
+
if (i >= str.length) return false;
|
|
96
|
+
const code = str.charCodeAt(i);
|
|
97
|
+
if (code < 128) return KINDS[code] === LOWER;
|
|
98
|
+
const c = str[i];
|
|
99
|
+
return c !== c.toUpperCase();
|
|
100
|
+
}
|
|
101
|
+
function toKeep(allowSymbols) {
|
|
102
|
+
if (allowSymbols === true) return true;
|
|
103
|
+
if (!allowSymbols) return false;
|
|
104
|
+
const table = /* @__PURE__ */ new Uint8Array(128);
|
|
105
|
+
for (let i = 0; i < 29; i++) if (allowSymbols.indexOf(SYMBOLS[i]) !== -1) table[SYMBOLS.charCodeAt(i)] = 1;
|
|
106
|
+
return table;
|
|
107
|
+
}
|
|
108
|
+
const NONE = 0;
|
|
109
|
+
const PREV_UPPER = 1;
|
|
110
|
+
const PREV_OTHER = 2;
|
|
111
|
+
const HAS_UPPER = 1;
|
|
112
|
+
const HAS_NON_ASCII = 2;
|
|
113
|
+
function toCase(word, flags, wordCase) {
|
|
114
|
+
if (wordCase === "lower") return flags === 0 ? word : word.toLowerCase();
|
|
115
|
+
if (wordCase === "upper") return flags & HAS_NON_ASCII ? word.toLowerCase().toUpperCase() : word.toUpperCase();
|
|
116
|
+
return word;
|
|
117
|
+
}
|
|
1628
118
|
/**
|
|
1629
119
|
* Splits a string in any case into lowercase words: on `_`, `-`, `.` and spaces,
|
|
1630
120
|
* before an uppercase letter that follows a lowercase letter or a digit (`helloWorld`),
|
|
@@ -1633,371 +123,179 @@ const isKept = (c, keep) => keep === true || typeof keep !== "boolean" && keep !
|
|
|
1633
123
|
* Symbols (ASCII punctuation) also start a new word. They are removed, unless `keep` is
|
|
1634
124
|
* `true` or lists them: a kept symbol sticks to the start of the next word (`hello$World`
|
|
1635
125
|
* → `hello`, `$world`), or to the end of the previous one when no word follows (`total%`).
|
|
1636
|
-
* Words keep their original case when
|
|
126
|
+
* Words are uppercased when `wordCase` is `'upper'`, and keep their original case when it's `'keep'`.
|
|
1637
127
|
*/
|
|
1638
|
-
function words(str, keep = false,
|
|
128
|
+
function words(str, keep = false, wordCase = "lower", path = false) {
|
|
129
|
+
const kinds = path ? PATH_KINDS : KINDS;
|
|
130
|
+
const length = str.length;
|
|
1639
131
|
const result = [];
|
|
1640
|
-
let
|
|
1641
|
-
let
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
132
|
+
let start = 0;
|
|
133
|
+
let prefix = "";
|
|
134
|
+
let flags = 0;
|
|
135
|
+
let prev = NONE;
|
|
136
|
+
for (let i = 0; i < length; i++) {
|
|
137
|
+
const kind = kindAt(str, i, kinds);
|
|
138
|
+
if (kind === SEPARATOR) {
|
|
139
|
+
if (i > start || prefix) result.push(toCase(prefix + str.slice(start, i), flags, wordCase));
|
|
140
|
+
start = i + 1;
|
|
141
|
+
prefix = "";
|
|
142
|
+
flags = 0;
|
|
143
|
+
prev = NONE;
|
|
1651
144
|
continue;
|
|
1652
145
|
}
|
|
1653
|
-
if (
|
|
146
|
+
if (kind === SYMBOL) {
|
|
1654
147
|
let kept = "";
|
|
1655
148
|
let j = i;
|
|
1656
|
-
for (; j <
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
prev = "";
|
|
149
|
+
for (; j < length; j++) {
|
|
150
|
+
const code = str.charCodeAt(j);
|
|
151
|
+
if (code >= 128 || kinds[code] !== SYMBOL) break;
|
|
152
|
+
if (keep === true || keep !== false && keep[code] === 1) kept += str[j];
|
|
1661
153
|
}
|
|
1662
|
-
word
|
|
154
|
+
const word = prefix + str.slice(start, i);
|
|
155
|
+
if (j < length && kinds[str.charCodeAt(j)] !== SEPARATOR) {
|
|
156
|
+
if (word) result.push(toCase(word, flags, wordCase));
|
|
157
|
+
prefix = kept;
|
|
158
|
+
prev = NONE;
|
|
159
|
+
} else if (word || kept) {
|
|
160
|
+
result.push(toCase(word + kept, flags, wordCase));
|
|
161
|
+
prefix = "";
|
|
162
|
+
}
|
|
163
|
+
flags = 0;
|
|
164
|
+
start = j;
|
|
1663
165
|
i = j - 1;
|
|
1664
166
|
continue;
|
|
1665
167
|
}
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
168
|
+
if (kind === UPPER) {
|
|
169
|
+
if (prev !== NONE && (prev !== PREV_UPPER || isLowerAt(str, i + 1))) {
|
|
170
|
+
const word = prefix + str.slice(start, i);
|
|
171
|
+
if (word) result.push(toCase(word, flags, wordCase));
|
|
172
|
+
start = i;
|
|
173
|
+
prefix = "";
|
|
174
|
+
flags = 0;
|
|
175
|
+
}
|
|
176
|
+
flags |= HAS_UPPER;
|
|
177
|
+
prev = PREV_UPPER;
|
|
178
|
+
} else prev = PREV_OTHER;
|
|
179
|
+
if (str.charCodeAt(i) >= 128) flags |= HAS_NON_ASCII;
|
|
1670
180
|
}
|
|
1671
|
-
push();
|
|
181
|
+
if (length > start || prefix) result.push(toCase(prefix + str.slice(start), flags, wordCase));
|
|
1672
182
|
return result;
|
|
1673
183
|
}
|
|
1674
184
|
/** Uppercases the first character that is not a symbol: `'$id'` → `'$Id'`. */
|
|
1675
185
|
function capitalize(word) {
|
|
186
|
+
const code = word.charCodeAt(0);
|
|
187
|
+
if (code >= 97 && code <= 122) return String.fromCharCode(code - 32) + word.slice(1);
|
|
1676
188
|
let i = 0;
|
|
1677
|
-
while (i < word.length &&
|
|
189
|
+
while (i < word.length && word.charCodeAt(i) < 128 && KINDS[word.charCodeAt(i)] === SYMBOL) i++;
|
|
1678
190
|
return word.slice(0, i) + word.charAt(i).toUpperCase() + word.slice(i + 1);
|
|
1679
191
|
}
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
const
|
|
1693
|
-
const
|
|
1694
|
-
const
|
|
192
|
+
function join(list, separator, first, rest) {
|
|
193
|
+
let result = "";
|
|
194
|
+
for (let i = 0; i < list.length; i++) if (i === 0) result = first ? capitalize(list[0]) : list[0];
|
|
195
|
+
else result += separator + (rest ? capitalize(list[i]) : list[i]);
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
/** Changes the case of the whole string, or keeps it when `transform` is `undefined`. */
|
|
199
|
+
function applyTransform(str, transform) {
|
|
200
|
+
if (transform === "lowercase") return str.toLowerCase();
|
|
201
|
+
if (transform === "uppercase") return str.toUpperCase();
|
|
202
|
+
return str;
|
|
203
|
+
}
|
|
204
|
+
const ToCamel = (str, keep) => join(words(str, keep), "", false, true);
|
|
205
|
+
const ToPascal = (str, keep) => join(words(str, keep), "", true, true);
|
|
206
|
+
const ToSnake = (str, keep) => join(words(str, keep), "_", false, false);
|
|
207
|
+
const ToKebab = (str, keep) => join(words(str, keep), "-", false, false);
|
|
208
|
+
const ToUpperSnake = (str, keep) => join(words(str, keep, "upper"), "_", false, false);
|
|
209
|
+
const ToUpperKebab = (str, keep) => join(words(str, keep, "upper"), "-", false, false);
|
|
210
|
+
const ToTrain = (str, keep) => join(words(str, keep), "-", true, true);
|
|
211
|
+
const ToDot = (str, keep, transform) => applyTransform(join(words(str, keep, "keep"), ".", false, false), transform);
|
|
212
|
+
const ToTitle = (str, keep) => join(words(str, keep), " ", true, true);
|
|
213
|
+
const ToSentence = (str, keep) => join(words(str, keep), " ", true, false);
|
|
214
|
+
const ToPascalSnake = (str, keep) => join(words(str, keep), "_", true, true);
|
|
215
|
+
const ToPath = (str, keep, transform, separator = "/") => applyTransform(join(words(str, keep, "keep", true), separator, false, false), transform);
|
|
216
|
+
const ToSpace = (str, keep) => join(words(str, keep, "keep"), " ", false, false);
|
|
217
|
+
const ToLower = (str, keep) => join(words(str, keep), " ", false, false);
|
|
218
|
+
const ToUpper = (str, keep) => join(words(str, keep, "upper"), " ", false, false);
|
|
1695
219
|
//#endregion
|
|
1696
220
|
//#region src/anyCase/anyCase.ts
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
221
|
+
const KEEP_NONE = { keep: false };
|
|
222
|
+
const KEEP_ALL = { keep: true };
|
|
223
|
+
/** Reads the second argument of a `toX` function: the `allowSymbols` shorthand, or an options object. */
|
|
224
|
+
function parseOptions(options) {
|
|
225
|
+
if (options === void 0 || options === false) return KEEP_NONE;
|
|
226
|
+
if (options === true) return KEEP_ALL;
|
|
227
|
+
if (typeof options === "object" && options !== null && !Array.isArray(options)) {
|
|
228
|
+
const { allowSymbols, transform, separator, ignore } = options;
|
|
229
|
+
return {
|
|
230
|
+
keep: toKeep(allowSymbols),
|
|
231
|
+
transform,
|
|
232
|
+
separator,
|
|
233
|
+
ignore
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
return { keep: toKeep(options) };
|
|
1712
237
|
}
|
|
1713
|
-
|
|
1714
|
-
|
|
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));
|
|
238
|
+
function toCamel(input, options) {
|
|
239
|
+
const { keep, ignore } = parseOptions(options);
|
|
240
|
+
return convert(input, (key) => ToCamel(key, keep), ignore);
|
|
1728
241
|
}
|
|
1729
|
-
|
|
1730
|
-
|
|
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));
|
|
242
|
+
function toPascal(input, options) {
|
|
243
|
+
const { keep, ignore } = parseOptions(options);
|
|
244
|
+
return convert(input, (key) => ToPascal(key, keep), ignore);
|
|
1744
245
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
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));
|
|
246
|
+
function toSnake(input, options) {
|
|
247
|
+
const { keep, ignore } = parseOptions(options);
|
|
248
|
+
return convert(input, (key) => ToSnake(key, keep), ignore);
|
|
1760
249
|
}
|
|
1761
|
-
|
|
1762
|
-
|
|
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));
|
|
250
|
+
function toKebab(input, options) {
|
|
251
|
+
const { keep, ignore } = parseOptions(options);
|
|
252
|
+
return convert(input, (key) => ToKebab(key, keep), ignore);
|
|
1776
253
|
}
|
|
1777
|
-
|
|
1778
|
-
|
|
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));
|
|
254
|
+
function toUpperSnake(input, options) {
|
|
255
|
+
const { keep, ignore } = parseOptions(options);
|
|
256
|
+
return convert(input, (key) => ToUpperSnake(key, keep), ignore);
|
|
1792
257
|
}
|
|
1793
|
-
|
|
1794
|
-
|
|
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));
|
|
258
|
+
function toUpperKebab(input, options) {
|
|
259
|
+
const { keep, ignore } = parseOptions(options);
|
|
260
|
+
return convert(input, (key) => ToUpperKebab(key, keep), ignore);
|
|
1808
261
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
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));
|
|
262
|
+
function toTrain(input, options) {
|
|
263
|
+
const { keep, ignore } = parseOptions(options);
|
|
264
|
+
return convert(input, (key) => ToTrain(key, keep), ignore);
|
|
1824
265
|
}
|
|
1825
|
-
|
|
1826
|
-
|
|
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));
|
|
266
|
+
function toDot(input, options) {
|
|
267
|
+
const { keep, transform, ignore } = parseOptions(options);
|
|
268
|
+
return convert(input, (key) => ToDot(key, keep, transform), ignore);
|
|
1840
269
|
}
|
|
1841
|
-
|
|
1842
|
-
|
|
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));
|
|
270
|
+
function toTitle(input, options) {
|
|
271
|
+
const { keep, ignore } = parseOptions(options);
|
|
272
|
+
return convert(input, (key) => ToTitle(key, keep), ignore);
|
|
1856
273
|
}
|
|
1857
|
-
|
|
1858
|
-
|
|
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));
|
|
274
|
+
function toSentence(input, options) {
|
|
275
|
+
const { keep, ignore } = parseOptions(options);
|
|
276
|
+
return convert(input, (key) => ToSentence(key, keep), ignore);
|
|
1872
277
|
}
|
|
1873
|
-
|
|
1874
|
-
|
|
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));
|
|
278
|
+
function toPascalSnake(input, options) {
|
|
279
|
+
const { keep, ignore } = parseOptions(options);
|
|
280
|
+
return convert(input, (key) => ToPascalSnake(key, keep), ignore);
|
|
1888
281
|
}
|
|
1889
|
-
|
|
1890
|
-
|
|
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));
|
|
282
|
+
function toPath(input, options) {
|
|
283
|
+
const { keep, transform, separator, ignore } = parseOptions(options);
|
|
284
|
+
return convert(input, (key) => ToPath(key, keep, transform, separator === "\\" ? "\\" : "/"), ignore);
|
|
1904
285
|
}
|
|
1905
|
-
|
|
1906
|
-
|
|
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));
|
|
286
|
+
function toSpace(input, options) {
|
|
287
|
+
const { keep, ignore } = parseOptions(options);
|
|
288
|
+
return convert(input, (key) => ToSpace(key, keep), ignore);
|
|
1920
289
|
}
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
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));
|
|
290
|
+
function toLower(input, options) {
|
|
291
|
+
const { keep, ignore } = parseOptions(options);
|
|
292
|
+
return convert(input, (key) => ToLower(key, keep), ignore);
|
|
293
|
+
}
|
|
294
|
+
function toUpper(input, options) {
|
|
295
|
+
const { keep, ignore } = parseOptions(options);
|
|
296
|
+
return convert(input, (key) => ToUpper(key, keep), ignore);
|
|
1936
297
|
}
|
|
1937
298
|
//#endregion
|
|
1938
|
-
exports.camelToDash = camelToDash;
|
|
1939
|
-
exports.camelToDot = camelToDot;
|
|
1940
|
-
exports.camelToPascal = camelToPascal;
|
|
1941
|
-
exports.camelToSentence = camelToSentence;
|
|
1942
|
-
exports.camelToSnake = camelToSnake;
|
|
1943
|
-
exports.camelToTitle = camelToTitle;
|
|
1944
|
-
exports.camelToTrain = camelToTrain;
|
|
1945
|
-
exports.camelToUpperDash = camelToUpperDash;
|
|
1946
|
-
exports.camelToUpperSnake = camelToUpperSnake;
|
|
1947
|
-
exports.dashToCamel = dashToCamel;
|
|
1948
|
-
exports.dashToDot = dashToDot;
|
|
1949
|
-
exports.dashToPascal = dashToPascal;
|
|
1950
|
-
exports.dashToSentence = dashToSentence;
|
|
1951
|
-
exports.dashToSnake = dashToSnake;
|
|
1952
|
-
exports.dashToTitle = dashToTitle;
|
|
1953
|
-
exports.dashToTrain = dashToTrain;
|
|
1954
|
-
exports.dashToUpperDash = dashToUpperDash;
|
|
1955
|
-
exports.dashToUpperSnake = dashToUpperSnake;
|
|
1956
|
-
exports.dotToCamel = dotToCamel;
|
|
1957
|
-
exports.dotToDash = dotToDash;
|
|
1958
|
-
exports.dotToPascal = dotToPascal;
|
|
1959
|
-
exports.dotToSentence = dotToSentence;
|
|
1960
|
-
exports.dotToSnake = dotToSnake;
|
|
1961
|
-
exports.dotToTitle = dotToTitle;
|
|
1962
|
-
exports.dotToTrain = dotToTrain;
|
|
1963
|
-
exports.dotToUpperDash = dotToUpperDash;
|
|
1964
|
-
exports.dotToUpperSnake = dotToUpperSnake;
|
|
1965
|
-
exports.pascalToCamel = pascalToCamel;
|
|
1966
|
-
exports.pascalToDash = pascalToDash;
|
|
1967
|
-
exports.pascalToDot = pascalToDot;
|
|
1968
|
-
exports.pascalToSentence = pascalToSentence;
|
|
1969
|
-
exports.pascalToSnake = pascalToSnake;
|
|
1970
|
-
exports.pascalToTitle = pascalToTitle;
|
|
1971
|
-
exports.pascalToTrain = pascalToTrain;
|
|
1972
|
-
exports.pascalToUpperDash = pascalToUpperDash;
|
|
1973
|
-
exports.pascalToUpperSnake = pascalToUpperSnake;
|
|
1974
|
-
exports.sentenceToCamel = sentenceToCamel;
|
|
1975
|
-
exports.sentenceToDash = sentenceToDash;
|
|
1976
|
-
exports.sentenceToDot = sentenceToDot;
|
|
1977
|
-
exports.sentenceToPascal = sentenceToPascal;
|
|
1978
|
-
exports.sentenceToSnake = sentenceToSnake;
|
|
1979
|
-
exports.sentenceToTitle = sentenceToTitle;
|
|
1980
|
-
exports.sentenceToTrain = sentenceToTrain;
|
|
1981
|
-
exports.sentenceToUpperDash = sentenceToUpperDash;
|
|
1982
|
-
exports.sentenceToUpperSnake = sentenceToUpperSnake;
|
|
1983
|
-
exports.snakeToCamel = snakeToCamel;
|
|
1984
|
-
exports.snakeToDash = snakeToDash;
|
|
1985
|
-
exports.snakeToDot = snakeToDot;
|
|
1986
|
-
exports.snakeToPascal = snakeToPascal;
|
|
1987
|
-
exports.snakeToSentence = snakeToSentence;
|
|
1988
|
-
exports.snakeToTitle = snakeToTitle;
|
|
1989
|
-
exports.snakeToTrain = snakeToTrain;
|
|
1990
|
-
exports.snakeToUpperDash = snakeToUpperDash;
|
|
1991
|
-
exports.snakeToUpperSnake = snakeToUpperSnake;
|
|
1992
|
-
exports.titleToCamel = titleToCamel;
|
|
1993
|
-
exports.titleToDash = titleToDash;
|
|
1994
|
-
exports.titleToDot = titleToDot;
|
|
1995
|
-
exports.titleToPascal = titleToPascal;
|
|
1996
|
-
exports.titleToSentence = titleToSentence;
|
|
1997
|
-
exports.titleToSnake = titleToSnake;
|
|
1998
|
-
exports.titleToTrain = titleToTrain;
|
|
1999
|
-
exports.titleToUpperDash = titleToUpperDash;
|
|
2000
|
-
exports.titleToUpperSnake = titleToUpperSnake;
|
|
2001
299
|
exports.toCamel = toCamel;
|
|
2002
300
|
exports.toDot = toDot;
|
|
2003
301
|
exports.toKebab = toKebab;
|
|
@@ -2013,30 +311,3 @@ exports.toTrain = toTrain;
|
|
|
2013
311
|
exports.toUpper = toUpper;
|
|
2014
312
|
exports.toUpperKebab = toUpperKebab;
|
|
2015
313
|
exports.toUpperSnake = toUpperSnake;
|
|
2016
|
-
exports.trainToCamel = trainToCamel;
|
|
2017
|
-
exports.trainToDash = trainToDash;
|
|
2018
|
-
exports.trainToDot = trainToDot;
|
|
2019
|
-
exports.trainToPascal = trainToPascal;
|
|
2020
|
-
exports.trainToSentence = trainToSentence;
|
|
2021
|
-
exports.trainToSnake = trainToSnake;
|
|
2022
|
-
exports.trainToTitle = trainToTitle;
|
|
2023
|
-
exports.trainToUpperDash = trainToUpperDash;
|
|
2024
|
-
exports.trainToUpperSnake = trainToUpperSnake;
|
|
2025
|
-
exports.upperDashToCamel = upperDashToCamel;
|
|
2026
|
-
exports.upperDashToDash = upperDashToDash;
|
|
2027
|
-
exports.upperDashToDot = upperDashToDot;
|
|
2028
|
-
exports.upperDashToPascal = upperDashToPascal;
|
|
2029
|
-
exports.upperDashToSentence = upperDashToSentence;
|
|
2030
|
-
exports.upperDashToSnake = upperDashToSnake;
|
|
2031
|
-
exports.upperDashToTitle = upperDashToTitle;
|
|
2032
|
-
exports.upperDashToTrain = upperDashToTrain;
|
|
2033
|
-
exports.upperDashToUpperSnake = upperDashToUpperSnake;
|
|
2034
|
-
exports.upperSnakeToCamel = upperSnakeToCamel;
|
|
2035
|
-
exports.upperSnakeToDash = upperSnakeToDash;
|
|
2036
|
-
exports.upperSnakeToDot = upperSnakeToDot;
|
|
2037
|
-
exports.upperSnakeToPascal = upperSnakeToPascal;
|
|
2038
|
-
exports.upperSnakeToSentence = upperSnakeToSentence;
|
|
2039
|
-
exports.upperSnakeToSnake = upperSnakeToSnake;
|
|
2040
|
-
exports.upperSnakeToTitle = upperSnakeToTitle;
|
|
2041
|
-
exports.upperSnakeToTrain = upperSnakeToTrain;
|
|
2042
|
-
exports.upperSnakeToUpperDash = upperSnakeToUpperDash;
|