uncamel
v0.0.1
Published
Small lib for camelize and decamelize objects
Readme
uncamel
Convert object keys to camel case using camelcase and decamelize by cache
Instalation
npm install uncamelUsage
import { camelize, decamelize } from 'uncamel';
const refObj = {
FooBar: 'baz',
};
const camelizeObj = camelize(refObj);
// => { fooBar: 'baz' }
const decamelizeObj = decamelize(camelizeObj);
// => { FooBar: 'baz' }Options
Syntax:
camelize(obj, options);
| Option name | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| deep | boolean | false | Use recursive walker |
| pascalCase | boolean | false | Transform to PascalCase: foo-bar → FooBar |
| preserveConsecutiveUppercase | boolean | false | Preserve consecutive uppercase characters: foo-BAR → FooBAR |
Custom walker
You can use custom function for transform keys:
import { walker, cache } from 'uncamel';
const refObj = {
FooBar: 'baz',
};
const mappedObj = walker(refObj, (val, key) => {
const newKey = `custom_${key}`;
cache.set(newKey, key);
return [val, newKey];
}, options);
// => { custom_FooBar: 'baz' }