Skip to content

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

Open
GHolk wants to merge 1 commit intohughsk:masterfrom
GHolk:opt-empty-array
Open

Distinct array or object by keeping a empty array literal#164
GHolk wants to merge 1 commit intohughsk:masterfrom
GHolk:opt-empty-array

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