Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
decamelize-keys
Advanced tools
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.
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' }
Similar to `decamelize-keys`, `humps` can also convert keys between camelCase and snake_case. However, `humps` provides more comprehensive options for both decamelizing and camelizing keys, making it a versatile choice for different case conversion needs.
The `snakeize` package is focused on converting object keys to snake_case. While it serves a similar purpose to `decamelize-keys` in terms of changing the case of keys, it is specifically tailored for snake_case conversion without the flexibility of choosing a custom separator.
As the inverse of `decamelize-keys`, `camelcase-keys` converts object keys from snake_case or kebab-case to camelCase. It's useful for scenarios where you need to convert data to match JavaScript's naming conventions, offering a complementary functionality.
Convert object keys from camel case using
decamelize
npm install decamelize-keys
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}]
Type: object | object[]
An object or array of objects to decamelize.
Type: object
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}
Type: Array<string | RegExp>
Default: []
Exclude keys from being decamelized.
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}}
FAQs
Convert object keys from camel case
We found that decamelize-keys demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.