Socket
Socket
Sign inDemoInstall

immutable-object-methods

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immutable-object-methods - npm Package Compare versions

Comparing version 1.3.2 to 2.0.0

.prettierignore

30

example.js

@@ -1,4 +0,12 @@

import {getIn, setIn, mergeDeep, assign, set, without, chain} from 'immutable-object-methods';
import {
getIn,
setIn,
mergeDeep,
assign,
set,
without,
chain,
} from 'immutable-object-methods';
const input = {a: {b: 'c'}};
const input = { a: { b: 'c' } };
const updated = setIn(input, ['a', 'd'], 'e');

@@ -9,13 +17,10 @@

const merged = mergeDeep(
{foo: 'bar'},
{beep: {boop: 4711}, foo: 'bas'}
);
const merged = mergeDeep({ foo: 'bar' }, { beep: { boop: 4711 }, foo: 'bas' });
console.log(merged);
// immutable assign
const assigned = assign({foo: 'bar'}, {foz: 'baz'});
const assigned = assign({ foo: 'bar' }, { foz: 'baz' });
console.log(assigned);
const value = getIn({a: {b: 'c'}}, ['a', 'b']);
const value = getIn({ a: { b: 'c' } }, ['a', 'b']);
// will print out 'c'

@@ -28,13 +33,12 @@ console.log(value);

const data = set({beep: 'boop'}, 'foo', 'bar');
const data = set({ beep: 'boop' }, 'foo', 'bar');
console.log(data);
const beep = without({foo: 'bar'}, 'foo');
const beep = without({ foo: 'bar' }, 'foo');
console.log(beep);
// all of these can also be used chained, like
const chained = chain({foo: 'bar'})
const chained = chain({ foo: 'bar' })
.set('beep', 'boop')
.without('foo')
.value;
.without('foo').value;
console.log(chained);

@@ -1,8 +0,28 @@

import _assign from 'object-assign';
// @ts-check
const assign = (first, ...args) =>
Array.isArray(first)
? _assign([], first, ...args)
: _assign({}, first, ...args);
const set = require('./set');
export default assign;
/**
*
* @param {Object} input
* @param {...Object} args
*/
const assign = (input, ...args) => {
const changes = {};
args.forEach((obj) => {
for (const key in obj) {
changes[key] = obj[key];
}
});
let result = input;
for (const key in changes) {
result = set(result, key, changes[key]);
}
return result;
};
module.exports = assign;

@@ -1,16 +0,31 @@

