1.0.2 • Published 6 years ago

keys-to-camelcase v1.0.2

Weekly downloads
8
License
MIT
Repository
github
Last release
6 years ago

keys-to-camelcase

Build Status

:building_construction: Convert object keys to camelCase using camelcase :building_construction:

:thumbsup: Can be used within node or the browser :thumbsup:

:rocket: This fork plays nicely with tools like uglifyjs-webpack-plugin :rocket:

Install

npm

$ npm install --save keys-to-camelcase

Yarn

$ yarn add keys-to-camelcase

Usage

const keysToCamelcase = require('keys-to-camelcase');

// Convert an object
keysToCamelcase({ 'foo-bar': true });
//=> {fooBar: true}

// Convert an array of objects
keysToCamelcase([{ 'foo-bar': true }, { 'bar-foo': false }]);
//=> [{fooBar: true}, {barFoo: false}]

keysToCamelcase(
  { 'foo-bar': true, nested: { unicorn_rainbow: true } },
  { deep: true }
);
//=> {fooBar: true, nested: {unicornRainbow: true}}
const keysToCamelcase = require('keys-to-camelcase');

const argv = require('minimist')(process.argv.slice(2));
//=> {_: [], 'foo-bar': true}

keysToCamelcase(argv);
//=> {_: [], fooBar: true}

API

keysToCamelcase(input, options)

input

Type: Object Object[]

Object or array of objects to camelCase.

options

Type: Object

exclude

Type: string[] RegExp[] Default: []

Exclude keys from being camelCased.

e.g.

keysToCamelcase({ 'foo-bar': true, 'bar-foo': true }, { exclude: [/^f/] });
//=> { 'foo-bar': true, barFoo: true }
deep

Type: boolean Default: false

Recurse nested objects and objects in arrays.

e.g.

keysToCamelcase(
  { 'foo-bar': true, 'another-one': { 'bar-foo': false } },
  { deep: true }
);
//=> { fooBar: true, anotherOne: { barFoo: false }}

Related

License

MIT © Sindre Sorhus
MIT © Jon Short