Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for bracket notation #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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'}}}

@@ -65,6 +65,7 @@ unflatten({
### delimiter

Use a custom delimiter for (un)flattening your objects, instead of `.`.
To use bracket notation set the delimiter option to `[]`,`{}`, or `()`.
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