Socket
Socket
Sign inDemoInstall

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.1 to 1.0.2

17

dist/index.js

@@ -16,2 +16,4 @@ 'use strict';

function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
var changesInput = function changesInput(input, keys, value) {

@@ -31,11 +33,12 @@ for (var i = 0; i < keys.length; ++i) {

var input = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var keys = arguments[1];
var value = arguments[2];
var _ref = arguments[1];
var key = keys[0];
if (keys.length === 1) {
return (0, _objectAssign2.default)({}, input, _defineProperty({}, key, value));
}
var _ref2 = _toArray(_ref);
return (0, _objectAssign2.default)({}, input, _defineProperty({}, key, _setIn(input[key], keys.slice(1), value)));
var key = _ref2[0];
var rest = _ref2.slice(1);
var value = arguments[2];
return (0, _objectAssign2.default)({}, input, _defineProperty({}, key, rest.length ? _setIn(input[key], rest, value) : value));
};

@@ -42,0 +45,0 @@

import {setIn} from 'immutable-object-methods';
const input = {a: {b: 'c'}};
const updated = setIn(input, ['a', 'd'], e);
const updated = setIn(input, ['a', 'd'], 'e');
console.log(input);
console.log(updated);

@@ -15,13 +15,9 @@ import assign from 'object-assign';

const _setIn = (input = {}, keys, value) => {
const key = keys[0];
if (keys.length === 1) {
return assign({}, input, {[key]: value});
const _setIn = (input = {}, [key, ...rest], value) => assign(
{}, input, {
[key]: rest.length ? _setIn(input[key], rest, value) : value
}
);
return assign({}, input, {[key]: _setIn(input[key], keys.slice(1), value)});
};
export const setIn = (input, keys, value) => {
return changesInput(input, keys, value) ? _setIn(input, keys, value) : input;
};
export const setIn = (input, keys, value) =>
changesInput(input, keys, value) ? _setIn(input, keys, value) : input;
{
"name": "immutable-object-methods",
"version": "1.0.1",
"version": "1.0.2",
"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",
"scripts": {
"test": "ava",
"test": "ava && semistandard | snazzy",
"build": "rm -rf dist && mkdir -p dist && babel lib --out-dir dist",

@@ -9,0 +9,0 @@ "watch": "rm -rf dist && mkdir -p dist && babel -w lib --out-dir dist",

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