richie5um / FlattenJS

9 stars 0 forks source link

Feature request or bug: keep the last element as array #4

Open HapLifeMan opened 3 years ago

HapLifeMan commented 3 years ago

Hello,

Amazing library and work here!

I wanted to know if it was possible to add an option (or do it by default) to keep the last element as array?

For instance:

// For instance:

{
  world: 'Earth',
  countries: [
    'France',
    'Spain',
    'Italia',
    // ...
  ],
  people: [
    { country: 'France', number: 67000000 },
    // ...
  ],
}

// would be flattened to:

{
  'world': 'Earth',
  'countries': ['France', 'Spain', 'Italia'],
  'people[0].country': 'France',
  'people[0].number': 67000000,
}

// instead of:

{
  'world': 'Earth',
  'countries[0]': 'France',
  'countries[1]': 'Spain',
  'countries[2]': 'Italia',
  'people[0].country': 'France',
  'people[0].number': 67000000,
}

What do you think? 😊

richie5um commented 3 years ago

Thank you :).

I don’t think that would benefit this package, but I’m wondering if you can easily do that yourself?

Perhaps your own function that wraps the FlattenJS call, extracts the property from the object before you flatten, and then add it back (ie in unflattened form) to the resulting flattened object?!

Best, Rich

On Wed, 2 Dec 2020, at 7:10 PM, Thomas Reichling wrote:

Hello,

Amazing library and work here!

I wanted to know if it was possible to add an option (or do it by default) to keep the last element as array?

For instance:

// For instance:

{ world: 'Earth', countries: [ 'France', 'Spain', 'Italia', // ... ], people: [ { country: 'France', number: 67000000 }, // ... ], }

// would be flattened to:

{ 'world': 'Earth', 'countries': ['France', 'Spain', 'Italia'], 'people[0].country': 'France', 'people[0].number': 67000000, }

// instead of:

{ 'world': 'Earth', 'countries[0]': 'France', 'countries[1]': 'Spain', 'countries[2]': 'Italia', 'people[0].country': 'France', 'people[0].number': 67000000, } What do you think? 😊

β€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/richie5um/FlattenJS/issues/4, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG5OGLIYDLJAYPCEEZSLELSS2GJ5ANCNFSM4UK5OTKA.