🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-immutable-proptypes

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-immutable-proptypes - npm Package Compare versions

Comparing version

to
0.1.4

53

dist/__tests__/ImmutablePropTypes-test.js

@@ -34,5 +34,2 @@ "use strict";

Immutable = require("immutable");
// ReactFragment = require('ReactFragment');
// ReactPropTypeLocations = require('ReactPropTypeLocations');
// ReactTestUtils = require('ReactTestUtils');
});

@@ -153,2 +150,52 @@

});
describe("MapOf Type", function () {
it("should support the mapOf propTypes", function () {
typeCheckPass(PropTypes.mapOf(React.PropTypes.number), new Immutable.Map({ 1: 1, 2: 2, 3: 3 }));
typeCheckPass(PropTypes.mapOf(React.PropTypes.string), new Immutable.Map({ 1: "a", 2: "b", 3: "c" }));
typeCheckPass(PropTypes.mapOf(React.PropTypes.oneOf(["a", "b"])), new Immutable.Map({ 1: "a", 2: "b" }));
});
it("should support mapOf with complex types", function () {
typeCheckPass(PropTypes.mapOf(React.PropTypes.shape({ a: React.PropTypes.number.isRequired })), new Immutable.Map({ 1: { a: 1 }, 2: { a: 2 } }));
typeCheckPass(PropTypes.mapOf(PropTypes.shape({ a: React.PropTypes.number.isRequired })), Immutable.fromJS({ 1: { a: 1 }, 2: { a: 2 } }));
function Thing() {}
typeCheckPass(PropTypes.mapOf(React.PropTypes.instanceOf(Thing)), new Immutable.Map({ 1: new Thing(), 2: new Thing() }));
});
it("should warn with invalid items in the map list", function () {
typeCheckFail(PropTypes.mapOf(React.PropTypes.number), new Immutable.Map({ 1: 1, 2: 2, 3: "b" }), "Invalid prop `2` of type `string` supplied to `testComponent`, " + "expected `number`.");
});
it("should warn with invalid complex types", function () {
function Thing() {}
var name = Thing.name || "<<anonymous>>";
typeCheckFail(PropTypes.mapOf(React.PropTypes.instanceOf(Thing)), new Immutable.Map({ 1: new Thing(), 2: "xyz" }), "Invalid prop `1` supplied to `testComponent`, expected instance of `" + name + "`.");
});
it("should warn when passed something other than an Immutable.Map", function () {
typeCheckFail(PropTypes.mapOf(React.PropTypes.number), { "0": "maybe-array", length: 1 }, "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected an Immutable.js Map.");
typeCheckFail(PropTypes.mapOf(PropTypes.number), 123, "Invalid prop `testProp` of type `number` supplied to " + "`testComponent`, expected an Immutable.js Map.");
typeCheckFail(PropTypes.mapOf(PropTypes.number), "string", "Invalid prop `testProp` of type `string` supplied to " + "`testComponent`, expected an Immutable.js Map.");
typeCheckFail(PropTypes.mapOf(PropTypes.number), [1, 2, 3], "Invalid prop `testProp` of type `array` supplied to " + "`testComponent`, expected an Immutable.js Map.");
});
it("should not warn when passing an empty object", function () {
typeCheckPass(PropTypes.mapOf(PropTypes.number), new Immutable.Map());
typeCheckPass(PropTypes.mapOf(PropTypes.number), new Immutable.Map({}));
});
it("should be implicitly optional and not warn without values", function () {
typeCheckPass(PropTypes.mapOf(PropTypes.number), null);
typeCheckPass(PropTypes.mapOf(PropTypes.number), undefined);
});
it("should warn for missing required values", function () {
typeCheckFail(PropTypes.mapOf(PropTypes.number).isRequired, null, requiredMessage);
typeCheckFail(PropTypes.mapOf(PropTypes.number).isRequired, undefined, requiredMessage);
});
});
});

@@ -15,2 +15,3 @@ /**

listOf: createListOfTypeChecker,
mapOf: createMapOfTypeChecker,
shape: createShapeTypeChecker

@@ -71,2 +72,21 @@ };

function createMapOfTypeChecker(typeChecker) {
function validate(props, propName, componentName, location) {
var propValue = props[propName];
if (!Immutable.Map.isMap(propValue)) {
var locationName = location;
var propType = getPropType(propValue);
return new Error("Invalid " + locationName + " `" + propName + "` of type " + ("`" + propType + "` supplied to `" + componentName + "`, expected an Immutable.js Map."));
}
var propValues = propValue.toArray();
for (var i = 0, len = propValues.length; i < len; i++) {
var error = typeChecker(propValues, i, componentName, location);
if (error instanceof Error) {
return error;
}
}
}
return createChainableTypeChecker(validate);
}
// there is some irony in the fact that shapeTypes is a standard hash and not an immutable collection

@@ -73,0 +93,0 @@ function createShapeTypeChecker(shapeTypes) {

2

package.json
{
"name": "react-immutable-proptypes",
"version": "0.1.3",
"version": "0.1.4",
"description": "PropType validators that work with Immutable.js.",

@@ -5,0 +5,0 @@ "main": "dist/ImmutablePropTypes.js",

@@ -7,3 +7,6 @@ # react-immutable-proptypes

## Version Updates
0.1.3 updated package.json to support React v0.11.0+ (including 0.13.1). Thanks [Andrey Okonetchnikov](https://github.com/okonet)!
## About

@@ -10,0 +13,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet