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

Create an inverse function #13

Closed
o0101 opened this issue Sep 10, 2018 · 3 comments
Closed

Create an inverse function #13

o0101 opened this issue Sep 10, 2018 · 3 comments

Comments

@o0101
Copy link

o0101 commented Sep 10, 2018

Turn an object into the minimal set of key paths and values.

@lukeed
Copy link
Owner

lukeed commented Sep 10, 2018

Hey, I'm not sure if I'm understanding correctly.

Are you looking to get the deeply-nested values via a keypath? If so, then dlv covers that for you.

Or, are you wanting to convert an object into a flat object with values?

let obj = {
  a: 1,
  b: {
    c: 3,
    d: {
      e: 5
    }
  }
}

//=>

{
  a: 1,
  'b.c': 3,
  'b.d.e': 5
}

If that's the case, then you can use flat-obj and change the glue to '.' (or whatever you want).

@o0101
Copy link
Author

o0101 commented Sep 11, 2018

Ah, @lukeed you already did this! 😂 Amazing you come up with some many useful, specific utilities. True skill you have. Very cool.

BTW I meant your second case. So https://github.com/lukeed/flat-obj covers that for objects. Does it also work if arrays are in the structure?

@o0101 o0101 closed this as completed Sep 11, 2018
@lukeed
Copy link
Owner

lukeed commented Sep 11, 2018

Haha, thanks! There are lots of them I learned (over time) but I just write things that I need when I needed them, especially when I was getting started. I think that module was one of my first modules ever, too

It will handle array keys but the initial item has to be an object

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

No branches or pull requests

2 participants