@agilebot/decamelize-keys
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

decamelize-keys

Convert object keys from camel case using decamelize

Install

npm install decamelize-keys

Usage

import decamelizeKeys from 'decamelize-keys';

// Convert an object
decamelizeKeys({fooBar: true});
//=> {foo_bar: true}

// Convert an array of objects
decamelizeKeys([{fooBar: true}, {barFoo: false}]);
//=> [{foo_bar: true}, {bar_foo: false}]

API

decamelizeKeys(input, options?)

input

Type: object | object[]

An object or array of objects to decamelize.

options

Type: object

separator

Type: string
Default: '_'

The character or string used to separate words.

import decamelizeKeys from 'decamelize-keys';

decamelizeKeys({fooBar: true});
//=> {foo_bar: true}

decamelizeKeys({fooBar: true}, {separator: '-'});
//=> {'foo-bar': true}
exclude

Type: Array<string | RegExp>
Default: []

Exclude keys from being decamelized.

stopPaths

Type: string
Default: []

Exclude children at the given object paths in dot-notation from being decamel-cased. For example, with an object like {a: {b: '🦄'}}, the object path to reach the unicorn is 'a.b'.

decamelizeKeys({
	aB: 1,
	aC: {
		cD: 1,
		cE: {
			eF: 1
		}
	}
}, {
	deep: true,
	stopPaths: [
		'aC.cE'
	]
}),
/*
{
	a_b: 1,
	a_c: {
		c_d: 1,
		c_e: {
			eF: 1
		}
	}
}
*/
deep

Type: boolean
Default: false

Recurse nested objects and objects in arrays.

import decamelizeKeys from 'decamelize-keys';

decamelizeKeys({fooBar: true, nested: {unicornRainbow: true}}, {deep: true});
//=> {foo_bar: true, nested: {unicorn_rainbow: true}}

Related

Package Sidebar

Install

npm i @agilebot/decamelize-keys

Weekly Downloads

1

Version

2.0.2

License

MIT

Unpacked Size

9.78 kB

Total Files

5

Last publish

Collaborators

  • kokororin