lukeed / dset

A tiny (194B) utility for safely writing deep Object values~!
MIT License
754 stars 22 forks source link

Create an inverse function #13

Closed o0101 closed 5 years ago

o0101 commented 5 years ago

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

lukeed commented 5 years ago

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 commented 5 years ago

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?

lukeed commented 5 years ago

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