Comparing version 0.6.1 to 1.0.0
# Changelog | ||
## 1.0.0 (June 13, 2016) | ||
* **Use semantic versioning** | ||
* [minor] Bump development dependencies | ||
## 0.6.1 (Apr. 22, 2016) | ||
@@ -4,0 +9,0 @@ |
// @flow | ||
// | Timm | ||
// | (c) Guillermo Grau Panea 2016 | ||
// | License: MIT | ||
/*! | ||
* Timm | ||
* | ||
* Immutability helpers with fast reads and acceptable writes. | ||
* | ||
* @copyright Guillermo Grau Panea 2016 | ||
* @license MIT | ||
*/ | ||
@@ -15,3 +20,3 @@ const INVALID_ARGS = 'INVALID_ARGS'; | ||
function _throw(msg: string) { | ||
function throwStr(msg: string) { | ||
throw new Error(msg); | ||
@@ -33,5 +38,5 @@ } | ||
function _merge(fAddDefaults: boolean, ...rest: any): ArrayOrObject { | ||
function doMerge(fAddDefaults: boolean, ...rest: any): ArrayOrObject { | ||
let out = rest[0]; | ||
!(out != null) && _throw(process.env.NODE_ENV !== 'production' ? | ||
!(out != null) && throwStr(process.env.NODE_ENV !== 'production' ? | ||
'At least one object should be provided to merge()' : INVALID_ARGS); | ||
@@ -67,3 +72,3 @@ let fChanged = false; | ||
function _isObject(o: any): boolean { | ||
function isObject(o: any): boolean { | ||
const type = typeof o; | ||
@@ -77,3 +82,3 @@ return (o != null) && (type === 'object' || type === 'function'); | ||
// val = obj[key] | ||
// if _isObject(val) and not Object.isFrozen val | ||
// if isObject(val) and not Object.isFrozen val | ||
// _deepFreeze val | ||
@@ -217,3 +222,3 @@ // obj | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, d: {d1: 3, d2: 4}, e: ['a', 'b', 'c']} | ||
// -- obj = { a: 1, b: 2, d: { d1: 3, d2: 4 }, e: ['a', 'b', 'c'] } | ||
// -- getIn(obj, ['d', 'd1']) | ||
@@ -226,3 +231,3 @@ // -- // 3 | ||
path: Array<Key>): any { | ||
!(Array.isArray(path)) && _throw(process.env.NODE_ENV !== 'production' ? | ||
!(Array.isArray(path)) && throwStr(process.env.NODE_ENV !== 'production' ? | ||
'A path array should be provided when calling getIn()' : INVALID_ARGS); | ||
@@ -251,5 +256,5 @@ if (obj == null) { | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, c: 3} | ||
// -- obj = { a: 1, b: 2, c: 3 } | ||
// -- obj2 = set(obj, 'b', 5) | ||
// -- // {a: 1, b: 5, c: 3} | ||
// -- // { a: 1, b: 5, c: 3 } | ||
// -- obj2 === obj | ||
@@ -285,5 +290,5 @@ // -- // false | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, d: {d1: 3, d2: 4}, e: {e1: 'foo', e2: 'bar'}} | ||
// -- obj = { a: 1, b: 2, d: { d1: 3, d2: 4 }, e: { e1: 'foo', e2: 'bar' } } | ||
// -- obj2 = setIn(obj, ['d', 'd1'], 4) | ||
// -- // {a: 1, b: 2, d: {d1: 4, d2: 4}, e: {e1: 'foo', e2: 'bar'}} | ||
// -- // { a: 1, b: 2, d: { d1: 4, d2: 4 }, e: { e1: 'foo', e2: 'bar' } } | ||
// -- obj2 === obj | ||
@@ -298,3 +303,3 @@ // -- // false | ||
// -- obj3 = setIn(obj, ['d', 'd1'], 3) | ||
// -- // {a: 1, b: 2, d: {d1: 3, d2: 4}, e: {e1: 'foo', e2: 'bar'}} | ||
// -- // { a: 1, b: 2, d: { d1: 3, d2: 4 }, e: { e1: 'foo', e2: 'bar' } } | ||
// -- obj3 === obj | ||
@@ -308,6 +313,6 @@ // -- // true | ||
// -- // ... unknown paths create intermediate keys: | ||
// -- setIn({a: 3}, ['unknown', 'path'], 4) | ||
// -- // {a: 3, unknown: {path: 4}} | ||
// -- setIn({ a: 3 }, ['unknown', 'path'], 4) | ||
// -- // { a: 3, unknown: { path: 4 } } | ||
// -- ``` | ||
function _setIn(obj: ArrayOrObject, path: Array<Key>, val: any, idx: number): ArrayOrObject { | ||
function doSetIn(obj: ArrayOrObject, path: Array<Key>, val: any, idx: number): ArrayOrObject { | ||
let newValue; | ||
@@ -318,4 +323,4 @@ const key: any = path[idx]; | ||
} else { | ||
const nestedObj = _isObject(obj) ? obj[key] : {}; | ||
newValue = _setIn(nestedObj, path, val, idx + 1); | ||
const nestedObj = isObject(obj) ? obj[key] : {}; | ||
newValue = doSetIn(nestedObj, path, val, idx + 1); | ||
} | ||
@@ -329,3 +334,3 @@ return set(obj, key, newValue); | ||
} | ||
return _setIn(obj, path, val, 0); | ||
return doSetIn(obj, path, val, 0); | ||
} | ||
@@ -343,5 +348,5 @@ | ||
// -- ```js | ||
// -- obj = {a: 1, d: {d1: 3, d2: 4}} | ||
// -- obj2 = updateIn(obj, ['d', 'd1'], function(val){return val + 1}) | ||
// -- // {a: 1, d: {d1: 4, d2: 4}} | ||
// -- obj = { a: 1, d: { d1: 3, d2: 4 } } | ||
// -- obj2 = updateIn(obj, ['d', 'd1'], (val) => val + 1) | ||
// -- // { a: 1, d: { d1: 4, d2: 4 } } | ||
// -- obj2 === obj | ||
@@ -351,4 +356,4 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- obj3 = updateIn(obj, ['d', 'd1'], function(val){return val}) | ||
// -- // {a: 1, d: {d1: 3, d2: 4}} | ||
// -- obj3 = updateIn(obj, ['d', 'd1'], (val) => val) | ||
// -- // { a: 1, d: { d1: 3, d2: 4 } } | ||
// -- obj3 === obj | ||
@@ -384,6 +389,6 @@ // -- // true | ||
// -- ```js | ||
// -- obj1 = {a: 1, b: 2, c: 3} | ||
// -- obj2 = {c: 4, d: 5} | ||
// -- obj1 = { a: 1, b: 2, c: 3 } | ||
// -- obj2 = { c: 4, d: 5 } | ||
// -- obj3 = merge(obj1, obj2) | ||
// -- // {a: 1, b: 2, c: 4, d: 5} | ||
// -- // { a: 1, b: 2, c: 4, d: 5 } | ||
// -- obj3 === obj1 | ||
@@ -393,3 +398,3 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- merge(obj1, {c: 3}) === obj1 | ||
// -- merge(obj1, { c: 3 }) === obj1 | ||
// -- // true | ||
@@ -403,5 +408,5 @@ // -- ``` | ||
if (rest.length) { | ||
out = _merge.call(null, false, a, b, c, d, e, f, ...rest); | ||
out = doMerge.call(null, false, a, b, c, d, e, f, ...rest); | ||
} else { | ||
out = _merge(false, a, b, c, d, e, f); | ||
out = doMerge(false, a, b, c, d, e, f); | ||
} | ||
@@ -421,6 +426,6 @@ return out; | ||
// -- ```js | ||
// -- obj1 = {a: 1, d: {b: {d1: 3, d2: 4}}} | ||
// -- obj2 = {d3: 5} | ||
// -- obj1 = { a: 1, d: { b: { d1: 3, d2: 4 } } } | ||
// -- obj2 = { d3: 5 } | ||
// -- obj3 = mergeIn(obj1, ['d', 'b'], obj2) | ||
// -- // {a: 1, d: {b: {d1: 3, d2: 4, d3: 5}}} | ||
// -- // { a: 1, d: { b: { d1: 3, d2: 4, d3: 5 } } } | ||
// -- obj3 === obj1 | ||
@@ -430,3 +435,3 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- mergeIn(obj1, ['d', 'b'], {d2: 4}) === obj1 | ||
// -- mergeIn(obj1, ['d', 'b'], { d2: 4 }) === obj1 | ||
// -- // true | ||
@@ -444,5 +449,5 @@ // -- ``` | ||
if (rest.length) { | ||
nextVal = _merge.call(null, false, prevVal, b, c, d, e, f, ...rest); | ||
nextVal = doMerge.call(null, false, prevVal, b, c, d, e, f, ...rest); | ||
} else { | ||
nextVal = _merge(false, prevVal, b, c, d, e, f); | ||
nextVal = doMerge(false, prevVal, b, c, d, e, f); | ||
} | ||
@@ -458,7 +463,7 @@ return setIn(a, path, nextVal); | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, c: 3, d: 4} | ||
// -- obj = { a: 1, b: 2, c: 3, d: 4 } | ||
// -- omit(obj, 'a') | ||
// -- // {b: 2, c: 3, d: 4} | ||
// -- // { b: 2, c: 3, d: 4 } | ||
// -- omit(obj, ['b', 'c']) | ||
// -- // {a: 1, d: 4} | ||
// -- // { a: 1, d: 4 } | ||
// -- | ||
@@ -500,6 +505,6 @@ // -- // The same object is returned if there are no changes: | ||
// -- ```js | ||
// -- obj1 = {a: 1, b: 2, c: 3} | ||
// -- obj2 = {c: 4, d: 5, e: null} | ||
// -- obj1 = { a: 1, b: 2, c: 3 } | ||
// -- obj2 = { c: 4, d: 5, e: null } | ||
// -- obj3 = addDefaults(obj1, obj2) | ||
// -- // {a: 1, b: 2, c: 3, d: 5, e: null} | ||
// -- // { a: 1, b: 2, c: 3, d: 5, e: null } | ||
// -- obj3 === obj1 | ||
@@ -509,3 +514,3 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- addDefaults(obj1, {c: 4}) === obj1 | ||
// -- addDefaults(obj1, { c: 4 }) === obj1 | ||
// -- // true | ||
@@ -519,5 +524,5 @@ // -- ``` | ||
if (rest.length) { | ||
out = _merge.call(null, true, a, b, c, d, e, f, ...rest); | ||
out = doMerge.call(null, true, a, b, c, d, e, f, ...rest); | ||
} else { | ||
out = _merge(true, a, b, c, d, e, f); | ||
out = doMerge(true, a, b, c, d, e, f); | ||
} | ||
@@ -524,0 +529,0 @@ return out; |
// | Timm | ||
// | (c) Guillermo Grau Panea 2016 | ||
// | License: MIT | ||
/*! | ||
* Timm | ||
* | ||
* Immutability helpers with fast reads and acceptable writes. | ||
* | ||
* @copyright Guillermo Grau Panea 2016 | ||
* @license MIT | ||
*/ | ||
@@ -14,3 +19,3 @@ const INVALID_ARGS = 'INVALID_ARGS'; | ||
function _throw(msg) { | ||
function throwStr(msg) { | ||
throw new Error(msg); | ||
@@ -32,5 +37,5 @@ } | ||
function _merge(fAddDefaults, ...rest) { | ||
function doMerge(fAddDefaults, ...rest) { | ||
let out = rest[0]; | ||
!(out != null) && _throw(process.env.NODE_ENV !== 'production' ? 'At least one object should be provided to merge()' : INVALID_ARGS); | ||
!(out != null) && throwStr(process.env.NODE_ENV !== 'production' ? 'At least one object should be provided to merge()' : INVALID_ARGS); | ||
let fChanged = false; | ||
@@ -65,3 +70,3 @@ for (let idx = 1; idx < rest.length; idx++) { | ||
function _isObject(o) { | ||
function isObject(o) { | ||
const type = typeof o; | ||
@@ -75,3 +80,3 @@ return o != null && (type === 'object' || type === 'function'); | ||
// val = obj[key] | ||
// if _isObject(val) and not Object.isFrozen val | ||
// if isObject(val) and not Object.isFrozen val | ||
// _deepFreeze val | ||
@@ -207,3 +212,3 @@ // obj | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, d: {d1: 3, d2: 4}, e: ['a', 'b', 'c']} | ||
// -- obj = { a: 1, b: 2, d: { d1: 3, d2: 4 }, e: ['a', 'b', 'c'] } | ||
// -- getIn(obj, ['d', 'd1']) | ||
@@ -215,3 +220,3 @@ // -- // 3 | ||
export function getIn(obj, path) { | ||
!Array.isArray(path) && _throw(process.env.NODE_ENV !== 'production' ? 'A path array should be provided when calling getIn()' : INVALID_ARGS); | ||
!Array.isArray(path) && throwStr(process.env.NODE_ENV !== 'production' ? 'A path array should be provided when calling getIn()' : INVALID_ARGS); | ||
if (obj == null) { | ||
@@ -239,5 +244,5 @@ return undefined; | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, c: 3} | ||
// -- obj = { a: 1, b: 2, c: 3 } | ||
// -- obj2 = set(obj, 'b', 5) | ||
// -- // {a: 1, b: 5, c: 3} | ||
// -- // { a: 1, b: 5, c: 3 } | ||
// -- obj2 === obj | ||
@@ -273,5 +278,5 @@ // -- // false | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, d: {d1: 3, d2: 4}, e: {e1: 'foo', e2: 'bar'}} | ||
// -- obj = { a: 1, b: 2, d: { d1: 3, d2: 4 }, e: { e1: 'foo', e2: 'bar' } } | ||
// -- obj2 = setIn(obj, ['d', 'd1'], 4) | ||
// -- // {a: 1, b: 2, d: {d1: 4, d2: 4}, e: {e1: 'foo', e2: 'bar'}} | ||
// -- // { a: 1, b: 2, d: { d1: 4, d2: 4 }, e: { e1: 'foo', e2: 'bar' } } | ||
// -- obj2 === obj | ||
@@ -286,3 +291,3 @@ // -- // false | ||
// -- obj3 = setIn(obj, ['d', 'd1'], 3) | ||
// -- // {a: 1, b: 2, d: {d1: 3, d2: 4}, e: {e1: 'foo', e2: 'bar'}} | ||
// -- // { a: 1, b: 2, d: { d1: 3, d2: 4 }, e: { e1: 'foo', e2: 'bar' } } | ||
// -- obj3 === obj | ||
@@ -296,6 +301,6 @@ // -- // true | ||
// -- // ... unknown paths create intermediate keys: | ||
// -- setIn({a: 3}, ['unknown', 'path'], 4) | ||
// -- // {a: 3, unknown: {path: 4}} | ||
// -- setIn({ a: 3 }, ['unknown', 'path'], 4) | ||
// -- // { a: 3, unknown: { path: 4 } } | ||
// -- ``` | ||
function _setIn(obj, path, val, idx) { | ||
function doSetIn(obj, path, val, idx) { | ||
let newValue; | ||
@@ -306,4 +311,4 @@ const key = path[idx]; | ||
} else { | ||
const nestedObj = _isObject(obj) ? obj[key] : {}; | ||
newValue = _setIn(nestedObj, path, val, idx + 1); | ||
const nestedObj = isObject(obj) ? obj[key] : {}; | ||
newValue = doSetIn(nestedObj, path, val, idx + 1); | ||
} | ||
@@ -317,3 +322,3 @@ return set(obj, key, newValue); | ||
} | ||
return _setIn(obj, path, val, 0); | ||
return doSetIn(obj, path, val, 0); | ||
} | ||
@@ -331,5 +336,5 @@ | ||
// -- ```js | ||
// -- obj = {a: 1, d: {d1: 3, d2: 4}} | ||
// -- obj2 = updateIn(obj, ['d', 'd1'], function(val){return val + 1}) | ||
// -- // {a: 1, d: {d1: 4, d2: 4}} | ||
// -- obj = { a: 1, d: { d1: 3, d2: 4 } } | ||
// -- obj2 = updateIn(obj, ['d', 'd1'], (val) => val + 1) | ||
// -- // { a: 1, d: { d1: 4, d2: 4 } } | ||
// -- obj2 === obj | ||
@@ -339,4 +344,4 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- obj3 = updateIn(obj, ['d', 'd1'], function(val){return val}) | ||
// -- // {a: 1, d: {d1: 3, d2: 4}} | ||
// -- obj3 = updateIn(obj, ['d', 'd1'], (val) => val) | ||
// -- // { a: 1, d: { d1: 3, d2: 4 } } | ||
// -- obj3 === obj | ||
@@ -371,6 +376,6 @@ // -- // true | ||
// -- ```js | ||
// -- obj1 = {a: 1, b: 2, c: 3} | ||
// -- obj2 = {c: 4, d: 5} | ||
// -- obj1 = { a: 1, b: 2, c: 3 } | ||
// -- obj2 = { c: 4, d: 5 } | ||
// -- obj3 = merge(obj1, obj2) | ||
// -- // {a: 1, b: 2, c: 4, d: 5} | ||
// -- // { a: 1, b: 2, c: 4, d: 5 } | ||
// -- obj3 === obj1 | ||
@@ -380,3 +385,3 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- merge(obj1, {c: 3}) === obj1 | ||
// -- merge(obj1, { c: 3 }) === obj1 | ||
// -- // true | ||
@@ -387,5 +392,5 @@ // -- ``` | ||
if (rest.length) { | ||
out = _merge.call(null, false, a, b, c, d, e, f, ...rest); | ||
out = doMerge.call(null, false, a, b, c, d, e, f, ...rest); | ||
} else { | ||
out = _merge(false, a, b, c, d, e, f); | ||
out = doMerge(false, a, b, c, d, e, f); | ||
} | ||
@@ -405,6 +410,6 @@ return out; | ||
// -- ```js | ||
// -- obj1 = {a: 1, d: {b: {d1: 3, d2: 4}}} | ||
// -- obj2 = {d3: 5} | ||
// -- obj1 = { a: 1, d: { b: { d1: 3, d2: 4 } } } | ||
// -- obj2 = { d3: 5 } | ||
// -- obj3 = mergeIn(obj1, ['d', 'b'], obj2) | ||
// -- // {a: 1, d: {b: {d1: 3, d2: 4, d3: 5}}} | ||
// -- // { a: 1, d: { b: { d1: 3, d2: 4, d3: 5 } } } | ||
// -- obj3 === obj1 | ||
@@ -414,3 +419,3 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- mergeIn(obj1, ['d', 'b'], {d2: 4}) === obj1 | ||
// -- mergeIn(obj1, ['d', 'b'], { d2: 4 }) === obj1 | ||
// -- // true | ||
@@ -425,5 +430,5 @@ // -- ``` | ||
if (rest.length) { | ||
nextVal = _merge.call(null, false, prevVal, b, c, d, e, f, ...rest); | ||
nextVal = doMerge.call(null, false, prevVal, b, c, d, e, f, ...rest); | ||
} else { | ||
nextVal = _merge(false, prevVal, b, c, d, e, f); | ||
nextVal = doMerge(false, prevVal, b, c, d, e, f); | ||
} | ||
@@ -439,7 +444,7 @@ return setIn(a, path, nextVal); | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, c: 3, d: 4} | ||
// -- obj = { a: 1, b: 2, c: 3, d: 4 } | ||
// -- omit(obj, 'a') | ||
// -- // {b: 2, c: 3, d: 4} | ||
// -- // { b: 2, c: 3, d: 4 } | ||
// -- omit(obj, ['b', 'c']) | ||
// -- // {a: 1, d: 4} | ||
// -- // { a: 1, d: 4 } | ||
// -- | ||
@@ -481,6 +486,6 @@ // -- // The same object is returned if there are no changes: | ||
// -- ```js | ||
// -- obj1 = {a: 1, b: 2, c: 3} | ||
// -- obj2 = {c: 4, d: 5, e: null} | ||
// -- obj1 = { a: 1, b: 2, c: 3 } | ||
// -- obj2 = { c: 4, d: 5, e: null } | ||
// -- obj3 = addDefaults(obj1, obj2) | ||
// -- // {a: 1, b: 2, c: 3, d: 5, e: null} | ||
// -- // { a: 1, b: 2, c: 3, d: 5, e: null } | ||
// -- obj3 === obj1 | ||
@@ -490,3 +495,3 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- addDefaults(obj1, {c: 4}) === obj1 | ||
// -- addDefaults(obj1, { c: 4 }) === obj1 | ||
// -- // true | ||
@@ -497,5 +502,5 @@ // -- ``` | ||
if (rest.length) { | ||
out = _merge.call(null, true, a, b, c, d, e, f, ...rest); | ||
out = doMerge.call(null, true, a, b, c, d, e, f, ...rest); | ||
} else { | ||
out = _merge(true, a, b, c, d, e, f); | ||
out = doMerge(true, a, b, c, d, e, f); | ||
} | ||
@@ -502,0 +507,0 @@ return out; |
@@ -25,5 +25,10 @@ 'use strict'; | ||
// | Timm | ||
// | (c) Guillermo Grau Panea 2016 | ||
// | License: MIT | ||
/*! | ||
* Timm | ||
* | ||
* Immutability helpers with fast reads and acceptable writes. | ||
* | ||
* @copyright Guillermo Grau Panea 2016 | ||
* @license MIT | ||
*/ | ||
@@ -37,3 +42,3 @@ var INVALID_ARGS = 'INVALID_ARGS'; | ||
function _throw(msg) { | ||
function throwStr(msg) { | ||
throw new Error(msg); | ||
@@ -55,3 +60,3 @@ } | ||
function _merge(fAddDefaults) { | ||
function doMerge(fAddDefaults) { | ||
for (var _len = arguments.length, rest = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -62,3 +67,3 @@ rest[_key - 1] = arguments[_key]; | ||
var out = rest[0]; | ||
!(out != null) && _throw(process.env.NODE_ENV !== 'production' ? 'At least one object should be provided to merge()' : INVALID_ARGS); | ||
!(out != null) && throwStr(process.env.NODE_ENV !== 'production' ? 'At least one object should be provided to merge()' : INVALID_ARGS); | ||
var fChanged = false; | ||
@@ -93,3 +98,3 @@ for (var idx = 1; idx < rest.length; idx++) { | ||
function _isObject(o) { | ||
function isObject(o) { | ||
var type = typeof o === 'undefined' ? 'undefined' : _typeof(o); | ||
@@ -103,3 +108,3 @@ return o != null && (type === 'object' || type === 'function'); | ||
// val = obj[key] | ||
// if _isObject(val) and not Object.isFrozen val | ||
// if isObject(val) and not Object.isFrozen val | ||
// _deepFreeze val | ||
@@ -235,3 +240,3 @@ // obj | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, d: {d1: 3, d2: 4}, e: ['a', 'b', 'c']} | ||
// -- obj = { a: 1, b: 2, d: { d1: 3, d2: 4 }, e: ['a', 'b', 'c'] } | ||
// -- getIn(obj, ['d', 'd1']) | ||
@@ -243,3 +248,3 @@ // -- // 3 | ||
function getIn(obj, path) { | ||
!Array.isArray(path) && _throw(process.env.NODE_ENV !== 'production' ? 'A path array should be provided when calling getIn()' : INVALID_ARGS); | ||
!Array.isArray(path) && throwStr(process.env.NODE_ENV !== 'production' ? 'A path array should be provided when calling getIn()' : INVALID_ARGS); | ||
if (obj == null) { | ||
@@ -267,5 +272,5 @@ return undefined; | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, c: 3} | ||
// -- obj = { a: 1, b: 2, c: 3 } | ||
// -- obj2 = set(obj, 'b', 5) | ||
// -- // {a: 1, b: 5, c: 3} | ||
// -- // { a: 1, b: 5, c: 3 } | ||
// -- obj2 === obj | ||
@@ -301,5 +306,5 @@ // -- // false | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, d: {d1: 3, d2: 4}, e: {e1: 'foo', e2: 'bar'}} | ||
// -- obj = { a: 1, b: 2, d: { d1: 3, d2: 4 }, e: { e1: 'foo', e2: 'bar' } } | ||
// -- obj2 = setIn(obj, ['d', 'd1'], 4) | ||
// -- // {a: 1, b: 2, d: {d1: 4, d2: 4}, e: {e1: 'foo', e2: 'bar'}} | ||
// -- // { a: 1, b: 2, d: { d1: 4, d2: 4 }, e: { e1: 'foo', e2: 'bar' } } | ||
// -- obj2 === obj | ||
@@ -314,3 +319,3 @@ // -- // false | ||
// -- obj3 = setIn(obj, ['d', 'd1'], 3) | ||
// -- // {a: 1, b: 2, d: {d1: 3, d2: 4}, e: {e1: 'foo', e2: 'bar'}} | ||
// -- // { a: 1, b: 2, d: { d1: 3, d2: 4 }, e: { e1: 'foo', e2: 'bar' } } | ||
// -- obj3 === obj | ||
@@ -324,6 +329,6 @@ // -- // true | ||
// -- // ... unknown paths create intermediate keys: | ||
// -- setIn({a: 3}, ['unknown', 'path'], 4) | ||
// -- // {a: 3, unknown: {path: 4}} | ||
// -- setIn({ a: 3 }, ['unknown', 'path'], 4) | ||
// -- // { a: 3, unknown: { path: 4 } } | ||
// -- ``` | ||
function _setIn(obj, path, val, idx) { | ||
function doSetIn(obj, path, val, idx) { | ||
var newValue = void 0; | ||
@@ -334,4 +339,4 @@ var key = path[idx]; | ||
} else { | ||
var nestedObj = _isObject(obj) ? obj[key] : {}; | ||
newValue = _setIn(nestedObj, path, val, idx + 1); | ||
var nestedObj = isObject(obj) ? obj[key] : {}; | ||
newValue = doSetIn(nestedObj, path, val, idx + 1); | ||
} | ||
@@ -345,3 +350,3 @@ return set(obj, key, newValue); | ||
} | ||
return _setIn(obj, path, val, 0); | ||
return doSetIn(obj, path, val, 0); | ||
} | ||
@@ -359,5 +364,5 @@ | ||
// -- ```js | ||
// -- obj = {a: 1, d: {d1: 3, d2: 4}} | ||
// -- obj2 = updateIn(obj, ['d', 'd1'], function(val){return val + 1}) | ||
// -- // {a: 1, d: {d1: 4, d2: 4}} | ||
// -- obj = { a: 1, d: { d1: 3, d2: 4 } } | ||
// -- obj2 = updateIn(obj, ['d', 'd1'], (val) => val + 1) | ||
// -- // { a: 1, d: { d1: 4, d2: 4 } } | ||
// -- obj2 === obj | ||
@@ -367,4 +372,4 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- obj3 = updateIn(obj, ['d', 'd1'], function(val){return val}) | ||
// -- // {a: 1, d: {d1: 3, d2: 4}} | ||
// -- obj3 = updateIn(obj, ['d', 'd1'], (val) => val) | ||
// -- // { a: 1, d: { d1: 3, d2: 4 } } | ||
// -- obj3 === obj | ||
@@ -399,6 +404,6 @@ // -- // true | ||
// -- ```js | ||
// -- obj1 = {a: 1, b: 2, c: 3} | ||
// -- obj2 = {c: 4, d: 5} | ||
// -- obj1 = { a: 1, b: 2, c: 3 } | ||
// -- obj2 = { c: 4, d: 5 } | ||
// -- obj3 = merge(obj1, obj2) | ||
// -- // {a: 1, b: 2, c: 4, d: 5} | ||
// -- // { a: 1, b: 2, c: 4, d: 5 } | ||
// -- obj3 === obj1 | ||
@@ -408,3 +413,3 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- merge(obj1, {c: 3}) === obj1 | ||
// -- merge(obj1, { c: 3 }) === obj1 | ||
// -- // true | ||
@@ -420,5 +425,5 @@ // -- ``` | ||
if (rest.length) { | ||
out = _merge.call.apply(_merge, [null, false, a, b, c, d, e, f].concat(rest)); | ||
out = doMerge.call.apply(doMerge, [null, false, a, b, c, d, e, f].concat(rest)); | ||
} else { | ||
out = _merge(false, a, b, c, d, e, f); | ||
out = doMerge(false, a, b, c, d, e, f); | ||
} | ||
@@ -438,6 +443,6 @@ return out; | ||
// -- ```js | ||
// -- obj1 = {a: 1, d: {b: {d1: 3, d2: 4}}} | ||
// -- obj2 = {d3: 5} | ||
// -- obj1 = { a: 1, d: { b: { d1: 3, d2: 4 } } } | ||
// -- obj2 = { d3: 5 } | ||
// -- obj3 = mergeIn(obj1, ['d', 'b'], obj2) | ||
// -- // {a: 1, d: {b: {d1: 3, d2: 4, d3: 5}}} | ||
// -- // { a: 1, d: { b: { d1: 3, d2: 4, d3: 5 } } } | ||
// -- obj3 === obj1 | ||
@@ -447,3 +452,3 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- mergeIn(obj1, ['d', 'b'], {d2: 4}) === obj1 | ||
// -- mergeIn(obj1, ['d', 'b'], { d2: 4 }) === obj1 | ||
// -- // true | ||
@@ -463,5 +468,5 @@ // -- ``` | ||
if (rest.length) { | ||
nextVal = _merge.call.apply(_merge, [null, false, prevVal, b, c, d, e, f].concat(rest)); | ||
nextVal = doMerge.call.apply(doMerge, [null, false, prevVal, b, c, d, e, f].concat(rest)); | ||
} else { | ||
nextVal = _merge(false, prevVal, b, c, d, e, f); | ||
nextVal = doMerge(false, prevVal, b, c, d, e, f); | ||
} | ||
@@ -477,7 +482,7 @@ return setIn(a, path, nextVal); | ||
// -- ```js | ||
// -- obj = {a: 1, b: 2, c: 3, d: 4} | ||
// -- obj = { a: 1, b: 2, c: 3, d: 4 } | ||
// -- omit(obj, 'a') | ||
// -- // {b: 2, c: 3, d: 4} | ||
// -- // { b: 2, c: 3, d: 4 } | ||
// -- omit(obj, ['b', 'c']) | ||
// -- // {a: 1, d: 4} | ||
// -- // { a: 1, d: 4 } | ||
// -- | ||
@@ -519,6 +524,6 @@ // -- // The same object is returned if there are no changes: | ||
// -- ```js | ||
// -- obj1 = {a: 1, b: 2, c: 3} | ||
// -- obj2 = {c: 4, d: 5, e: null} | ||
// -- obj1 = { a: 1, b: 2, c: 3 } | ||
// -- obj2 = { c: 4, d: 5, e: null } | ||
// -- obj3 = addDefaults(obj1, obj2) | ||
// -- // {a: 1, b: 2, c: 3, d: 5, e: null} | ||
// -- // { a: 1, b: 2, c: 3, d: 5, e: null } | ||
// -- obj3 === obj1 | ||
@@ -528,3 +533,3 @@ // -- // false | ||
// -- // The same object is returned if there are no changes: | ||
// -- addDefaults(obj1, {c: 4}) === obj1 | ||
// -- addDefaults(obj1, { c: 4 }) === obj1 | ||
// -- // true | ||
@@ -540,5 +545,5 @@ // -- ``` | ||
if (rest.length) { | ||
out = _merge.call.apply(_merge, [null, true, a, b, c, d, e, f].concat(rest)); | ||
out = doMerge.call.apply(doMerge, [null, true, a, b, c, d, e, f].concat(rest)); | ||
} else { | ||
out = _merge(true, a, b, c, d, e, f); | ||
out = doMerge(true, a, b, c, d, e, f); | ||
} | ||
@@ -545,0 +550,0 @@ return out; |
@@ -1,5 +0,9 @@ | ||
"use strict";function _throw(e){throw new Error(e)}function clone(e){if(Array.isArray(e))return[].concat(e);for(var r=Object.keys(e),t={},n=0;n<r.length;n++){var a=r[n];t[a]=e[a]}return t}function _merge(e){for(var r=arguments.length,t=Array(r>1?r-1:0),n=1;r>n;n++)t[n-1]=arguments[n];var a=t[0];!(null!=a)&&_throw(INVALID_ARGS);for(var o=!1,s=1;s<t.length;s++){var u=t[s];if(null!=u){var i=Object.keys(u);if(i.length)for(var c=0;c<=i.length;c++){var l=i[c];if(!e||void 0===a[l]){var f=u[l];void 0!==f&&f!==a[l]&&(o||(o=!0,a=clone(a)),a[l]=f)}}}}return a}function _isObject(e){var r="undefined"==typeof e?"undefined":_typeof(e);return null!=e&&("object"===r||"function"===r)}function addLast(e,r){return e.concat(Array.isArray(r)?r:[r])}function addFirst(e,r){return Array.isArray(r)?r.concat(e):[r].concat(e)}function insert(e,r,t){return e.slice(0,r).concat(Array.isArray(t)?t:[t]).concat(e.slice(r))}function removeAt(e,r){return e.slice(0,r).concat(e.slice(r+1))}function replaceAt(e,r,t){return e[r]===t?e:e.slice(0,r).concat([t]).concat(e.slice(r+1))}function getIn(e,r){if(!Array.isArray(r)&&_throw(INVALID_ARGS),null==e)return void 0;for(var t=e,n=0;n<r.length;n++){var a=r[n];if(t=null!=t?t[a]:void 0,void 0===t)return t}return t}function set(e,r,t){var n=null==e?{}:e;if(n[r]===t)return n;var a=clone(n);return a[r]=t,a}function _setIn(e,r,t,n){var a=void 0,o=r[n];if(n===r.length-1)a=t;else{var s=_isObject(e)?e[o]:{};a=_setIn(s,r,t,n+1)}return set(e,o,a)}function setIn(e,r,t){return r.length?_setIn(e,r,t,0):t}function updateIn(e,r,t){var n=getIn(e,r),a=t(n);return setIn(e,r,a)}function merge(e,r,t,n,a,o){for(var s=void 0,u=arguments.length,i=Array(u>6?u-6:0),c=6;u>c;c++)i[c-6]=arguments[c];return s=i.length?_merge.call.apply(_merge,[null,!1,e,r,t,n,a,o].concat(i)):_merge(!1,e,r,t,n,a,o)}function mergeIn(e,r,t,n,a,o,s){var u=getIn(e,r);null==u&&(u={});for(var i=void 0,c=arguments.length,l=Array(c>7?c-7:0),f=7;c>f;f++)l[f-7]=arguments[f];return i=l.length?_merge.call.apply(_merge,[null,!1,u,t,n,a,o,s].concat(l)):_merge(!1,u,t,n,a,o,s),setIn(e,r,i)}function omit(e,r){for(var t=Array.isArray(r)?r:[r],n=!1,a=0;a<t.length;a++)if(e.hasOwnProperty(t[a])){n=!0;break}if(!n)return e;for(var o={},s=Object.keys(e),u=0;u<s.length;u++){var i=s[u];t.indexOf(i)>=0||(o[i]=e[i])}return o}function addDefaults(e,r,t,n,a,o){for(var s=void 0,u=arguments.length,i=Array(u>6?u-6:0),c=6;u>c;c++)i[c-6]=arguments[c];return s=i.length?_merge.call.apply(_merge,[null,!0,e,r,t,n,a,o].concat(i)):_merge(!0,e,r,t,n,a,o)}Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};exports.clone=clone,exports.addLast=addLast,exports.addFirst=addFirst,exports.insert=insert,exports.removeAt=removeAt,exports.replaceAt=replaceAt,exports.getIn=getIn,exports.set=set,exports.setIn=setIn,exports.updateIn=updateIn,exports.merge=merge,exports.mergeIn=mergeIn,exports.omit=omit,exports.addDefaults=addDefaults; | ||
// | Timm | ||
// | (c) Guillermo Grau Panea 2016 | ||
// | License: MIT | ||
"use strict";function throwStr(e){throw new Error(e)}function clone(e){if(Array.isArray(e))return[].concat(e);for(var r=Object.keys(e),t={},n=0;n<r.length;n++){var o=r[n];t[o]=e[o]}return t}function doMerge(e){for(var r=arguments.length,t=Array(r>1?r-1:0),n=1;r>n;n++)t[n-1]=arguments[n];var o=t[0];!(null!=o)&&throwStr(INVALID_ARGS);for(var a=!1,s=1;s<t.length;s++){var u=t[s];if(null!=u){var i=Object.keys(u);if(i.length)for(var c=0;c<=i.length;c++){var l=i[c];if(!e||void 0===o[l]){var d=u[l];void 0!==d&&d!==o[l]&&(a||(a=!0,o=clone(o)),o[l]=d)}}}}return o}function isObject(e){var r="undefined"==typeof e?"undefined":_typeof(e);return null!=e&&("object"===r||"function"===r)}function addLast(e,r){return e.concat(Array.isArray(r)?r:[r])}function addFirst(e,r){return Array.isArray(r)?r.concat(e):[r].concat(e)}function insert(e,r,t){return e.slice(0,r).concat(Array.isArray(t)?t:[t]).concat(e.slice(r))}function removeAt(e,r){return e.slice(0,r).concat(e.slice(r+1))}function replaceAt(e,r,t){return e[r]===t?e:e.slice(0,r).concat([t]).concat(e.slice(r+1))}function getIn(e,r){if(!Array.isArray(r)&&throwStr(INVALID_ARGS),null==e)return void 0;for(var t=e,n=0;n<r.length;n++){var o=r[n];if(t=null!=t?t[o]:void 0,void 0===t)return t}return t}function set(e,r,t){var n=null==e?{}:e;if(n[r]===t)return n;var o=clone(n);return o[r]=t,o}function doSetIn(e,r,t,n){var o=void 0,a=r[n];if(n===r.length-1)o=t;else{var s=isObject(e)?e[a]:{};o=doSetIn(s,r,t,n+1)}return set(e,a,o)}function setIn(e,r,t){return r.length?doSetIn(e,r,t,0):t}function updateIn(e,r,t){var n=getIn(e,r),o=t(n);return setIn(e,r,o)}function merge(e,r,t,n,o,a){for(var s=void 0,u=arguments.length,i=Array(u>6?u-6:0),c=6;u>c;c++)i[c-6]=arguments[c];return s=i.length?doMerge.call.apply(doMerge,[null,!1,e,r,t,n,o,a].concat(i)):doMerge(!1,e,r,t,n,o,a)}function mergeIn(e,r,t,n,o,a,s){var u=getIn(e,r);null==u&&(u={});for(var i=void 0,c=arguments.length,l=Array(c>7?c-7:0),d=7;c>d;d++)l[d-7]=arguments[d];return i=l.length?doMerge.call.apply(doMerge,[null,!1,u,t,n,o,a,s].concat(l)):doMerge(!1,u,t,n,o,a,s),setIn(e,r,i)}function omit(e,r){for(var t=Array.isArray(r)?r:[r],n=!1,o=0;o<t.length;o++)if(e.hasOwnProperty(t[o])){n=!0;break}if(!n)return e;for(var a={},s=Object.keys(e),u=0;u<s.length;u++){var i=s[u];t.indexOf(i)>=0||(a[i]=e[i])}return a}function addDefaults(e,r,t,n,o,a){for(var s=void 0,u=arguments.length,i=Array(u>6?u-6:0),c=6;u>c;c++)i[c-6]=arguments[c];return s=i.length?doMerge.call.apply(doMerge,[null,!0,e,r,t,n,o,a].concat(i)):doMerge(!0,e,r,t,n,o,a)}Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};exports.clone=clone,exports.addLast=addLast,exports.addFirst=addFirst,exports.insert=insert,exports.removeAt=removeAt,exports.replaceAt=replaceAt,exports.getIn=getIn,exports.set=set,exports.setIn=setIn,exports.updateIn=updateIn,exports.merge=merge,exports.mergeIn=mergeIn,exports.omit=omit,exports.addDefaults=addDefaults;/*! | ||
* Timm | ||
* | ||
* Immutability helpers with fast reads and acceptable writes. | ||
* | ||
* @copyright Guillermo Grau Panea 2016 | ||
* @license MIT | ||
*/ | ||
var INVALID_ARGS="INVALID_ARGS",timm={addLast:addLast,addFirst:addFirst,insert:insert,removeAt:removeAt,replaceAt:replaceAt,getIn:getIn,set:set,setIn:setIn,updateIn:updateIn,merge:merge,mergeIn:mergeIn,addDefaults:addDefaults};exports["default"]=timm; |
{ | ||
"name": "timm", | ||
"version": "0.6.1", | ||
"version": "1.0.0", | ||
"description": "Immutability helpers with fast reads and acceptable writes", | ||
@@ -8,25 +8,28 @@ "main": "lib/timm.js", | ||
"devDependencies": { | ||
"ava": "^0.13.0", | ||
"babel-cli": "^6.6.5", | ||
"babel-core": "^6.7.2", | ||
"babel-eslint": "^5.0.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.7.0", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-preset-stage-2": "^6.5.0", | ||
"chalk": "^1.1.1", | ||
"ava": "0.15.2", | ||
"babel-cli": "6.10.1", | ||
"babel-core": "6.9.1", | ||
"babel-eslint": "6.0.4", | ||
"babel-plugin-transform-flow-strip-types": "6.8.0", | ||
"babel-preset-es2015": "6.9.0", | ||
"babel-preset-stage-2": "6.5.0", | ||
"chalk": "1.1.3", | ||
"coffee-script": "1.10.0", | ||
"coveralls": "2.11.6", | ||
"cross-env": "^1.0.7", | ||
"envify": "^3.4.0", | ||
"eslint": "^2.4.0", | ||
"eslint-config-airbnb": "^6.2.0", | ||
"eslint-plugin-flowtype": "^2.2.2", | ||
"eslint-plugin-react": "^4.3.0", | ||
"extract-docs": "^1.0.1", | ||
"flow-bin": "^0.22.1", | ||
"immutable": "^3.7.6", | ||
"lodash": "^4.5.0", | ||
"nyc": "^6.1.1", | ||
"seamless-immutable": "^5.0.1", | ||
"uglifyjs": "^2.4.10" | ||
"coveralls": "2.11.9", | ||
"cross-env": "1.0.8", | ||
"envify": "3.4.0", | ||
"eslint": "2.12.0", | ||
"eslint-config-airbnb": "9.0.1", | ||
"eslint-plugin-flowtype": "2.2.7", | ||
"eslint-plugin-import": "1.8.1", | ||
"eslint-plugin-jsx-a11y": "1.4.2", | ||
"eslint-plugin-react": "5.1.1", | ||
"extract-docs": "1.3.0", | ||
"flow-bin": "0.27.0", | ||
"immutable": "3.8.1", | ||
"lodash": "4.13.1", | ||
"nyc": "6.4.4", | ||
"seamless-immutable": "6.1.0", | ||
"uglifyjs": "2.4.10", | ||
"xxl": "0.1.1" | ||
}, | ||
@@ -49,5 +52,6 @@ "scripts": { | ||
"docs": "extract-docs --template docs/README_TEMPLATE.md --output README.md", | ||
"uglify": "cross-env NODE_ENV=production envify lib/timm.js | uglifyjs - -o lib/timm.min.js --mangle --compress --comments \"/^\\s\\|/\"", | ||
"build": "npm run lint && npm run flow && npm run compile && npm run uglify && npm run testCovFull && npm run docs", | ||
"uglify": "cross-env NODE_ENV=production envify lib/timm.js | uglifyjs - -o lib/timm.min.js --mangle --compress --comments \"/^!/\"", | ||
"build": "npm run lint && npm run flow && npm run compile && npm run uglify && npm run testCovFull && npm run docs && npm run xxl", | ||
"travis": "npm run compile && npm run testCovNoMin", | ||
"xxl": "xxl --src \"[\\\"src\\\"]\"", | ||
"benchmarks": "coffee tools/benchmarks.coffee" | ||
@@ -54,0 +58,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1505
1
53554
26
9
1
0