Socket
Socket
Sign inDemoInstall

immutability-helper

Package Overview
Dependencies
0
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.2 to 3.1.1

12

index.d.ts

@@ -0,5 +1,7 @@

export declare function invariant(condition: boolean, message: () => string): void;
export declare class Context {
private commands;
constructor();
isEquals: (x: any, y: any) => boolean;
get isEquals(): (x: any, y: any) => boolean;
set isEquals(value: (x: any, y: any) => boolean);
extend<T>(directive: string, fn: (param: any, old: T) => T): void;

@@ -15,3 +17,3 @@ update<T, C extends CustomCommands<object> = never>(object: T, $spec: Spec<T, C>): T;

};
export declare type Spec<T, C extends CustomCommands<object> = never> = (T extends (Array<infer U> | ReadonlyArray<infer U>) ? ArraySpec<U, C> : T extends (Map<infer K, infer V> | ReadonlyMap<infer K, infer V>) ? MapSpec<K, V> : T extends (Set<infer X> | ReadonlySet<infer X>) ? SetSpec<X> : T extends object ? ObjectSpec<T, C> : never) | {
export declare type Spec<T, C extends CustomCommands<object> = never> = (T extends (Array<infer U> | ReadonlyArray<infer U>) ? ArraySpec<U, C> : T extends (Map<infer K, infer V> | ReadonlyMap<infer K, infer V>) ? MapSpec<K, V, C> : T extends (Set<infer X> | ReadonlySet<infer X>) ? SetSpec<X> : T extends object ? ObjectSpec<T, C> : never) | {
$set: T;

@@ -30,3 +32,3 @@ } | {

};
declare type MapSpec<K, V> = {
declare type MapSpec<K, V, C extends CustomCommands<object>> = {
$add: ReadonlyArray<[K, V]>;

@@ -36,5 +38,3 @@ } | {

} | {
[key: string]: {
$set: V;
};
[key: string]: Spec<V, C>;
};

@@ -41,0 +41,0 @@ declare type SetSpec<T> = {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var invariant = require("invariant");
function stringifiable(obj) {
// Safely stringify Object.create(null)
/* istanbul ignore next */
return typeof obj === 'object' && !('toString' in obj) ?
Object.prototype.toString.call(obj).slice(8, -1) :
obj;
}
var isProduction = typeof process === 'object' && process.env.NODE_ENV === 'production';
function invariant(condition, message) {
if (!condition) {
/* istanbul ignore next */
if (isProduction) {
throw new Error('Invariant failed');
}
throw new Error(message());
}
}
exports.invariant = invariant;
var hasOwnProperty = Object.prototype.hasOwnProperty;

@@ -60,9 +77,9 @@ var splice = Array.prototype.splice;

if (!(Array.isArray(object) && Array.isArray(spec))) {
invariant(!Array.isArray(spec), 'update(): You provided an invalid spec to update(). The spec may ' +
'not contain an array except as the value of $set, $push, $unshift, ' +
'$splice or any custom command allowing an array value.');
invariant(!Array.isArray(spec), function () { return "update(): You provided an invalid spec to update(). The spec may " +
"not contain an array except as the value of $set, $push, $unshift, " +
"$splice or any custom command allowing an array value."; });
}
invariant(typeof spec === 'object' && spec !== null, 'update(): You provided an invalid spec to update(). The spec and ' +
'every included key path must be plain objects containing one of the ' +
'following commands: %s.', Object.keys(this.commands).join(', '));
invariant(typeof spec === 'object' && spec !== null, function () { return "update(): You provided an invalid spec to update(). The spec and " +
"every included key path must be plain objects containing one of the " +
("following commands: " + Object.keys(_this.commands).join(', ') + "."); });
var nextObject = object;

@@ -206,30 +223,30 @@ getAllKeys(spec).forEach(function (key) {

function invariantPushAndUnshift(value, spec, command) {
invariant(Array.isArray(value), 'update(): expected target of %s to be an array; got %s.', command, value);
invariant(Array.isArray(value), function () { return "update(): expected target of " + stringifiable(command) + " to be an array; got " + stringifiable(value) + "."; });
invariantSpecArray(spec[command], command);
}
function invariantSpecArray(spec, command) {
invariant(Array.isArray(spec), 'update(): expected spec of %s to be an array; got %s. ' +
'Did you forget to wrap your parameter in an array?', command, spec);
invariant(Array.isArray(spec), function () { return "update(): expected spec of " + stringifiable(command) + " to be an array; got " + stringifiable(spec) + ". " +
"Did you forget to wrap your parameter in an array?"; });
}
function invariantSplices(value, spec) {
invariant(Array.isArray(value), 'Expected $splice target to be an array; got %s', value);
invariant(Array.isArray(value), function () { return "Expected $splice target to be an array; got " + stringifiable(value); });
invariantSplice(spec.$splice);
}
function invariantSplice(value) {
invariant(Array.isArray(value), 'update(): expected spec of $splice to be an array of arrays; got %s. ' +
'Did you forget to wrap your parameters in an array?', value);
invariant(Array.isArray(value), function () { return "update(): expected spec of $splice to be an array of arrays; got " + stringifiable(value) + ". " +
"Did you forget to wrap your parameters in an array?"; });
}
function invariantApply(fn) {
invariant(typeof fn === 'function', 'update(): expected spec of $apply to be a function; got %s.', fn);
invariant(typeof fn === 'function', function () { return "update(): expected spec of $apply to be a function; got " + stringifiable(fn) + "."; });
}
function invariantSet(spec) {
invariant(Object.keys(spec).length === 1, 'Cannot have more than one key in an object with $set');
invariant(Object.keys(spec).length === 1, function () { return "Cannot have more than one key in an object with $set"; });
}
function invariantMerge(target, specValue) {
invariant(specValue && typeof specValue === 'object', 'update(): $merge expects a spec of type \'object\'; got %s', specValue);
invariant(target && typeof target === 'object', 'update(): $merge expects a target of type \'object\'; got %s', target);
invariant(specValue && typeof specValue === 'object', function () { return "update(): $merge expects a spec of type 'object'; got " + stringifiable(specValue); });
invariant(target && typeof target === 'object', function () { return "update(): $merge expects a target of type 'object'; got " + stringifiable(target); });
}
function invariantMapOrSet(target, command) {
var typeOfTarget = type(target);
invariant(typeOfTarget === 'Map' || typeOfTarget === 'Set', 'update(): %s expects a target of type Set or Map; got %s', command, typeOfTarget);
invariant(typeOfTarget === 'Map' || typeOfTarget === 'Set', function () { return "update(): " + stringifiable(command) + " expects a target of type Set or Map; got " + stringifiable(typeOfTarget); });
}
{
"name": "immutability-helper",
"version": "3.0.2",
"version": "3.1.1",
"description": "mutate a copy of data without changing the original source",

@@ -52,7 +52,4 @@ "main": "index.js",

"tslint": "^5.11.0",
"typescript": "^3.2.2"
"typescript": "^3.8.3"
},
"dependencies": {
"invariant": "^2.2.4"
},
"repository": {

@@ -59,0 +56,0 @@ "type": "git",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc