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

Clean and traverse arrays #22

Merged
merged 1 commit into from
Apr 26, 2017
Merged

Clean and traverse arrays #22

merged 1 commit into from
Apr 26, 2017

Conversation

nunofgs
Copy link
Owner

@nunofgs nunofgs commented Apr 26, 2017

Note: this PR introduces a BC so it will be released in 3.0.0.

Fixes #19.

@nunofgs nunofgs merged commit 7049b24 into master Apr 26, 2017
@nunofgs nunofgs deleted the bugfix/traverse-arrays branch April 26, 2017 23:10
@callmevlad
Copy link
Contributor

👏 Thank you!

@miskiw
Copy link
Contributor

miskiw commented Apr 27, 2017

I am not sure the breaking change was really necessary... but I suppose cleaning objects inside an array is what would be expected from a library with "deep" in the name.

I still think there should be an option to disable this feature (default the option to ON..since the breaking change was introduced) .. just like there are options to disable removing of empty arrays.

either way.. thanks for getting this in. Cheers

@nunofgs
Copy link
Owner Author

nunofgs commented Apr 27, 2017

but I suppose cleaning objects inside an array is what would be expected from a library with "deep" in the name.

That's exactly the reason 😄

I still think there should be an option to disable this feature

We don't have an option to disable nested object cleaning, which is why I believe this is appropriate.

Having said that, this is a small lib so let's see what our users say. If we get requests for adding those two flags I'll gladly add them as a 3.x.x minor bump.

@miskiw
Copy link
Contributor

miskiw commented Apr 27, 2017

👍

@Morriz
Copy link

Morriz commented Sep 29, 2021

Coming after 4 years to say this is problematic, and should be configurable. Imagine this:

react-json-schema-forms creates an undefined value in an array, to render it onscreen to be populated. Now this lib cleans those arrays, even though emptyArrays === false.

How can we disable this lib from cleaning arrays? I deem those as special and should not be touched...

@Morriz
Copy link

Morriz commented Sep 29, 2021

I suggest this option: cleanArrays = true, that will be used in the logic traversal for arrays like this:

    // Recurse into arrays and objects.
    if ((Array.isArray(value) && cleanArrays) || isPlainObject(value)) {
...

the way it stays backwards compatible

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

Successfully merging this pull request may close these issues.

Objects inside arrays are not cleaned
4 participants