From 04f22fb927e1ba90b0283589a87aa3d14f628ff3 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Tue, 10 Jan 2023 12:30:40 -0500 Subject: [PATCH] updates to code --- src/filter.test.ts | 21 +++++ src/filter.ts | 12 +++ src/index.ts | 34 ++++++- src/map.test.ts | 82 +++++++++-------- src/matches.test.ts | 11 +++ src/matches.ts | 15 ++++ src/omit.test.ts | 19 ++++ src/omit.ts | 16 ++++ src/omitBy.test.ts | 20 +++++ src/omitBy.ts | 12 +++ src/pick.test.ts | 23 +++++ src/pick.ts | 12 +++ src/pickBy.test.ts | 21 +++++ src/pickBy.ts | 12 +++ src/reject.test.ts | 21 +++++ src/reject.ts | 12 +++ src/same-if-unchanged.test.ts | 23 +++++ src/update.ts | 14 ++- src/updeep.test.ts | 164 ++++++++++++++++++---------------- 19 files changed, 420 insertions(+), 124 deletions(-) create mode 100644 src/filter.test.ts create mode 100644 src/filter.ts create mode 100644 src/matches.test.ts create mode 100644 src/matches.ts create mode 100644 src/omit.test.ts create mode 100644 src/omit.ts create mode 100644 src/omitBy.test.ts create mode 100644 src/omitBy.ts create mode 100644 src/pick.test.ts create mode 100644 src/pick.ts create mode 100644 src/pickBy.test.ts create mode 100644 src/pickBy.ts create mode 100644 src/reject.test.ts create mode 100644 src/reject.ts create mode 100644 src/same-if-unchanged.test.ts diff --git a/src/filter.test.ts b/src/filter.test.ts new file mode 100644 index 0000000..ec5c6de --- /dev/null +++ b/src/filter.test.ts @@ -0,0 +1,21 @@ +import { expect, it } from "vitest"; +import filter from "./filter.js"; +import u from "./index.js"; + +it("can filter", () => { + const result = u({ foo: filter((v, k) => k === 1) })({ + foo: ["a", "b"], + }); + + expect(result).to.eql({ foo: ["b"] }); +}); + +it("freezes the result", () => { + expect(Object.isFrozen(filter([1], () => true))).to.be.true; +}); + +it("doesn't change the obj if nothing is modified", () => { + const orig = [1, 2, 3]; + const result = filter(() => true)(orig); + expect(result).to.be.equal(orig); +}); diff --git a/src/filter.ts b/src/filter.ts new file mode 100644 index 0000000..8db4048 --- /dev/null +++ b/src/filter.ts @@ -0,0 +1,12 @@ +import { filter as _filter } from "remeda"; + +import wrap from "./wrap.js"; + +const sizeOf = (obj) => obj.length; + +function filter(dataIn, predicate) { + const result = _filter.indexed(dataIn, predicate); + return sizeOf(result) === sizeOf(dataIn) ? dataIn : result; +} + +export default wrap(filter) as typeof _filter.indexed; diff --git a/src/index.ts b/src/index.ts index f487b50..1265875 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,11 +2,23 @@ import freeze from "./freeze.js"; import is from "./is.js"; import _if from "./if.js"; import ifElse from "./ifElse.js"; -import update, { omitted } from "./update.js"; +import update, { skip } from "./update.js"; import updateIn from "./updateIn.js"; import constant from "./constant.js"; +import omit from "./omit.js"; +import omitBy from "./omitBy.js"; +import pick from "./pick.js"; +import pickBy from "./pickBy.js"; +import filter from "./filter.js"; +import reject from "./reject.js"; const functions = { + filter, + reject, + pickBy, + pick, + omit, + omitBy, constant, if: _if, ifElse, @@ -14,11 +26,29 @@ const functions = { freeze, update, updateIn, - omitted, + skip, }; +export { + filter, + reject, + pickBy, + pick, + omit, + omitBy, + constant, + _if as if, + ifElse, + is, + freeze, + update, + updateIn, + skip, +} + const merged = update; Object.entries(functions).forEach(([k, v]) => (merged[k] = v)); export default merged as typeof merged & typeof functions; + diff --git a/src/map.test.ts b/src/map.test.ts index 687065c..2d25bcd 100644 --- a/src/map.test.ts +++ b/src/map.test.ts @@ -1,58 +1,56 @@ import { expect, test, describe } from "vitest"; import map from "./map.js"; -describe("map", () => { - test("applies updates to each item in an array", () => { - const object = [0, 1, 2]; - const inc = (x) => x + 1; - const result = map(object, inc); +test("applies updates to each item in an array", () => { + const object = [0, 1, 2]; + const inc = (x) => x + 1; + const result = map(object, inc); - expect(result).to.eql([1, 2, 3]); - }); + expect(result).to.eql([1, 2, 3]); +}); - test("applies updates to each value in an object", () => { - const object = { a: 0, b: 1, c: 2 }; - const inc = (x) => x + 1; - const result = map(inc)(object); +test("applies updates to each value in an object", () => { + const object = { a: 0, b: 1, c: 2 }; + const inc = (x) => x + 1; + const result = map(inc)(object); - expect(result).to.eql({ a: 1, b: 2, c: 3 }); - }); + expect(result).to.eql({ a: 1, b: 2, c: 3 }); +}); - test("can update with a regular updates object", () => { - const object = [{ a: 0 }, { a: 0 }]; - const result = map({ a: 1 })(object); +test("can update with a regular updates object", () => { + const object = [{ a: 0 }, { a: 0 }]; + const result = map({ a: 1 })(object); - expect(result).to.eql([{ a: 1 }, { a: 1 }]); - }); + expect(result).to.eql([{ a: 1 }, { a: 1 }]); +}); - test("returns the same object if no updates are made", () => { - const array = [0, 1]; - const ident = (x) => x; - let result = map(ident)(array); +test("returns the same object if no updates are made", () => { + const array = [0, 1]; + const ident = (x) => x; + let result = map(ident)(array); - expect(result).to.equal(array); + expect(result).to.equal(array); - const object = { a: 0 }; - result = map(ident)(object); + const object = { a: 0 }; + result = map(ident)(object); - expect(result).to.equal(object); - }); + expect(result).to.equal(object); +}); - test("passes the key or index as the second parameter to the iteratee", () => { - const object = { - a: { x: 0 }, - b: [3, 3], - }; - const setToKey = (_, key) => key; - const result = map(object, map(setToKey)); +test("passes the key or index as the second parameter to the iteratee", () => { + const object = { + a: { x: 0 }, + b: [3, 3], + }; + const setToKey = (_, key) => key; + const result = map(object, map(setToKey)); - expect(result).to.eql({ - a: { x: "x" }, - b: [0, 1], - }); - }); - - test("freezes the result", () => { - expect(Object.isFrozen(map({}, {}))).to.be.true; + expect(result).to.eql({ + a: { x: "x" }, + b: [0, 1], }); }); + +test("freezes the result", () => { + expect(Object.isFrozen(map({}, {}))).to.be.true; +}); diff --git a/src/matches.test.ts b/src/matches.test.ts new file mode 100644 index 0000000..c84289e --- /dev/null +++ b/src/matches.test.ts @@ -0,0 +1,11 @@ +import { test, expect } from "vitest"; + +import matches from "./matches.js"; + +test("basic", () => { + expect(matches(1, 1)).toBeTruthy(); + expect(matches(1, 2)).not.toBeTruthy(); + expect(matches({ a: 1, b: 2 }, { a: 1 })).toBeTruthy(); + expect(matches({ a: 2, b: 2 }, { a: 1 })).not.toBeTruthy(); + expect(matches({ 2: { a: (x) => x > 2 } })([1, 1, { a: 3 }])).toBeTruthy(); +}); diff --git a/src/matches.ts b/src/matches.ts new file mode 100644 index 0000000..0df55ee --- /dev/null +++ b/src/matches.ts @@ -0,0 +1,15 @@ +import { purry } from "remeda"; + +function matches(target, condition) { + if (typeof condition === "function") return condition(target); + + if (typeof condition === "object") { + return Object.entries(condition).every(([key, value]) => + matches(target[key], value) + ); + } + + return target === condition; +} + +export default (...args) => purry(matches, args); diff --git a/src/omit.test.ts b/src/omit.test.ts new file mode 100644 index 0000000..f0364c7 --- /dev/null +++ b/src/omit.test.ts @@ -0,0 +1,19 @@ +import { expect, it } from "vitest"; +import omit from "./omit.js"; +import u from "./index.js"; + +it("can omit a key", () => { + const result = u({ foo: omit(["bar"]) })({ foo: { bar: 7 } }); + + expect(result).to.eql({ foo: {} }); +}); + +it("freezes the result", () => { + expect(Object.isFrozen(omit({}, ["a"]))).to.be.true; +}); + +it("doesn't change the obj if nothing is omitted", () => { + const orig = { a: 1 }; + const result = omit(["b"])(orig); + expect(result).to.be.equal(orig); +}); diff --git a/src/omit.ts b/src/omit.ts new file mode 100644 index 0000000..368bd6a --- /dev/null +++ b/src/omit.ts @@ -0,0 +1,16 @@ +import { omit as _omit } from "remeda"; +import wrap from "./wrap.js"; + +const sizeOf = (obj) => Object.keys(obj).length; + +function omit(dataIn, toOmit) { + const result = _omit(dataIn, toOmit); + return sizeOf(result) === sizeOf(dataIn) ? dataIn : result; +} + +export interface Omit { + (dataIn: any, toOmit: (string | number)[]): any; + (toOmit: (string | number)[]): (dataIn: any) => any; +} + +export default wrap(omit) as Omit; diff --git a/src/omitBy.test.ts b/src/omitBy.test.ts new file mode 100644 index 0000000..51882cc --- /dev/null +++ b/src/omitBy.test.ts @@ -0,0 +1,20 @@ +import { expect, it, describe } from "vitest"; +import u from "./index.js"; +import omitBy from "./omitBy.js"; + +it("can omitBy with a function", () => { + const predicate = (value, key) => value === 7 && key === "bar"; + const result = u({ foo: u.omitBy(predicate) })({ foo: { bar: 7, baz: "a" } }); + + expect(result).to.eql({ foo: { baz: "a" } }); +}); + +it("freezes the result", () => { + expect(Object.isFrozen(u.omitBy("a" as any)({}))).to.be.true; +}); + +it("doesn't change the obj if nothing is omitted", () => { + const orig = { a: 1 }; + const result = omitBy(() => false)(orig); + expect(result).to.be.equal(orig); +}); diff --git a/src/omitBy.ts b/src/omitBy.ts new file mode 100644 index 0000000..915852c --- /dev/null +++ b/src/omitBy.ts @@ -0,0 +1,12 @@ +import { omitBy as _omitBy } from "remeda"; + +import wrap from "./wrap.js"; + +const sizeOf = (obj) => Object.keys(obj).length; + +function omitBy(dataIn, predicate) { + const result = _omitBy(dataIn, predicate); + return sizeOf(result) === sizeOf(dataIn) ? dataIn : result; +} + +export default wrap(omitBy) as typeof _omitBy; diff --git a/src/pick.test.ts b/src/pick.test.ts new file mode 100644 index 0000000..bc88c7a --- /dev/null +++ b/src/pick.test.ts @@ -0,0 +1,23 @@ +import { expect, it } from "vitest"; +import pick from "./pick.js"; +import u from "./index.js"; + +it("can pick a key", () => { + const pickBar = pick(["bar"] as any); + + const result = u({ foo: pickBar })({ + foo: { bar: 7, baz: 8 }, + }); + + expect(result).to.eql({ foo: { bar: 7 } }); +}); + +it("freezes the result", () => { + expect(Object.isFrozen(pick({ a: 1 }, ["a"]))).to.be.true; +}); + +it("doesn't change the obj if nothing is modified", () => { + const orig = { a: 1 }; + const result = pick(["a"])(orig); + expect(result).to.be.equal(orig); +}); diff --git a/src/pick.ts b/src/pick.ts new file mode 100644 index 0000000..bdb3313 --- /dev/null +++ b/src/pick.ts @@ -0,0 +1,12 @@ +import { pick as _pick } from "remeda"; + +import wrap from "./wrap.js"; + +const sizeOf = (obj) => Object.keys(obj).length; + +function pick(dataIn, keys) { + const result = _pick(dataIn, keys); + return sizeOf(result) === sizeOf(dataIn) ? dataIn : result; +} + +export default wrap(pick) as typeof _pick; diff --git a/src/pickBy.test.ts b/src/pickBy.test.ts new file mode 100644 index 0000000..74a1e7a --- /dev/null +++ b/src/pickBy.test.ts @@ -0,0 +1,21 @@ +import { expect, it } from "vitest"; +import pickBy from "./pickBy.js"; +import u from "./index.js"; + +it("can pick a key", () => { + const result = u({ foo: pickBy((v, k) => k === "bar") })({ + foo: { bar: 7, baz: 8 }, + }); + + expect(result).to.eql({ foo: { bar: 7 } }); +}); + +it("freezes the result", () => { + expect(Object.isFrozen(pickBy({}, () => true))).to.be.true; +}); + +it("doesn't change the obj if nothing is modified", () => { + const orig = { a: 1 }; + const result = pickBy(() => true)(orig); + expect(result).to.be.equal(orig); +}); diff --git a/src/pickBy.ts b/src/pickBy.ts new file mode 100644 index 0000000..5c75ee6 --- /dev/null +++ b/src/pickBy.ts @@ -0,0 +1,12 @@ +import { pickBy as _pick } from "remeda"; + +import wrap from "./wrap.js"; + +const sizeOf = (obj) => Object.keys(obj).length; + +function pickBy(dataIn, predicate) { + const result = _pick(dataIn, predicate); + return sizeOf(result) === sizeOf(dataIn) ? dataIn : result; +} + +export default wrap(pickBy) as typeof _pick; diff --git a/src/reject.test.ts b/src/reject.test.ts new file mode 100644 index 0000000..e6ad518 --- /dev/null +++ b/src/reject.test.ts @@ -0,0 +1,21 @@ +import { expect, it } from "vitest"; +import reject from "./reject.js"; +import u from "./index.js"; + +it("can reject", () => { + const result = u({ foo: reject((v, k) => k === 1) })({ + foo: ["a", "b"], + }); + + expect(result).to.eql({ foo: ["a"] }); +}); + +it("freezes the result", () => { + expect(Object.isFrozen(reject([1], () => true))).to.be.true; +}); + +it("doesn't change the obj if nothing is modified", () => { + const orig = [1, 2, 3]; + const result = reject(() => false)(orig); + expect(result).to.be.equal(orig); +}); diff --git a/src/reject.ts b/src/reject.ts new file mode 100644 index 0000000..8cd614b --- /dev/null +++ b/src/reject.ts @@ -0,0 +1,12 @@ +import { reject as _reject } from "remeda"; + +import wrap from "./wrap.js"; + +const sizeOf = (obj) => obj.length; + +function reject(dataIn, predicate) { + const result = _reject.indexed(dataIn, predicate); + return sizeOf(result) === sizeOf(dataIn) ? dataIn : result; +} + +export default wrap(reject) as typeof _reject.indexed; diff --git a/src/same-if-unchanged.test.ts b/src/same-if-unchanged.test.ts new file mode 100644 index 0000000..be529c8 --- /dev/null +++ b/src/same-if-unchanged.test.ts @@ -0,0 +1,23 @@ +import { test, expect, describe } from "vitest"; + +import u from "./index.js"; + +describe("update", () => { + test("basic", () => { + const orig = { a: 1 }; + const result = u(orig, { a: 1 }); + expect(result).toBe(orig); + }); + + test("array", () => { + const orig = [1, 2, 3]; + const result = u(orig, { 1: 2 }); + expect(result).toBe(orig); + }); + + test.only("with u.skip", () => { + const orig = { a: 1 }; + const result = u(orig, { b: u.skip }); + expect(result).toBe(orig); + }); +}); diff --git a/src/update.ts b/src/update.ts index 04b380a..f935678 100644 --- a/src/update.ts +++ b/src/update.ts @@ -1,10 +1,10 @@ import wrap from "./wrap.js"; import constant from "./constant.js"; -import { omitBy, isObject } from "remeda"; +import { omitBy, isObject, merge } from "remeda"; -const innerOmitted = { __omitted: true }; -export const omitted = constant(innerOmitted); +const innerOmitted = { __skip: true }; +export const skip = constant(innerOmitted); function isEmpty(object) { return !Object.keys(object).length; @@ -86,6 +86,12 @@ function update(object, updates) { const resolvedUpdates = resolveUpdates(updates, defaultedObject); + Object.entries(resolvedUpdates).forEach(([key, value]) => { + if (value === innerOmitted) { + if (!defaultedObject.hasOwnProperty(key)) delete resolvedUpdates[key]; + } + }); + if (isEmpty(resolvedUpdates)) { return defaultedObject; } @@ -97,7 +103,7 @@ function update(object, updates) { } return omitBy( - { ...defaultedObject, ...resolvedUpdates }, + merge(defaultedObject, resolvedUpdates), (value) => value === innerOmitted ); } diff --git a/src/updeep.test.ts b/src/updeep.test.ts index 1f3330b..5f4aa3e 100644 --- a/src/updeep.test.ts +++ b/src/updeep.test.ts @@ -2,154 +2,166 @@ import { expect, it, describe } from "vitest"; import u from "./index.js"; it("does not change anything if no updates are specified", () => { - const object = { foo: 3, bar: [7, 5] }; - const result = u(object, {}); + const object = { foo: 3, bar: [7, 5] }; + const result = u(object, {}); - expect(result).to.equal(object); + expect(result).to.equal(object); }); it("can update with fixed values", () => { - const object = { foo: 3, bar: [7, 5] }; - const result = u(object, { foo: 4 }); + const object = { foo: 3, bar: [7, 5] }; + const result = u(object, { foo: 4 }); - expect(result).to.deep.equal({ foo: 4, bar: [7, 5] }); + expect(result).to.deep.equal({ foo: 4, bar: [7, 5] }); }); it("returns the same instance if an update doesn't make changes", () => { - const object = { foo: 3 }; - const result = u({ foo: 3 })(object); + const object = { foo: 3 }; + const result = u({ foo: 3 })(object); - expect(result).to.equal(object); + expect(result).to.equal(object); }); it("can update a nested structure", () => { - const object = { foo: { bar: 7, bam: 3 }, baz: 32 }; - const result = u({ foo: { bar: 8 } })(object); + const object = { foo: { bar: 7, bam: 3 }, baz: 32 }; + const result = u({ foo: { bar: 8 } })(object); - expect(result).to.deep.equal({ foo: { bar: 8, bam: 3 }, baz: 32 }); + expect(result).to.deep.equal({ foo: { bar: 8, bam: 3 }, baz: 32 }); }); it("can update arrays", () => { - const object = [1, 2, 3]; - const result = u({ 1: 7 })(object); + const object = [1, 2, 3]; + const result = u({ 1: 7 })(object); - expect(result).to.deep.equal([1, 7, 3]); + expect(result).to.deep.equal([1, 7, 3]); }); it("replaces the object outright if updates are a constant", () => { - expect(u(3)({})).to.equal(3); - expect(u(null)({})).to.be.null; + expect(u(3)({})).to.equal(3); + expect(u(null)({})).to.be.null; }); it("can add an element to an array", () => { - const object = []; - const result = u({ 0: 3 })(object); + const object = []; + const result = u({ 0: 3 })(object); - expect(result).to.eql([3]); + expect(result).to.eql([3]); }); it("can update nested arrays", () => { - const object = { foo: [1, 2, 3], bar: 9 }; - const result = u({ foo: { 1: 7 } })(object); + const object = { foo: [1, 2, 3], bar: 9 }; + const result = u({ foo: { 1: 7 } })(object); - expect(result).to.deep.equal({ foo: [1, 7, 3], bar: 9 }); + expect(result).to.deep.equal({ foo: [1, 7, 3], bar: 9 }); }); it("can use functions to update values", () => { - const inc = (i) => i + 1; - const object = { foo: 3, bar: 4, baz: 7 }; - const result = u({ foo: inc, bar: inc })(object); + const inc = (i) => i + 1; + const object = { foo: 3, bar: 4, baz: 7 }; + const result = u({ foo: inc, bar: inc })(object); - expect(result).to.deep.equal({ foo: 4, bar: 5, baz: 7 }); + expect(result).to.deep.equal({ foo: 4, bar: 5, baz: 7 }); }); it("can be partially applied", () => { - const inc = (i) => i + 1; - const object = { foo: 3 }; - const incFoo = u({ foo: inc }); + const inc = (i) => i + 1; + const object = { foo: 3 }; + const incFoo = u({ foo: inc }); - const result = incFoo(object); + const result = incFoo(object); - expect(result).to.deep.equal({ foo: 4 }); + expect(result).to.deep.equal({ foo: 4 }); }); it("can update if the value is an array", () => { - const object = {}; - const result = u({ foo: [0, 1] })(object); + const object = {}; + const result = u({ foo: [0, 1] })(object); - expect(result).to.deep.equal({ foo: [0, 1] }); + expect(result).to.deep.equal({ foo: [0, 1] }); }); it("can update when original object is undefined", () => { - const result = u({ foo: [0, 1] })(undefined); + const result = u({ foo: [0, 1] })(undefined); - expect(result).to.deep.equal({ foo: [0, 1] }); + expect(result).to.deep.equal({ foo: [0, 1] }); }); it("can take a function as the updater", () => { - const result = u((i) => i + 1)(7); + const result = u((i) => i + 1)(7); - expect(result).to.eql(8); + expect(result).to.eql(8); }); it("deeply freezes the result", () => { - const result = u({ foo: { bar: 3 } }, { foo: { bar: 0 } }); + const result = u({ foo: { bar: 3 } }, { foo: { bar: 0 } }); - expect(Object.isFrozen(result)).to.be.true; - expect(Object.isFrozen(result.foo)).to.be.true; + expect(Object.isFrozen(result)).to.be.true; + expect(Object.isFrozen(result.foo)).to.be.true; }); it("assigns null values", () => { - expect(u({ isNull: null }, {})).to.eql({ isNull: null }); + expect(u({ isNull: null }, {})).to.eql({ isNull: null }); }); it("defaults to an empty object when null or undefined", () => { - let result = u({ a: { b: 0 } })({ a: null }); - expect(result).to.eql({ a: { b: 0 } }); + let result = u({ a: { b: 0 } })({ a: null }); + expect(result).to.eql({ a: { b: 0 } }); - result = u({ a: { b: 0 } })({ a: undefined }); - expect(result).to.eql({ a: { b: 0 } }); + result = u({ a: { b: 0 } })({ a: undefined }); + expect(result).to.eql({ a: { b: 0 } }); - result = u({ a: { b: 0 } })({}); - expect(result).to.eql({ a: { b: 0 } }); + result = u({ a: { b: 0 } })({}); + expect(result).to.eql({ a: { b: 0 } }); }); it("preserves empty objects when empty updates are specified", () => { - const result = u({ a: {} })({}); - expect(result).to.eql({ a: {} }); + const result = u({ a: {} })({}); + expect(result).to.eql({ a: {} }); }); it("works with date objects", () => { - const date = new Date(); - const result = u({ created: date })({}); - expect(result).toEqual({ created: date }); + const date = new Date(); + const result = u({ created: date })({}); + expect(result).toEqual({ created: date }); }); const expectU = (update, orig, expected) => - expect(update(orig)).to.eql(expected); + expect(update(orig)).to.eql(expected); -describe("u.omitted", () => { - it("omit properties via u.omitted", () => { - expectU(u({ a: u.omitted, b: (i) => i + 1 }), { a: 1, b: 2 }, { b: 3 }); - }); +describe("u.skip", () => { + it("omit properties via u.skip", () => { + expectU(u({ a: u.skip, b: (i) => i + 1 }), { a: 1, b: 2 }, { b: 3 }); + }); - it("omit array and object properties", () => { - expectU( - u({ a: u.omitted, b: "stuff", c: u.omitted }), - { a: [1, 2, 3], b: "orig", c: { z: "bar" } }, - { b: "stuff" } - ); - }); + it("omit array and object properties", () => { + expectU( + u({ a: u.skip, b: "stuff", c: u.skip }), + { a: [1, 2, 3], b: "orig", c: { z: "bar" } }, + { b: "stuff" } + ); + }); - it("deep omit", () => { - expectU( - u({ a: { b: u.omitted, c: "stuff" } }), - { a: { b: "foo", z: "bar" } }, - { a: { z: "bar", c: "stuff" } } - ); - }); + it("deep omit", () => { + expectU( + u({ a: { b: u.skip, c: "stuff" } }), + { a: { b: "foo", z: "bar" } }, + { a: { z: "bar", c: "stuff" } } + ); + }); - it("omitting an array item filters it out", () => { - expectU(u({ 1: u.omitted }), ["a", "b", "c"], ["a", "c"]); - }); + it("omitting an array item filters it out", () => { + expectU(u({ 1: u.skip }), ["a", "b", "c"], ["a", "c"]); + }); + + it("doesn't change the obj if nothing is omitted", () => { + const orig = { a: 1 } + const result = u(orig, { b: u.skip }) + expect(result).to.be.equal(orig) + }) + + it("doesn't change the array if nothing is omitted", () => { + const orig = [1, 2, 3] + const result = u({ 4: u.skip })(orig) + expect(result).to.be.equal(orig) + }) });