recursively transform key strings to camel-case
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"
}
]
}
var camelize = require('camelize')
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.
With npm do:
npm install camelize
To use in the browser, use browserify.
MIT