inflekt 0.5.0 → 0.6.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 CHANGED
@@ -34,7 +34,9 @@ import {
34
34
  distinctPluralize,
35
35
  lcFirst,
36
36
  ucFirst,
37
- camelize,
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
- // Snake case / camel case conversions
62
- camelize('user_profile'); // 'UserProfile'
63
- camelize('user_profile', true); // 'userProfile'
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, (key) => camelize(key, true));
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
- - `camelize(str, lowFirstLetter?)` - Convert snake_case to PascalCase (or camelCase if lowFirstLetter is true)
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, (key) => camelize(key, true));
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, (key) => camelize(key, true), {
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, (key) => camelize(key, true), {
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, (key) => camelize(key, true), {
177
+ const result3 = inflektTree(deepObject, toCamelCase, {
171
178
  skip: (key, path) => path.length > 1
172
179
  });
173
180
  ```
package/case.d.ts CHANGED
@@ -1,53 +1,29 @@
1
1
  /**
2
2
  * Case transformation utilities
3
+ *
4
+ * Pure case transforms are delegated to komoji (the origin of truth).
5
+ * This module re-exports them for backward compatibility and adds
6
+ * inflekt-specific helpers (fixCapitalisedPlural, underscore, toScreamingSnake).
3
7
  */
4
- /**
5
- * Convert PascalCase to camelCase (lowercase first character)
6
- * @example "UserProfile" -> "userProfile"
7
- */
8
- export declare function lcFirst(str: string): string;
9
- /**
10
- * Convert camelCase to PascalCase (uppercase first character)
11
- * @example "userProfile" -> "UserProfile"
12
- */
13
- export declare function ucFirst(str: string): string;
8
+ import { lcFirst, ucFirst, toPascalCase, toSnakeCase, toConstantCase } from 'komoji';
9
+ export { lcFirst, ucFirst, toPascalCase, toSnakeCase, toConstantCase };
10
+ export declare function toCamelCase(str: string): string;
14
11
  /**
15
12
  * Fix capitalized plurals that end with a number followed by 'S'
16
13
  * This solves the issue with `blah-table1s` becoming `blahTable1S`
17
14
  * @example "Table1S" -> "Table1s"
18
15
  */
19
16
  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
17
  /**
29
18
  * Convert PascalCase or camelCase to snake_case
19
+ * @deprecated Use toSnakeCase from komoji instead
30
20
  * @example underscore('UserProfile') -> 'user_profile'
31
21
  * @example underscore('userProfile') -> 'user_profile'
32
22
  */
33
23
  export declare function underscore(str: string): string;
34
- /**
35
- * Convert a hyphenated or underscored string to camelCase.
36
- * Unlike `camelize`, this also handles hyphens and preserves
37
- * camelCase boundaries that are already present.
38
- * @example toCamelCase('user-profile') -> 'userProfile'
39
- * @example toCamelCase('user_profile') -> 'userProfile'
40
- */
41
- export declare function toCamelCase(str: string): string;
42
- /**
43
- * Convert a hyphenated or underscored string to PascalCase.
44
- * Unlike `camelize`, this also handles hyphens.
45
- * @example toPascalCase('user-profile') -> 'UserProfile'
46
- * @example toPascalCase('user_profile') -> 'UserProfile'
47
- */
48
- export declare function toPascalCase(str: string): string;
49
24
  /**
50
25
  * Convert a camelCase or PascalCase string to SCREAMING_SNAKE_CASE.
26
+ * @deprecated Use toConstantCase from komoji instead
51
27
  * @example toScreamingSnake('userProfile') -> 'USER_PROFILE'
52
28
  * @example toScreamingSnake('UserProfile') -> 'USER_PROFILE'
53
29
  */
package/case.js CHANGED
@@ -1,29 +1,27 @@
1
1
  "use strict";
2
2
  /**
3
3
  * Case transformation utilities
4
+ *
5
+ * Pure case transforms are delegated to komoji (the origin of truth).
6
+ * This module re-exports them for backward compatibility and adds
7
+ * inflekt-specific helpers (fixCapitalisedPlural, underscore, toScreamingSnake).
4
8
  */
5
9
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.lcFirst = lcFirst;
7
- exports.ucFirst = ucFirst;
10
+ exports.toConstantCase = exports.toSnakeCase = exports.toPascalCase = exports.ucFirst = exports.lcFirst = void 0;
11
+ exports.toCamelCase = toCamelCase;
8
12
  exports.fixCapitalisedPlural = fixCapitalisedPlural;
9
- exports.camelize = camelize;
10
13
  exports.underscore = underscore;
11
- exports.toCamelCase = toCamelCase;
12
- exports.toPascalCase = toPascalCase;
13
14
  exports.toScreamingSnake = toScreamingSnake;
14
- /**
15
- * Convert PascalCase to camelCase (lowercase first character)
16
- * @example "UserProfile" -> "userProfile"
17
- */
18
- function lcFirst(str) {
19
- return str.charAt(0).toLowerCase() + str.slice(1);
20
- }
21
- /**
22
- * Convert camelCase to PascalCase (uppercase first character)
23
- * @example "userProfile" -> "UserProfile"
24
- */
25
- function ucFirst(str) {
26
- return str.charAt(0).toUpperCase() + str.slice(1);
15
+ const komoji_1 = require("komoji");
16
+ Object.defineProperty(exports, "lcFirst", { enumerable: true, get: function () { return komoji_1.lcFirst; } });
17
+ Object.defineProperty(exports, "ucFirst", { enumerable: true, get: function () { return komoji_1.ucFirst; } });
18
+ Object.defineProperty(exports, "toPascalCase", { enumerable: true, get: function () { return komoji_1.toPascalCase; } });
19
+ Object.defineProperty(exports, "toSnakeCase", { enumerable: true, get: function () { return komoji_1.toSnakeCase; } });
20
+ Object.defineProperty(exports, "toConstantCase", { enumerable: true, get: function () { return komoji_1.toConstantCase; } });
21
+ // Re-export toCamelCase — komoji's version accepts a second parameter
22
+ // (stripLeadingNonAlphabetChars) so we wrap to keep the simpler inflekt signature
23
+ function toCamelCase(str) {
24
+ return (0, komoji_1.toCamelCase)(str);
27
25
  }
28
26
  /**
29
27
  * Fix capitalized plurals that end with a number followed by 'S'
@@ -33,66 +31,21 @@ function ucFirst(str) {
33
31
  function fixCapitalisedPlural(str) {
34
32
  return str.replace(/[0-9]S(?=[A-Z]|$)/g, (match) => match.toLowerCase());
35
33
  }
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
34
  /**
54
35
  * Convert PascalCase or camelCase to snake_case
36
+ * @deprecated Use toSnakeCase from komoji instead
55
37
  * @example underscore('UserProfile') -> 'user_profile'
56
38
  * @example underscore('userProfile') -> 'user_profile'
57
39
  */
58
40
  function underscore(str) {
59
- return str
60
- .replace(/([A-Z])/g, '_$1')
61
- .replace(/^_/, '')
62
- .toLowerCase();
63
- }
64
- /**
65
- * Convert a hyphenated or underscored string to camelCase.
66
- * Unlike `camelize`, this also handles hyphens and preserves
67
- * camelCase boundaries that are already present.
68
- * @example toCamelCase('user-profile') -> 'userProfile'
69
- * @example toCamelCase('user_profile') -> 'userProfile'
70
- */
71
- function toCamelCase(str) {
72
- return str
73
- .replace(/[-_](.)/g, (_, char) => char.toUpperCase())
74
- .replace(/^(.)/, (_, char) => char.toLowerCase());
75
- }
76
- /**
77
- * Convert a hyphenated or underscored string to PascalCase.
78
- * Unlike `camelize`, this also handles hyphens.
79
- * @example toPascalCase('user-profile') -> 'UserProfile'
80
- * @example toPascalCase('user_profile') -> 'UserProfile'
81
- */
82
- function toPascalCase(str) {
83
- return str
84
- .replace(/[-_](.)/g, (_, char) => char.toUpperCase())
85
- .replace(/^(.)/, (_, char) => char.toUpperCase());
41
+ return (0, komoji_1.toSnakeCase)(str);
86
42
  }
87
43
  /**
88
44
  * Convert a camelCase or PascalCase string to SCREAMING_SNAKE_CASE.
45
+ * @deprecated Use toConstantCase from komoji instead
89
46
  * @example toScreamingSnake('userProfile') -> 'USER_PROFILE'
90
47
  * @example toScreamingSnake('UserProfile') -> 'USER_PROFILE'
91
48
  */
92
49
  function toScreamingSnake(str) {
93
- return str
94
- .replace(/([A-Z])/g, '_$1')
95
- .replace(/[-\s]/g, '_')
96
- .toUpperCase()
97
- .replace(/^_/, '');
50
+ return (0, komoji_1.toConstantCase)(str);
98
51
  }
package/esm/case.js CHANGED
@@ -1,19 +1,17 @@
1
1
  /**
2
2
  * Case transformation utilities
3
- */
4
- /**
5
- * Convert PascalCase to camelCase (lowercase first character)
6
- * @example "UserProfile" -> "userProfile"
7
- */
8
- export function lcFirst(str) {
9
- return str.charAt(0).toLowerCase() + str.slice(1);
10
- }
11
- /**
12
- * Convert camelCase to PascalCase (uppercase first character)
13
- * @example "userProfile" -> "UserProfile"
14
- */
15
- export function ucFirst(str) {
16
- return str.charAt(0).toUpperCase() + str.slice(1);
3
+ *
4
+ * Pure case transforms are delegated to komoji (the origin of truth).
5
+ * This module re-exports them for backward compatibility and adds
6
+ * inflekt-specific helpers (fixCapitalisedPlural, underscore, toScreamingSnake).
7
+ */
8
+ import { lcFirst, ucFirst, toCamelCase as _toCamelCase, toPascalCase, toSnakeCase, toConstantCase, } from 'komoji';
9
+ // Re-export komoji functions directly
10
+ export { lcFirst, ucFirst, toPascalCase, toSnakeCase, toConstantCase };
11
+ // Re-export toCamelCase — komoji's version accepts a second parameter
12
+ // (stripLeadingNonAlphabetChars) so we wrap to keep the simpler inflekt signature
13
+ export function toCamelCase(str) {
14
+ return _toCamelCase(str);
17
15
  }
18
16
  /**
19
17
  * Fix capitalized plurals that end with a number followed by 'S'
@@ -23,66 +21,21 @@ export function ucFirst(str) {
23
21
  export function fixCapitalisedPlural(str) {
24
22
  return str.replace(/[0-9]S(?=[A-Z]|$)/g, (match) => match.toLowerCase());
25
23
  }
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
24
  /**
44
25
  * Convert PascalCase or camelCase to snake_case
26
+ * @deprecated Use toSnakeCase from komoji instead
45
27
  * @example underscore('UserProfile') -> 'user_profile'
46
28
  * @example underscore('userProfile') -> 'user_profile'
47
29
  */
48
30
  export function underscore(str) {
49
- return str
50
- .replace(/([A-Z])/g, '_$1')
51
- .replace(/^_/, '')
52
- .toLowerCase();
53
- }
54
- /**
55
- * Convert a hyphenated or underscored string to camelCase.
56
- * Unlike `camelize`, this also handles hyphens and preserves
57
- * camelCase boundaries that are already present.
58
- * @example toCamelCase('user-profile') -> 'userProfile'
59
- * @example toCamelCase('user_profile') -> 'userProfile'
60
- */
61
- export function toCamelCase(str) {
62
- return str
63
- .replace(/[-_](.)/g, (_, char) => char.toUpperCase())
64
- .replace(/^(.)/, (_, char) => char.toLowerCase());
65
- }
66
- /**
67
- * Convert a hyphenated or underscored string to PascalCase.
68
- * Unlike `camelize`, this also handles hyphens.
69
- * @example toPascalCase('user-profile') -> 'UserProfile'
70
- * @example toPascalCase('user_profile') -> 'UserProfile'
71
- */
72
- export function toPascalCase(str) {
73
- return str
74
- .replace(/[-_](.)/g, (_, char) => char.toUpperCase())
75
- .replace(/^(.)/, (_, char) => char.toUpperCase());
31
+ return toSnakeCase(str);
76
32
  }
77
33
  /**
78
34
  * Convert a camelCase or PascalCase string to SCREAMING_SNAKE_CASE.
35
+ * @deprecated Use toConstantCase from komoji instead
79
36
  * @example toScreamingSnake('userProfile') -> 'USER_PROFILE'
80
37
  * @example toScreamingSnake('UserProfile') -> 'USER_PROFILE'
81
38
  */
82
39
  export function toScreamingSnake(str) {
83
- return str
84
- .replace(/([A-Z])/g, '_$1')
85
- .replace(/[-\s]/g, '_')
86
- .toUpperCase()
87
- .replace(/^_/, '');
40
+ return toConstantCase(str);
88
41
  }
@@ -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, (key) => camelize(key, true));
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, (key) => camelize(key, true), {
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.0",
3
+ "version": "0.6.0",
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",
@@ -41,7 +41,8 @@
41
41
  "makage": "0.1.10"
42
42
  },
43
43
  "dependencies": {
44
- "inflection": "^3.0.0"
44
+ "inflection": "^3.0.0",
45
+ "komoji": "0.9.0"
45
46
  },
46
- "gitHead": "d45378ff6379b3e8db0a38dfe17258f623859c6b"
47
+ "gitHead": "db30bc2755067006e1d6b6e36e84312a3953f033"
47
48
  }
@@ -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, (key) => camelize(key, true));
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, (key) => camelize(key, true), {
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, (key) => camelize(key, true));
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, (key) => camelize(key, true), {
31
+ * inflektTree(obj, toCamelCase, {
32
32
  * skip: (key) => key.startsWith('_')
33
33
  * });
34
34
  */