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

immutable-object-methods

Package Overview
Dependencies
Maintainers
1
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.0.0 to 1.0.1

13

dist/index.js

@@ -17,12 +17,11 @@ 'use strict';

var changesInput = function changesInput(input, keys, value) {
var key = keys[0];
if (keys.length === 1) {
return input[key] !== value;
}
for (var i = 0; i < keys.length; ++i) {
if (!input) {
return true;
}
if (!input[key]) {
return true;
input = input[keys[i]];
}
return changesInput(input[key], keys.slice(1), value);
return input !== value;
};

@@ -29,0 +28,0 @@

import assign from 'object-assign';
const changesInput = (input, keys, value) => {
const key = keys[0];
if (keys.length === 1) {
return input[key] !== value;
}
for (let i = 0; i < keys.length; ++i) {
if (!input) {
return true;
}
if (!input[key]) {
return true;
input = input[keys[i]];
}
return changesInput(input[key], keys.slice(1), value);
return input !== value;
};

@@ -15,0 +14,0 @@

{
"name": "immutable-object-methods",
"version": "1.0.0",
"version": "1.0.1",
"description": "Update normal plain javascript object, immutable style. Simlar to how immutable.js, seamless-immutable etc does it but a lot smaller and simpler.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -23,3 +23,3 @@ import test from 'ava';

});
const actual = setIn(input, ['a'], 'yo');
const actual = setIn(input, Object.freeze(['a']), 'yo');
const expected = {

@@ -39,5 +39,31 @@ a: 'yo',

});
const actual = setIn(input, ['a', 'b'], 'c');
const actual = setIn(input, Object.freeze(['a', 'b']), 'c');
const expected = input;
t.is(actual, expected);
});
test('setIn with nested changed value', t => {
const input = Object.freeze({
a: {
b: 'c'
}
});
const actual = setIn(input, Object.freeze(['a', 'b']), 'd');
const expected = {
a: {
b: 'd'
}
};
t.deepEqual(actual, expected);
});
test('setIn with null value, unchanged', t => {
const input = Object.freeze({
a: {
b: 0
}
});
const actual = setIn(input, Object.freeze(['a', 'b']), 0);
const expected = input;
t.is(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