npm

Bring the best of OSS JavaScript development to your projects with npm Orgs - private packages & team management tools.Learn more »

camelize2

1.0.0 • Public • Published

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!

✅ This library provides new features according to developer needs.

✅ This library fixes issues of camelize.

✅ This library uses Mocha for testing

✅ 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

install

npm i camelize2

Downloadsweekly downloads

6

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability