Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update type for input and optiopns and update README #122

Merged
merged 7 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ camelcaseKeys(commandLineArguments);
```
*/
export default function camelcaseKeys<
T extends Record<string, unknown> | readonly any[],
T extends Record<string, unknown> | ReadonlyArray<Record<string, unknown>>,
OptionsType extends Options = Options,
>(
input: T,
Expand Down
22 changes: 2 additions & 20 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ expectType<Array<{fooBar: boolean}>>(camelFooBarArray);

expectType<Array<{fooBar: boolean}>>(camelcaseKeys([{'foo-bar': true}]));

expectType<string[]>(camelcaseKeys(['name 1', 'name 2']));

expectType<string[]>(camelcaseKeys(['name 1', 'name 2'], {deep: true}));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the unsupported array format test.

expectType<readonly [{readonly fooBar: true}, {readonly fooBaz: true}]>(
camelcaseKeys([{'foo-bar': true}, {'foo-baz': true}] as const),
);
Expand Down Expand Up @@ -440,31 +436,17 @@ expectType<{
}),
);

expectType<[
() => 'foo',
{foo: string},
Promise<unknown>,
]>(
camelcaseKeys([
() => 'foo',
{foo: 'bar'},
new Promise(resolve => {
resolve(true);
}),
]),
);

// Test for function with inferred type
// eslint-disable-next-line @typescript-eslint/comma-dangle
function camelcaseKeysDeep<
T extends Record<string, unknown> | readonly unknown[]
T extends Record<string, unknown> | ReadonlyArray<Record<string, unknown>>
>(response: T): CamelCaseKeys<T, true> {
return camelcaseKeys(response, {deep: true});
}

// eslint-disable-next-line @typescript-eslint/comma-dangle
function camelcaseKeysPascalCase<
T extends Record<string, unknown> | readonly unknown[]
T extends Record<string, unknown> | ReadonlyArray<Record<string, unknown>>
>(response: T): CamelCaseKeys<T, false, true> {
return camelcaseKeys(response, {pascalCase: true});
}
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ camelcaseKeys(commandLineArguments);

#### input

Type: `object | object[]`
Type: `Record<string, unknown> | ReadonlyArray<Record<string, unknown>>`

An object or array of objects to camel-case.
An `Record<string, unknown>` or array of `Record<string, unknown>` to camel-case.

#### options

Type: `object`
Type: `Options`

##### exclude

Expand Down