Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior with Arrays #28

Open
cinderblock opened this issue Nov 23, 2018 · 3 comments
Open

Inconsistent behavior with Arrays #28

cinderblock opened this issue Nov 23, 2018 · 3 comments

Comments

@cinderblock
Copy link

const camelcaseKeys = require('camelcase-keys');

At top level, array members are turned into array elements.

(a = [{test_one: 1}]).test_two = {}; a;
// [ { test_one: 1 }, test_two: {} ]
camelcaseKeys(a);
// [ { testOne: 1 }, {} ]

At lower levels, array members are lost.

(o = {deep: [{test_one: 1}]}).deep.test_two = 1; o;
// { deep: [ { test_one: 1 }, test_two: 1 ] }
camelcaseKeys(o, {deep: true});
// { deep: [ { testOne: 1 } ] } }

I realize this is bad practice.
However, that this library mangles them and, in particular, inconsistently is I think problematic.

Proposed solution

map-obj already has the ability to handle Arrays.
Simply remove the extra function at module.exports and export camelCaseConvert directly.

Side note

Doesn't map-obj already have a caching mechanism?
It seems a little redundant to me to have a caching layer in this package.
Maybe I'm missing something?

@sindresorhus
Copy link
Owner

map-obj already has the ability to handle Arrays.

Only nested arrays. Not a top-level array.

Doesn't map-obj already have a caching mechanism?

No

@sindresorhus
Copy link
Owner

Your use-case is very obscure, but I'm willing to merge a good PR from anyone that includes tests.

@cinderblock
Copy link
Author

cinderblock commented Mar 20, 2019

map-obj already has the ability to handle Arrays.

Only nested arrays. Not a top-level array.

I'm not following what you're saying. It seems to support them to me:

const mapObj = require('map-obj');
console.log('mapped:', mapObj(['test']));
// mapped: [ 'test' ]

Also: https://github.com/sindresorhus/camelcase-keys/blob/master/test.js#L29-L35

Doesn't map-obj already have a caching mechanism?

No

Forgive my persistence, but it sure seems to https://github.com/sindresorhus/map-obj/blob/master/index.js#L17-L23 Am I missing something?

On that subject, any thoughts on sindresorhus/map-obj#15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants