es-toolkit icon indicating copy to clipboard operation
es-toolkit copied to clipboard

Support for `pick` in `es-toolkit/compat`

Open raon0211 opened this issue 1 year ago • 5 comments

Support for pick is desirable. Reference

  • pick with object paths like a.b.c should be in es-toolkit/compat.
    • It would be easy to implement if we use get.
  • pick with simple object keys should be in the original es-toolkit.

raon0211 avatar Jul 18 '24 14:07 raon0211

Hello, @raon0211! Let me implement this! :)

seungrodotlee avatar Jul 19 '24 01:07 seungrodotlee

Thanks! :)

raon0211 avatar Jul 19 '24 01:07 raon0211

Hey just a heads up that lodash pick supports const three = pick({ array: [1, 2, 3] }, "array[2]") and also const item = pick({ my: { deep: { item: true }}, "my.deep.item"). Not sure how compatible you want to be although just wanted to make you aware of the array syntax too. Thanks!

bitttttten avatar Jul 20 '24 22:07 bitttttten

@bitttttten Thank you for information! I guess it should be implemented since es-toolkit/compat is designed to provide an identical API to lodash

seungrodotlee avatar Jul 21 '24 06:07 seungrodotlee

It probably is a larger api and larger file size, so I can imagine pick and pickDeep existing side by side but then indeed the api will diverge from lodash.

bitttttten avatar Jul 21 '24 20:07 bitttttten

hey @bitttttten , I just found out a difference between pick from lodash and es-toolkit/compat. es-toolkit/compat:

const obj1 = {
  a: 'hello',
  b: 'world'
};
console.log(pick(obj1, ['a', 'b', 'c']));
---
{ a: 'hello', b: 'world', c: undefined }

lodash:

const obj1 = {
  a: 'hello',
  b: 'world'
};
console.log(_.pick(obj1, ['a', 'b', 'c']));
---
{ a: 'hello', b: 'world' }

akira28 avatar Sep 23 '24 08:09 akira28

Hello, closing this issue since we have pick with 100% compatibility with lodash.

Also, pick adding undefined values was fixed in our latest version of the library!

raon0211 avatar Oct 01 '24 06:10 raon0211

I just grabbed 1.24.0 and pick from es-toolkit/compat still adds the undefined

Xiot avatar Oct 09 '24 01:10 Xiot