Skip to content

Commit 63954f6

Browse files
committed
fix(utils): default predicate was checking for key instead of value
1 parent d81f832 commit 63954f6

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/utils/object.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @param {(key: string, value: any, obj: object ) => boolean | Array<string>} keys The keys
88
* @return {object} Copy of the object with filtered values
99
*/
10-
function pick(obj, keys = (k) => Boolean(k)) {
10+
function pick(obj, keys = (_k, v) => Boolean(v)) {
1111
if (Array.isArray(keys)) {
1212
return pick(obj, (key) => keys.includes(key));
1313
}

tests/utils-object.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const test = require("ava").default;
22
const { pick, pickByKeyPrefix, mapKeys } = require("../lib/utils/object.js");
33

4-
test("pick: should pick values based on truthy", async (t) => {
5-
t.deepEqual(pick({ a: "a", b: "b", c: false }, ["a", "b"]), {
4+
test("pick: should pick properites based on truthy values", async (t) => {
5+
t.deepEqual(pick({ a: "a", b: "b", c: false }), {
66
a: "a",
77
b: "b",
88
});
99
});
1010

11-
test("pick: should pick values based on predicate", async (t) => {
11+
test("pick: should pick properites based on predicate", async (t) => {
1212
t.deepEqual(
1313
pick({ a: "a", b: "b", c: false }, (_k, v) => !v),
1414
{
@@ -17,11 +17,11 @@ test("pick: should pick values based on predicate", async (t) => {
1717
);
1818
});
1919

20-
test("pick: should pick values from array of keys", async (t) => {
20+
test("pick: should pick properites using array of keys", async (t) => {
2121
t.deepEqual(pick({ a: "a", b: "b", c: "c" }, ["a", "b"]), { a: "a", b: "b" });
2222
});
2323

24-
test("pickByKeyPrefix: should pick values based on key prefix", async (t) => {
24+
test("pickByKeyPrefix: should pick properites based on key prefix", async (t) => {
2525
t.deepEqual(pickByKeyPrefix({ aKey: "a", anotherKey: "b", c: "c" }, "a"), {
2626
aKey: "a",
2727
anotherKey: "b",

0 commit comments

Comments
 (0)