Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

snakecase-keys

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snakecase-keys

Convert an object's keys to snake case

  • 5.4.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
588K
increased by2.96%
Maintainers
1
Weekly downloads
 
Created

What is snakecase-keys?

The snakecase-keys npm package is a utility that converts the keys of an object to snake_case. This can be particularly useful when working with APIs or databases that require snake_case formatting.

What are snakecase-keys's main functionalities?

Convert Object Keys to Snake Case

This feature allows you to convert the keys of an object from camelCase to snake_case. It works recursively, so nested objects are also converted.

const snakecaseKeys = require('snakecase-keys');
const camelCaseObject = { fooBar: 'baz', nestedObject: { helloWorld: 'value' } };
const snakeCaseObject = snakecaseKeys(camelCaseObject);
console.log(snakeCaseObject); // { foo_bar: 'baz', nested_object: { hello_world: 'value' } }

Exclude Specific Keys

This feature allows you to exclude specific keys from being converted to snake_case. You can pass an array of keys to the `exclude` option.

const snakecaseKeys = require('snakecase-keys');
const camelCaseObject = { fooBar: 'baz', nestedObject: { helloWorld: 'value' }, excludeMe: 'no_change' };
const snakeCaseObject = snakecaseKeys(camelCaseObject, { exclude: ['excludeMe'] });
console.log(snakeCaseObject); // { foo_bar: 'baz', nested_object: { hello_world: 'value' }, excludeMe: 'no_change' }

Deep Conversion

This feature ensures that all nested objects are also converted to snake_case. By default, the conversion is deep, but you can control this behavior with the `deep` option.

const snakecaseKeys = require('snakecase-keys');
const camelCaseObject = { fooBar: 'baz', nestedObject: { helloWorld: 'value' } };
const snakeCaseObject = snakecaseKeys(camelCaseObject, { deep: true });
console.log(snakeCaseObject); // { foo_bar: 'baz', nested_object: { hello_world: 'value' } }

Other packages similar to snakecase-keys

Keywords

FAQs

Package last updated on 28 Aug 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc