npm

Bring the best of OSS JavaScript development to your projects with npm Orgs - private packages & team management tools.Learn more »

keys-to-camelcase

1.0.2 • Public • Published

keys-to-camelcase

Build Status

🏗 Convert object keys to camelCase using camelcase 🏗

👍 Can be used within node or the browser 👍

🚀 This fork plays nicely with tools like uglifyjs-webpack-plugin 🚀

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

  • snakecase-keys - Convert an object's keys to snake case
  • camelcase-keys - The original project which was forked to create keys-to-camelcase

License

MIT © Sindre Sorhus
MIT © Jon Short

install

npm i keys-to-camelcase

Downloadsweekly downloads

2

version

1.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability