Repository navigation
Proposal: unflattenObject (inverse of flattenObject) #2167
minseonkkim
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I'd like to propose
unflattenObject, the inverse offlattenObject.es-toolkit can flatten an object, but there is no way to restore it. This is useful when you flatten an object to work with it by key and then need the original shape back, or when handling dotted form field names like
user.address.city.I used flattenObject to compare two settings objects key by key, but then had to write my own code to rebuild the nested object from the result.
It would take the same
delimiteroption asflattenObject, and skip keys like__proto__to avoid prototype pollution.One question:
flattenObjectturns arrays into index keys ('d.0','d.1'). ShouldunflattenObjectrebuild them as arrays so the round trip works, or keep them as objects ({ 0: ..., 1: ... }) for simplicity? I'd prefer arrays.All reactions