Skip to content

Conversation

@dna113p
Copy link

@dna113p dna113p commented Nov 18, 2015

I found this useful myself recently and thought others might as well.

flatten({
     hello: {
       world: {
         again: 'good morning'
       }
     }
   }, {delimiter: '[]' })
//returns:  'hello[world][again]': 'good morning'

unflatten({'hello[world][again]': 'good morning'}, {delimiter: '[]' })
})

//returns:{hello: {world: {again: 'good morning'}}}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps mention any two characters can be used. I do worry a bit about the inability to escape any delimited character, though this isn't necessarily specifically a problem for your proposed change.

@timoxley
Copy link
Contributor

What if someone is currently specifying two characters as a delimiter? Perhaps this should be delimiters instead in order to avoid any conflict with that. This then raises question: if someone supplies both delimiter & delimiters? Which is used? both? Perhaps the opt-in signal for this behaviour should then be delimiter + an array (rather than a string).

@FranMackinlay
Copy link

This would definitely solve so many issues, good job man! Hope this will get merged soon!

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.

3 participants