Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

timm

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timm - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

4

CHANGELOG.md
# Changelog
## 0.6.1 (Apr. 22, 2016)
* Add `omit()`
## 0.6.0 (Mar. 24, 2016)

@@ -4,0 +8,0 @@

@@ -19,3 +19,3 @@ // @flow

function _clone(obj: ArrayOrObject): ArrayOrObject {
export function clone(obj: ArrayOrObject): ArrayOrObject {
if (Array.isArray(obj)) {

@@ -58,3 +58,3 @@ return [].concat(obj);

fChanged = true;
out = _clone(out);
out = clone(out);
}

@@ -184,3 +184,3 @@ out[key] = nextVal;

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- replaceAt(arr, 1, 'b') === arr

@@ -254,3 +254,3 @@ // -- // true

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- set(obj, 'b', 2) === obj

@@ -264,3 +264,3 @@ // -- // true

}
const obj2: any = _clone(finalObj);
const obj2: any = clone(finalObj);
obj2[key] = val;

@@ -293,3 +293,3 @@ return obj2;

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- obj3 = setIn(obj, ['d', 'd1'], 3)

@@ -343,3 +343,3 @@ // -- // {a: 1, b: 2, d: {d1: 3, d2: 4}, e: {e1: 'foo', e2: 'bar'}}

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- obj3 = updateIn(obj, ['d', 'd1'], function(val){return val})

@@ -384,3 +384,3 @@ // -- // {a: 1, d: {d1: 3, d2: 4}}

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- merge(obj1, {c: 3}) === obj1

@@ -414,3 +414,3 @@ // -- // true

// -- obj2 = {d3: 5}
// -- obj2 = mergeIn(obj1, ['d', 'b'], obj2)
// -- obj3 = mergeIn(obj1, ['d', 'b'], obj2)
// -- // {a: 1, d: {b: {d1: 3, d2: 4, d3: 5}}}

@@ -420,3 +420,3 @@ // -- obj3 === obj1

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- mergeIn(obj1, ['d', 'b'], {d2: 4}) === obj1

@@ -442,2 +442,38 @@ // -- // true

// -- #### omit()
// -- Returns an object excluding one or several attributes.
// --
// -- Usage: `omit(obj: Object, attrs: Array<string>|string): Object`
//
// -- ```js
// -- obj = {a: 1, b: 2, c: 3, d: 4}
// -- omit(obj, 'a')
// -- // {b: 2, c: 3, d: 4}
// -- omit(obj, ['b', 'c'])
// -- // {a: 1, d: 4}
// --
// -- // The same object is returned if there are no changes:
// -- omit(obj, 'z') === obj1
// -- // true
// -- ```
export function omit(obj: Object, attrs: Array<string>|string): Object {
const omitList = Array.isArray(attrs) ? attrs : [attrs];
let fDoSomething = false;
for (let i = 0; i < omitList.length; i++) {
if (obj.hasOwnProperty(omitList[i])) {
fDoSomething = true;
break;
}
}
if (!fDoSomething) return obj;
const out = {};
const keys = Object.keys(obj);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (omitList.indexOf(key) >= 0) continue;
out[key] = obj[key];
}
return out;
}
// -- #### addDefaults()

@@ -461,3 +497,3 @@ // -- Returns a new object built as follows: `undefined` keys in the first one

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- addDefaults(obj1, {c: 4}) === obj1

@@ -464,0 +500,0 @@ // -- // true

@@ -18,3 +18,3 @@

function _clone(obj) {
export function clone(obj) {
if (Array.isArray(obj)) {

@@ -56,3 +56,3 @@ return [].concat(obj);

fChanged = true;
out = _clone(out);
out = clone(out);
}

@@ -177,3 +177,3 @@ out[key] = nextVal;

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- replaceAt(arr, 1, 'b') === arr

@@ -242,3 +242,3 @@ // -- // true

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- set(obj, 'b', 2) === obj

@@ -252,3 +252,3 @@ // -- // true

}
const obj2 = _clone(finalObj);
const obj2 = clone(finalObj);
obj2[key] = val;

@@ -281,3 +281,3 @@ return obj2;

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- obj3 = setIn(obj, ['d', 'd1'], 3)

@@ -331,3 +331,3 @@ // -- // {a: 1, b: 2, d: {d1: 3, d2: 4}, e: {e1: 'foo', e2: 'bar'}}

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- obj3 = updateIn(obj, ['d', 'd1'], function(val){return val})

@@ -371,3 +371,3 @@ // -- // {a: 1, d: {d1: 3, d2: 4}}

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- merge(obj1, {c: 3}) === obj1

@@ -398,3 +398,3 @@ // -- // true

// -- obj2 = {d3: 5}
// -- obj2 = mergeIn(obj1, ['d', 'b'], obj2)
// -- obj3 = mergeIn(obj1, ['d', 'b'], obj2)
// -- // {a: 1, d: {b: {d1: 3, d2: 4, d3: 5}}}

@@ -404,3 +404,3 @@ // -- obj3 === obj1

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- mergeIn(obj1, ['d', 'b'], {d2: 4}) === obj1

@@ -423,2 +423,38 @@ // -- // true

// -- #### omit()
// -- Returns an object excluding one or several attributes.
// --
// -- Usage: `omit(obj: Object, attrs: Array<string>|string): Object`
//
// -- ```js
// -- obj = {a: 1, b: 2, c: 3, d: 4}
// -- omit(obj, 'a')
// -- // {b: 2, c: 3, d: 4}
// -- omit(obj, ['b', 'c'])
// -- // {a: 1, d: 4}
// --
// -- // The same object is returned if there are no changes:
// -- omit(obj, 'z') === obj1
// -- // true
// -- ```
export function omit(obj, attrs) {
const omitList = Array.isArray(attrs) ? attrs : [attrs];
let fDoSomething = false;
for (let i = 0; i < omitList.length; i++) {
if (obj.hasOwnProperty(omitList[i])) {
fDoSomething = true;
break;
}
}
if (!fDoSomething) return obj;
const out = {};
const keys = Object.keys(obj);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (omitList.indexOf(key) >= 0) continue;
out[key] = obj[key];
}
return out;
}
// -- #### addDefaults()

