inflekt 0.5.0 → 0.5.1
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 +17 -10
- package/case.d.ts +6 -13
- package/case.js +6 -23
- package/esm/case.js +6 -22
- package/esm/transform-keys.js +2 -2
- package/package.json +2 -2
- package/transform-keys.d.ts +2 -2
- package/transform-keys.js +2 -2
package/README.md
CHANGED
|
@@ -34,7 +34,9 @@ import {
|
|
|
34
34
|
distinctPluralize,
|
|
35
35
|
lcFirst,
|
|
36
36
|
ucFirst,
|
|
37
|
-
|
|
37
|
+
toCamelCase,
|
|
38
|
+
toPascalCase,
|
|
39
|
+
toScreamingSnake,
|
|
38
40
|
underscore,
|
|
39
41
|
toFieldName,
|
|
40
42
|
toQueryName,
|
|
@@ -58,9 +60,12 @@ pluralizeLast('UserProfile'); // 'UserProfiles'
|
|
|
58
60
|
lcFirst('UserProfile'); // 'userProfile'
|
|
59
61
|
ucFirst('userProfile'); // 'UserProfile'
|
|
60
62
|
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
// Case conversions (handles underscores, hyphens, and camelCase boundaries)
|
|
64
|
+
toCamelCase('user_profile'); // 'userProfile'
|
|
65
|
+
toCamelCase('user-profile'); // 'userProfile'
|
|
66
|
+
toPascalCase('user_profile'); // 'UserProfile'
|
|
67
|
+
toPascalCase('user-profile'); // 'UserProfile'
|
|
68
|
+
toScreamingSnake('userProfile'); // 'USER_PROFILE'
|
|
64
69
|
underscore('UserProfile'); // 'user_profile'
|
|
65
70
|
|
|
66
71
|
// GraphQL naming helpers
|
|
@@ -72,7 +77,7 @@ const apiResponse = {
|
|
|
72
77
|
user_name: 'John',
|
|
73
78
|
order_items: [{ item_id: 1, product_name: 'Widget' }]
|
|
74
79
|
};
|
|
75
|
-
inflektTree(apiResponse,
|
|
80
|
+
inflektTree(apiResponse, toCamelCase);
|
|
76
81
|
// Result: { userName: 'John', orderItems: [{ itemId: 1, productName: 'Widget' }] }
|
|
77
82
|
```
|
|
78
83
|
|
|
@@ -91,7 +96,9 @@ inflektTree(apiResponse, (key) => camelize(key, true));
|
|
|
91
96
|
|
|
92
97
|
- `lcFirst(str)` - Convert first character to lowercase (PascalCase to camelCase)
|
|
93
98
|
- `ucFirst(str)` - Convert first character to uppercase (camelCase to PascalCase)
|
|
94
|
-
- `
|
|
99
|
+
- `toCamelCase(str)` - Convert to camelCase (handles underscores, hyphens, and PascalCase input)
|
|
100
|
+
- `toPascalCase(str)` - Convert to PascalCase (handles underscores, hyphens, and camelCase input)
|
|
101
|
+
- `toScreamingSnake(str)` - Convert to SCREAMING_SNAKE_CASE
|
|
95
102
|
- `underscore(str)` - Convert PascalCase/camelCase to snake_case
|
|
96
103
|
- `fixCapitalisedPlural(str)` - Fix capitalized S after numbers (e.g., `Table1S` -> `Table1s`)
|
|
97
104
|
|
|
@@ -124,7 +131,7 @@ const apiResponse = {
|
|
|
124
131
|
]
|
|
125
132
|
};
|
|
126
133
|
|
|
127
|
-
const result = inflektTree(apiResponse,
|
|
134
|
+
const result = inflektTree(apiResponse, toCamelCase);
|
|
128
135
|
// Result:
|
|
129
136
|
// {
|
|
130
137
|
// userName: 'John',
|
|
@@ -156,18 +163,18 @@ const input = {
|
|
|
156
163
|
_metadata: { _internal: true }
|
|
157
164
|
};
|
|
158
165
|
|
|
159
|
-
const result = inflektTree(input,
|
|
166
|
+
const result = inflektTree(input, toCamelCase, {
|
|
160
167
|
skip: (key) => key.startsWith('_')
|
|
161
168
|
});
|
|
162
169
|
// Result: { userName: 'John', _private_field: 'secret', _metadata: { _internal: true } }
|
|
163
170
|
|
|
164
171
|
// Skip specific keys
|
|
165
|
-
const result2 = inflektTree(input,
|
|
172
|
+
const result2 = inflektTree(input, toCamelCase, {
|
|
166
173
|
skip: (key) => key === 'created_at' || key === 'updated_at'
|
|
167
174
|
});
|
|
168
175
|
|
|
169
176
|
// Skip based on path depth (only transform top 2 levels)
|
|
170
|
-
const result3 = inflektTree(deepObject,
|
|
177
|
+
const result3 = inflektTree(deepObject, toCamelCase, {
|
|
171
178
|
skip: (key, path) => path.length > 1
|
|
172
179
|
});
|
|
173
180
|
```
|
package/case.d.ts
CHANGED
|
@@ -17,14 +17,6 @@ export declare function ucFirst(str: string): string;
|
|
|
17
17
|
* @example "Table1S" -> "Table1s"
|
|
18
18
|
*/
|
|
19
19
|
export declare function fixCapitalisedPlural(str: string): string;
|
|
20
|
-
/**
|
|
21
|
-
* Convert snake_case to PascalCase (or camelCase if lowFirstLetter is true)
|
|
22
|
-
* @param str - The snake_case string to convert
|
|
23
|
-
* @param lowFirstLetter - If true, returns camelCase instead of PascalCase
|
|
24
|
-
* @example camelize('user_profile') -> 'UserProfile'
|
|
25
|
-
* @example camelize('user_profile', true) -> 'userProfile'
|
|
26
|
-
*/
|
|
27
|
-
export declare function camelize(str: string, lowFirstLetter?: boolean): string;
|
|
28
20
|
/**
|
|
29
21
|
* Convert PascalCase or camelCase to snake_case
|
|
30
22
|
* @example underscore('UserProfile') -> 'user_profile'
|
|
@@ -32,18 +24,19 @@ export declare function camelize(str: string, lowFirstLetter?: boolean): string;
|
|
|
32
24
|
*/
|
|
33
25
|
export declare function underscore(str: string): string;
|
|
34
26
|
/**
|
|
35
|
-
* Convert a hyphenated or
|
|
36
|
-
*
|
|
37
|
-
* camelCase boundaries that are already present.
|
|
27
|
+
* Convert a hyphenated, underscored, or already-camelCased string to camelCase.
|
|
28
|
+
* Handles both `-` and `_` delimiters.
|
|
38
29
|
* @example toCamelCase('user-profile') -> 'userProfile'
|
|
39
30
|
* @example toCamelCase('user_profile') -> 'userProfile'
|
|
31
|
+
* @example toCamelCase('UserProfile') -> 'userProfile'
|
|
40
32
|
*/
|
|
41
33
|
export declare function toCamelCase(str: string): string;
|
|
42
34
|
/**
|
|
43
|
-
* Convert a hyphenated or
|
|
44
|
-
*
|
|
35
|
+
* Convert a hyphenated, underscored, or already-camelCased string to PascalCase.
|
|
36
|
+
* Handles both `-` and `_` delimiters.
|
|
45
37
|
* @example toPascalCase('user-profile') -> 'UserProfile'
|
|
46
38
|
* @example toPascalCase('user_profile') -> 'UserProfile'
|
|
39
|
+
* @example toPascalCase('userProfile') -> 'UserProfile'
|
|
47
40
|
*/
|
|
48
41
|
export declare function toPascalCase(str: string): string;
|
|
49
42
|
/**
|
package/case.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.lcFirst = lcFirst;
|
|
7
7
|
exports.ucFirst = ucFirst;
|
|
8
8
|
exports.fixCapitalisedPlural = fixCapitalisedPlural;
|
|
9
|
-
exports.camelize = camelize;
|
|
10
9
|
exports.underscore = underscore;
|
|
11
10
|
exports.toCamelCase = toCamelCase;
|
|
12
11
|
exports.toPascalCase = toPascalCase;
|
|
@@ -33,23 +32,6 @@ function ucFirst(str) {
|
|
|
33
32
|
function fixCapitalisedPlural(str) {
|
|
34
33
|
return str.replace(/[0-9]S(?=[A-Z]|$)/g, (match) => match.toLowerCase());
|
|
35
34
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Convert snake_case to PascalCase (or camelCase if lowFirstLetter is true)
|
|
38
|
-
* @param str - The snake_case string to convert
|
|
39
|
-
* @param lowFirstLetter - If true, returns camelCase instead of PascalCase
|
|
40
|
-
* @example camelize('user_profile') -> 'UserProfile'
|
|
41
|
-
* @example camelize('user_profile', true) -> 'userProfile'
|
|
42
|
-
*/
|
|
43
|
-
function camelize(str, lowFirstLetter) {
|
|
44
|
-
const result = str
|
|
45
|
-
.split('_')
|
|
46
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
47
|
-
.join('');
|
|
48
|
-
if (lowFirstLetter) {
|
|
49
|
-
return lcFirst(result);
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
35
|
/**
|
|
54
36
|
* Convert PascalCase or camelCase to snake_case
|
|
55
37
|
* @example underscore('UserProfile') -> 'user_profile'
|
|
@@ -62,11 +44,11 @@ function underscore(str) {
|
|
|
62
44
|
.toLowerCase();
|
|
63
45
|
}
|
|
64
46
|
/**
|
|
65
|
-
* Convert a hyphenated or
|
|
66
|
-
*
|
|
67
|
-
* camelCase boundaries that are already present.
|
|
47
|
+
* Convert a hyphenated, underscored, or already-camelCased string to camelCase.
|
|
48
|
+
* Handles both `-` and `_` delimiters.
|
|
68
49
|
* @example toCamelCase('user-profile') -> 'userProfile'
|
|
69
50
|
* @example toCamelCase('user_profile') -> 'userProfile'
|
|
51
|
+
* @example toCamelCase('UserProfile') -> 'userProfile'
|
|
70
52
|
*/
|
|
71
53
|
function toCamelCase(str) {
|
|
72
54
|
return str
|
|
@@ -74,10 +56,11 @@ function toCamelCase(str) {
|
|
|
74
56
|
.replace(/^(.)/, (_, char) => char.toLowerCase());
|
|
75
57
|
}
|
|
76
58
|
/**
|
|
77
|
-
* Convert a hyphenated or
|
|
78
|
-
*
|
|
59
|
+
* Convert a hyphenated, underscored, or already-camelCased string to PascalCase.
|
|
60
|
+
* Handles both `-` and `_` delimiters.
|
|
79
61
|
* @example toPascalCase('user-profile') -> 'UserProfile'
|
|
80
62
|
* @example toPascalCase('user_profile') -> 'UserProfile'
|
|
63
|
+
* @example toPascalCase('userProfile') -> 'UserProfile'
|
|
81
64
|
*/
|
|
82
65
|
function toPascalCase(str) {
|
|
83
66
|
return str
|
package/esm/case.js
CHANGED
|
@@ -23,23 +23,6 @@ export function ucFirst(str) {
|
|
|
23
23
|
export function fixCapitalisedPlural(str) {
|
|
24
24
|
return str.replace(/[0-9]S(?=[A-Z]|$)/g, (match) => match.toLowerCase());
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Convert snake_case to PascalCase (or camelCase if lowFirstLetter is true)
|
|
28
|
-
* @param str - The snake_case string to convert
|
|
29
|
-
* @param lowFirstLetter - If true, returns camelCase instead of PascalCase
|
|
30
|
-
* @example camelize('user_profile') -> 'UserProfile'
|
|
31
|
-
* @example camelize('user_profile', true) -> 'userProfile'
|
|
32
|
-
*/
|
|
33
|
-
export function camelize(str, lowFirstLetter) {
|
|
34
|
-
const result = str
|
|
35
|
-
.split('_')
|
|
36
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
37
|
-
.join('');
|
|
38
|
-
if (lowFirstLetter) {
|
|
39
|
-
return lcFirst(result);
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
26
|
/**
|
|
44
27
|
* Convert PascalCase or camelCase to snake_case
|
|
45
28
|
* @example underscore('UserProfile') -> 'user_profile'
|
|
@@ -52,11 +35,11 @@ export function underscore(str) {
|
|
|
52
35
|
.toLowerCase();
|
|
53
36
|
}
|
|
54
37
|
/**
|
|
55
|
-
* Convert a hyphenated or
|
|
56
|
-
*
|
|
57
|
-
* camelCase boundaries that are already present.
|
|
38
|
+
* Convert a hyphenated, underscored, or already-camelCased string to camelCase.
|
|
39
|
+
* Handles both `-` and `_` delimiters.
|
|
58
40
|
* @example toCamelCase('user-profile') -> 'userProfile'
|
|
59
41
|
* @example toCamelCase('user_profile') -> 'userProfile'
|
|
42
|
+
* @example toCamelCase('UserProfile') -> 'userProfile'
|
|
60
43
|
*/
|
|
61
44
|
export function toCamelCase(str) {
|
|
62
45
|
return str
|
|
@@ -64,10 +47,11 @@ export function toCamelCase(str) {
|
|
|
64
47
|
.replace(/^(.)/, (_, char) => char.toLowerCase());
|
|
65
48
|
}
|
|
66
49
|
/**
|
|
67
|
-
* Convert a hyphenated or
|
|
68
|
-
*
|
|
50
|
+
* Convert a hyphenated, underscored, or already-camelCased string to PascalCase.
|
|
51
|
+
* Handles both `-` and `_` delimiters.
|
|
69
52
|
* @example toPascalCase('user-profile') -> 'UserProfile'
|
|
70
53
|
* @example toPascalCase('user_profile') -> 'UserProfile'
|
|
54
|
+
* @example toPascalCase('userProfile') -> 'UserProfile'
|
|
71
55
|
*/
|
|
72
56
|
export function toPascalCase(str) {
|
|
73
57
|
return str
|
package/esm/transform-keys.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* @example
|
|
15
15
|
* // Convert snake_case keys to camelCase
|
|
16
16
|
* const apiResponse = { user_name: 'John', order_items: [{ item_id: 1 }] };
|
|
17
|
-
* const result = inflektTree(apiResponse,
|
|
17
|
+
* const result = inflektTree(apiResponse, toCamelCase);
|
|
18
18
|
* // Result: { userName: 'John', orderItems: [{ itemId: 1 }] }
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*
|
|
26
26
|
* @example
|
|
27
27
|
* // Skip keys starting with underscore
|
|
28
|
-
* inflektTree(obj,
|
|
28
|
+
* inflektTree(obj, toCamelCase, {
|
|
29
29
|
* skip: (key) => key.startsWith('_')
|
|
30
30
|
* });
|
|
31
31
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inflekt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Inflection utilities for pluralization and singularization with PostGraphile-compatible Latin suffix handling",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"homepage": "https://github.com/constructive-io/dev-utils",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"inflection": "^3.0.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "29ca836c31e0c462da8436db1970f215cecc53e2"
|
|
47
47
|
}
|
package/transform-keys.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface InflektTreeOptions {
|
|
|
24
24
|
* @example
|
|
25
25
|
* // Convert snake_case keys to camelCase
|
|
26
26
|
* const apiResponse = { user_name: 'John', order_items: [{ item_id: 1 }] };
|
|
27
|
-
* const result = inflektTree(apiResponse,
|
|
27
|
+
* const result = inflektTree(apiResponse, toCamelCase);
|
|
28
28
|
* // Result: { userName: 'John', orderItems: [{ itemId: 1 }] }
|
|
29
29
|
*
|
|
30
30
|
* @example
|
|
@@ -35,7 +35,7 @@ export interface InflektTreeOptions {
|
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
37
37
|
* // Skip keys starting with underscore
|
|
38
|
-
* inflektTree(obj,
|
|
38
|
+
* inflektTree(obj, toCamelCase, {
|
|
39
39
|
* skip: (key) => key.startsWith('_')
|
|
40
40
|
* });
|
|
41
41
|
*/
|
package/transform-keys.js
CHANGED
|
@@ -17,7 +17,7 @@ exports.inflektTree = inflektTree;
|
|
|
17
17
|
* @example
|
|
18
18
|
* // Convert snake_case keys to camelCase
|
|
19
19
|
* const apiResponse = { user_name: 'John', order_items: [{ item_id: 1 }] };
|
|
20
|
-
* const result = inflektTree(apiResponse,
|
|
20
|
+
* const result = inflektTree(apiResponse, toCamelCase);
|
|
21
21
|
* // Result: { userName: 'John', orderItems: [{ itemId: 1 }] }
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
@@ -28,7 +28,7 @@ exports.inflektTree = inflektTree;
|
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* // Skip keys starting with underscore
|
|
31
|
-
* inflektTree(obj,
|
|
31
|
+
* inflektTree(obj, toCamelCase, {
|
|
32
32
|
* skip: (key) => key.startsWith('_')
|
|
33
33
|
* });
|
|
34
34
|
*/
|