case-key
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-alpha.2 • Public • Published

case-key

Convert object keys from camelCase to snake_case or vice versa

This lib is originated from sindresorhus/camelcase-keys and bendrucker/snakecase-keys, for exclude option in camelcase-keys and snakecase-keys does not stop recursion in nested objects.

Usage

interface KeyCaseOptions {
  deep?: boolean; // default true
  exclude?: Array<RegExp>; // default []
  strictKey?: boolean; // default true
}
 
camelcase(targetobject, optionKeyCaseOptions);
 
snakecase(targetobject, optionKeyCaseOptions);

Demo Code

import { camelcase, snakecase } from 'case-key';
 
camelcase({
  hello_world: {
    camel_case: {
      some_key: 123
    }
  }
}, {
  exclude: [/case/]
});
 
/*
{
  helloWorld: {
    camel_case: {
      some_key: 123
    }
  }
}
*/
 
camelcase({ 'hello.world': 'case' }, { strictKey: true }); // output hello.world
 
camelcase({ 'hello.world': 'case' }, { strictKey: false }); // output helloWorld

Readme

Keywords

none

Package Sidebar

Install

npm i case-key

Weekly Downloads

1

Version

0.0.1-alpha.2

License

WTFPL

Unpacked Size

5.47 kB

Total Files

6

Last publish

Collaborators

  • oyang