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/README.md
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
# [CaseParser
|
|
1
|
+
# [CaseParser](https://github.com/NandoMB/caseparser)
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/caseparser)
|
|
4
|
+
[](https://jsr.io/@nandomb/caseparser)
|
|
5
|
+
[](https://jsr.io/@nandomb/caseparser)
|
|
6
|
+
[](https://github.com/NandoMB/caseparser/actions/workflows/main.yml)
|
|
7
|
+
[](https://www.npmjs.com/package/caseparser)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
|
|
2
10
|
Convert **Strings** and **JSON (Object Keys)** from a **case type** to another one with **type inference** based on parameter's type.
|
|
3
11
|
|
|
12
|
+
- Zero dependencies
|
|
13
|
+
- Written in TypeScript, published as ESM and CommonJS with type declarations
|
|
14
|
+
- Available on [npm](https://www.npmjs.com/package/caseparser) and [JSR](https://jsr.io/@nandomb/caseparser)
|
|
15
|
+
- Tree-shakeable
|
|
16
|
+
|
|
4
17
|
|
|
5
18
|
###### Note:
|
|
6
|
-
>
|
|
19
|
+
> If you're looking for version 1.x.x, [click here](https://github.com/NandoMB/caseparser/tree/v1.x.x) to see the docs.
|
|
7
20
|
|
|
8
21
|
|
|
9
22
|
## Installation
|
|
@@ -20,6 +33,32 @@ npm add caseparser
|
|
|
20
33
|
```sh
|
|
21
34
|
pnpm add caseparser
|
|
22
35
|
```
|
|
36
|
+
###### Deno (JSR)
|
|
37
|
+
```sh
|
|
38
|
+
deno add jsr:@nandomb/caseparser
|
|
39
|
+
```
|
|
40
|
+
```ts
|
|
41
|
+
import { camelToSnake } from '@nandomb/caseparser';
|
|
42
|
+
```
|
|
43
|
+
###### Bun / Node.js from JSR
|
|
44
|
+
```sh
|
|
45
|
+
bunx jsr add @nandomb/caseparser
|
|
46
|
+
npx jsr add @nandomb/caseparser
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Compatibility
|
|
50
|
+
|
|
51
|
+
| Environment | Supported |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| ESM (`import`) | Node.js 12.22+, Deno, Bun, bundlers |
|
|
54
|
+
| CommonJS (`require`) | Node.js 8+ |
|
|
55
|
+
| TypeScript | 4.1+ (any `moduleResolution`: `node`, `node16`/`nodenext`, `bundler`) |
|
|
56
|
+
| Browsers | Any ES2015 browser (via bundler) |
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
// CommonJS
|
|
60
|
+
const { camelToSnake } = require('caseparser');
|
|
61
|
+
```
|
|
23
62
|
|
|
24
63
|
## How to use
|
|
25
64
|
|
|
@@ -138,6 +177,14 @@ upperDashToSnake(data);
|
|
|
138
177
|
upperDashToUpperSnake(data);
|
|
139
178
|
```
|
|
140
179
|
|
|
180
|
+
## Security
|
|
181
|
+
|
|
182
|
+
caseparser is safe to use with untrusted input (e.g. request bodies or `JSON.parse` output): keys such as `__proto__` are copied as regular keys and never change an object's prototype, and only the object's own properties are converted.
|
|
183
|
+
|
|
184
|
+
Releases are built and published from GitHub Actions without long-lived tokens (OIDC), with [npm provenance](https://docs.npmjs.com/generating-provenance-statements), so every published version can be traced back to the exact commit and workflow that built it. On npm, new versions are [staged](https://docs.npmjs.com/staged-publishing/) and only go live after a maintainer approves them with 2FA.
|
|
185
|
+
|
|
186
|
+
Found a vulnerability? Please report it privately, see [SECURITY.md](./SECURITY.md).
|
|
187
|
+
|
|
141
188
|
## License
|
|
142
189
|
The MIT License (MIT)
|
|
143
190
|
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
function isString(input) {
|
|
4
|
+
return typeof input === "string";
|
|
5
|
+
}
|
|
6
|
+
function isObject(input) {
|
|
7
|
+
return typeof input === "object" && (input === null || input === void 0 ? void 0 : input.constructor) === Object;
|
|
8
|
+
}
|
|
9
|
+
function isArray(input) {
|
|
10
|
+
return Array.isArray(input);
|
|
11
|
+
}
|
|
12
|
+
function Lowercase(str) {
|
|
13
|
+
return str.toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
function Uppercase(str) {
|
|
16
|
+
return str.toUpperCase();
|
|
17
|
+
}
|
|
18
|
+
function Capitalize(str) {
|
|
19
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
20
|
+
}
|
|
21
|
+
function Uncapitalize(str) {
|
|
22
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/parser/stringParser.ts
|
|
26
|
+
const CamelToDash = (str) => str.replace(/([A-Z])/g, (g) => "-" + g[0].toLowerCase());
|
|
27
|
+
const CamelToPascal = (str) => Capitalize(str);
|
|
28
|
+
const CamelToSnake = (str) => str.replace(/([A-Z])/g, (g) => "_" + g[0].toLowerCase());
|
|
29
|
+
const CamelToUpperDash = (str) => Uppercase(CamelToDash(str));
|
|
30
|
+
const CamelToUpperSnake = (str) => Uppercase(CamelToSnake(str));
|
|
31
|
+
const DashToCamel = (str) => str.replace(/(\-\w)/g, (g) => g[1].toUpperCase());
|
|
32
|
+
const DashToPascal = (str) => Capitalize(DashToCamel(str));
|
|
33
|
+
const DashToSnake = (str) => str.replace(/(\-)/g, "_");
|
|
34
|
+
const DashToUpperDash = (str) => Uppercase(str);
|
|
35
|
+
const DashToUpperSnake = (str) => Uppercase(DashToSnake(str));
|
|
36
|
+
const PascalToCamel = (str) => Uncapitalize(str);
|
|
37
|
+
const PascalToDash = (str) => CamelToDash(Uncapitalize(str));
|
|
38
|
+
const PascalToSnake = (str) => CamelToSnake(Uncapitalize(str));
|
|
39
|
+
const PascalToUpperDash = (str) => Uppercase(PascalToDash(str));
|
|
40
|
+
const PascalToUpperSnake = (str) => Uppercase(PascalToSnake(str));
|
|
41
|
+
const SnakeToCamel = (str) => str.replace(/(\_\w)/g, (g) => g[1].toUpperCase());
|
|
42
|
+
const SnakeToDash = (str) => str.replace(/(\_)/g, "-");
|
|
43
|
+
const SnakeToPascal = (str) => Capitalize(SnakeToCamel(str));
|
|
44
|
+
const SnakeToUpperDash = (str) => Uppercase(SnakeToDash(str));
|
|
45
|
+
const SnakeToUpperSnake = (str) => Uppercase(str);
|
|
46
|
+
const UpperDashToCamel = (str) => DashToCamel(Lowercase(str));
|
|
47
|
+
const UpperDashToDash = (str) => Lowercase(str);
|
|
48
|
+
const UpperDashToPascal = (str) => Capitalize(UpperDashToCamel(str));
|
|
49
|
+
const UpperDashToSnake = (str) => DashToSnake(UpperDashToDash(str));
|
|
50
|
+
const UpperDashToUpperSnake = (str) => Uppercase(UpperDashToSnake(str));
|
|
51
|
+
const UpperSnakeToCamel = (str) => SnakeToCamel(Lowercase(str));
|
|
52
|
+
const UpperSnakeToDash = (str) => str.replace(/(\_)/g, "-").toLowerCase();
|
|
53
|
+
const UpperSnakeToPascal = (str) => SnakeToPascal(Lowercase(str));
|
|
54
|
+
const UpperSnakeToSnake = (str) => Lowercase(str);
|
|
55
|
+
const UpperSnakeToUpperDash = (str) => Uppercase(UpperSnakeToDash(str));
|
|
56
|
+
function parse(input, type) {
|
|
57
|
+
return {
|
|
58
|
+
CamelToDash,
|
|
59
|
+
CamelToPascal,
|
|
60
|
+
CamelToSnake,
|
|
61
|
+
CamelToUpperDash,
|
|
62
|
+
CamelToUpperSnake,
|
|
63
|
+
DashToCamel,
|
|
64
|
+
DashToSnake,
|
|
65
|
+
DashToPascal,
|
|
66
|
+
DashToUpperSnake,
|
|
67
|
+
DashToUpperDash,
|
|
68
|
+
PascalToCamel,
|
|
69
|
+
PascalToSnake,
|
|
70
|
+
PascalToDash,
|
|
71
|
+
PascalToUpperSnake,
|
|
72
|
+
PascalToUpperDash,
|
|
73
|
+
SnakeToCamel,
|
|
74
|
+
SnakeToDash,
|
|
75
|
+
SnakeToPascal,
|
|
76
|
+
SnakeToUpperSnake,
|
|
77
|
+
SnakeToUpperDash,
|
|
78
|
+
UpperSnakeToCamel,
|
|
79
|
+
UpperSnakeToSnake,
|
|
80
|
+
UpperSnakeToDash,
|
|
81
|
+
UpperSnakeToPascal,
|
|
82
|
+
UpperSnakeToUpperDash,
|
|
83
|
+
UpperDashToCamel,
|
|
84
|
+
UpperDashToSnake,
|
|
85
|
+
UpperDashToDash,
|
|
86
|
+
UpperDashToPascal,
|
|
87
|
+
UpperDashToUpperSnake
|
|
88
|
+
}[type](input);
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/parser/objectParser.ts
|
|
92
|
+
function objectParser(input, type) {
|
|
93
|
+
const result = {};
|
|
94
|
+
for (const property of Object.keys(input)) {
|
|
95
|
+
const parsedKey = parse(property, type);
|
|
96
|
+
const value = input[property];
|
|
97
|
+
let parsedValue;
|
|
98
|
+
if (isArray(value)) parsedValue = arrayParser(value, type);
|
|
99
|
+
else if (isObject(value)) parsedValue = objectParser(value, type);
|
|
100
|
+
else parsedValue = value;
|
|
101
|
+
Object.defineProperty(result, parsedKey, {
|
|
102
|
+
value: parsedValue,
|
|
103
|
+
enumerable: true,
|
|
104
|
+
writable: true,
|
|
105
|
+
configurable: true
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/parser/arrayParser.ts
|
|
112
|
+
function arrayParser(input, type) {
|
|
113
|
+
return input.map((item) => {
|
|
114
|
+
if (isArray(item)) return arrayParser(item, type);
|
|
115
|
+
if (isObject(item)) return objectParser(item, type);
|
|
116
|
+
return item;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/parser/parser.ts
|
|
121
|
+
function converter(input, type) {
|
|
122
|
+
let result;
|
|
123
|
+
if (isString(input)) result = parse(input, type);
|
|
124
|
+
if (isArray(input)) result = arrayParser(input, type);
|
|
125
|
+
if (isObject(input)) result = objectParser(input, type);
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/camelCase/camelCase.ts
|
|
130
|
+
/**
|
|
131
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to dash-case.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* camelToDash('helloWorld'); // 'hello-world'
|
|
136
|
+
* camelToDash({ firstName: 'John' }); // { 'first-name': 'John' }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
function camelToDash(input) {
|
|
140
|
+
return converter(input, "CamelToDash");
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to snake_case.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* camelToSnake('helloWorld'); // 'hello_world'
|
|
148
|
+
* camelToSnake({ firstName: 'John' }); // { first_name: 'John' }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
function camelToSnake(input) {
|
|
152
|
+
return converter(input, "CamelToSnake");
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to PascalCase.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* camelToPascal('helloWorld'); // 'HelloWorld'
|
|
160
|
+
* camelToPascal({ firstName: 'John' }); // { FirstName: 'John' }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
function camelToPascal(input) {
|
|
164
|
+
return converter(input, "CamelToPascal");
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to UPPER_SNAKE_CASE.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* camelToUpperSnake('helloWorld'); // 'HELLO_WORLD'
|
|
172
|
+
* camelToUpperSnake({ firstName: 'John' }); // { FIRST_NAME: 'John' }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
function camelToUpperSnake(input) {
|
|
176
|
+
return converter(input, "CamelToUpperSnake");
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Converts a string, or the keys of an object/array (deeply), from camelCase to UPPER-DASH-CASE.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* camelToUpperDash('helloWorld'); // 'HELLO-WORLD'
|
|
184
|
+
* camelToUpperDash({ firstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
function camelToUpperDash(input) {
|
|
188
|
+
return converter(input, "CamelToUpperDash");
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/dashCase/dashCase.ts
|
|
192
|
+
/**
|
|
193
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to snake_case.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* dashToSnake('hello-world'); // 'hello_world'
|
|
198
|
+
* dashToSnake({ 'first-name': 'John' }); // { first_name: 'John' }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
function dashToSnake(input) {
|
|
202
|
+
return converter(input, "DashToSnake");
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to camelCase.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* dashToCamel('hello-world'); // 'helloWorld'
|
|
210
|
+
* dashToCamel({ 'first-name': 'John' }); // { firstName: 'John' }
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
function dashToCamel(input) {
|
|
214
|
+
return converter(input, "DashToCamel");
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to PascalCase.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* dashToPascal('hello-world'); // 'HelloWorld'
|
|
222
|
+
* dashToPascal({ 'first-name': 'John' }); // { FirstName: 'John' }
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
function dashToPascal(input) {
|
|
226
|
+
return converter(input, "DashToPascal");
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to UPPER_SNAKE_CASE.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* dashToUpperSnake('hello-world'); // 'HELLO_WORLD'
|
|
234
|
+
* dashToUpperSnake({ 'first-name': 'John' }); // { FIRST_NAME: 'John' }
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
function dashToUpperSnake(input) {
|
|
238
|
+
return converter(input, "DashToUpperSnake");
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Converts a string, or the keys of an object/array (deeply), from dash-case to UPPER-DASH-CASE.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* dashToUpperDash('hello-world'); // 'HELLO-WORLD'
|
|
246
|
+
* dashToUpperDash({ 'first-name': 'John' }); // { 'FIRST-NAME': 'John' }
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
function dashToUpperDash(input) {
|
|
250
|
+
return converter(input, "DashToUpperDash");
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/pascalCase/pascalCase.ts
|
|
254
|
+
/**
|
|
255
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to camelCase.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```ts
|
|
259
|
+
* pascalToCamel('HelloWorld'); // 'helloWorld'
|
|
260
|
+
* pascalToCamel({ FirstName: 'John' }); // { firstName: 'John' }
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
function pascalToCamel(input) {
|
|
264
|
+
return converter(input, "PascalToCamel");
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to snake_case.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* pascalToSnake('HelloWorld'); // 'hello_world'
|
|
272
|
+
* pascalToSnake({ FirstName: 'John' }); // { first_name: 'John' }
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
function pascalToSnake(input) {
|
|
276
|
+
return converter(input, "PascalToSnake");
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to dash-case.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```ts
|
|
283
|
+
* pascalToDash('HelloWorld'); // 'hello-world'
|
|
284
|
+
* pascalToDash({ FirstName: 'John' }); // { 'first-name': 'John' }
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
function pascalToDash(input) {
|
|
288
|
+
return converter(input, "PascalToDash");
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to UPPER_SNAKE_CASE.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* pascalToUpperSnake('HelloWorld'); // 'HELLO_WORLD'
|
|
296
|
+
* pascalToUpperSnake({ FirstName: 'John' }); // { FIRST_NAME: 'John' }
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
function pascalToUpperSnake(input) {
|
|
300
|
+
return converter(input, "PascalToUpperSnake");
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Converts a string, or the keys of an object/array (deeply), from PascalCase to UPPER-DASH-CASE.
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```ts
|
|
307
|
+
* pascalToUpperDash('HelloWorld'); // 'HELLO-WORLD'
|
|
308
|
+
* pascalToUpperDash({ FirstName: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
function pascalToUpperDash(input) {
|
|
312
|
+
return converter(input, "PascalToUpperDash");
|
|
313
|
+
}
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/snakeCase/snakeCase.ts
|
|
316
|
+
/**
|
|
317
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to camelCase.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* snakeToCamel('hello_world'); // 'helloWorld'
|
|
322
|
+
* snakeToCamel({ first_name: 'John' }); // { firstName: 'John' }
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
function snakeToCamel(input) {
|
|
326
|
+
return converter(input, "SnakeToCamel");
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to dash-case.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```ts
|
|
333
|
+
* snakeToDash('hello_world'); // 'hello-world'
|
|
334
|
+
* snakeToDash({ first_name: 'John' }); // { 'first-name': 'John' }
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
function snakeToDash(input) {
|
|
338
|
+
return converter(input, "SnakeToDash");
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to PascalCase.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* snakeToPascal('hello_world'); // 'HelloWorld'
|
|
346
|
+
* snakeToPascal({ first_name: 'John' }); // { FirstName: 'John' }
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
function snakeToPascal(input) {
|
|
350
|
+
return converter(input, "SnakeToPascal");
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to UPPER_SNAKE_CASE.
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
357
|
+
* snakeToUpperSnake('hello_world'); // 'HELLO_WORLD'
|
|
358
|
+
* snakeToUpperSnake({ first_name: 'John' }); // { FIRST_NAME: 'John' }
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
function snakeToUpperSnake(input) {
|
|
362
|
+
return converter(input, "SnakeToUpperSnake");
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Converts a string, or the keys of an object/array (deeply), from snake_case to UPPER-DASH-CASE.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```ts
|
|
369
|
+
* snakeToUpperDash('hello_world'); // 'HELLO-WORLD'
|
|
370
|
+
* snakeToUpperDash({ first_name: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
function snakeToUpperDash(input) {
|
|
374
|
+
return converter(input, "SnakeToUpperDash");
|
|
375
|
+
}
|
|
376
|
+
//#endregion
|
|
377
|
+
//#region src/upperDashCase/upperDashCase.ts
|
|
378
|
+
/**
|
|
379
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to camelCase.
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```ts
|
|
383
|
+
* upperDashToCamel('HELLO-WORLD'); // 'helloWorld'
|
|
384
|
+
* upperDashToCamel({ 'FIRST-NAME': 'John' }); // { firstName: 'John' }
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
function upperDashToCamel(input) {
|
|
388
|
+
return converter(input, "UpperDashToCamel");
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to snake_case.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```ts
|
|
395
|
+
* upperDashToSnake('HELLO-WORLD'); // 'hello_world'
|
|
396
|
+
* upperDashToSnake({ 'FIRST-NAME': 'John' }); // { first_name: 'John' }
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
function upperDashToSnake(input) {
|
|
400
|
+
return converter(input, "UpperDashToSnake");
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to dash-case.
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* upperDashToDash('HELLO-WORLD'); // 'hello-world'
|
|
408
|
+
* upperDashToDash({ 'FIRST-NAME': 'John' }); // { 'first-name': 'John' }
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
function upperDashToDash(input) {
|
|
412
|
+
return converter(input, "UpperDashToDash");
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to PascalCase.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```ts
|
|
419
|
+
* upperDashToPascal('HELLO-WORLD'); // 'HelloWorld'
|
|
420
|
+
* upperDashToPascal({ 'FIRST-NAME': 'John' }); // { FirstName: 'John' }
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
function upperDashToPascal(input) {
|
|
424
|
+
return converter(input, "UpperDashToPascal");
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER-DASH-CASE to UPPER_SNAKE_CASE.
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```ts
|
|
431
|
+
* upperDashToUpperSnake('HELLO-WORLD'); // 'HELLO_WORLD'
|
|
432
|
+
* upperDashToUpperSnake({ 'FIRST-NAME': 'John' }); // { FIRST_NAME: 'John' }
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
function upperDashToUpperSnake(input) {
|
|
436
|
+
return converter(input, "UpperDashToUpperSnake");
|
|
437
|
+
}
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/upperSnakeCase/upperSnakeCase.ts
|
|
440
|
+
/**
|
|
441
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to camelCase.
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```ts
|
|
445
|
+
* upperSnakeToCamel('HELLO_WORLD'); // 'helloWorld'
|
|
446
|
+
* upperSnakeToCamel({ FIRST_NAME: 'John' }); // { firstName: 'John' }
|
|
447
|
+
* ```
|
|
448
|
+
*/
|
|
449
|
+
function upperSnakeToCamel(input) {
|
|
450
|
+
return converter(input, "UpperSnakeToCamel");
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to snake_case.
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
* ```ts
|
|
457
|
+
* upperSnakeToSnake('HELLO_WORLD'); // 'hello_world'
|
|
458
|
+
* upperSnakeToSnake({ FIRST_NAME: 'John' }); // { first_name: 'John' }
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
function upperSnakeToSnake(input) {
|
|
462
|
+
return converter(input, "UpperSnakeToSnake");
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to dash-case.
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```ts
|
|
469
|
+
* upperSnakeToDash('HELLO_WORLD'); // 'hello-world'
|
|
470
|
+
* upperSnakeToDash({ FIRST_NAME: 'John' }); // { 'first-name': 'John' }
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
function upperSnakeToDash(input) {
|
|
474
|
+
return converter(input, "UpperSnakeToDash");
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to PascalCase.
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```ts
|
|
481
|
+
* upperSnakeToPascal('HELLO_WORLD'); // 'HelloWorld'
|
|
482
|
+
* upperSnakeToPascal({ FIRST_NAME: 'John' }); // { FirstName: 'John' }
|
|
483
|
+
* ```
|
|
484
|
+
*/
|
|
485
|
+
function upperSnakeToPascal(input) {
|
|
486
|
+
return converter(input, "UpperSnakeToPascal");
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Converts a string, or the keys of an object/array (deeply), from UPPER_SNAKE_CASE to UPPER-DASH-CASE.
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* ```ts
|
|
493
|
+
* upperSnakeToUpperDash('HELLO_WORLD'); // 'HELLO-WORLD'
|
|
494
|
+
* upperSnakeToUpperDash({ FIRST_NAME: 'John' }); // { 'FIRST-NAME': 'John' }
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
function upperSnakeToUpperDash(input) {
|
|
498
|
+
return converter(input, "UpperSnakeToUpperDash");
|
|
499
|
+
}
|
|
500
|
+
//#endregion
|
|
501
|
+
exports.camelToDash = camelToDash;
|
|
502
|
+
exports.camelToPascal = camelToPascal;
|
|
503
|
+
exports.camelToSnake = camelToSnake;
|
|
504
|
+
exports.camelToUpperDash = camelToUpperDash;
|
|
505
|
+
exports.camelToUpperSnake = camelToUpperSnake;
|
|
506
|
+
exports.dashToCamel = dashToCamel;
|
|
507
|
+
exports.dashToPascal = dashToPascal;
|
|
508
|
+
exports.dashToSnake = dashToSnake;
|
|
509
|
+
exports.dashToUpperDash = dashToUpperDash;
|
|
510
|
+
exports.dashToUpperSnake = dashToUpperSnake;
|
|
511
|
+
exports.pascalToCamel = pascalToCamel;
|
|
512
|
+
exports.pascalToDash = pascalToDash;
|
|
513
|
+
exports.pascalToSnake = pascalToSnake;
|
|
514
|
+
exports.pascalToUpperDash = pascalToUpperDash;
|
|
515
|
+
exports.pascalToUpperSnake = pascalToUpperSnake;
|
|
516
|
+
exports.snakeToCamel = snakeToCamel;
|
|
517
|
+
exports.snakeToDash = snakeToDash;
|
|
518
|
+
exports.snakeToPascal = snakeToPascal;
|
|
519
|
+
exports.snakeToUpperDash = snakeToUpperDash;
|
|
520
|
+
exports.snakeToUpperSnake = snakeToUpperSnake;
|
|
521
|
+
exports.upperDashToCamel = upperDashToCamel;
|
|
522
|
+
exports.upperDashToDash = upperDashToDash;
|
|
523
|
+
exports.upperDashToPascal = upperDashToPascal;
|
|
524
|
+
exports.upperDashToSnake = upperDashToSnake;
|
|
525
|
+
exports.upperDashToUpperSnake = upperDashToUpperSnake;
|
|
526
|
+
exports.upperSnakeToCamel = upperSnakeToCamel;
|
|
527
|
+
exports.upperSnakeToDash = upperSnakeToDash;
|
|
528
|
+
exports.upperSnakeToPascal = upperSnakeToPascal;
|
|
529
|
+
exports.upperSnakeToSnake = upperSnakeToSnake;
|
|
530
|
+
exports.upperSnakeToUpperDash = upperSnakeToUpperDash;
|