Socket
Socket
Sign inDemoInstall

decamelize-keys

Package Overview
Dependencies
4
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

decamelize-keys

Convert object keys from camel case


Version published
Maintainers
1
Weekly downloads
8,104,361
decreased by-18.2%
Install size
305 kB

Weekly downloads

Package description

What is decamelize-keys?

The `decamelize-keys` npm package is designed to convert object keys from camelCase to lowercase with a customizable separator, making it useful for transforming JavaScript object keys to match different coding or data format conventions.

What are decamelize-keys's main functionalities?

Convert object keys from camelCase to a custom separator

This feature allows you to convert the keys of an object from camelCase to another format using a custom separator, such as a hyphen. It's particularly useful for preparing data to be sent to APIs or systems that require a different naming convention.

const decamelizeKeys = require('decamelize-keys');
const result = decamelizeKeys({ 'fooBar': true, 'barBaz': 'yes' }, '-');
console.log(result); // Output: { 'foo-bar': true, 'bar-baz': 'yes' }

Exclude specific keys from being decamelized

This functionality allows you to exclude certain keys from being transformed. It's useful when you have specific keys that need to remain in camelCase for consistency or compatibility reasons.

const decamelizeKeys = require('decamelize-keys');
const options = { exclude: ['fooBar'] };
const result = decamelizeKeys({ 'fooBar': true, 'barBaz': 'yes' }, '-', options);
console.log(result); // Output: { 'fooBar': true, 'bar-baz': 'yes' }

Other packages similar to decamelize-keys

Readme

Source

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.

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}}
  • camelcase-keys - The inverse of this package.

Keywords

FAQs

Last updated on 30 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc