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