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
Feature request: Convert an Object into dot-delimited paths #1
Comments
Hi @maoosi, Thanks for the request! |
This is now available in
The new method is named import { flatten } from 'wild-wild-utils'
const target = {
username: 'johndoe',
profile: { image: 'avatar.jpg', verified: true, views: 5 },
tags: ['foo', 'bar']
}
flatten(target)
// {
// "username": "johndoe",
// "profile.image": "avatar.jpg",
// "profile.verified": true,
// "profile.views": 5,
// "tags.0": "foo",
// "tags.1": "bar"
// }
flatten(target, { sort: true })
// {
// "profile.image": "avatar.jpg",
// "profile.verified": true,
// "profile.views": 5,
// "tags.0": "foo",
// "tags.1": "bar",
// "username": "johndoe"
// }
flatten(target, { shallowArrays: true })
// {
// "username": "johndoe",
// "profile.image": "avatar.jpg",
// "profile.verified": true,
// "profile.views": 5,
// "tags": ["foo", "bar"]
// } As part of this, I also added a new option Please note the dot-delimited paths are safe to use with other I hope this works! |
@all-contributors Please add @maoosi for those great ideas. |
I've put up a pull request to add @maoosi! 🎉 |
Wow that was quick @ehmicky, awesome work! I should now be able to use Thanks! |
Guidelines
Which problem is this feature request solving?
Thanks for the work, very useful library!
One thing I’d love to see added is the ability to convert an Object into dot-delimited paths.
Describe the solution you'd like
Example:
Result with
keepArrays: true
:Result with
keepArrays: false
:Pull request (optional)
The text was updated successfully, but these errors were encountered: