Skip to content

Commit 0f08769

Browse files
committed
Revert argv change. Update camelize to suppor kebab case
1 parent ae788e7 commit 0f08769

6 files changed

Lines changed: 17 additions & 210 deletions

File tree

packages/inflekt/README.md

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import {
3939
toFieldName,
4040
toQueryName,
4141
inflektTree,
42-
camelizeArgv,
4342
} from 'inflekt';
4443

4544
// Basic singularization/pluralization
@@ -75,11 +74,6 @@ const apiResponse = {
7574
};
7675
inflektTree(apiResponse, (key) => camelize(key, true));
7776
// Result: { userName: 'John', orderItems: [{ itemId: 1, productName: 'Widget' }] }
78-
79-
// CLI argument transformation (kebab-case to camelCase)
80-
const argv = { 'schema-file': 'test.graphql', 'dry-run': true, _: [] };
81-
camelizeArgv(argv);
82-
// Result: { schemaFile: 'test.graphql', dryRun: true, _: [] }
8377
```
8478

8579
## API
@@ -110,10 +104,6 @@ camelizeArgv(argv);
110104

111105
- `inflektTree(obj, transformer, options?)` - Recursively transform all property names in an object tree
112106

113-
### CLI Argument Utilities
114-
115-
- `camelizeArgv(argv)` - Transform CLI argument keys (kebab-case/snake_case) to camelCase, preserving minimist internals
116-
117107
## Deep Object Key Transformation
118108

119109
The `inflektTree` function recursively transforms all property names in an object tree using any transformer function. This is useful for converting API responses between naming conventions.
@@ -190,40 +180,6 @@ const result3 = inflektTree(deepObject, (key) => camelize(key, true), {
190180
- Returns primitives unchanged
191181
- Works with any transformer function
192182

193-
## CLI Argument Transformation
194-
195-
The `camelizeArgv` function is a specialized utility for transforming CLI argument objects (typically from minimist or similar parsers) from kebab-case or snake_case to camelCase.
196-
197-
### Usage
198-
199-
```typescript
200-
import { camelizeArgv } from 'inflekt';
201-
202-
// Transform CLI arguments
203-
const argv = {
204-
'schema-file': 'test.graphql',
205-
'dry-run': true,
206-
output_dir: 'dist',
207-
_: ['arg1', 'arg2']
208-
};
209-
210-
const parsedArgv = camelizeArgv(argv);
211-
// Result:
212-
// {
213-
// schemaFile: 'test.graphql',
214-
// dryRun: true,
215-
// outputDir: 'dist',
216-
// _: ['arg1', 'arg2']
217-
// }
218-
```
219-
220-
### Features
221-
222-
- Transforms kebab-case and snake_case keys to camelCase
223-
- Only transforms top-level keys (preserves nested object structure)
224-
- Preserves minimist internal keys (`_` and keys starting with `_`)
225-
- Built on top of `inflektTree` for consistency
226-
227183
## Latin Suffix Overrides
228184

229185
This library handles Latin plural suffixes differently than the standard `inflection` package to match PostGraphile's behavior:

packages/inflekt/__tests__/argv.test.ts

Lines changed: 0 additions & 133 deletions
This file was deleted.

packages/inflekt/__tests__/inflection.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ describe('camelize', () => {
141141
expect(camelize('api_schema', true)).toBe('apiSchema');
142142
});
143143

144+
it('should convert kebab-case to PascalCase by default', () => {
145+
expect(camelize('schema-file')).toBe('SchemaFile');
146+
expect(camelize('dry-run')).toBe('DryRun');
147+
expect(camelize('output-dir')).toBe('OutputDir');
148+
});
149+
150+
it('should convert kebab-case to camelCase when lowFirstLetter is true', () => {
151+
expect(camelize('schema-file', true)).toBe('schemaFile');
152+
expect(camelize('dry-run', true)).toBe('dryRun');
153+
expect(camelize('output-dir', true)).toBe('outputDir');
154+
});
155+
144156
it('should handle single words', () => {
145157
expect(camelize('user')).toBe('User');
146158
expect(camelize('user', true)).toBe('user');

packages/inflekt/src/argv.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/inflekt/src/case.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ export function fixCapitalisedPlural(str: string): string {
2828
}
2929

3030
/**
31-
* Convert snake_case to PascalCase (or camelCase if lowFirstLetter is true)
32-
* @param str - The snake_case string to convert
31+
* Convert snake_case or kebab-case to PascalCase (or camelCase if lowFirstLetter is true)
32+
* @param str - The snake_case or kebab-case string to convert
3333
* @param lowFirstLetter - If true, returns camelCase instead of PascalCase
3434
* @example camelize('user_profile') -> 'UserProfile'
3535
* @example camelize('user_profile', true) -> 'userProfile'
36+
* @example camelize('schema-file') -> 'SchemaFile'
37+
* @example camelize('schema-file', true) -> 'schemaFile'
3638
*/
3739
export function camelize(str: string, lowFirstLetter?: boolean): string {
3840
const result = str
39-
.split('_')
41+
.split(/[-_]/)
4042
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
4143
.join('');
4244

packages/inflekt/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ export * from './pluralize';
99
export * from './case';
1010
export * from './naming';
1111
export * from './transform-keys';
12-
export * from './argv';

0 commit comments

Comments
 (0)