jmsv / oaty

Object Array Transposer(y) - JS objects with multiple key/value structures
https://www.npmjs.com/package/oaty
MIT License
10 stars 0 forks source link

Add new index key function #7

Open jmsv opened 5 years ago

jmsv commented 5 years ago

Add a new indexing key that wasn't specified at constructor time

e.g.:

oaty.addKey('colour')
oaty.get('colour', 'blue')
j-m commented 5 years ago

If we did this I think we shoud also create a removeKey. But what should we do with the data that has already been transposed? We may have to add options to it like removeKey('color, { delete: true }).

We also have a similar problem with addKey. The way you've described it is that if someone added a key after adding all the data then that key would have a transpoition of all exisiting data already. Which means that we would either have to transpose all keys as we go (which we do on redesign unless you specify options.keys) or transpose the entirety of original again, which would be costly.

I don't think we should do this. If someone specifies options.key then they must stick to that and, if they don't, then all keys are transposed anyway in redesign.