What is camelize?
The camelize npm package is designed to convert strings (including object keys) from various formats like snake_case, kebab-case, etc., into camelCase. This is particularly useful in JavaScript programming where camelCase is a common convention for naming variables and object keys.
What are camelize's main functionalities?
Camelizing strings
Converts a kebab-case or any other non-camelCase string into camelCase. For example, 'my-example-string' would be converted to 'myExampleString'.
"my-example-string".camelize()
Camelizing object keys
Converts all keys in an object from other formats into camelCase. For example, an object with keys 'my-key' and 'another_key' would have its keys converted to 'myKey' and 'anotherKey', respectively.
camelize({ 'my-key': true, 'another_key': 'value' })
Other packages similar to camelize
humps
Similar to camelize, humps is designed to convert strings and object keys between camelCase and snake_case. It offers more comprehensive options for decamelizing and camelize keys recursively in nested objects, which might make it a more versatile choice for some projects.
change-case
Change-case is a more comprehensive string manipulation library that includes functions for transforming strings into various cases, including camel case. It offers a wider range of case transformations compared to camelize, making it suitable for projects that require more than just camelization.
camelize
recursively transform key strings to camel-case
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"
}
]
}
methods
var camelize = require('camelize')
camelize(obj)
Convert the key strings in obj
to camel-case recursively.
install
With npm do:
npm install camelize
To use in the browser, use browserify.
license
MIT