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.4 to 2.0.5

bitbucket-pipelines.yml

113

deploy/iassign.d.ts

@@ -1,66 +0,71 @@

declare namespace ImmutableAssign {
interface ICopyFunc {
<T>(value: T, propName: string): T;
}
interface ICopyFunc {
<T>(value: T, propName: string): T;
}
interface IIassignOption {
freeze?: boolean; // Deep freeze both input and output
freezeInput?: boolean; // Deep freeze input
freezeOutput?: boolean; // Deep freeze output
useConstructor?: boolean; // Uses the constructor to create new instances
copyFunc?: ICopyFunc; // Custom copy function, can be used to handle special types, e.g., Map, Set
disableAllCheck?: boolean;
disableHasReturnCheck?: boolean;
// Disable validation for extra statements in the getProp() function,
// which is needed when running the coverage, e.g., istanbul.js does add
// instrument statements in our getProp() function, which can be safely ignored.
disableExtraStatementCheck?: boolean;
interface IIassignOption {
freeze?: boolean; // Deep freeze both input and output
freezeInput?: boolean; // Deep freeze input
freezeOutput?: boolean; // Deep freeze output
useConstructor?: boolean; // Uses the constructor to create new instances
copyFunc?: ICopyFunc; // Custom copy function, can be used to handle special types, e.g., Map, Set
disableAllCheck?: boolean;
disableHasReturnCheck?: boolean;
// Disable validation for extra statements in the getProp() function,
// which is needed when running the coverage, e.g., istanbul.js does add
// instrument statements in our getProp() function, which can be safely ignored.
disableExtraStatementCheck?: boolean;
// Return the same object if setProp() returns its parameter (i.e., reference pointer not changed).
ignoreIfNoChange?: boolean;
}
// Return the same object if setProp() returns its parameter (i.e., reference pointer not changed).
ignoreIfNoChange?: boolean;
}
type getPropFunc<TObj, TProp, TContext> = (
obj: TObj,
context: TContext
) => TProp;
type setPropFunc<TProp> = (prop: TProp) => TProp;
type getPropFunc<TObj, TProp, TContext> = (obj: TObj, context: TContext) => TProp;
type setPropFunc<TProp> = (prop: TProp) => TProp;
interface IIassign extends IIassignOption {
// Intellisense for the TObj parameter in getProp will only work if we remove the auto added closing bracket of iassign,
// and manually add the closing bracket at last. i.e.,
//
// 1. Type iassign( in the editor
// 2. Most editor will auto complete with closing bracket, e.g., iassign()
// 3. If we continue to type without removing the closing bracket, e.g., iassign(nested, (n) => n.),
// editor such as VS Code will not show any intellisense for "n"
// 4. We must remove the closing bracket of iassign(), and intellisense will be shown for "n"
interface IIassign extends IIassignOption {
<TObj, TProp, TContext>(
obj: TObj,
getProp: getPropFunc<TObj, TProp, TContext>,
setProp: setPropFunc<TProp>,
context?: TContext,
option?: IIassignOption
): TObj;
// Intellisense for the TObj parameter in getProp will only work if we remove the auto added closing bracket of iassign,
// and manually add the closing bracket at last. i.e.,
//
// 1. Type iassign( in the editor
// 2. Most editor will auto complete with closing bracket, e.g., iassign()
// 3. If we continue to type without removing the closing bracket, e.g., iassign(nested, (n) => n.),
// editor such as VS Code will not show any intellisense for "n"
// 4. We must remove the closing bracket of iassign(), and intellisense will be shown for "n"
<TObj>(
obj: TObj,
setProp: setPropFunc<TObj>,
option?: IIassignOption
): TObj;
<TObj, TProp, TContext>(
obj: TObj,
getProp: getPropFunc<TObj, TProp, TContext>,
setProp: setPropFunc<TProp>,
context?: TContext,
option?: IIassignOption): TObj;
// functional programming friendly style, moved obj to the last parameter and supports currying
fp<TObj, TProp, TContext>(
option: IIassignOption,
getProp: getPropFunc<TObj, TProp, TContext>,
setProp: setPropFunc<TProp>,
context?: TContext,
obj?: TObj
): TObj;
<TObj>(
obj: TObj,
setProp: setPropFunc<TObj>,
option?: IIassignOption): TObj;
// In ES6, you cannot set property on imported module directly, because they are default
// to readonly, in this case you need to use this method.
setOption(option: IIassignOption): void;
// functional programming friendly style, moved obj to the last parameter and supports currying
fp<TObj, TProp, TContext>(
option: IIassignOption,
getProp: getPropFunc<TObj, TProp, TContext>,
setProp: setPropFunc<TProp>,
context?: TContext,
obj?: TObj): TObj;
deepFreeze: DeepFreeze.DeepFreezeInterface;
// In ES6, you cannot set property on imported module directly, because they are default
// to readonly, in this case you need to use this method.
setOption(option: IIassignOption): void;
// ES6 default export
default: ImmutableAssign.IIassign;
}
// ES6 default export
default: ImmutableAssign.IIassign;
}
}

@@ -67,0 +72,0 @@

@@ -29,3 +29,3 @@ "use strict";

return function curried() {
return fn.apply(this, args.concat(toArray(arguments)));
return fn.apply(undefined, args.concat(toArray(arguments)));
};

@@ -38,7 +38,7 @@ };

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

@@ -50,2 +50,3 @@ };

iassign.fp = autoCurry(_iassignFp);
iassign.freeze = process.env.NODE_ENV !== "production";
iassign.setOption = function (option) {

@@ -148,3 +149,3 @@ copyOption(iassign, option);

return obj[propKey];
},
}
};

