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

immutable-assign

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immutable-assign - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

.prettierignore

124

deploy/iassign.js
"use strict";
(function (root, factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
if (typeof module === "object" && typeof module.exports === "object") {
try {

@@ -10,20 +10,14 @@ var deepFreeze = require("deep-freeze-strict");

}
try {
var proxyPolyfill = require('proxy-polyfill');
}
catch (ex) {
console.warn("Cannot load proxy-polyfill module. iassign() will not work in IE 11 or other old browsers.");
}
var v = factory(deepFreeze, proxyPolyfill, exports);
var v = factory(deepFreeze, exports);
if (v !== undefined)
module.exports = v;
}
else if (typeof define === 'function' && define.amd) {
define(["deep-freeze-strict", 'proxy-polyfill', "exports"], factory);
else if (typeof define === "function" && define.amd) {
define(["deep-freeze-strict", "exports"], factory);
}
else {
// Browser globals (root is window)
root.iassign = factory(root.deepFreeze, undefined, {});
root.iassign = factory(root.deepFreeze, {});
}
})(this, function (deepFreeze, proxyPolyfill, exports) {
})(this, function (deepFreeze, exports) {
var autoCurry = (function () {

@@ -43,5 +37,5 @@ var toArray = function toArray(arr, from) {

if (arguments.length < numArgs) {
return numArgs - arguments.length > 0 ?
autoCurry(curry.apply(this, [fn].concat(toArray(arguments))), numArgs - arguments.length) :
curry.apply(this, [fn].concat(toArray(arguments)));
return numArgs - arguments.length > 0
? autoCurry(curry.apply(this, [fn].concat(toArray(arguments))), numArgs - arguments.length)
: curry.apply(this, [fn].concat(toArray(arguments)));
}

@@ -53,3 +47,3 @@ else {

};
}());
})();
var iassign = _iassign;

@@ -101,7 +95,15 @@ iassign.fp = autoCurry(_iassignFp);

}
var propPath = getPropPath(getProp, obj, context, option);
if (!propPath) {
throw new Error('getProp() function does not return a part of obj');
var funcText = getProp.toString();
var arrowIndex = funcText.indexOf("=>");
if (arrowIndex <= -1) {
var returnIndex = funcText.indexOf("return ");
if (returnIndex <= -1) {
throw new Error("getProp() function does not return a part of obj");
}
}
obj = updateProperty(obj, setProp, newValue, context, propPath, option);
var propPaths = getPropPath(getProp, obj, context, option);
if (!propPaths) {
throw new Error("getProp() function does not return a part of obj");
}
obj = updateProperty(obj, setProp, newValue, context, propPaths, option);
}

@@ -117,42 +119,34 @@ if (deepFreeze && (option.freeze || option.freezeOutput)) {

function getPropPath(getProp, obj, context, option) {
// will be a double map, both original values and proxied objects will have the path indexed
var pathMap = new Map();
var handlers = {
get: function (target, prop) {
switch (prop) {
// Allows this object be used as a primitive for self-referential access (e.g. obj.a[obj.b])
// See http://www.adequatelygood.com/Object-to-Primitive-Conversions-in-JavaScript.html
case 'valueOf':
return function () { return target.valueOf(); };
case 'toString':
return function () { return target.toString(); };
}
var nextValue = target[prop];
if (nextValue === undefined || nextValue === null) {
return nextValue;
}
var nextObj;
if (typeof nextValue !== 'object') {
nextObj = {
valueOf: function () { return nextValue; },
toString: function () { return nextValue.toString(); },
};
}
else {
nextObj = quickCopy(nextValue, prop, option.useConstructor, option.copyFunc);
}
var prevPath = pathMap.get(target) || [];
var nextPath = prevPath.concat(prop);
var proxied = new Proxy(nextObj, handlers);
pathMap.set(nextObj, nextPath);
pathMap.set(proxied, nextPath);
return proxied;
},
};
var coreObj = quickCopy(obj, undefined, option.useConstructor, option.copyFunc);
coreObj = new Proxy(coreObj, handlers);
pathMap.set(coreObj, []);
pathMap.set(obj, []);
return pathMap.get(getProp(coreObj, context));
var objCopy = quickCopy(obj, undefined, option.useConstructor, option.copyFunc);
var paths = [];
_getPropPath(obj, objCopy, paths);
getProp(objCopy, context);
return paths;
}
function _getPropPath(obj, objCopy, paths, level) {
if (level === void 0) { level = 0; }
var propertyNames = Object.getOwnPropertyNames(obj);
propertyNames.forEach(function (propKey) {
var descriptor = Object.getOwnPropertyDescriptor(obj, propKey);
if (descriptor && (!(obj instanceof Array) || propKey != "length")) {
var copyDescriptor = {
enumerable: descriptor.enumerable,
configurable: false,
get: function () {
if (level == paths.length) {
paths.push(propKey);
var propValue = obj[propKey];
var propValueCopy = quickCopy(propValue);
if (propValue != undefined) {
_getPropPath(propValue, propValueCopy, paths, level + 1);
}
return propValueCopy;
}
return obj[propKey];
},
};
Object.defineProperty(objCopy, propKey, copyDescriptor);
}
});
}
// For performance

@@ -191,11 +185,11 @@ function copyOption(target, option, defaultOption) {

}
function updateProperty(obj, setProp, newValue, context, propPath, option) {
function updateProperty(obj, setProp, newValue, context, propPaths, option) {
var propValue = quickCopy(obj, undefined, option.useConstructor, option.copyFunc);
obj = propValue;
if (!propPath.length) {
if (!propPaths.length) {
return option.ignoreIfNoChange ? newValue : setProp(propValue);
}
for (var propIndex = 0; propIndex < propPath.length; ++propIndex) {
var propName = propPath[propIndex];
var isLast = propIndex + 1 === propPath.length;
for (var propIndex = 0; propIndex < propPaths.length; ++propIndex) {
var propName = propPaths[propIndex];
var isLast = propIndex + 1 === propPaths.length;
var prevPropValue = propValue;

@@ -216,3 +210,3 @@ propValue = propValue[propName];

}
else if (typeof (value) === "object") {
else if (typeof value === "object") {
if (useConstructor) {

@@ -219,0 +213,0 @@ var target = new value.constructor();

{
"name": "immutable-assign",
"version": "2.0.1",
"description": "Lightweight immutable helper that allows you to continue working with Plain JavaScript Objects",
"main": "deploy/iassign.js",
"types": "deploy/iassign.d.ts",
"scripts": {
"test": "node node_modules/istanbul/lib/cli.js cover node_modules/jasmine/bin/jasmine.js",
"test-backup": "node node_modules/jasmine/bin/jasmine.js",
"test-karma": "node_modules/.bin/karma start",
"test-karma-win": "node_modules/.bin/karma start --browsers Chrome,Edge,IE",
"test-karma-chrome": "node_modules/.bin/karma start --browsers Chrome --reporters dots",
"test-karma-mac": "node_modules/.bin/karma start --browsers Safari,Chrome",
"cover": "node node_modules/istanbul/lib/cli.js cover node_modules/jasmine/bin/jasmine.js",
"build": "gulp",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
"benchmarks": "node debug/benchmarks"
},
"author": {
"name": "engineforce",
"url": "https://github.com/engineforce"
},
"repository": {
"type": "git",
"url": "https://github.com/engineforce/ImmutableAssign.git"
},
"homepage": "https://github.com/engineforce/ImmutableAssign",
"license": "MIT",
"keywords": [
"immutable",
"typescript",
"javascript",
"data",
"stateless"
],
"dependencies": {},
"optionalDependencies": {
"deep-freeze-strict": "^1.1.1",
"proxy-polyfill": "^0.1.7"
},
"devDependencies": {
"@types/lodash": "^4.14.74",
"chalk": "^1.1.3",
"core-js": "^2.4.1",
"coveralls": "^2.11.15",
"deep-freeze": "0.0.1",
"edge-launcher": "*",
"gulp": "^3.9.1",
"gulp-less": "^3.1.0",
"gulp-typescript": "^3.1.6",
"immutable": "^3.8.1",
"istanbul": "^0.4.3",
"jasmine": "^2.4.1",
"karma": "^1.1.2",
"karma-chrome-launcher": "^1.0.1",
"karma-edge-launcher": "^0.4.2",
"karma-firefox-launcher": "^1.0.0",
"karma-ie-launcher": "^1.0.0",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.1",
"karma-safari-launcher": "^1.0.0",
"karma-sauce-launcher": "^1.1.0",
"lodash": "^4.13.1",
"merge2": "^1.0.2",
"seamless-immutable": "^7.0.1",
"timm": "^1.2.3",
"typescript": "^2.3.2",
"vinyl-source-stream": "^1.1.0"
}
"name": "immutable-assign",
"version": "2.0.2",
"description":
"Lightweight immutable helper that allows you to continue working with Plain JavaScript Objects",
"main": "deploy/iassign.js",
"types": "deploy/iassign.d.ts",
"scripts": {
"test": "node node_modules/istanbul/lib/cli.js cover node_modules/jasmine/bin/jasmine.js",
"test-backup": "node node_modules/jasmine/bin/jasmine.js",
"test-karma": "node_modules/.bin/karma start",
"test-karma-win": "node_modules/.bin/karma start --browsers Chrome,Edge,IE",
"test-karma-mac": "node_modules/.bin/karma start --browsers Safari,Chrome",
"cover": "node node_modules/istanbul/lib/cli.js cover node_modules/jasmine/bin/jasmine.js",
"debug": "node --inspect --inspect-brk node_modules/jasmine/bin/jasmine.js",
"build": "gulp",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
"benchmarks": "node debug/benchmarks"
},
"author": {
"name": "engineforce",
"url": "https://github.com/engineforce"
},
"repository": {
"type": "git",
"url": "https://github.com/engineforce/ImmutableAssign.git"
},
"homepage": "https://github.com/engineforce/ImmutableAssign",
"license": "MIT",
"keywords": ["immutable", "typescript", "javascript", "data", "stateless"],
"dependencies": {},
"optionalDependencies": {
"deep-freeze-strict": "^1.1.1"
},
"devDependencies": {
"@types/lodash": "^4.14.74",
"chalk": "^1.1.3",
"core-js": "^2.4.1",
"coveralls": "^2.11.15",
"deep-freeze": "0.0.1",
"edge-launcher": "*",
"gulp": "^3.9.1",
"gulp-less": "^3.1.0",
"gulp-typescript": "^3.1.6",
"immutable": "^3.8.1",
"istanbul": "^0.4.3",
"jasmine": "^2.4.1",
"karma": "^1.1.2",
"karma-chrome-launcher": "^1.0.1",
"karma-edge-launcher": "^0.4.2",
"karma-firefox-launcher": "^1.0.0",
"karma-ie-launcher": "^1.0.0",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.1",
"karma-safari-launcher": "^1.0.0",
"karma-sauce-launcher": "^1.1.0",
"lodash": "^4.13.1",
"merge2": "^1.0.2",
"seamless-immutable": "^7.0.1",
"timm": "^1.2.3",
"typescript": "^2.3.2",
"vinyl-source-stream": "^1.1.0"
}
}

@@ -482,2 +482,3 @@ # immutable-assign (iassign.js)

* 2.0.2 - Removed dependency on ES6 Proxy (including the proxy-polyfill), uses Object.defineProperty() instead which has much better browser support.
* 2.0.1 - Minor bug fixes.

@@ -484,0 +485,0 @@ * 2.0.0 -

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