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

Distinct array or object by keeping a empty array literal #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GHolk
Copy link

@GHolk GHolk commented Jun 30, 2023

The numeric keys is ambiguous, which could mean object keys or array indice.
If flatten function output a empty array for a array, it would be precise the numeric keys mean the array indice.

Eg: {a: [1,2]} is flatten to {a: [], 'a.0': 1, 'a.1': 2},
and {a: {'0': 1, '1': 2}} is flatten to {'a.0': 1, 'a.1': 2},
so we can distinct array and object.

A new option useEmptyArray will to turn on this feature.

This is similar to the safe option, but the values in array still get flatten.

The docs and the tests are not updated yet, and this seem to cause some side effects on flatten object while unflatten.
I will update them if hughsk is interested in merging this feature.

Somewhat relate to #74 .

Make `{a: [1,2]}` produce `{a: [], 'a.0': 1, 'a.1': 2}`,
so we can distinct array and object.

Add a `opts.useEmptyArray` option to turn on this feature.
@GHolk GHolk changed the title Distinct array or object by keep a empty array literal Distinct array or object by keeping a empty array literal Jun 30, 2023
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.

1 participant