-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a352c0
commit e0537f0
Showing
4 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
declare namespace camelcaseKeys { | ||
interface Options { | ||
/** | ||
Recurse nested objects and objects in arrays. | ||
@default false | ||
*/ | ||
readonly deep?: boolean; | ||
|
||
/** | ||
Exclude keys from being camelCased. | ||
@default [] | ||
*/ | ||
readonly exclude?: Array<string | RegExp>; | ||
} | ||
} | ||
|
||
/** | ||
Convert object keys to camelCase using [`camelcase`](https://github.com/sindresorhus/camelcase). | ||
@param input - Object or array of objects to camelCase. | ||
@example | ||
``` | ||
import camelcaseKeys = require('camelcase-keys'); | ||
// Convert an object | ||
camelcaseKeys({'foo-bar': true}); | ||
//=> {fooBar: true} | ||
// Convert an array of objects | ||
camelcaseKeys([{'foo-bar': true}, {'bar-foo': false}]); | ||
//=> [{fooBar: true}, {barFoo: false}] | ||
camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true}); | ||
//=> {fooBar: true, nested: {unicornRainbow: true}} | ||
import minimist = require('minimist'); | ||
const argv = minimist(process.argv.slice(2)); | ||
//=> {_: [], 'foo-bar': true} | ||
camelcaseKeys(argv); | ||
//=> {_: [], fooBar: true} | ||
``` | ||
*/ | ||
declare function camelcaseKeys( | ||
input: unknown, | ||
options?: camelcaseKeys.Options | ||
): {[key: string]: unknown}; | ||
|
||
export = camelcaseKeys; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {expectType} from 'tsd'; | ||
import camelcaseKeys = require('.'); | ||
|
||
expectType<{[key: string]: unknown}>(camelcaseKeys({'foo-bar': true})); | ||
expectType<{[key: string]: unknown}>( | ||
camelcaseKeys({'foo-bar': true}, {deep: true}) | ||
); | ||
expectType<{[key: string]: unknown}>( | ||
camelcaseKeys({'foo-bar': true}, {exclude: ['foo', /bar/]}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters