caseparser 3.0.0 → 4.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 +49 -2
- package/dist/index.cjs +530 -0
- package/dist/index.d.cts +360 -0
- package/dist/index.d.ts +332 -48
- package/dist/index.js +453 -271
- package/package.json +43 -22
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -40
- package/dist/index.mjs +0 -262
package/dist/index.js
CHANGED
|
@@ -1,318 +1,500 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
camelToDash: () => camelToDash,
|
|
24
|
-
camelToPascal: () => camelToPascal,
|
|
25
|
-
camelToSnake: () => camelToSnake,
|
|
26
|
-
camelToUpperDash: () => camelToUpperDash,
|
|
27
|
-
camelToUpperSnake: () => camelToUpperSnake,
|
|
28
|
-
dashToCamel: () => dashToCamel,
|
|
29
|
-
dashToPascal: () => dashToPascal,
|
|
30
|
-
dashToSnake: () => dashToSnake,
|
|
31
|
-
dashToUpperDash: () => dashToUpperDash,
|
|
32
|
-
dashToUpperSnake: () => dashToUpperSnake,
|
|
33
|
-
pascalToCamel: () => pascalToCamel,
|
|
34
|
-
pascalToDash: () => pascalToDash,
|
|
35
|
-
pascalToSnake: () => pascalToSnake,
|
|
36
|
-
pascalToUpperDash: () => pascalToUpperDash,
|
|
37
|
-
pascalToUpperSnake: () => pascalToUpperSnake,
|
|
38
|
-
snakeToCamel: () => snakeToCamel,
|
|
39
|
-
snakeToDash: () => snakeToDash,
|
|
40
|
-
snakeToPascal: () => snakeToPascal,
|
|
41
|
-
snakeToUpperDash: () => snakeToUpperDash,
|
|
42
|
-
snakeToUpperSnake: () => snakeToUpperSnake,
|
|
43
|
-
upperDashToCamel: () => upperDashToCamel,
|
|
44
|
-
upperDashToDash: () => upperDashToDash,
|
|
45
|
-
upperDashToPascal: () => upperDashToPascal,
|
|
46
|
-
upperDashToSnake: () => upperDashToSnake,
|
|
47
|
-
upperDashToUpperSnake: () => upperDashToUpperSnake,
|
|
48
|
-
upperSnakeToCamel: () => upperSnakeToCamel,
|
|
49
|
-
upperSnakeToDash: () => upperSnakeToDash,
|
|
50
|
-
upperSnakeToPascal: () => upperSnakeToPascal,
|
|
51
|
-
upperSnakeToSnake: () => upperSnakeToSnake,
|
|
52
|
-
upperSnakeToUpperDash: () => upperSnakeToUpperDash
|
|
53
|
-
});
|
|
54
|
-
module.exports = __toCommonJS(src_exports);
|
|
55
|
-
|
|
56
|
-
// src/utils.ts
|
|
1
|
+
//#region src/utils.ts
|
|
57
2
|
function isString(input) {
|
|
58
|
-
|
|
3
|
+
return typeof input === "string";
|
|
59
4
|
}
|
|
60
5
|
function isObject(input) {
|
|
61
|
-
|
|
6
|
+
return typeof input === "object" && (input === null || input === void 0 ? void 0 : input.constructor) === Object;
|
|
62
7
|
}
|
|
63
8
|
function isArray(input) {
|
|
64
|
-
|
|
9
|
+
return Array.isArray(input);
|
|
65
10
|
}
|
|
66
11
|
function Lowercase(str) {
|
|
67
|
-
|
|
12
|
+
return str.toLowerCase();
|
|
68
13
|
}
|
|
69
14
|
function Uppercase(str) {
|
|
70
|
-
|
|
15
|
+
return str.toUpperCase();
|
|
71
16
|
}
|
|
72
17
|
function Capitalize(str) {
|
|
73
|
-
|
|
18
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
74
19
|
}
|
|
75
20
|
function Uncapitalize(str) {
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
21
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/parser/stringParser.ts
|
|
25
|
+
const CamelToDash = (str) => str.replace(/([A-Z])/g, (g) => "-" + g[0].toLowerCase());
|
|
26
|
+
const CamelToPascal = (str) => Capitalize(str);
|
|
27
|
+
const CamelToSnake = (str) => str.replace(/([A-Z])/g, (g) => "_" + g[0].toLowerCase());
|
|
28
|
+
const CamelToUpperDash = (str) => Uppercase(CamelToDash(str));
|
|
29
|
+
const CamelToUpperSnake = (str) => Uppercase(CamelToSnake(str));
|
|
30
|
+
const DashToCamel = (str) => str.replace(/(\-\w)/g, (g) => g[1].toUpperCase());
|
|
31
|
+
const DashToPascal = (str) => Capitalize(DashToCamel(str));
|
|
32
|
+
const DashToSnake = (str) => str.replace(/(\-)/g, "_");
|
|
33
|
+
const DashToUpperDash = (str) => Uppercase(str);
|
|
34
|
+
const DashToUpperSnake = (str) => Uppercase(DashToSnake(str));
|
|
35
|
+
const PascalToCamel = (str) => Uncapitalize(str);
|
|
36
|
+
const PascalToDash = (str) => CamelToDash(Uncapitalize(str));
|
|
37
|
+
const PascalToSnake = (str) => CamelToSnake(Uncapitalize(str));
|
|
38
|
+
const PascalToUpperDash = (str) => Uppercase(PascalToDash(str));
|
|
39
|
+
const PascalToUpperSnake = (str) => Uppercase(PascalToSnake(str));
|
|
40
|
+
const SnakeToCamel = (str) => str.replace(/(\_\w)/g, (g) => g[1].toUpperCase());
|
|
41
|
+
const SnakeToDash = (str) => str.replace(/(\_)/g, "-");
|
|
42
|
+
const SnakeToPascal = (str) => Capitalize(SnakeToCamel(str));
|
|
43
|
+
const SnakeToUpperDash = (str) => Uppercase(SnakeToDash(str));
|
|
44
|
+
const SnakeToUpperSnake = (str) => Uppercase(str);
|
|
45
|
+
const UpperDashToCamel = (str) => DashToCamel(Lowercase(str));
|
|
46
|
+
const UpperDashToDash = (str) => Lowercase(str);
|
|
47
|
+
const UpperDashToPascal = (str) => Capitalize(UpperDashToCamel(str));
|
|
48
|
+
const UpperDashToSnake = (str) => DashToSnake(UpperDashToDash(str));
|
|
49
|
+
const UpperDashToUpperSnake = (str) => Uppercase(UpperDashToSnake(str));
|
|
50
|
+
const UpperSnakeToCamel = (str) => SnakeToCamel(Lowercase(str));
|
|
51
|
+
const UpperSnakeToDash = (str) => str.replace(/(\_)/g, "-").toLowerCase();
|
|
52
|
+
const UpperSnakeToPascal = (str) => SnakeToPascal(Lowercase(str));
|
|
53
|
+
const UpperSnakeToSnake = (str) => Lowercase(str);
|
|
54
|
+
const UpperSnakeToUpperDash = (str) => Uppercase(UpperSnakeToDash(str));
|
|
110
55
|
function parse(input, type) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
56
|
+
return {
|
|
57
|
+
CamelToDash,
|
|
58
|
+
CamelToPascal,
|
|
59
|
+
CamelToSnake,
|
|
60
|
+
CamelToUpperDash,
|
|
61
|
+
CamelToUpperSnake,
|
|
62
|
+
DashToCamel,
|
|
63
|
+
DashToSnake,
|
|
64
|
+
DashToPascal,
|
|
65
|
+
DashToUpperSnake,
|
|
66
|
+
DashToUpperDash,
|
|
67
|
+
PascalToCamel,
|
|
68
|
+
PascalToSnake,
|
|
69
|
+
PascalToDash,
|
|
70
|
+
PascalToUpperSnake,
|
|
71
|
+
PascalToUpperDash,
|
|
72
|
+
SnakeToCamel,
|
|
73
|
+
SnakeToDash,
|
|
74
|
+
SnakeToPascal,
|
|
75
|
+
SnakeToUpperSnake,
|
|
76
|
+
SnakeToUpperDash,
|
|
77
|
+
UpperSnakeToCamel,
|
|
78
|
+
UpperSnakeToSnake,
|
|
79
|
+
UpperSnakeToDash,
|
|
80
|
+
UpperSnakeToPascal,
|
|
81
|
+
UpperSnakeToUpperDash,
|
|
82
|
+
UpperDashToCamel,
|
|
83
|
+
UpperDashToSnake,
|
|
84
|
+
UpperDashToDash,
|
|
85
|
+
UpperDashToPascal,
|
|
86
|
+
UpperDashToUpperSnake
|
|
87
|
+
}[type](input);
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/parser/objectParser.ts
|
|
146
91
|
function objectParser(input, type) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
92
|
+
const result = {};
|
|
93
|
+
for (const property of Object.keys(input)) {
|
|
94
|
+
const parsedKey = parse(property, type);
|
|
95
|
+
const value = input[property];
|
|
96
|
+
let parsedValue;
|
|
97
|
+
if (isArray(value)) parsedValue = arrayParser(value, type);
|
|
98
|
+
else if (isObject(value)) parsedValue = objectParser(value, type);
|
|
99
|
+
else parsedValue = value;
|
|
100
|
+
Object.defineProperty(result, parsedKey, {
|
|
101
|
+
value: parsedValue,
|
|
102
|
+
enumerable: true,
|
|
103
|
+
writable: true,
|
|
104
|
+
configurable: true
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/parser/arrayParser.ts
|
|
163
111
|
function arrayParser(input, type) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
// src/parser/parser.ts
|
|
112
|
+
return input.map((item) => {
|
|
113
|
+
if (isArray(item)) return arrayParser(item, type);
|
|
114
|
+
if (isObject(item)) return objectParser(item, type);
|
|
115
|
+
return item;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/parser/parser.ts
|
|
174
120
|
function converter(input, type) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
121
|
+
let result;
|
|
122
|
+
if (isString(input)) result = parse(input, type);
|
|
123
|
+
if (isArray(input)) result = arrayParser(input, type);
|
|
124
|
+
if (isObject(input)) result = objectParser(input, type);
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/camelCase/camelCase.ts
|
|
129
|
+
/**
|
|
130
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to dash-case.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* camelToDash('helloWorld'); // 'hello-world'
|
|
135
|
+
* camelToDash({ firstName: 'John' }); // { 'first-name': 'John' }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
186
138
|
function camelToDash(input) {
|
|
187
|
-
|
|
188
|
-
}
|
|
139
|
+
return converter(input, "CamelToDash");
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to snake_case.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* camelToSnake('helloWorld'); // 'hello_world'
|
|
147
|
+
* camelToSnake({ firstName: 'John' }); // { first_name: 'John' }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
189
150
|
function camelToSnake(input) {
|
|
190
|
-
|
|
191
|
-
}
|
|
151
|
+
return converter(input, "CamelToSnake");
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to PascalCase.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* camelToPascal('helloWorld'); // 'HelloWorld'
|
|
159
|
+
* camelToPascal({ firstName: 'John' }); // { FirstName: 'John' }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
192
162
|
function camelToPascal(input) {
|
|
193
|
-
|
|
194
|
-
}
|
|
163
|
+
return converter(input, "CamelToPascal");
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to UPPER_SNAKE_CASE.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* camelToUpperSnake('helloWorld'); // 'HELLO_WORLD'
|
|
171
|
+
* camelToUpperSnake({ firstName: 'John' }); // { FIRST_NAME: 'John' }
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
195
174
|
function camelToUpperSnake(input) {
|
|
196
|
-
|
|
197
|
-
}
|
|
175
|
+
return converter(input, "CamelToUpperSnake");
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to UPPER-DASH-CASE.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* camelToUpperDash('helloWorld'); // 'HELLO-WORLD'
|
|
183
|
+
* camelToUpperDash({ firstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
198
186
|
function camelToUpperDash(input) {
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
187
|
+
return converter(input, "CamelToUpperDash");
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/dashCase/dashCase.ts
|
|
191
|
+
/**
|
|
192
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to snake_case.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* dashToSnake('hello-world'); // 'hello_world'
|
|
197
|
+
* dashToSnake({ 'first-name': 'John' }); // { first_name: 'John' }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
203
200
|
function dashToSnake(input) {
|
|
204
|
-
|
|
205
|
-
}
|
|
201
|
+
return converter(input, "DashToSnake");
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to camelCase.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* dashToCamel('hello-world'); // 'helloWorld'
|
|
209
|
+
* dashToCamel({ 'first-name': 'John' }); // { firstName: 'John' }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
206
212
|
function dashToCamel(input) {
|
|
207
|
-
|
|
208
|
-
}
|
|
213
|
+
return converter(input, "DashToCamel");
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to PascalCase.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* dashToPascal('hello-world'); // 'HelloWorld'
|
|
221
|
+
* dashToPascal({ 'first-name': 'John' }); // { FirstName: 'John' }
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
209
224
|
function dashToPascal(input) {
|
|
210
|
-
|
|
211
|
-
}
|
|
225
|
+
return converter(input, "DashToPascal");
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to UPPER_SNAKE_CASE.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* dashToUpperSnake('hello-world'); // 'HELLO_WORLD'
|
|
233
|
+
* dashToUpperSnake({ 'first-name': 'John' }); // { FIRST_NAME: 'John' }
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
212
236
|
function dashToUpperSnake(input) {
|
|
213
|
-
|
|
214
|
-
}
|
|
237
|
+
return converter(input, "DashToUpperSnake");
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to UPPER-DASH-CASE.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* dashToUpperDash('hello-world'); // 'HELLO-WORLD'
|
|
245
|
+
* dashToUpperDash({ 'first-name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
215
248
|
function dashToUpperDash(input) {
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
249
|
+
return converter(input, "DashToUpperDash");
|
|
250
|
+
}
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/pascalCase/pascalCase.ts
|
|
253
|
+
/**
|
|
254
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to camelCase.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* pascalToCamel('HelloWorld'); // 'helloWorld'
|
|
259
|
+
* pascalToCamel({ FirstName: 'John' }); // { firstName: 'John' }
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
220
262
|
function pascalToCamel(input) {
|
|
221
|
-
|
|
222
|
-
}
|
|
263
|
+
return converter(input, "PascalToCamel");
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to snake_case.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* pascalToSnake('HelloWorld'); // 'hello_world'
|
|
271
|
+
* pascalToSnake({ FirstName: 'John' }); // { first_name: 'John' }
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
223
274
|
function pascalToSnake(input) {
|
|
224
|
-
|
|
225
|
-
}
|
|
275
|
+
return converter(input, "PascalToSnake");
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to dash-case.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* pascalToDash('HelloWorld'); // 'hello-world'
|
|
283
|
+
* pascalToDash({ FirstName: 'John' }); // { 'first-name': 'John' }
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
226
286
|
function pascalToDash(input) {
|
|
227
|
-
|
|
228
|
-
}
|
|
287
|
+
return converter(input, "PascalToDash");
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to UPPER_SNAKE_CASE.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts
|
|
294
|
+
* pascalToUpperSnake('HelloWorld'); // 'HELLO_WORLD'
|
|
295
|
+
* pascalToUpperSnake({ FirstName: 'John' }); // { FIRST_NAME: 'John' }
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
229
298
|
function pascalToUpperSnake(input) {
|
|
230
|
-
|
|
231
|
-
}
|
|
299
|
+
return converter(input, "PascalToUpperSnake");
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to UPPER-DASH-CASE.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```ts
|
|
306
|
+
* pascalToUpperDash('HelloWorld'); // 'HELLO-WORLD'
|
|
307
|
+
* pascalToUpperDash({ FirstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
232
310
|
function pascalToUpperDash(input) {
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
311
|
+
return converter(input, "PascalToUpperDash");
|
|
312
|
+
}
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/snakeCase/snakeCase.ts
|
|
315
|
+
/**
|
|
316
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to camelCase.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts
|
|
320
|
+
* snakeToCamel('hello_world'); // 'helloWorld'
|
|
321
|
+
* snakeToCamel({ first_name: 'John' }); // { firstName: 'John' }
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
237
324
|
function snakeToCamel(input) {
|
|
238
|
-
|
|
239
|
-
}
|
|
325
|
+
return converter(input, "SnakeToCamel");
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to dash-case.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```ts
|
|
332
|
+
* snakeToDash('hello_world'); // 'hello-world'
|
|
333
|
+
* snakeToDash({ first_name: 'John' }); // { 'first-name': 'John' }
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
240
336
|
function snakeToDash(input) {
|
|
241
|
-
|
|
242
|
-
}
|
|
337
|
+
return converter(input, "SnakeToDash");
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to PascalCase.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* snakeToPascal('hello_world'); // 'HelloWorld'
|
|
345
|
+
* snakeToPascal({ first_name: 'John' }); // { FirstName: 'John' }
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
243
348
|
function snakeToPascal(input) {
|
|
244
|
-
|
|
245
|
-
}
|
|
349
|
+
return converter(input, "SnakeToPascal");
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to UPPER_SNAKE_CASE.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* snakeToUpperSnake('hello_world'); // 'HELLO_WORLD'
|
|
357
|
+
* snakeToUpperSnake({ first_name: 'John' }); // { FIRST_NAME: 'John' }
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
246
360
|
function snakeToUpperSnake(input) {
|
|
247
|
-
|
|
248
|
-
}
|
|
361
|
+
return converter(input, "SnakeToUpperSnake");
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to UPPER-DASH-CASE.
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ```ts
|
|
368
|
+
* snakeToUpperDash('hello_world'); // 'HELLO-WORLD'
|
|
369
|
+
* snakeToUpperDash({ first_name: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
249
372
|
function snakeToUpperDash(input) {
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
373
|
+
return converter(input, "SnakeToUpperDash");
|
|
374
|
+
}
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/upperDashCase/upperDashCase.ts
|
|
377
|
+
/**
|
|
378
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to camelCase.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```ts
|
|
382
|
+
* upperDashToCamel('HELLO-WORLD'); // 'helloWorld'
|
|
383
|
+
* upperDashToCamel({ 'FIRST-NAME': 'John' }); // { firstName: 'John' }
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
254
386
|
function upperDashToCamel(input) {
|
|
255
|
-
|
|
256
|
-
}
|
|
387
|
+
return converter(input, "UpperDashToCamel");
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to snake_case.
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```ts
|
|
394
|
+
* upperDashToSnake('HELLO-WORLD'); // 'hello_world'
|
|
395
|
+
* upperDashToSnake({ 'FIRST-NAME': 'John' }); // { first_name: 'John' }
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
257
398
|
function upperDashToSnake(input) {
|
|
258
|
-
|
|
259
|
-
}
|
|
399
|
+
return converter(input, "UpperDashToSnake");
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to dash-case.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```ts
|
|
406
|
+
* upperDashToDash('HELLO-WORLD'); // 'hello-world'
|
|
407
|
+
* upperDashToDash({ 'FIRST-NAME': 'John' }); // { 'first-name': 'John' }
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
260
410
|
function upperDashToDash(input) {
|
|
261
|
-
|
|
262
|
-
}
|
|
411
|
+
return converter(input, "UpperDashToDash");
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to PascalCase.
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```ts
|
|
418
|
+
* upperDashToPascal('HELLO-WORLD'); // 'HelloWorld'
|
|
419
|
+
* upperDashToPascal({ 'FIRST-NAME': 'John' }); // { FirstName: 'John' }
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
263
422
|
function upperDashToPascal(input) {
|
|
264
|
-
|
|
265
|
-
}
|
|
423
|
+
return converter(input, "UpperDashToPascal");
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to UPPER_SNAKE_CASE.
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```ts
|
|
430
|
+
* upperDashToUpperSnake('HELLO-WORLD'); // 'HELLO_WORLD'
|
|
431
|
+
* upperDashToUpperSnake({ 'FIRST-NAME': 'John' }); // { FIRST_NAME: 'John' }
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
266
434
|
function upperDashToUpperSnake(input) {
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
435
|
+
return converter(input, "UpperDashToUpperSnake");
|
|
436
|
+
}
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/upperSnakeCase/upperSnakeCase.ts
|
|
439
|
+
/**
|
|
440
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to camelCase.
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```ts
|
|
444
|
+
* upperSnakeToCamel('HELLO_WORLD'); // 'helloWorld'
|
|
445
|
+
* upperSnakeToCamel({ FIRST_NAME: 'John' }); // { firstName: 'John' }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
271
448
|
function upperSnakeToCamel(input) {
|
|
272
|
-
|
|
273
|
-
}
|
|
449
|
+
return converter(input, "UpperSnakeToCamel");
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to snake_case.
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```ts
|
|
456
|
+
* upperSnakeToSnake('HELLO_WORLD'); // 'hello_world'
|
|
457
|
+
* upperSnakeToSnake({ FIRST_NAME: 'John' }); // { first_name: 'John' }
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
274
460
|
function upperSnakeToSnake(input) {
|
|
275
|
-
|
|
276
|
-
}
|
|
461
|
+
return converter(input, "UpperSnakeToSnake");
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to dash-case.
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```ts
|
|
468
|
+
* upperSnakeToDash('HELLO_WORLD'); // 'hello-world'
|
|
469
|
+
* upperSnakeToDash({ FIRST_NAME: 'John' }); // { 'first-name': 'John' }
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
277
472
|
function upperSnakeToDash(input) {
|
|
278
|
-
|
|
279
|
-
}
|
|
473
|
+
return converter(input, "UpperSnakeToDash");
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to PascalCase.
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* ```ts
|
|
480
|
+
* upperSnakeToPascal('HELLO_WORLD'); // 'HelloWorld'
|
|
481
|
+
* upperSnakeToPascal({ FIRST_NAME: 'John' }); // { FirstName: 'John' }
|
|
482
|
+
* ```
|
|
483
|
+
*/
|
|
280
484
|
function upperSnakeToPascal(input) {
|
|
281
|
-
|
|
282
|
-
}
|
|
485
|
+
return converter(input, "UpperSnakeToPascal");
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to UPPER-DASH-CASE.
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```ts
|
|
492
|
+
* upperSnakeToUpperDash('HELLO_WORLD'); // 'HELLO-WORLD'
|
|
493
|
+
* upperSnakeToUpperDash({ FIRST_NAME: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
283
496
|
function upperSnakeToUpperDash(input) {
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
camelToDash,
|
|
289
|
-
camelToPascal,
|
|
290
|
-
camelToSnake,
|
|
291
|
-
camelToUpperDash,
|
|
292
|
-
camelToUpperSnake,
|
|
293
|
-
dashToCamel,
|
|
294
|
-
dashToPascal,
|
|
295
|
-
dashToSnake,
|
|
296
|
-
dashToUpperDash,
|
|
297
|
-
dashToUpperSnake,
|
|
298
|
-
pascalToCamel,
|
|
299
|
-
pascalToDash,
|
|
300
|
-
pascalToSnake,
|
|
301
|
-
pascalToUpperDash,
|
|
302
|
-
pascalToUpperSnake,
|
|
303
|
-
snakeToCamel,
|
|
304
|
-
snakeToDash,
|
|
305
|
-
snakeToPascal,
|
|
306
|
-
snakeToUpperDash,
|
|
307
|
-
snakeToUpperSnake,
|
|
308
|
-
upperDashToCamel,
|
|
309
|
-
upperDashToDash,
|
|
310
|
-
upperDashToPascal,
|
|
311
|
-
upperDashToSnake,
|
|
312
|
-
upperDashToUpperSnake,
|
|
313
|
-
upperSnakeToCamel,
|
|
314
|
-
upperSnakeToDash,
|
|
315
|
-
upperSnakeToPascal,
|
|
316
|
-
upperSnakeToSnake,
|
|
317
|
-
upperSnakeToUpperDash
|
|
318
|
-
});
|
|
497
|
+
return converter(input, "UpperSnakeToUpperDash");
|
|
498
|
+
}
|
|
499
|
+
//#endregion
|
|
500
|
+
export { camelToDash, camelToPascal, camelToSnake, camelToUpperDash, camelToUpperSnake, dashToCamel, dashToPascal, dashToSnake, dashToUpperDash, dashToUpperSnake, pascalToCamel, pascalToDash, pascalToSnake, pascalToUpperDash, pascalToUpperSnake, snakeToCamel, snakeToDash, snakeToPascal, snakeToUpperDash, snakeToUpperSnake, upperDashToCamel, upperDashToDash, upperDashToPascal, upperDashToSnake, upperDashToUpperSnake, upperSnakeToCamel, upperSnakeToDash, upperSnakeToPascal, upperSnakeToSnake, upperSnakeToUpperDash };
|