es-toolkit
es-toolkit copied to clipboard
Support for `pick` in `es-toolkit/compat`
Support for pick is desirable. Reference
pickwith object paths likea.b.cshould be ines-toolkit/compat.- It would be easy to implement if we use get.
pickwith simple object keys should be in the originales-toolkit.
Hello, @raon0211! Let me implement this! :)
Thanks! :)
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 Thank you for information! I guess it should be implemented since es-toolkit/compat is designed to provide an identical API to lodash
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.
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' }
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!
I just grabbed 1.24.0 and pick from es-toolkit/compat still adds the undefined