seamless-immutable
Advanced tools
Comparing version 2.1.0 to 2.2.0
{ | ||
"name": "seamless-immutable", | ||
"main": "seamless-immutable.js", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"homepage": "https://github.com/rtfeldman/seamless-immutable", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "seamless-immutable", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.", | ||
"main": "seamless-immutable.js", | ||
"main": "seamless-immutable.development.js", | ||
"devDependencies": { | ||
"chai": "1.9.2", | ||
"coveralls": "2.11.2", | ||
"envify": "3.4.0", | ||
"grunt": "0.4.5", | ||
"grunt-contrib-uglify": "0.8.1", | ||
"grunt-mocha-test": "0.12.7", | ||
"istanbul": "0.3.2", | ||
@@ -21,3 +25,3 @@ "jscheck": "0.2.0", | ||
"test-watch": "mocha --watch test/*.spec.js", | ||
"jshint": "jshint seamless-immutable.js", | ||
"jshint": "jshint seamless-immutable.development.js", | ||
"coverage": "export ISTANBUL_REPORTERS=text-summary,html,lcov && rm -rf tmp/ && rm -rf html-report/ && istanbul instrument test/ -o tmp/ && mocha --reporter mocha-istanbul tmp/*.spec.js && echo Open html-report/index.html to view results as HTML.", | ||
@@ -24,0 +28,0 @@ "zuul": "zuul -- test/*.spec.js", |
@@ -196,2 +196,6 @@ seamless-immutable | ||
#### 2.2.0 | ||
Adds a minified production build with no freezing or defensive unsupported methods, for a ~2x performance boost. | ||
#### 2.1.0 | ||
@@ -198,0 +202,0 @@ |
@@ -1,3 +0,1 @@ | ||
var Immutable = require("../seamless-immutable.js"); | ||
var TestUtils = require("./TestUtils.js"); | ||
var JSC = require("jscheck"); | ||
@@ -7,22 +5,32 @@ var _ = require("lodash"); | ||
describe("Immutable.isImmutable", function() { | ||
_.each({ | ||
"ImmutableArrays": [true, TestUtils.ImmutableArraySpecifier(JSC)], | ||
"strings": [true, JSC.string()], | ||
"numbers": [true, JSC.number()], | ||
"booleans": [true, JSC.boolean()], | ||
"undefined": [true, JSC.literal(undefined)], | ||
"null": [true, JSC.literal(null)], | ||
"objects": [false, JSC.object()], | ||
"arrays": [false, JSC.array()] | ||
}, function(tuple, type) { | ||
var expectImmutable = tuple[0]; | ||
var specifier = tuple[1]; | ||
[ | ||
{id: "dev", name: "Development build", src: "../seamless-immutable.development.js"}, | ||
{id: "prod", name: "Production build", src: "../seamless-immutable.production.min.js"} | ||
].forEach(function(config) { | ||
var Immutable = require(config.src); | ||
var TestUtils = require("./TestUtils.js")(Immutable); | ||
it("recognizes " + type + (expectImmutable ? " as immutable" : " as MUTABLE"), function() { | ||
TestUtils.check(100, [specifier], function(value) { | ||
assert.strictEqual(expectImmutable, Immutable.isImmutable(value)); | ||
describe(config.name, function () { | ||
describe("Immutable.isImmutable", function () { | ||
_.each({ | ||
"ImmutableArrays": [true, TestUtils.ImmutableArraySpecifier(JSC)], | ||
"strings": [true, JSC.string()], | ||
"numbers": [true, JSC.number()], | ||
"booleans": [true, JSC.boolean()], | ||
"undefined": [true, JSC.literal(undefined)], | ||
"null": [true, JSC.literal(null)], | ||
"objects": [false, JSC.object()], | ||
"arrays": [false, JSC.array()] | ||
}, function (tuple, type) { | ||
var expectImmutable = tuple[0]; | ||
var specifier = tuple[1]; | ||
it("recognizes " + type + (expectImmutable ? " as immutable" : " as MUTABLE"), function () { | ||
TestUtils.check(100, [specifier], function (value) { | ||
assert.strictEqual(expectImmutable, Immutable.isImmutable(value)); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -1,67 +0,75 @@ | ||
var Immutable = require("../seamless-immutable.js"); | ||
var JSC = require("jscheck"); | ||
var TestUtils = require("./TestUtils.js"); | ||
var assert = require("chai").assert; | ||
var _ = require("lodash"); | ||
describe("Immutable", function() { | ||
it("converts multiple arguments into an array, but leaves single arguments alone", function() { | ||
TestUtils.check(100, [JSC.array()], function(args) { | ||
var immutable = Immutable.apply(Immutable, args); | ||
[ | ||
{id: "dev", name: "Development build", src: "../seamless-immutable.development.js"}, | ||
{id: "prod", name: "Production build", src: "../seamless-immutable.production.min.js"} | ||
].forEach(function(config) { | ||
var Immutable = require(config.src); | ||
var TestUtils = require("./TestUtils.js")(Immutable); | ||
if (args.length > 1) { | ||
assert.deepEqual(immutable, Immutable(args)); | ||
} else if (isNaN(immutable) && isNaN(args[0])) { | ||
assert.ok(true); | ||
} else { | ||
assert.strictEqual(immutable, args[0]); | ||
} | ||
}) | ||
}); | ||
describe(config.name, function () { | ||
describe("Immutable", function () { | ||
it("converts multiple arguments into an array, but leaves single arguments alone", function () { | ||
TestUtils.check(100, [JSC.array()], function (args) { | ||
var immutable = Immutable.apply(Immutable, args); | ||
it("makes an Immutable Array when passed a mutable array", function() { | ||
TestUtils.check(100, [JSC.array()], function(mutable) { | ||
var immutable = Immutable(mutable); | ||
if (args.length > 1) { | ||
assert.deepEqual(immutable, Immutable(args)); | ||
} else if (isNaN(immutable) && isNaN(args[0])) { | ||
assert.ok(true); | ||
} else { | ||
assert.strictEqual(immutable, args[0]); | ||
} | ||
}) | ||
}); | ||
assert.deepEqual(immutable, mutable); | ||
assert.isTrue( Immutable.isImmutable(immutable)); | ||
assert.isFalse(Immutable.isImmutable(mutable)); | ||
}); | ||
}); | ||
it("makes an Immutable Array when passed a mutable array", function () { | ||
TestUtils.check(100, [JSC.array()], function (mutable) { | ||
var immutable = Immutable(mutable); | ||
it("makes an Immutable Object when passed a mutable object", function() { | ||
TestUtils.check(100, [JSC.object()], function(mutable) { | ||
var immutable = Immutable(mutable); | ||
assert.deepEqual(immutable, mutable); | ||
assert.isTrue(Immutable.isImmutable(immutable)); | ||
assert.isFalse(Immutable.isImmutable(mutable)); | ||
}); | ||
}); | ||
assert.typeOf(immutable, "object") | ||
assert.isTrue( Immutable.isImmutable(immutable)); | ||
assert.isFalse(Immutable.isImmutable(mutable)); | ||
}); | ||
}); | ||
it("makes an Immutable Object when passed a mutable object", function () { | ||
TestUtils.check(100, [JSC.object()], function (mutable) { | ||
var immutable = Immutable(mutable); | ||
it("makes a deeply Immutable Object when passed a complex mutable object", function() { | ||
var complexObjFactory = JSC.array([ JSC.integer(), JSC.object() ]) | ||
TestUtils.check(100, [complexObjFactory], function(mutable) { | ||
var immutable = Immutable(mutable) | ||
assert.typeOf(immutable, "object"); | ||
assert.isTrue(Immutable.isImmutable(immutable)); | ||
assert.isFalse(Immutable.isImmutable(mutable)); | ||
}); | ||
}); | ||
assert.deepEqual(immutable, mutable) | ||
assert.isTrue( Immutable.isImmutable(immutable) ) | ||
assert.isTrue( Immutable.isImmutable(immutable[1]) ) | ||
}) | ||
}) | ||
it("makes a deeply Immutable Object when passed a complex mutable object", function () { | ||
var complexObjFactory = JSC.array([JSC.integer(), JSC.object()]); | ||
TestUtils.check(100, [complexObjFactory], function (mutable) { | ||
var immutable = Immutable(mutable); | ||
// These are already immutable, and should pass through Immutable() untouched. | ||
_.each({ | ||
"string": JSC.string(), | ||
"number": JSC.number(), | ||
"boolean": JSC.boolean(), | ||
"null": JSC.literal(null), | ||
"undefined": JSC.literal(undefined) | ||
}, function(specifier, type) { | ||
it("simply returns its argument when passed a value of type " + type, function() { | ||
TestUtils.check(100, [specifier], function(value) { | ||
assert.strictEqual(Immutable(value), value); | ||
assert.deepEqual(immutable, mutable); | ||
assert.isTrue(Immutable.isImmutable(immutable)); | ||
assert.isTrue(Immutable.isImmutable(immutable[1])) | ||
}) | ||
}) | ||
// These are already immutable, and should pass through Immutable() untouched. | ||
_.each({ | ||
"string": JSC.string(), | ||
"number": JSC.number(), | ||
"boolean": JSC.boolean(), | ||
"null": JSC.literal(null), | ||
"undefined": JSC.literal(undefined) | ||
}, function (specifier, type) { | ||
it("simply returns its argument when passed a value of type " + type, function () { | ||
TestUtils.check(100, [specifier], function (value) { | ||
assert.strictEqual(Immutable(value), value); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -6,7 +6,14 @@ var testCompat = require("./ImmutableArray/test-compat.js"); | ||
describe("ImmutableArray", function() { | ||
testCompat(); | ||
testFlatMap(); | ||
testAsObject(); | ||
testToMutable(); | ||
[ | ||
{id: "dev", name: "Development build", src: "../../seamless-immutable.development.js"}, | ||
{id: "prod", name: "Production build", src: "../../seamless-immutable.production.min.js"} | ||
].forEach(function(config) { | ||
describe(config.name, function () { | ||
describe("ImmutableArray", function () { | ||
testCompat(config); | ||
testFlatMap(config); | ||
testAsObject(config); | ||
testToMutable(config); | ||
}); | ||
}); | ||
}); |
@@ -1,9 +0,10 @@ | ||
var Immutable = require("../../seamless-immutable.js"); | ||
var JSC = require("jscheck"); | ||
var TestUtils = require("../TestUtils.js"); | ||
var assert = require("chai").assert; | ||
var _ = require("lodash") | ||
var check = TestUtils.check; | ||
var _ = require("lodash"); | ||
module.exports = function() { | ||
module.exports = function(config) { | ||
var Immutable = require(config.src); | ||
var TestUtils = require("../TestUtils.js")(Immutable); | ||
var check = TestUtils.check; | ||
describe("#asMutable", function() { | ||
@@ -33,2 +34,2 @@ it("returns a shallow mutable copy if not provided the deep flag", function() { | ||
}); | ||
}; | ||
}; |
@@ -1,9 +0,10 @@ | ||
var Immutable = require("../../seamless-immutable.js"); | ||
var JSC = require("jscheck"); | ||
var TestUtils = require("../TestUtils.js"); | ||
var assert = require("chai").assert; | ||
var _ = require("lodash") | ||
var check = TestUtils.check; | ||
var _ = require("lodash"); | ||
module.exports = function() { | ||
module.exports = function(config) { | ||
var Immutable = require(config.src); | ||
var TestUtils = require("../TestUtils.js")(Immutable); | ||
var check = TestUtils.check; | ||
describe("#asObject", function() { | ||
@@ -52,2 +53,2 @@ it("works on arrays of various lengths", function() { | ||
}); | ||
}; | ||
}; |
@@ -1,11 +0,13 @@ | ||
var Immutable = require("../../seamless-immutable.js"); | ||
var JSC = require("jscheck"); | ||
var TestUtils = require("../TestUtils.js"); | ||
var assert = require("chai").assert; | ||
var _ = require("lodash") | ||
var _ = require("lodash"); | ||
var identityFunction = function(arg) { return arg; } | ||
var checkImmutableMutable = TestUtils.checkImmutableMutable(100, [JSC.array([TestUtils.ComplexObjectSpecifier()])]); | ||
var identityFunction = function(arg) { return arg; }; | ||
module.exports = function() { | ||
module.exports = function(config) { | ||
var Immutable = require(config.src); | ||
var TestUtils = require("../TestUtils.js")(Immutable); | ||
var checkImmutableMutable = TestUtils.checkImmutableMutable(100, [JSC.array([TestUtils.ComplexObjectSpecifier()])]); | ||
describe("ImmutableArray", function() { | ||
@@ -78,8 +80,18 @@ describe("which is compatible with vanilla mutable arrays", function() { | ||
it("is frozen", function() { | ||
checkImmutableMutable(function(immutable, mutable) { | ||
assert.isTrue(Object.isFrozen(immutable)); | ||
if (config.id === "dev") { | ||
it("is frozen", function() { | ||
checkImmutableMutable(function(immutable, mutable) { | ||
assert.isTrue(Object.isFrozen(immutable)); | ||
}); | ||
}); | ||
}); | ||
} | ||
if (config.id === "prod") { | ||
it("is not frozen", function() { | ||
checkImmutableMutable(function(immutable, mutable) { | ||
assert.isFalse(Object.isFrozen(immutable)); | ||
}); | ||
}); | ||
} | ||
it("is tagged as immutable", function() { | ||
@@ -91,12 +103,25 @@ checkImmutableMutable(function(immutable, mutable) { | ||
it("cannot have its elements directly mutated", function() { | ||
checkImmutableMutable(function(immutable, mutable, randomIndex, randomData) { | ||
immutable[randomIndex] = randomData; | ||
if (config.id === "dev") { | ||
it("cannot have its elements directly mutated", function () { | ||
checkImmutableMutable(function (immutable, mutable, randomIndex, randomData) { | ||
immutable[randomIndex] = randomData; | ||
assert.typeOf(randomIndex, "number"); | ||
assert.strictEqual(immutable.length, mutable.length); | ||
assert.deepEqual(immutable[randomIndex], mutable[randomIndex]); | ||
}, [JSC.integer(), JSC.any()]); | ||
}); | ||
assert.typeOf(randomIndex, "number"); | ||
assert.strictEqual(immutable.length, mutable.length); | ||
assert.deepEqual(immutable[randomIndex], mutable[randomIndex]); | ||
}, [JSC.integer(), JSC.any()]); | ||
}); | ||
} | ||
if (config.id === "prod") { | ||
it("can have its elements directly mutated", function () { | ||
var immutableArr = Immutable([1, 2, 3]); | ||
immutableArr[0] = 4; | ||
assert.equal(immutableArr[0], 4); | ||
immutableArr.sort(); | ||
assert.deepEqual(immutableArr, [2, 3, 4]); | ||
}); | ||
} | ||
it("makes nested content immutable as well", function() { | ||
@@ -172,2 +197,2 @@ checkImmutableMutable(function(immutable, mutable, innerArray, obj) { | ||
}); | ||
}; | ||
}; |
@@ -1,9 +0,10 @@ | ||
var Immutable = require("../../seamless-immutable.js"); | ||
var JSC = require("jscheck"); | ||
var TestUtils = require("../TestUtils.js"); | ||
var assert = require("chai").assert; | ||
var _ = require("lodash") | ||
var check = TestUtils.check; | ||
var _ = require("lodash"); | ||
module.exports = function() { | ||
module.exports = function(config) { | ||
var Immutable = require(config.src); | ||
var TestUtils = require("../TestUtils.js")(Immutable); | ||
var check = TestUtils.check; | ||
describe("#flatMap", function() { | ||
@@ -62,2 +63,2 @@ // Sanity check to make sure our QuickCheck logic isn't off the rails. | ||
}); | ||
}; | ||
}; |
var testMerge = require("./ImmutableObject/test-merge.js"); | ||
var testCompat = require("./ImmutableObject/test-compat.js"); | ||
var testWithout = require("./ImmutableObject/test-without.js"); | ||
var testToMutable = require("./ImmutableArray/test-asMutable.js"); | ||
var testToMutable = require("./ImmutableObject/test-asMutable.js"); | ||
describe("ImmutableObject", function() { | ||
testCompat(); | ||
testMerge(); | ||
testWithout(); | ||
testToMutable(); | ||
[ | ||
{id: "dev", name: "Development build", src: "../../seamless-immutable.development.js"}, | ||
{id: "prod", name: "Production build", src: "../../seamless-immutable.production.min.js"} | ||
].forEach(function(config) { | ||
describe(config.name, function () { | ||
describe("ImmutableObject", function () { | ||
testCompat(config); | ||
testMerge(config); | ||
testWithout(config); | ||
testToMutable(config); | ||
}); | ||
}); | ||
}); |
@@ -1,9 +0,10 @@ | ||
var Immutable = require("../../seamless-immutable.js"); | ||
var JSC = require("jscheck"); | ||
var TestUtils = require("../TestUtils.js"); | ||
var assert = require("chai").assert; | ||
var _ = require("lodash") | ||
var check = TestUtils.check; | ||
var _ = require("lodash"); | ||
module.exports = function() { | ||
module.exports = function(config) { | ||
var Immutable = require(config.src); | ||
var TestUtils = require("../TestUtils.js")(Immutable); | ||
var check = TestUtils.check; | ||
describe("#asMutable", function() { | ||
@@ -32,2 +33,2 @@ it("returns a shallow mutable copy if not provided the deep flag", function() { | ||
}); | ||
}; | ||
}; |
@@ -1,10 +0,6 @@ | ||
var Immutable = require("../../seamless-immutable.js"); | ||
var JSC = require("jscheck"); | ||
var TestUtils = require("../TestUtils.js"); | ||
var assert = require("chai").assert; | ||
var _ = require("lodash") | ||
var check = TestUtils.check; | ||
var _ = require("lodash"); | ||
var checkImmutableMutable = TestUtils.checkImmutableMutable(100, [TestUtils.ComplexObjectSpecifier()]); | ||
var identityFunction = function(arg) { return arg; } | ||
var identityFunction = function(arg) { return arg; }; | ||
@@ -15,3 +11,8 @@ function notParseableAsInt(str) { | ||
module.exports = function() { | ||
module.exports = function(config) { | ||
var Immutable = require(config.src); | ||
var TestUtils = require("../TestUtils.js")(Immutable); | ||
var checkImmutableMutable = TestUtils.checkImmutableMutable(100, [TestUtils.ComplexObjectSpecifier()]); | ||
describe("which is compatible with vanilla mutable objects", function() { | ||
@@ -79,8 +80,18 @@ it("is an instance of Object", function() { | ||
it("is frozen", function() { | ||
checkImmutableMutable(function(immutable, mutable) { | ||
assert.isTrue(Object.isFrozen(immutable)); | ||
if (config.id === "dev") { | ||
it("is frozen", function () { | ||
checkImmutableMutable(function (immutable, mutable) { | ||
assert.isTrue(Object.isFrozen(immutable)); | ||
}); | ||
}); | ||
}); | ||
} | ||
if (config.id === "prod") { | ||
it("is frozen", function () { | ||
checkImmutableMutable(function (immutable, mutable) { | ||
assert.isFalse(Object.isFrozen(immutable)); | ||
}); | ||
}); | ||
} | ||
it("is tagged as immutable", function() { | ||
@@ -92,12 +103,26 @@ checkImmutableMutable(function(immutable, mutable) { | ||
it("cannot have its elements directly mutated", function() { | ||
checkImmutableMutable(function(immutable, mutable, randomIndex, randomData) { | ||
immutable[randomIndex] = randomData; | ||
if (config.id === "dev") { | ||
it("cannot have its elements directly mutated", function () { | ||
checkImmutableMutable(function (immutable, mutable, randomIndex, randomData) { | ||
immutable[randomIndex] = randomData; | ||
assert.typeOf(randomIndex, "number"); | ||
assert.strictEqual(immutable.length, mutable.length); | ||
assert.deepEqual(immutable[randomIndex], mutable[randomIndex]); | ||
}, [JSC.integer(), JSC.any()]); | ||
}); | ||
assert.typeOf(randomIndex, "number"); | ||
assert.strictEqual(immutable.length, mutable.length); | ||
assert.deepEqual(immutable[randomIndex], mutable[randomIndex]); | ||
}, [JSC.integer(), JSC.any()]); | ||
}); | ||
} | ||
if (config.id === "prod") { | ||
it("can have its elements directly mutated", function () { | ||
var immutable = Immutable({id: 3, name: "base"}); | ||
immutable.id = 4; | ||
immutable.name = "belong"; | ||
assert.equal(immutable.id, 4); | ||
assert.equal(immutable.name, "belong"); | ||
}); | ||
} | ||
it("makes nested content immutable as well", function() { | ||
@@ -139,2 +164,2 @@ checkImmutableMutable(function(immutable, mutable, innerArray, obj) { | ||
}); | ||
}; | ||
}; |
@@ -1,12 +0,5 @@ | ||
var Immutable = require("../../seamless-immutable.js"); | ||
var JSC = require("jscheck"); | ||
var TestUtils = require("../TestUtils.js"); | ||
var assert = require("chai").assert; | ||
var _ = require("lodash") | ||
var check = TestUtils.check; | ||
var _ = require("lodash"); | ||
function generateArrayOfObjects() { | ||
return JSC.array()().map(function() { return TestUtils.ComplexObjectSpecifier()(); }); | ||
} | ||
// Anything but an object, array, or undefined. | ||
@@ -21,3 +14,11 @@ function invalidMergeArgumentSpecifier() { | ||
module.exports = function() { | ||
module.exports = function(config) { | ||
var Immutable = require(config.src); | ||
var TestUtils = require("../TestUtils.js")(Immutable); | ||
var check = TestUtils.check; | ||
function generateArrayOfObjects() { | ||
return JSC.array()().map(function() { return TestUtils.ComplexObjectSpecifier()(); }); | ||
} | ||
describe("#merge", function() { | ||
@@ -24,0 +25,0 @@ function generateMergeTestsFor(specifiers, config) { |
@@ -1,7 +0,4 @@ | ||
var Immutable = require("../../seamless-immutable.js"); | ||
var JSC = require("jscheck"); | ||
var TestUtils = require("../TestUtils.js"); | ||
var assert = require("chai").assert; | ||
var _ = require("lodash") | ||
var check = TestUtils.check; | ||
var _ = require("lodash"); | ||
@@ -12,6 +9,10 @@ function generateArrayOfStrings() { | ||
module.exports = function() { | ||
module.exports = function(config) { | ||
var Immutable = require(config.src); | ||
var TestUtils = require("../TestUtils.js")(Immutable); | ||
var check = TestUtils.check; | ||
describe("#without", function() { | ||
function generateWithoutTestsFor(specifiers) { | ||
var runs = 100 | ||
var runs = 100; | ||
@@ -101,2 +102,2 @@ function checkMultiple(callback) { | ||
}); | ||
}; | ||
}; |
@@ -1,2 +0,1 @@ | ||
var Immutable = require("../seamless-immutable.js"); | ||
var JSC = require("jscheck"); | ||
@@ -6,7 +5,9 @@ var assert = require("chai").assert; | ||
function assertImmutable(methodName, immutableArray, mutableArray, args) { | ||
var mutableResult = mutableArray[methodName].apply(mutableArray, args); | ||
var immutableResult = Immutable(immutableArray[methodName].apply(immutableArray, args)); | ||
function wrapAssertImmutable(Immutable) { | ||
return function assertImmutable(methodName, immutableArray, mutableArray, args) { | ||
var mutableResult = mutableArray[methodName].apply(mutableArray, args); | ||
var immutableResult = Immutable(immutableArray[methodName].apply(immutableArray, args)); | ||
assert.deepEqual(immutableResult, mutableResult); | ||
assert.deepEqual(immutableResult, mutableResult); | ||
} | ||
} | ||
@@ -16,7 +17,9 @@ | ||
// are shallowly immutable. For tests, though, we want to be thorough! | ||
function assertIsDeeplyImmutable(obj) { | ||
assert(Immutable.isImmutable(obj)); | ||
function wrapAssertIsDeeplyImmutable(Immutable) { | ||
return function assertIsDeeplyImmutable(obj) { | ||
assert(Immutable.isImmutable(obj)); | ||
if (typeof obj === "object") { | ||
_.each(obj, assertIsDeeplyImmutable); | ||
if (typeof obj === "object") { | ||
_.each(obj, assertIsDeeplyImmutable); | ||
} | ||
} | ||
@@ -68,9 +71,11 @@ } | ||
function ImmutableArraySpecifier(JSC) { | ||
var args = Array.prototype.slice.call(arguments); | ||
function wrapImmutableArraySpecifier(Immutable) { | ||
return function ImmutableArraySpecifier(JSC) { | ||
var args = Array.prototype.slice.call(arguments); | ||
return function generator() { | ||
var mutable = JSC.array.apply(JSC.array, args)(); | ||
return function generator() { | ||
var mutable = JSC.array.apply(JSC.array, args)(); | ||
return Immutable(mutable); | ||
return Immutable(mutable); | ||
} | ||
} | ||
@@ -94,23 +99,27 @@ } | ||
function checkImmutableMutable(runs, specifiers) { | ||
return function(callback, extraSpecifiers) { | ||
extraSpecifiers = extraSpecifiers || []; | ||
function wrapCheckImmutableMutable(Immutable) { | ||
return function checkImmutableMutable(runs, specifiers) { | ||
return function (callback, extraSpecifiers) { | ||
extraSpecifiers = extraSpecifiers || []; | ||
check(runs, specifiers.concat(extraSpecifiers), function(mutable) { | ||
var immutable = Immutable(mutable); | ||
var args = Array.prototype.slice.call(arguments); | ||
check(runs, specifiers.concat(extraSpecifiers), function (mutable) { | ||
var immutable = Immutable(mutable); | ||
var args = Array.prototype.slice.call(arguments); | ||
callback.apply(callback, [immutable].concat(args)); | ||
}); | ||
}; | ||
callback.apply(callback, [immutable].concat(args)); | ||
}); | ||
}; | ||
} | ||
} | ||
module.exports = { | ||
assertImmutable: assertImmutable, | ||
assertIsDeeplyImmutable: assertIsDeeplyImmutable, | ||
ImmutableArraySpecifier: ImmutableArraySpecifier, | ||
ComplexObjectSpecifier: ComplexObjectSpecifier, | ||
TraversableObjectSpecifier: TraversableObjectSpecifier, | ||
check: check, | ||
checkImmutableMutable: checkImmutableMutable | ||
} | ||
module.exports = function(Immutable) { | ||
return { | ||
assertImmutable: wrapAssertImmutable(Immutable), | ||
assertIsDeeplyImmutable: wrapAssertIsDeeplyImmutable(Immutable), | ||
ImmutableArraySpecifier: wrapImmutableArraySpecifier(Immutable), | ||
ComplexObjectSpecifier: ComplexObjectSpecifier, | ||
TraversableObjectSpecifier: TraversableObjectSpecifier, | ||
check: check, | ||
checkImmutableMutable: wrapCheckImmutableMutable(Immutable) | ||
} | ||
}; |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
93593
24
1594
238
14
11