transform-obj-keys

3.0.0 • Public • Published

transform-obj-keys

Transform object keys easily using whatever transform function like: camelcase, decamelize, uppercamelcase, to-case or simple String.prototype.toLowerCase()

Install

$ npm install --save transform-obj-keys

Usage

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}}
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

Dependencies (1)

Dev Dependencies (16)

Package Sidebar

Install

npm i transform-obj-keys

Weekly Downloads

1,122

Version

3.0.0

License

MIT

Unpacked Size

167 kB

Total Files

18

Last publish

Collaborators

  • kamahl19