@@ -168,3 +169,3 @@ Object.defineProperty(objCopy, propKey, copyDescriptor);

return propValue;
},
}
};

@@ -265,3 +266,4 @@ return new Proxy(quickCopy(obj, paths[level - 1]), handlers);

iassign.default = iassign;
iassign.deepFreeze = function (obj) { return (iassign.freeze ? deepFreeze(obj) : obj); };
return iassign;
});
{
"name": "immutable-assign",
"version": "2.0.4",
"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",
"test-karma-mac-no-proxy": "NO_PROXY='true' yarn run test-karma-mac",
"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"
}
"name": "immutable-assign",
"version": "2.0.5",
"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",
"test-karma-mac-no-proxy": "NO_PROXY='true' yarn run test-karma-mac",
"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"
}
}

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

### Example 1: Update object
### Example 1: Update root object

@@ -77,3 +77,3 @@ ```javascript

### Example 2: Update list/array
### Example 2: Update root list/array

@@ -129,3 +129,3 @@ ```javascript

### Example 3: Update nested structures
### Example 3: Update nested object

@@ -212,3 +212,3 @@ ```javascript

### Advanced example 5: Update nested property
### Example 5: Update nested object

@@ -227,33 +227,6 @@ ```javascript

```
```javascript
//
// Jasmine Tests
//
// expect o1 has not been changed
expect(o1).toEqual({ a: { b: { c: [[{ d: 11, e: 12 }], [{ d: 21, e: 22 }]], c2: {} }, b2: {} }, a2: {} });
// expect o2 inner property has been updated.
expect(o2.a.b.c[0][0].d).toBe(12);
// expect object graph for changed property in o2 is now different from (!==) o1.
expect(o2).not.toBe(o1);
expect(o2.a).not.toBe(o1.a);
expect(o2.a.b).not.toBe(o1.a.b);
expect(o2.a.b.c).not.toBe(o1.a.b.c);
expect(o2.a.b.c[0]).not.toBe(o1.a.b.c[0]);
expect(o2.a.b.c[0][0]).not.toBe(o1.a.b.c[0][0]);
expect(o2.a.b.c[0][0].d).not.toBe(o1.a.b.c[0][0].d);
// expect object graph for unchanged property in o2 is still equal to (===) o1.
expect(o2.a2).toBe(o1.a2);
expect(o2.a.b2).toBe(o1.a.b2);
expect(o2.a.b.c2).toBe(o1.a.b.c2);
expect(o2.a.b.c[0][0].e).toBe(o1.a.b.c[0][0].e);
expect(o2.a.b.c[1][0]).toBe(o1.a.b.c[1][0]);
```
<br />
### Advanced example 6: Update array
### Example 6: Update nested array

@@ -272,32 +245,6 @@ ```javascript

```
```javascript
//
// Jasmine Tests
//
// expect o1 has not been changed
expect(o1).toEqual({ a: { b: { c: [[{ d: 11, e: 12 }], [{ d: 21, e: 22 }]], c2: {} }, b2: {} }, a2: {} });
// expect o2 inner property has been updated.
expect(o2.a.b.c[1][1]).toBe(101);
// expect object graph for changed property in o2 is now different from (!==) o1.
expect(o2).not.toBe(o1);
expect(o2.a).not.toBe(o1.a);
expect(o2.a.b).not.toBe(o1.a.b);
expect(o2.a.b.c).not.toBe(o1.a.b.c);
expect(o2.a.b.c[1]).not.toBe(o1.a.b.c[1]);
// expect object graph for unchanged property in o2 is still equal to (===) o1.
expect(o2.a2).toBe(o1.a2);
expect(o2.a.b2).toBe(o1.a.b2);
expect(o2.a.b.c2).toBe(o1.a.b.c2);
expect(o2.a.b.c[0]).toBe(o1.a.b.c[0]);
expect(o2.a.b.c[0][0]).toBe(o1.a.b.c[0][0]);
expect(o2.a.b.c[1][0]).toBe(o1.a.b.c[1][0]);
```
<br />
### Advanced example 7: Update nested property, referring to external context.
### Example 7: Update nested object, referring to external context.

@@ -319,32 +266,6 @@ ```javascript

```
```javascript
//
// Jasmine Tests
//
// expect o1 has not been changed
expect(o1).toEqual({ a: { b: { c: [{ d: 11, e: 12 }, { d: 21, e: 22 }] });
// expect o2 inner property has been updated.
expect(o2.a.b.c[external.a].d).toBe(12);
// expect object graph for changed property in o2 is now different from (!==) o1.
expect(o2).not.toBe(o1);
expect(o2.a).not.toBe(o1.a);
expect(o2.a.b).not.toBe(o1.a.b);
expect(o2.a.b.c).not.toBe(o1.a.b.c);
expect(o2.a.b.c[0]).not.toBe(o1.a.b.c[0]);
expect(o2.a.b.c[0].d).not.toBe(o1.a.b.c[0].d);
// expect object graph for unchanged property in o2 is still equal to (===) o1.
expect(o2.a.b.c[0].e).toBe(o1.a.b.c[0].e);
expect(o2.a.b.c[1]).toBe(o1.a.b.c[1]);
expect(o2.a.b.c[1].d).toBe(o1.a.b.c[1].d);
expect(o2.a.b.c[1].e).toBe(o1.a.b.c[1].e);
```
<br />
### Example 8: Update nested structures using iassign.fp() and currying
### Example 8: Update nested object using iassign.fp() and currying

@@ -351,0 +272,0 @@ ```javascript

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