export default unchainedMethods => {
const {map} = unchainedMethods;
// @ts-check
const chain = input => {
const methods = map(
unchainedMethods,
fn => (...args) => chain(fn(input, ...args)
));
const assign = require('./assign');
const mergeDeep = require('./merge-deep');
const setIn = require('./set-in');
const getIn = require('./get-in');
const set = require('./set');
const without = require('./without');
const map = require('./map');
methods.value = input;
const unchainedMethods = {
assign,
mergeDeep,
setIn,
getIn,
set,
without,
map,
};
return methods;
};
const chain = (input) => {
const methods = map(unchainedMethods, (fn) => (...args) =>
chain(fn(input, ...args)),
);
return input => chain(input);
methods.value = input;
return methods;
};
module.exports = chain;

@@ -0,1 +1,8 @@

// @ts-check
/**
*
* @param {Object} input
* @param {ReadonlyArray<(string|number)>} param1
*/
const getIn = (input = {}, [key, ...rest]) => {

@@ -6,5 +13,5 @@ if (!input) {

return rest.length ? getIn(input[key], rest) : input[key];
return rest[0] ? getIn(input[key], rest) : input[key];
};
export default getIn;
module.exports = getIn;

@@ -1,30 +0,10 @@

import _assign from './assign';
import _mergeDeep from './merge-deep';
import _setIn from './set-in';
import _getIn from './get-in';
import _set from './set';
import _without from './without';
import _map from './map';
import setupChain from './chain';
// @ts-check
export const assign = _assign;
export const mergeDeep = _mergeDeep;
export const setIn = _setIn;
export const getIn = _getIn;
export const set = _set;
export const without = _without;
export const map = _map;
export const chain = setupChain({
assign, mergeDeep, setIn, getIn, set, without, map
});
export default {
assign,
getIn,
setIn,
mergeDeep,
set,
without,
map,
chain
};
module.exports.assign = require('./assign');
module.exports.mergeDeep = require('./merge-deep');
module.exports.setIn = require('./set-in');
module.exports.getIn = require('./get-in');
module.exports.set = require('./set');
module.exports.without = require('./without');
module.exports.map = require('./map');
module.exports.chain = require('./chain');

@@ -0,14 +1,21 @@

// @ts-check
const set = require('./set');
/**
*
* @template {Object} T
* @param {Readonly<{[key: string]: T}>} input
* @param {(obj: Readonly<T>, key: string) => unknown} fn
*/
const map = (input, fn) => {
let changed = false;
const result = Object.keys(input).map((key) => {
return [key, input[key]];
}).reduce((result, [key, obj]) => {
const newObj = fn(input[key], key);
changed = changed || obj !== newObj;
result[key] = newObj;
return result;
}, {});
return changed ? result : input;
let result = input;
for (const key in input) {
result = set(result, key, fn(input[key], key));
}
return result;
};
export default map;
module.exports = map;

@@ -1,27 +0,29 @@

import assign from './assign';
// @ts-check
const isObject = obj => typeof obj === 'object' && obj !== null && !Array.isArray(obj);
const set = require('./set');
const isObject = (obj) =>
typeof obj === 'object' && obj !== null && !Array.isArray(obj);
/**
*
* @param {Object} input
* @param {Object} changes
*/
const mergeDeep = (input = {}, changes) => {
let result = input;
Object.keys(changes).forEach(key => {
const child = changes[key];
const newChild = isObject(child)
? mergeDeep(input[key], child) : child;
for (const key in changes) {
const childChange = changes[key];
if (result[key] !== newChild) {
if (result === input) {
result = assign(input, {
[key]: newChild
});
} else {
result[key] = newChild;
}
}
});
const newChild = isObject(childChange)
? mergeDeep(input[key], childChange)
: childChange;
result = set(result, key, newChild);
}
return result;
};
export default mergeDeep;
module.exports = mergeDeep;

@@ -1,10 +0,17 @@

import assign from './assign';
// @ts-check
const set = require('./set');
/**
*
* @param {Readonly<Object>} input
* @param {ReadonlyArray<(string|number)>} key
* @param {any} value
*/
const setIn = (input = {}, [key, ...rest], value) => {
const oldChild = input[key];
const newChild = rest.length ? setIn(oldChild, rest, value) : value;
return newChild === oldChild
? input : assign(input, {[key]: newChild});
const newChild = rest.length ? setIn(input[key], rest, value) : value;
return set(input, key, newChild);
};
export default setIn;
module.exports = setIn;

@@ -1,5 +0,25 @@

import setIn from './set-in';
// @ts-check
const set = (input, key, value) => setIn(input, [key], value);
/**
*
* @param {Readonly<Object>} input
* @param {Readonly<string|number>} key
* @param {any} value
*/
const set = (input, key, value) => {
if (input[key] === value) {
return input;
}
export default set;
const result = Array.isArray(input) ? [] : {};
for (const inputKey in input) {
result[inputKey] = inputKey === key ? value : input[inputKey];
}
result[key] = value;
return result;
};
module.exports = set;

@@ -1,13 +0,24 @@

import assign from './assign';
// @ts-check
/**
*
* @param {Object} input
* @param {string|number} key
*/
const without = (input, key) => {
if (input[key] === undefined) {
if (!(key in input)) {
return input;
}
const result = assign(input);
delete result[key];
const result = Array.isArray(input) ? [] : {};
for (const inputKey in input) {
if (inputKey !== String(key)) {
result[inputKey] = input[inputKey];
}
}
return result;
};
export default without;
module.exports = without;
{
"name": "immutable-object-methods",
"version": "1.3.2",
"version": "2.0.0",
"description": "Update normal plain javascript object, immutable style. Simlar to how immutable.js, seamless-immutable etc does it but a lot smaller and simpler.",
"main": "dist/index.js",
"main": "lib/index.js",
"scripts": {
"test": "ava && semistandard | snazzy",
"build": "rm -rf dist && mkdir -p dist && babel lib --out-dir dist",
"watch": "rm -rf dist && mkdir -p dist && babel -w lib --out-dir dist",
"prepublish": "npm run build",
"posttest": "package-json-to-readme package.json --travis > readme.md"
"test": "ava",
"posttest": "package-json-to-readme package.json > readme.md"
},
"repository": {
"type": "git",
"url": "git+https://github.com/micnews/immutable-object-methods.git"
"url": "git+https://github.com/pizza-skull/immutable-object-methods.git"
},

@@ -20,17 +17,11 @@ "author": "mic.com",

"bugs": {
"url": "https://github.com/micnews/immutable-object-methods/issues"
"url": "https://github.com/pizza-skull/immutable-object-methods/issues"
},
"homepage": "https://github.com/micnews/immutable-object-methods#readme",
"homepage": "https://github.com/pizza-skull/immutable-object-methods#readme",
"devDependencies": {
"ava": "^0.16.0",
"babel-cli": "^6.8.0",
"babel-core": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"package-json-to-readme": "^1.5.1",
"semistandard": "^9.0.0",
"snazzy": "^5.0.0"
"ava": "^1.4.1",
"package-json-to-readme": "^2.1.1",
"prettier": "^1.17.0"
},
"dependencies": {
"object-assign": "^4.1.0"
}
"dependencies": {}
}

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

# immutable-object-methods [![Build Status](https://travis-ci.org/micnews/immutable-object-methods.png?branch=master)](https://travis-ci.org/micnews/immutable-object-methods)
# immutable-object-methods

@@ -7,3 +7,8 @@ Update normal plain javascript object, immutable style. Simlar to how immutable.js, seamless-immutable etc does it but a lot smaller and simpler.

Download node at [nodejs.org](http://nodejs.org) and install it, if you haven't already.
This is a [Node.js](https://nodejs.org/) module available through the
[npm registry](https://www.npmjs.com/). It can be installed using the
[`npm`](https://docs.npmjs.com/getting-started/installing-npm-packages-locally)
or
[`yarn`](https://yarnpkg.com/en/)
command line tools.

@@ -17,5 +22,13 @@ ```sh

```js
import {getIn, setIn, mergeDeep, assign, set, without, chain} from 'immutable-object-methods';
import {
getIn,
setIn,
mergeDeep,
assign,
set,
without,
chain,
} from 'immutable-object-methods';
const input = {a: {b: 'c'}};
const input = { a: { b: 'c' } };
const updated = setIn(input, ['a', 'd'], 'e');

@@ -26,13 +39,10 @@

const merged = mergeDeep(
{foo: 'bar'},
{beep: {boop: 4711}, foo: 'bas'}
);
const merged = mergeDeep({ foo: 'bar' }, { beep: { boop: 4711 }, foo: 'bas' });
console.log(merged);
// immutable assign
const assigned = assign({foo: 'bar'}, {foz: 'baz'});
const assigned = assign({ foo: 'bar' }, { foz: 'baz' });
console.log(assigned);
const value = getIn({a: {b: 'c'}}, ['a', 'b']);
const value = getIn({ a: { b: 'c' } }, ['a', 'b']);
// will print out 'c'

@@ -45,13 +55,12 @@ console.log(value);

const data = set({beep: 'boop'}, 'foo', 'bar');
const data = set({ beep: 'boop' }, 'foo', 'bar');
console.log(data);
const beep = without({foo: 'bar'}, 'foo');
const beep = without({ foo: 'bar' }, 'foo');
console.log(beep);
// all of these can also be used chained, like
const chained = chain({foo: 'bar'})
const chained = chain({ foo: 'bar' })
.set('beep', 'boop')
.without('foo')
.value;
.without('foo').value;
console.log(chained);

@@ -70,19 +79,12 @@

- [object-assign](https://github.com/sindresorhus/object-assign): ES2015 `Object.assign()` ponyfill
None
## Dev Dependencies
- [ava](https://github.com/avajs/ava): Futuristic test runner 🚀
- [babel-cli](https://github.com/babel/babel/tree/master/packages): Babel command line.
- [babel-core](https://github.com/babel/babel/tree/master/packages): Babel compiler core.
- [babel-preset-es2015](https://github.com/babel/babel/tree/master/packages): Babel preset for all es2015 plugins.
- [package-json-to-readme](https://github.com/zeke/package-json-to-readme): Generate a README.md from package.json contents
- [semistandard](https://github.com/Flet/semistandard): All the goodness of `feross/standard` with semicolons sprinkled on top.
- [snazzy](https://github.com/feross/snazzy): Format JavaScript Standard Style as Stylish (i.e. snazzy) output
- [ava](https://ghub.io/ava): Testing can be a drag. AVA helps you get it done.
- [package-json-to-readme](https://ghub.io/package-json-to-readme): Generate a README.md from package.json contents
- [prettier](https://ghub.io/prettier): Prettier is an opinionated code formatter
## License
MIT
_Generated by [package-json-to-readme](https://github.com/zeke/package-json-to-readme)_

@@ -0,7 +1,17 @@

// @ts-check
import test from 'ava';
import 'babel-core/register';
import {assign, getIn, mergeDeep, setIn, set, without, map, chain,
default as objectMethods} from './lib';
import {
assign,
getIn,
mergeDeep,
setIn,
set,
without,
map,
chain,
default as objectMethods,
} from './lib';
test('default export', t => {
test('default export', (t) => {
t.is(objectMethods.assign, assign);

@@ -17,8 +27,8 @@ t.is(objectMethods.getIn, getIn);

test('set', t => {
const input = Object.freeze({a: 'b'});
test('set', (t) => {
const input = Object.freeze({ a: 'b' });
const actual = set(input, 'foo', 'bar');
const expected = {
a: 'b',
foo: 'bar'
foo: 'bar',
};

@@ -28,4 +38,4 @@ t.deepEqual(actual, expected);

test('set with unchanged data', t => {
const input = Object.freeze({foo: 'bar'});
test('set with unchanged data', (t) => {
const input = Object.freeze({ foo: 'bar' });
const actual = set(input, 'foo', 'bar');

@@ -36,3 +46,3 @@ const expected = input;

test('set with array', t => {
test('set with array', (t) => {
const input = Object.freeze([0, 1]);

@@ -46,3 +56,3 @@ const actual = set(input, 0, -1);

test('setIn', t => {
test('setIn', (t) => {
const input = Object.freeze({});

@@ -53,5 +63,5 @@ const actual = setIn(input, Object.freeze(['a', 'b', 'c']), 'foo');

b: {
c: 'foo'
}
}
c: 'foo',
},
},
};

@@ -61,6 +71,6 @@ t.deepEqual(actual, expected);

test('setIn with unchanged array', t => {
test('setIn with unchanged array', (t) => {
const input = Object.freeze({
a: 'b',
c: [1, 2, 3]
c: [1, 2, 3],
});

@@ -70,3 +80,3 @@ const actual = setIn(input, Object.freeze(['a']), 'yo');

a: 'yo',
c: [1, 2, 3]
c: [1, 2, 3],
};

@@ -77,7 +87,7 @@ t.deepEqual(actual, expected);

test('setIn with unchanged value', t => {
test('setIn with unchanged value', (t) => {
const input = Object.freeze({
a: {
b: 'c'
}
b: 'c',
},
});

@@ -89,7 +99,7 @@ const actual = setIn(input, Object.freeze(['a', 'b']), 'c');

test('setIn with nested changed value', t => {
test('setIn with nested changed value', (t) => {
const input = Object.freeze({
a: {
b: 'c'
}
b: 'c',
},
});

@@ -99,4 +109,4 @@ const actual = setIn(input, Object.freeze(['a', 'b']), 'd');

a: {
b: 'd'
}
b: 'd',
},
};

@@ -106,7 +116,7 @@ t.deepEqual(actual, expected);

test('setIn with null value, unchanged', t => {
test('setIn with null value, unchanged', (t) => {
const input = Object.freeze({
a: {
b: 0
}
b: 0,
},
});

@@ -118,3 +128,3 @@ const actual = setIn(input, Object.freeze(['a', 'b']), 0);

test('assign', t => {
test('assign', (t) => {
const actual = assign(Object.freeze({}));

@@ -126,9 +136,9 @@ const expected = {};

test('assign multiple', t => {
const actual = assign(Object.freeze({a: 'b'}), Object.freeze({c: 'd'}));
const expected = {a: 'b', c: 'd'};
test('assign multiple', (t) => {
const actual = assign(Object.freeze({ a: 'b' }), Object.freeze({ c: 'd' }));
const expected = { a: 'b', c: 'd' };
t.deepEqual(actual, expected);
});
test('assign w array', t => {
test('assign w array', (t) => {
const input = [0];

@@ -141,3 +151,26 @@ const actual = assign(input, [1, 2, 3]);

test('mergeDeep', t => {
test('assign unchanged', (t) => {
const input = { foo: 'bar', hello: 'world' };
const actual = assign(
input,
Object.freeze({ foo: 'bas' }),
Object.freeze({ foo: 'bar' }),
Object.freeze({ hello: 'world' }),
);
const expected = input;
t.is(actual, expected);
});
test('assign is shallow', (t) => {
const input = Object.freeze({ foo: { beep: 'boop' } });
const change = { foo: { hello: 'world' } };
const actual = assign(input, change);
const expected = change;
t.deepEqual(actual, expected);
t.not(actual, expected);
});
test('mergeDeep', (t) => {
const input = Object.freeze({});

@@ -147,6 +180,6 @@ const changes = Object.freeze({

b: {
c: 'foo'
}
c: 'foo',
},
},
d: 'bar'
d: 'bar',
});

@@ -158,12 +191,12 @@ const actual = mergeDeep(input, changes);

test('mergeDeep with unchanged array', t => {
test('mergeDeep with unchanged array', (t) => {
const input = Object.freeze({
a: 'b',
c: [1, 2, 3]
c: [1, 2, 3],
});
const changes = Object.freeze({a: 'yo'});
const changes = Object.freeze({ a: 'yo' });
const actual = mergeDeep(input, changes);
const expected = {
a: 'yo',
c: [1, 2, 3]
c: [1, 2, 3],
};

@@ -174,9 +207,9 @@ t.deepEqual(actual, expected);

test('mergeDeep with new unchanged array', t => {
test('mergeDeep with new unchanged array', (t) => {
const input = Object.freeze({
a: 'b'
a: 'b',
});
const changes = Object.freeze({
a: 'yo',
c: [1, 2, 3]
c: [1, 2, 3],
});

@@ -186,3 +219,3 @@ const actual = mergeDeep(input, changes);

a: 'yo',
c: [1, 2, 3]
c: [1, 2, 3],
};

@@ -193,10 +226,10 @@ t.deepEqual(actual, expected);

test('mergeDeep two arrays, new array should replace the old one', t => {
test('mergeDeep two arrays, new array should replace the old one', (t) => {
const input = Object.freeze({
a: 'b',
c: [1, 2, 3]
c: [1, 2, 3],
});
const changes = Object.freeze({
a: 'yo',
c: [1, 2, 3]
c: [1, 2, 3],
});

@@ -206,3 +239,3 @@ const actual = mergeDeep(input, changes);

a: 'yo',
c: [1, 2, 3]
c: [1, 2, 3],
};

@@ -213,13 +246,13 @@ t.deepEqual(actual, expected);

test('mergeDeep with unchanged value', t => {
test('mergeDeep with unchanged value', (t) => {
const input = Object.freeze({
a: {
b: 'c'
b: 'c',
},
beep: 'boop'
beep: 'boop',
});
const changes = Object.freeze({
a: {
b: 'c'
}
b: 'c',
},
});

@@ -231,15 +264,15 @@ const actual = mergeDeep(input, changes);

test('mergeDeep with unchanged values', t => {
test('mergeDeep with unchanged values', (t) => {
const input = Object.freeze({
a: {
b: 'c'
b: 'c',
},
beep: 'boop',
foo: 'bar'
foo: 'bar',
});
const changes = Object.freeze({
a: {
b: 'c'
b: 'c',
},
beep: 'boop'
beep: 'boop',
});

@@ -251,13 +284,13 @@ const actual = mergeDeep(input, changes);

test('mergeDeep with nested changed value', t => {
test('mergeDeep with nested changed value', (t) => {
const input = Object.freeze({
a: {
b: 'c'
b: 'c',
},
foo: 'bar'
foo: 'bar',
});
const changes = Object.freeze({
a: {
b: 'd'
}
b: 'd',
},
});

@@ -267,5 +300,5 @@ const actual = mergeDeep(input, changes);

a: {
b: 'd'
b: 'd',
},
foo: 'bar'
foo: 'bar',
};

@@ -275,13 +308,13 @@ t.deepEqual(actual, expected);

test('mergeDeep with null value, unchanged', t => {
test('mergeDeep with null value, unchanged', (t) => {
const input = Object.freeze({
a: {
b: 0
b: 0,
},
c: false
c: false,
});
const changes = Object.freeze({
a: {
b: 0
}
b: 0,
},
});

@@ -293,3 +326,22 @@ const actual = mergeDeep(input, changes);

test('getIn() with none object', t => {
test('mergeDeep with multiple values changed', (t) => {
const input = Object.freeze({
beep: 'boop',
});
const changes = Object.freeze({
foo: 'bar',
hello: 'world',
});
const actual = mergeDeep(input, changes);
const expected = {
beep: 'boop',
foo: 'bar',
hello: 'world',
};
t.deepEqual(actual, expected);
});
test('getIn() with none object', (t) => {
const input = null;

@@ -300,5 +352,5 @@ const actual = getIn(input, ['a']);

test('getIn() with simple object & exists', t => {
test('getIn() with simple object & exists', (t) => {
const input = {
a: {b: 'c'}
a: { b: 'c' },
};

@@ -310,5 +362,5 @@ const actual = getIn(input, ['a', 'b']);

test('getIn() with simple object & does not exists', t => {
test('getIn() with simple object & does not exists', (t) => {
const input = {
a: {b: 'c'}
a: { b: 'c' },
};

@@ -319,10 +371,10 @@ const actual = getIn(input, ['foo', 'bar']);

test('without()', t => {
test('without()', (t) => {
const input = Object.freeze({
a: 'b',
c: 'd'
c: 'd',
});
const actual = without(input, 'c');
const expected = {
a: 'b'
a: 'b',
};

@@ -332,6 +384,6 @@ t.deepEqual(actual, expected);

test('without() that does not change data', t => {
test('without() that does not change data', (t) => {
const input = Object.freeze({
a: 'b',
c: 'd'
c: 'd',
});

@@ -343,5 +395,5 @@ const actual = without(input, 'not exists');

test('without() with falsy value', t => {
test('without() with falsy value', (t) => {
const input = Object.freeze({
foo: null
foo: null,
});

@@ -353,12 +405,27 @@ const actual = without(input, 'foo');

test('map', t => {
const input = {a: 1, b: 2, c: 3, d: 4};
const actual = map(input, num => num % 2);
const expected = {a: 1, b: 0, c: 1, d: 0};
test('without() with undefined value', (t) => {
const input = Object.freeze({ foo: undefined });
const actual = without(input, 'foo');
const expected = {};
t.deepEqual(actual, expected);
});
test('map not changed values', t => {
const input = {a: 1, b: 2, c: 3};
const actual = map(input, num => num);
test('without() on array', (t) => {
const input = Object.freeze([1, 2, 3]);
const actual = without(input, 1);
const expected = [1, , 3];
t.deepEqual(actual, expected);
});
test('map', (t) => {
const input = { a: 1, b: 2, c: 3, d: 4 };
const actual = map(input, (num) => num % 2);
const expected = { a: 1, b: 0, c: 1, d: 0 };
t.deepEqual(actual, expected);
});
test('map not changed values', (t) => {
const input = Object.freeze({ a: 1, b: 2, c: 3 });
const actual = map(input, (num) => num);
const expected = input;

@@ -368,15 +435,15 @@ t.is(actual, expected);

test('map w key', t => {
const input = {a: '', b: ''};
const actual = map(input, (val, key) => key);
const expected = {a: 'a', b: 'b'};
test('map w key', (t) => {
const input = Object.freeze({ a: '', b: '' });
const actual = map(input, (_val, key) => key);
const expected = { a: 'a', b: 'b' };
t.deepEqual(actual, expected);
});
test('chained set()', t => {
const input = Object.freeze({a: 'b'});
test('chained set()', (t) => {
const input = Object.freeze({ a: 'b' });
const actual = chain(input).set('foo', 'bar').value;
const expected = {
a: 'b',
foo: 'bar'
foo: 'bar',
};

@@ -386,6 +453,5 @@ t.deepEqual(actual, expected);

test('chained setIn()', t => {
test('chained setIn()', (t) => {
const input = Object.freeze({});
const actual = chain(input)
.setIn(Object.freeze(['a', 'b', 'c']), 'foo')
const actual = chain(input).setIn(Object.freeze(['a', 'b', 'c']), 'foo')
.value;

@@ -395,5 +461,5 @@ const expected = {

b: {
c: 'foo'
}
}
c: 'foo',
},
},
};

@@ -403,11 +469,11 @@ t.deepEqual(actual, expected);

test('chained assign()', t => {
const actual = chain(Object.freeze({a: 'b'}))
.assign(Object.freeze({c: 'd'}))
.value;
const expected = {a: 'b', c: 'd'};
test('chained assign()', (t) => {
const actual = chain(Object.freeze({ a: 'b' })).assign(
Object.freeze({ c: 'd' }),
).value;
const expected = { a: 'b', c: 'd' };
t.deepEqual(actual, expected);
});
test('chained mergeDeep()', t => {
test('chained mergeDeep()', (t) => {
const input = Object.freeze({});

@@ -417,6 +483,6 @@ const changes = Object.freeze({

b: {
c: 'foo'
}
c: 'foo',
},
},
d: 'bar'
d: 'bar',
});

@@ -428,5 +494,5 @@ const actual = chain(input).mergeDeep(changes).value;

test('chained getIn()', t => {
test('chained getIn()', (t) => {
const input = {
a: {b: 'c'}
a: { b: 'c' },
};

@@ -438,10 +504,12 @@ const actual = chain(input).getIn(['a', 'b']).value;

test('chained getIn() + set()', t => {
test('chained getIn() + set()', (t) => {
const input = {
a: {b: 'c'}
a: { b: 'c' },
};
const actual = chain(input).getIn(['a']).set('c', 'd').value;
const actual = chain(input)
.getIn(['a'])
.set('c', 'd').value;
const expected = {
b: 'c',
c: 'd'
c: 'd',
};

@@ -451,10 +519,10 @@ t.deepEqual(actual, expected);

test('chained without()', t => {
test('chained without()', (t) => {
const input = Object.freeze({
a: 'b',
c: 'd'
c: 'd',
});
const actual = chain(input).without('c').value;
const expected = {
a: 'b'
a: 'b',
};

@@ -464,7 +532,7 @@ t.deepEqual(actual, expected);

test('chained map()', t => {
const input = {a: 1, b: 2, c: 3, d: 4};
const actual = chain(input).map(num => num % 2).value;
const expected = {a: 1, b: 0, c: 1, d: 0};
test('chained map()', (t) => {
const input = { a: 1, b: 2, c: 3, d: 4 };
const actual = chain(input).map((num) => num % 2).value;
const expected = { a: 1, b: 0, c: 1, d: 0 };
t.deepEqual(actual, expected);
});
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