Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kamahl19/transform-obj-keys
Transform object keys easily using whatever transform function
https://github.com/kamahl19/transform-obj-keys
Last synced: 1 day ago
JSON representation
Transform object keys easily using whatever transform function
- Host: GitHub
- URL: https://github.com/kamahl19/transform-obj-keys
- Owner: Kamahl19
- License: mit
- Created: 2018-02-23T10:08:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-02T01:19:53.000Z (almost 5 years ago)
- Last Synced: 2024-05-15T15:30:31.352Z (6 months ago)
- Language: JavaScript
- Size: 99.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# transform-obj-keys
> Transform object keys easily using whatever transform function like: [`camelcase`](https://github.com/sindresorhus/camelcase), [`decamelize`](https://github.com/sindresorhus/decamelize), [`uppercamelcase`](https://github.com/SamVerschueren/uppercamelcase), [`to-case`](https://github.com/ianstormtaylor/to-case) or simple String.prototype.toLowerCase()
## Install
```
$ npm install --save transform-obj-keys
```## Usage
```js
const transformObjKeys = require('transform-obj-keys');
const camelCase = require('camelcase');// Convert an object
transformObjKeys({'foo-bar': true}, camelCase);
//=> {fooBar: true}// Convert an array of objects
transformObjKeys([{'foo-bar': true}, {'bar-foo': false}], camelCase);
//=> [{fooBar: true}, {barFoo: false}]transformObjKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, camelCase, {deep: true});
//=> {fooBar: true, nested: {unicornRainbow: true}}
``````js
const transformObjKeys = require('transform-obj-keys');
const camelCase = require('camelcase');const argv = require('minimist')(process.argv.slice(2));
//=> {_: [], 'foo-bar': true}transformObjKeys(argv, camelCase);
//=> {_: [], fooBar: true}
```## API
### transformObjKeys(input, transformFunc, [options])
#### input
Type: `Object` `Object[]`
Object or array of objects to transform.
#### transformFunc
Type: `Function`
Function to manipulate strings
#### options
Type: `Object`
##### exclude
Type: `string[]` `RegExp[]`
Default: `[]`Exclude keys from being transformed.
##### deep
Type: `boolean`
Default: `false`Recurse nested objects and objects in arrays.
## License
MIT © [Martin Litvaj](https://litvaj.com)