camelcase-keys

  • Version 7.0.0
  • Published
  • 10.9 kB
  • 4 dependencies
  • MIT license

Install

npm i camelcase-keys
yarn add camelcase-keys
pnpm add camelcase-keys

Overview

Convert object keys to camel case

Index

Functions

function camelcaseKeys

camelcaseKeys: <
T extends readonly any[] | Record<string, any>,
Options extends camelcaseKeys.Options
>(
input: T,
options?: Options
) => CamelCaseKeys<
T,
WithDefault<Options['deep'], false>,
WithDefault<Options['pascalCase'], false>,
WithDefault<Options['exclude'], EmptyTuple>,
WithDefault<Options['stopPaths'], EmptyTuple>
>;
  • Convert object keys to camel case using [camelcase](https://github.com/sindresorhus/camelcase).

    Parameter input

    Object or array of objects to camel-case.

    Example 1

    import camelcaseKeys = require('camelcase-keys');
    // Convert an object
    camelcaseKeys({'foo-bar': true});
    //=> {fooBar: true}
    // Convert an array of objects
    camelcaseKeys([{'foo-bar': true}, {'bar-foo': false}]);
    //=> [{fooBar: true}, {barFoo: false}]
    camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true});
    //=> {fooBar: true, nested: {unicornRainbow: true}}
    // Convert object keys to pascal case
    camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true, pascalCase: true});
    //=> {FooBar: true, Nested: {UnicornRainbow: true}}
    import minimist = require('minimist');
    const argv = minimist(process.argv.slice(2));
    //=> {_: [], 'foo-bar': true}
    camelcaseKeys(argv);
    //=> {_: [], fooBar: true}

Interfaces

interface Options

interface Options {}

    property deep

    readonly deep?: boolean;
    • Recurse nested objects and objects in arrays.

      false

    property exclude

    readonly exclude?: ReadonlyArray<string | RegExp>;
    • Exclude keys from being camel-cased.

      If this option can be statically determined, it's recommended to add as const to it.

      []

    property pascalCase

    readonly pascalCase?: boolean;
    • Uppercase the first character as in bye-byeByeBye.

      false

    property stopPaths

    readonly stopPaths?: readonly string[];
    • Exclude children at the given object paths in dot-notation from being camel-cased. For example, with an object like {a: {b: '🦄'}}, the object path to reach the unicorn is 'a.b'.

      If this option can be statically determined, it's recommended to add as const to it.

      []

      Example 1

      ``` camelcaseKeys({ a_b: 1, a_c: { c_d: 1, c_e: { e_f: 1 } } }, { deep: true, stopPaths: [ 'a_c.c_e' ] }), // { // aB: 1, // aC: { // cD: 1, // cE: { // e_f: 1 // } // } // } ```

    Package Files (1)

    Dependencies (4)

    Dev Dependencies (4)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/camelcase-keys.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/camelcase-keys)
    • HTML
      <a href="https://www.jsdocs.io/package/camelcase-keys"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>