@replygirl/change-case-object
    TypeScript icon, indicating that this package has built-in type declarations

    1.3.0 • Public • Published

    change-case-object

    Recursively change the case of an object's keys

    Installation

    yarn add @replygirl/change-case-object

    Usage

    Functions

    import { /* function */ } from 'change-case-object'

    camelCase

    camelCase({ some_key: { some_other_key: true })
    // { someKey: { someOtherKey: true }}

    capitalCase

    capitalCase({ some_key: { some_other_key: true })
    // { 'Some Key': { 'Some Other Key': true }}

    constantCase

    constantCase({ some_key: { some_other_key: true })
    // { SOME_KEY: { SOME_OTHER_KEY: true }}

    dotCase

    Why would you do this??

    dotCase({ some_key: { some_other_key: true })
    // { 'some.key': { 'some.other.key': true }}

    headerCase

    headerCase({ some_key: { some_other_key: true })
    // { 'Some-Key': { 'Some-Other-Key': true }}

    noCase

    noCase({ some_key: { some_other_key: true })
    // { 'some key': { 'some other key': true }}

    paramCase

    paramCase({ some_key: { some_other_key: true })
    // { 'some-key': { 'some-other-key': true }}

    pascalCase

    pascalCase({ some_key: { some_other_key: true })
    // { SomeKey: { SomeOtherKey: true }}

    pathCase

    pathCase({ some_key: { some_other_key: true })
    // { 'some/key': { 'some/other/key': true }}

    sentenceCase

    sentenceCase({ some_key: { some_other_key: true })
    // { 'Some key': { 'Some other key': true }}

    snakeCase

    snakeCase({ 'some key': { 'some other key': true })
    // { some_key: { some_other_key: true }}

    CasedObject class

    import { CasedObject /*, Case */ } from 'change-case-object'

    Static functions

    All of the individual functions are available as static members.

    CasedObject.camelCase({ some_key: { some_other_key: true }})
    // { someKey: { someOtherKey: true }}

    Instances

    const someObj = { some_key: { 'some other key': true }}
    
    // initialize without changing case
    const foo = new CasedObject(someObj)
    console.info(foo.value) // { some_key: { 'some other key': true }}
    
    // initialize and change case
    const bar = new CasedObject(someObj, { case: 'camel' })
    console.info(bar.value) // { someKey: { someOtherKey: true }}
    
    // initialize and change case using enum
    const baz = new CasedObject(someObj, { case: Case.camel })
    console.info(baz.value) // { someKey: { someOtherKey: true }}
    
    // output the value with keys in a different case
    console.info(baz.snakeCase) // { some_key: { some_other_key: true }}
    console.info(baz.value) // { someKey: { someOtherKey: true }}
    
    // change the case of the value's keys
    baz.value = baz.snakeCase
    console.info(baz.value) // { some_key: { some_other_key: true }}

    License

    ISC (c) 2020 replygirl

    Keywords

    none

    Install

    npm i @replygirl/change-case-object

    DownloadsWeekly Downloads

    66

    Version

    1.3.0

    License

    ISC

    Unpacked Size

    19.4 kB

    Total Files

    14

    Last publish

    Collaborators

    • imogen