camelize2

recursively transform key strings to camel-case

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
camelize2
1.0.05 years ago5 years agoMinified + gzip package size for camelize2 in KB

Readme

camelize2
Super handy and flexible library for transforming any-shape key strings to camel-case
build status

Why do we need camelize2?

camelize is a great and simple library. But unfortunately repository seems to be dead and has not been updated for a long time.
Camelize2 for the resque!
:whitecheckmark: This library provides new features according to developer needs.
:whitecheckmark: This library fixes issues of camelize.
:whitecheckmark: This library uses Mocha for testing
:whitecheckmark: This library is opened for contributing.
Initially was forked from camelize.

Examples

const camelize = require('camelize2')

// You can pass strings
camelize('Foo-Bar')
//=> 'fooBar'


// You can pass objects
camelize({
    'abc.xyz': 'mno'
})
//=> {'abcXyz': 'mno'}


// You can pass arrays 
camelize([
     { 'abc.xyz': 'mno' },
     { 'foo-bar': 'baz' }
 ])
//=> [{'abcXyz': 'mno'}, {'fooBar': 'baz'}]


// Also you can pass more complex structures
camelize({
    fee_fie_foe: 'fum',
    beep_boop: [
        { 'abc.xyz': 'mno' },
        { 'foo-bar': 'baz' }
    ]
});
//=>    {
//=>        "feeFieFoe": "fum",
//=>        "beepBoop": [
//=>            {
//=>                "abcXyz": "mno"
//=>            },
//=>            {
//=>                "fooBar": "baz"
//=>            }
//=>        ]
//=>    }


// In case you passed other types, you get them back
camelize(true)
//=> true

When to use camelize2?

Let's say you've got following response from backend:
{
  "items": [
    {
      "product_name": "Table",
      "product_category_tags": [
        "chip",
        "handy"
      ],
      "short_url": "http://as.is/941"
    },
    {
      "product_name": "Chair",
      "product_category_tags": [
      ],
      "short_url": "http://as.is/943"
    }
  ],
  "count": 2
}

With camelcase2 you can easily convert to camel case:
{
  "items": [
    {
      "productName": "Table",
      "productCategoryTags": [
        "chip",
        "handy"
      ],
      "shortUrl": "http://as.is/941"
    },
    {
      "productName": "Chair",
      "productCategoryTags": [
      ],
      "shortUrl": "http://as.is/943"
    }
  ],
  "count": 2
}

Installing

NPM
npm install camelize2

Running the tests

You can run Mocha tests with the following command:
npm run test

Contributing

Please read CONTRIBUTING.md for the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • James Halliday - Initial work - camelize
  • Denys Ivko - Inspired follower -

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details