pax_global_header00006660000000000000000000000064136415311540014515gustar00rootroot0000000000000052 comment=aa2e9a64f519763b741c7b387d3c4534293104e9 camelcase-keys-6.2.2/000077500000000000000000000000001364153115400144125ustar00rootroot00000000000000camelcase-keys-6.2.2/.editorconfig000066400000000000000000000002571364153115400170730ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 camelcase-keys-6.2.2/.gitattributes000066400000000000000000000000231364153115400173000ustar00rootroot00000000000000* text=auto eol=lf camelcase-keys-6.2.2/.github/000077500000000000000000000000001364153115400157525ustar00rootroot00000000000000camelcase-keys-6.2.2/.github/funding.yml000066400000000000000000000001701364153115400201250ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/camelcase-keys custom: https://sindresorhus.com/donate camelcase-keys-6.2.2/.github/security.md000066400000000000000000000002631364153115400201440ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. camelcase-keys-6.2.2/.gitignore000066400000000000000000000000271364153115400164010ustar00rootroot00000000000000node_modules yarn.lock camelcase-keys-6.2.2/.npmrc000066400000000000000000000000231364153115400155250ustar00rootroot00000000000000package-lock=false camelcase-keys-6.2.2/.travis.yml000066400000000000000000000000651364153115400165240ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' camelcase-keys-6.2.2/bench/000077500000000000000000000000001364153115400154715ustar00rootroot00000000000000camelcase-keys-6.2.2/bench/bench.js000066400000000000000000000005641364153115400171130ustar00rootroot00000000000000/* globals bench suite set */ 'use strict'; const camelcaseKeysNpm = require('camelcase-keys'); const fixture = require('./fixture'); const camelcaseKeys = require('..'); suite('camelcaseKeys', () => { set('mintime', 1000); bench('npm', () => { camelcaseKeysNpm(fixture, {deep: true}); }); bench('master', () => { camelcaseKeys(fixture, {deep: true}); }); }); camelcase-keys-6.2.2/bench/fixture.json000066400000000000000000000023711364153115400200550ustar00rootroot00000000000000{ "_id": "58ca523329b7997ab7b741a2", "index": 0, "guid": "e58a19f6-5dc3-45a6-bf57-2db5d32171d6", "is_active": false, "balance": "$3,245.09", "picture": "http://placehold.it/32x32", "age": 21, "eye_color": "blue", "name": "Murphy Rivers", "gender": "male", "company": "OVOLO", "email": "murphyrivers@ovolo.com", "phone": "+1 (840) 432-3958", "address": "950 Wortman Avenue, Axis, New Jersey, 9085", "about": "Qui nulla proident voluptate ut qui laborum est qui aute pariatur consequat reprehenderit. Esse nulla aute sunt esse exercitation ipsum consequat consequat anim ipsum tempor non ex excepteur. Dolor sit id incididunt cillum veniam sint veniam et aliqua velit aute qui magna esse. Qui id minim mollit est magna sunt esse eiusmod. Amet cillum irure est fugiat. Ipsum consectetur Lorem excepteur laboris.", "registered": "2016-04-11T11:47:47 -04:00", "latitude": -79.956954, "longitude": 21.129594, "tags": [ "et", "occaecat", "aliqua", "ex", "Lorem", "excepteur", "do" ], "friends": [ { "id": 0, "name": "Penelope Castro" }, { "id": 1, "name": "Henderson Cannon" }, { "id": 2, "name": "Alicia Howard" } ], "greeting": "Hello, Murphy Rivers! You have 8 unread messages.", "favorite_fruit": "banana" } camelcase-keys-6.2.2/bench/package.json000066400000000000000000000000651364153115400177600ustar00rootroot00000000000000{ "devDependencies": { "camelcase-keys": "*" } } camelcase-keys-6.2.2/index.d.ts000066400000000000000000000041261364153115400163160ustar00rootroot00000000000000declare namespace camelcaseKeys { interface Options { /** Recurse nested objects and objects in arrays. @default false */ readonly deep?: boolean; /** Exclude keys from being camel-cased. @default [] */ readonly exclude?: ReadonlyArray; /** 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'`. @default [] @example ``` 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 // } // } // } ``` */ readonly stopPaths?: ReadonlyArray; /** Uppercase the first character as in `bye-bye` → `ByeBye`. @default false */ readonly pascalCase?: boolean; } } /** Convert object keys to camel case using [`camelcase`](https://github.com/sindresorhus/camelcase). @param input - Object or array of objects to camel-case. @example ``` 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} ``` */ declare function camelcaseKeys>( input: T, options?: camelcaseKeys.Options, ): T; declare function camelcaseKeys( input: T, options?: camelcaseKeys.Options, ): T; export = camelcaseKeys; camelcase-keys-6.2.2/index.js000066400000000000000000000031311364153115400160550ustar00rootroot00000000000000'use strict'; const mapObj = require('map-obj'); const camelCase = require('camelcase'); const QuickLru = require('quick-lru'); const has = (array, key) => array.some(x => { if (typeof x === 'string') { return x === key; } x.lastIndex = 0; return x.test(key); }); const cache = new QuickLru({maxSize: 100000}); // Reproduces behavior from `map-obj` const isObject = value => typeof value === 'object' && value !== null && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date); const camelCaseConvert = (input, options) => { if (!isObject(input)) { return input; } options = { deep: false, pascalCase: false, ...options }; const {exclude, pascalCase, stopPaths, deep} = options; const stopPathsSet = new Set(stopPaths); const makeMapper = parentPath => (key, value) => { if (deep && isObject(value)) { const path = parentPath === undefined ? key : `${parentPath}.${key}`; if (!stopPathsSet.has(path)) { value = mapObj(value, makeMapper(path)); } } if (!(exclude && has(exclude, key))) { const cacheKey = pascalCase ? `${key}_` : key; if (cache.has(cacheKey)) { key = cache.get(cacheKey); } else { const ret = camelCase(key, {pascalCase}); if (key.length < 100) { // Prevent abuse cache.set(cacheKey, ret); } key = ret; } } return [key, value]; }; return mapObj(input, makeMapper(undefined)); }; module.exports = (input, options) => { if (Array.isArray(input)) { return Object.keys(input).map(key => camelCaseConvert(input[key], options)); } return camelCaseConvert(input, options); }; camelcase-keys-6.2.2/index.test-d.ts000066400000000000000000000027661364153115400173030ustar00rootroot00000000000000import {expectType} from 'tsd'; import camelcaseKeys = require('.'); const fooBarObject = {'foo-bar': true}; const camelFooBarObject = camelcaseKeys(fooBarObject); expectType(camelFooBarObject); const fooBarArray = [{'foo-bar': true}]; const camelFooBarArray = camelcaseKeys(fooBarArray); expectType(camelFooBarArray); expectType>(camelcaseKeys([{'foo-bar': true}])); expectType(camelcaseKeys(['name 1', 'name 2'])); expectType(camelcaseKeys(['name 1', 'name 2'], {deep: true})); expectType<{[key in 'foo-bar']: true}>(camelcaseKeys({'foo-bar': true})); expectType<{[key in 'foo-bar']: true}>( camelcaseKeys({'foo-bar': true}, {deep: true}), ); expectType<{[key in 'foo-bar']: true}>( camelcaseKeys({'foo-bar': true}, {deep: true, pascalCase: true}), ); expectType<{[key in 'foo-bar']: true}>( camelcaseKeys({'foo-bar': true}, {exclude: ['foo', /bar/]}), ); expectType<{[key in 'foo-bar']: true}>( camelcaseKeys({'foo-bar': true}, {stopPaths: ['foo']}), ); interface SomeObject { someProperty: string; } const someObj: SomeObject = { someProperty: 'hello' }; expectType(camelcaseKeys(someObj)); expectType(camelcaseKeys([someObj])); type SomeTypeAlias = { someProperty: string; } const objectWithTypeAlias = { someProperty: 'this should also work' }; expectType(camelcaseKeys(objectWithTypeAlias)); expectType(camelcaseKeys([objectWithTypeAlias])); camelcase-keys-6.2.2/license000066400000000000000000000021251364153115400157570ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. camelcase-keys-6.2.2/package.json000066400000000000000000000022071364153115400167010ustar00rootroot00000000000000{ "name": "camelcase-keys", "version": "6.2.2", "description": "Convert object keys to camel case", "license": "MIT", "repository": "sindresorhus/camelcase-keys", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd", "bench": "matcha bench/bench.js" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "map", "obj", "object", "key", "keys", "value", "values", "val", "iterate", "camelcase", "camel-case", "camel", "case", "dash", "hyphen", "dot", "underscore", "separator", "string", "text", "convert", "pascalcase", "pascal-case", "deep", "recurse", "recursive" ], "dependencies": { "camelcase": "^5.3.1", "map-obj": "^4.0.0", "quick-lru": "^4.0.1" }, "devDependencies": { "ava": "^2.1.0", "matcha": "^0.7.0", "tsd": "^0.11.0", "xo": "^0.25.3" }, "xo": { "overrides": [ { "files": "bench/bench.js", "rules": { "import/no-unresolved": "off" } } ] } } camelcase-keys-6.2.2/readme.md000066400000000000000000000054201364153115400161720ustar00rootroot00000000000000# camelcase-keys [![Build Status](https://travis-ci.org/sindresorhus/camelcase-keys.svg?branch=master)](https://travis-ci.org/sindresorhus/camelcase-keys) > Convert object keys to camel case using [`camelcase`](https://github.com/sindresorhus/camelcase) ## Install ``` $ npm install camelcase-keys ``` ## Usage ```js const 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}} 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}}} // Convert object keys to pascal case camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true, pascalCase: true}); //=> {FooBar: true, Nested: {UnicornRainbow: true}} ``` ```js const camelcaseKeys = require('camelcase-keys'); const argv = require('minimist')(process.argv.slice(2)); //=> {_: [], 'foo-bar': true} camelcaseKeys(argv); //=> {_: [], fooBar: true} ``` ## API ### camelcaseKeys(input, options?) #### input Type: `object | object[]` An object or array of objects to camel-case. #### options Type: `object` ##### exclude Type: `Array`\ Default: `[]` Exclude keys from being camel-cased. ##### stopPaths Type: `string[]`\ Default: `[]` 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'`. ```js 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 } } } */ ``` ##### deep Type: `boolean`\ Default: `false` Recurse nested objects and objects in arrays. ##### pascalCase Type: `boolean`\ Default: `false` Uppercase the first character as in `bye-bye` → `ByeBye`. ## camelcase-keys for enterprise Available as part of the Tidelift Subscription. The maintainers of camelcase-keys and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-camelcase-keys?utm_source=npm-camelcase-keys&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) ## Related - [snakecase-keys](https://github.com/bendrucker/snakecase-keys) - [kebabcase-keys](https://github.com/mattiloh/kebabcase-keys) camelcase-keys-6.2.2/test.js000066400000000000000000000066411364153115400157360ustar00rootroot00000000000000import test from 'ava'; import camelcaseKeys from '.'; test('main', t => { t.true(camelcaseKeys({'foo-bar': true}).fooBar); }); test('exclude option', t => { t.true(camelcaseKeys({'--': true}, {exclude: ['--']})['--']); t.deepEqual(camelcaseKeys({'foo-bar': true}, {exclude: [/^f/]}), {'foo-bar': true}); }); test('deep option', t => { t.deepEqual( // eslint-disable-next-line camelcase camelcaseKeys({foo_bar: true, obj: {one_two: false, arr: [{three_four: true}]}}, {deep: true}), {fooBar: true, obj: {oneTwo: false, arr: [{threeFour: true}]}} ); }); test('stopPaths option', t => { t.deepEqual( // eslint-disable-next-line camelcase camelcaseKeys({foo_bar: true, obj: {one_two: false, arr: [{three_four: true}]}}, {deep: true, stopPaths: ['obj']}), // eslint-disable-next-line camelcase {fooBar: true, obj: {one_two: false, arr: [{three_four: true}]}} ); t.deepEqual( // eslint-disable-next-line camelcase camelcaseKeys({foo_bar: true, obj: {one_two: false, arr: [{three_four: true}]}}, {deep: true, stopPaths: ['obj.arr']}), // eslint-disable-next-line camelcase {fooBar: true, obj: {oneTwo: false, arr: [{three_four: true}]}} ); t.deepEqual( // eslint-disable-next-line camelcase camelcaseKeys({q_w_e: [[{foo_bar: 1}, {one_two: 2}, {foo_bar: 3, one_two: 4}]]}, {deep: true, stopPaths: ['q_w_e.foo_bar']}), {qWE: [[{fooBar: 1}, {oneTwo: 2}, {fooBar: 3, oneTwo: 4}]]} ); t.deepEqual( // eslint-disable-next-line camelcase camelcaseKeys({a_b: 1, a_c: {c_d: 1, c_e: {e_f: 1}}}, {deep: true, stopPaths: ['a_c.c_e']}), // eslint-disable-next-line camelcase {aB: 1, aC: {cD: 1, cE: {e_f: 1}}} ); }); test('pascalCase option only', t => { t.true(camelcaseKeys({'new-foo-bar': true}, {pascalCase: true}).NewFooBar); }); test('pascalCase and deep options', t => { t.deepEqual( // eslint-disable-next-line camelcase camelcaseKeys({p_foo_bar: true, p_obj: {p_two: false, p_arr: [{p_three_four: true}]}}, {deep: true, pascalCase: true}), {PFooBar: true, PObj: {PTwo: false, PArr: [{PThreeFour: true}]}} ); }); test('handles nested arrays', t => { t.deepEqual( // eslint-disable-next-line camelcase camelcaseKeys({q_w_e: [['a', 'b']]}, {deep: true}), {qWE: [['a', 'b']]} ); }); test('accepts an array of objects', t => { t.deepEqual( // eslint-disable-next-line camelcase camelcaseKeys([{foo_bar: true}, {bar_foo: false}, {'bar-foo': 'false'}]), [{fooBar: true}, {barFoo: false}, {barFoo: 'false'}] ); }); test('different pascalCase option values', t => { // eslint-disable-next-line camelcase t.true(camelcaseKeys({foo_bar_UPPERCASE: true}).fooBarUppercase); // eslint-disable-next-line camelcase t.true(camelcaseKeys({foo_bar_UPPERCASE: true}, {pascalCase: true}).FooBarUppercase); t.deepEqual( camelcaseKeys({'p-foo-bar': true, 'p-obj': {'p-two': false, 'p-arr': [{'p-three-four': true}]}}, {deep: true, pascalCase: true}), {PFooBar: true, PObj: {PTwo: false, PArr: [{PThreeFour: true}]}} ); t.deepEqual( camelcaseKeys({'p-foo-bar': true, 'p-obj': {'p-two': false, 'p-arr': [{'p-three-four': true}]}}, {deep: true}), {pFooBar: true, pObj: {pTwo: false, pArr: [{pThreeFour: true}]}} ); }); test('handle array of non-objects', t => { const input = ['name 1', 'name 2']; t.deepEqual( camelcaseKeys(input), input ); }); test('handle array of non-objects with `deep` option', t => { const input = ['name 1', 'name 2']; t.deepEqual( camelcaseKeys(input, {deep: true}), input ); });