@@ -442,3 +478,3 @@ // -- Returns a new object built as follows: `undefined` keys in the first one

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- addDefaults(obj1, {c: 4}) === obj1

@@ -445,0 +481,0 @@ // -- // true

@@ -9,2 +9,3 @@ 'use strict';

exports.clone = clone;
exports.addLast = addLast;

@@ -21,2 +22,3 @@ exports.addFirst = addFirst;

exports.mergeIn = mergeIn;
exports.omit = omit;
exports.addDefaults = addDefaults;

@@ -40,3 +42,3 @@

function _clone(obj) {
function clone(obj) {
if (Array.isArray(obj)) {

@@ -82,3 +84,3 @@ return [].concat(obj);

fChanged = true;
out = _clone(out);
out = clone(out);
}

@@ -203,3 +205,3 @@ out[key] = nextVal;

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- replaceAt(arr, 1, 'b') === arr

@@ -268,3 +270,3 @@ // -- // true

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- set(obj, 'b', 2) === obj

@@ -278,3 +280,3 @@ // -- // true

}
var obj2 = _clone(finalObj);
var obj2 = clone(finalObj);
obj2[key] = val;

@@ -307,3 +309,3 @@ return obj2;

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- obj3 = setIn(obj, ['d', 'd1'], 3)

@@ -357,3 +359,3 @@ // -- // {a: 1, b: 2, d: {d1: 3, d2: 4}, e: {e1: 'foo', e2: 'bar'}}

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- obj3 = updateIn(obj, ['d', 'd1'], function(val){return val})

@@ -397,3 +399,3 @@ // -- // {a: 1, d: {d1: 3, d2: 4}}

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- merge(obj1, {c: 3}) === obj1

@@ -429,3 +431,3 @@ // -- // true

// -- obj2 = {d3: 5}
// -- obj2 = mergeIn(obj1, ['d', 'b'], obj2)
// -- obj3 = mergeIn(obj1, ['d', 'b'], obj2)
// -- // {a: 1, d: {b: {d1: 3, d2: 4, d3: 5}}}

@@ -435,3 +437,3 @@ // -- obj3 === obj1

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- mergeIn(obj1, ['d', 'b'], {d2: 4}) === obj1

@@ -459,2 +461,38 @@ // -- // true

// -- #### omit()
// -- Returns an object excluding one or several attributes.
// --
// -- Usage: `omit(obj: Object, attrs: Array<string>|string): Object`
//
// -- ```js
// -- obj = {a: 1, b: 2, c: 3, d: 4}
// -- omit(obj, 'a')
// -- // {b: 2, c: 3, d: 4}
// -- omit(obj, ['b', 'c'])
// -- // {a: 1, d: 4}
// --
// -- // The same object is returned if there are no changes:
// -- omit(obj, 'z') === obj1
// -- // true
// -- ```
function omit(obj, attrs) {
var omitList = Array.isArray(attrs) ? attrs : [attrs];
var fDoSomething = false;
for (var i = 0; i < omitList.length; i++) {
if (obj.hasOwnProperty(omitList[i])) {
fDoSomething = true;
break;
}
}
if (!fDoSomething) return obj;
var out = {};
var keys = Object.keys(obj);
for (var _i = 0; _i < keys.length; _i++) {
var key = keys[_i];
if (omitList.indexOf(key) >= 0) continue;
out[key] = obj[key];
}
return out;
}
// -- #### addDefaults()

@@ -478,3 +516,3 @@ // -- Returns a new object built as follows: `undefined` keys in the first one

// --
// -- // ... but the same object is returned if there are no changes:
// -- // The same object is returned if there are no changes:
// -- addDefaults(obj1, {c: 4}) === obj1

@@ -481,0 +519,0 @@ // -- // true

2

lib/timm.min.js

@@ -1,2 +0,2 @@

"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 c=Object.keys(u);if(c.length)for(var l=0;l<=c.length;l++){var i=c[l];if(!e||void 0===a[i]){var f=u[i];void 0!==f&&f!==a[i]&&(o||(o=!0,a=_clone(a)),a[i]=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,c=Array(u>6?u-6:0),l=6;u>l;l++)c[l-6]=arguments[l];return s=c.length?_merge.call.apply(_merge,[null,!1,e,r,t,n,a,o].concat(c)):_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 c=void 0,l=arguments.length,i=Array(l>7?l-7:0),f=7;l>f;f++)i[f-7]=arguments[f];return c=i.length?_merge.call.apply(_merge,[null,!1,u,t,n,a,o,s].concat(i)):_merge(!1,u,t,n,a,o,s),setIn(e,r,c)}function addDefaults(e,r,t,n,a,o){for(var s=void 0,u=arguments.length,c=Array(u>6?u-6:0),l=6;u>l;l++)c[l-6]=arguments[l];return s=c.length?_merge.call.apply(_merge,[null,!0,e,r,t,n,a,o].concat(c)):_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.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.addDefaults=addDefaults;
"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

@@ -3,0 +3,0 @@ // | (c) Guillermo Grau Panea 2016

{
"name": "timm",
"version": "0.6.0",
"version": "0.6.1",
"description": "Immutability helpers with fast reads and acceptable writes",

@@ -23,2 +23,4 @@ "main": "lib/timm.js",

"eslint-plugin-flowtype": "^2.2.2",
"eslint-plugin-react": "^4.3.0",
"extract-docs": "^1.0.1",
"flow-bin": "^0.22.1",

@@ -46,3 +48,3 @@ "immutable": "^3.7.6",

"compile": "rm -rf ./lib && mkdir lib && babel -o lib/timm.js src/timm.js && babel --no-babelrc --plugins transform-flow-strip-types -o lib/timm_es6.js src/timm.js && cp src/timm.js lib/timm_es6_flow.js",
"docs": "coffee tools/extractDocs.coffee",
"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\\|/\"",

@@ -49,0 +51,0 @@ "build": "npm run lint && npm run flow && npm run compile && npm run uglify && npm run testCovFull && npm run docs",

@@ -146,3 +146,3 @@ # timm [![Build Status](https://travis-ci.org/guigrpa/timm.svg)](https://travis-ci.org/guigrpa/timm) [![Coverage Status](https://coveralls.io/repos/github/guigrpa/timm/badge.svg?branch=master)](https://coveralls.io/github/guigrpa/timm?branch=master) [![npm version](https://img.shields.io/npm/v/timm.svg)](https://www.npmjs.com/package/timm)

// ... but the same object is returned if there are no changes:
// The same object is returned if there are no changes:
replaceAt(arr, 1, 'b') === arr

@@ -189,3 +189,3 @@ // true

// ... but the same object is returned if there are no changes:
// The same object is returned if there are no changes:
set(obj, 'b', 2) === obj

@@ -218,3 +218,3 @@ // true

// ... but the same object is returned if there are no changes:
// The same object is returned if there are no changes:
obj3 = setIn(obj, ['d', 'd1'], 3)

@@ -250,3 +250,3 @@ // {a: 1, b: 2, d: {d1: 3, d2: 4}, e: {e1: 'foo', e2: 'bar'}}

// ... but the same object is returned if there are no changes:
// The same object is returned if there are no changes:
obj3 = updateIn(obj, ['d', 'd1'], function(val){return val})

@@ -285,3 +285,3 @@ // {a: 1, d: {d1: 3, d2: 4}}

// ... but the same object is returned if there are no changes:
// The same object is returned if there are no changes:
merge(obj1, {c: 3}) === obj1

@@ -303,3 +303,3 @@ // true

obj2 = {d3: 5}
obj2 = mergeIn(obj1, ['d', 'b'], obj2)
obj3 = mergeIn(obj1, ['d', 'b'], obj2)
// {a: 1, d: {b: {d1: 3, d2: 4, d3: 5}}}

@@ -309,3 +309,3 @@ obj3 === obj1

// ... but the same object is returned if there are no changes:
// The same object is returned if there are no changes:
mergeIn(obj1, ['d', 'b'], {d2: 4}) === obj1

@@ -315,2 +315,19 @@ // true

#### omit()
Returns an object excluding one or several attributes.
Usage: `omit(obj: Object, attrs: Array<string>|string): Object`
```js
obj = {a: 1, b: 2, c: 3, d: 4}
omit(obj, 'a')
// {b: 2, c: 3, d: 4}
omit(obj, ['b', 'c'])
// {a: 1, d: 4}
// The same object is returned if there are no changes:
omit(obj, 'z') === obj1
// true
```
#### addDefaults()

@@ -334,3 +351,3 @@ Returns a new object built as follows: `undefined` keys in the first one

// ... but the same object is returned if there are no changes:
// The same object is returned if there are no changes:
addDefaults(obj1, {c: 4}) === obj1

@@ -337,0 +354,0 @@ // true

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc