Skip to content

recursively transform key strings to camel-case

License

Notifications You must be signed in to change notification settings

apoorv2404/camelize

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

camelize

recursively transform key strings to camel-case

build status

browser support

example

var camelize = require('camelize');
var obj = {
    fee_fie_foe: 'fum',
    beep_boop: [
        { 'abc.xyz': 'mno' },
        { 'foo-bar': 'baz' }
    ]
};
var res = camelize(obj);
console.log(JSON.stringify(res, null, 2));

output:

{
  "feeFieFoe": "fum",
  "beepBoop": [
    {
      "abcXyz": "mno",
    },
    {
      "fooBar": "baz"
    }
  ]
}

Also supports ignoring certain keys by second parameter. This parameter should be an object with an "ignore" property, which is an array of key names to ignore. Useful for mongo "_id" fields.

var camelize = require('camelize');
var obj = {
    _id: "abc123",
    fee_fie_foe: 'fum',
    beep_boop: [
        { 'abc.xyz': 'mno', _id: "def456" },
        { 'foo-bar': 'baz' }
    ]
};
var res = camelize(obj, { ignore: ["_id"] });
console.log(JSON.stringify(res, null, 2));

output

{
  "_id": "abc123",
  "feeFieFoe": "fum",
  "beepBoop": [
    {
      "abcXyz": "mno",
      "_id": "def456"
    },
    {
      "fooBar": "baz"
    }
  ]
}

methods

var camelize = require('camelize')

camelize(obj, [options])

Convert the key strings in obj to camel-case recursively.

If provided, the second parameter should be an object that can have the following properties

  • ignore: should be an array of keys to ignore (leave as-is) when converting.

install

With npm do:

npm install camelize

To use in the browser, use browserify.

license

MIT

About

recursively transform key strings to camel-case

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%