diff --git a/CHANGELOG.md b/CHANGELOG.md index e929113..d578939 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [unreleased] * Add `u.is` to test predicates in a single path. (https://github.com/substantial/updeep/issues/13) +* Rename `u.in` to `u.updateIn`. With `u.is` and `u.if` it was too confusing. ## [0.4.0] * Add `u.if` and `u.ifElse` to conditionally update objects. (https://github.com/substantial/updeep/issues/12) diff --git a/README.md b/README.md index a74553d..564581e 100644 --- a/README.md +++ b/README.md @@ -117,24 +117,24 @@ u({ x: { [key]: 3 } }, { x: { a: 0, b: 0 } }); // => { x: { a: 0, b: 3 } } ``` -### `u.in(path(, value)(, object))` +### `u.updateIn(path(, value)(, object))` Update a single value with a simple string or array path. ```js -u.in('a.b', 3, { a: { b: 0 } }); +u.updateIn('a.b', 3, { a: { b: 0 } }); // => { a: { b: 3 } }; ``` ```js function inc(i) { return i + 1; } -u.in('a.b', inc, { a: { b: 0 } }); +u.updateIn('a.b', inc, { a: { b: 0 } }); // => { a: { b: 1 } }; ``` ```js u({ - x: u.in(['a', 'b'], 3) + x: u.updateIn(['a', 'b'], 3) }, { x: { a: { b: 0 } } }); // => { x: { a: { b: 3 } } }; ``` @@ -253,7 +253,7 @@ u.is('a.b', isEven, { a: { b: 4 } }); ```js u({ - person: u.if(u.is('name.first', 'Jen'), u.in('name.last', 'Simpson')) + person: u.if(u.is('name.first', 'Jen'), u.updateIn('name.last', 'Simpson')) }, { person: { name: { first: 'Jen', last: 'Matthews' } } }); // => { person: { name: { first: 'Jen', last: 'Simpson' } } } ``` diff --git a/lib/index.js b/lib/index.js index 486343a..97267d7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,5 @@ import freeze from './freeze'; -import _in from './in'; +import updateIn from './updateIn'; import is from './is'; import ifElse from './ifElse'; import map from './map'; @@ -14,7 +14,7 @@ const u = update; u.if = ifElse(_, _, {}); u.ifElse = ifElse; -u.in = _in; +u.updateIn = updateIn; u.is = is; u.freeze = freeze; u.map = map; diff --git a/lib/in.js b/lib/updateIn.js similarity index 100% rename from lib/in.js rename to lib/updateIn.js diff --git a/test/in-spec.js b/test/updateIn-spec.js similarity index 71% rename from test/in-spec.js rename to test/updateIn-spec.js index 0e3c0d3..6c15fb3 100644 --- a/test/in-spec.js +++ b/test/updateIn-spec.js @@ -1,45 +1,45 @@ import { expect } from 'chai'; import u from '../lib'; -describe('u.in', () => { +describe('u.updateIn', () => { it('can update a single path described with a string', () => { const object = { a: { b: 0 } }; - const result = u.in('a.b', 3, object); + const result = u.updateIn('a.b', 3, object); expect(result).to.eql({ a: { b: 3 } }); }); it('can update a single path described with a string with a function', () => { const inc = x => x + 1; const object = { a: { b: 0 } }; - const result = u.in('a.b', inc, object); + const result = u.updateIn('a.b', inc, object); expect(result).to.eql({ a: { b: 1 } }); }); it('can update a single path described with an array', () => { const object = { a: { b: 0 } }; - const result = u.in(['a', 'b'], 3, object); + const result = u.updateIn(['a', 'b'], 3, object); expect(result).to.eql({ a: { b: 3 } }); }); it('can update arrays', () => { const object = { a: [0, 0, 0] }; - const result = u.in('a.1', 3, object); + const result = u.updateIn('a.1', 3, object); expect(result).to.eql({ a: [0, 3, 0] }); }); it('can be partially applied', () => { const object = { a: { b: 0 } }; - const result = u.in('a.b')(3)(object); + const result = u.updateIn('a.b')(3)(object); expect(result).to.eql({ a: { b: 3 } }); }); it('replaces the object outright if the path is empty', () => { const object = {}; - const result = u.in('', 3, object); + const result = u.updateIn('', 3, object); expect(result).to.equal(3); }); it('freezes the result', () => { - expect(Object.isFrozen(u.in('a', 0, {}))).to.be.true; + expect(Object.isFrozen(u.updateIn('a', 0, {}))).to.be.true; }); });