Socket
Socket
Sign inDemoInstall

react-immutable-proptypes

Package Overview
Dependencies
1
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.1 to 1.2.2

17

CHANGELOG.md

@@ -1,2 +0,15 @@

## 1.2.0
- moved react from peer dependency to dev dependency since React is only used internally to test. This will allow the prop type validators to work on beta/rc versions of react.
## 1.2.x
- 1.2.2 [Nik Butenko](http://butenko.me/) gave us some nice updates ()
- [Issue #10](https://github.com/HurricaneJames/react-immutable-proptypes/pull/10) now have better errors when typechecker(s) provided in `propTypes` definition is invalid
- [Issue #9](https://github.com/HurricaneJames/react-immutable-proptypes/pull/9) removed use of `new` Immutable objects in tests
- 1.2.1 updated documentation to reflect that Immutable object instantiation does not require `new`
- 1.2.0 moved react from peer dependency to dev dependency since React is only used internally to test. This will allow the prop type validators to work on beta/rc versions of react.
## Prior Version Updates
- 1.1.0 added `contains` to replace `shape` validator. `shape` is deprecated and will be removed in v 1.2.0
- 1.0.0 marked as stable, no other changes
- 0.1.8 added `setOf` checker. Thanks to [Don Abrams](https://github.com/donabrams)!
- 0.1.7 added convencience checkers for "primitive" immutable types (map, list, etc...)
- 0.1.6 added `iterableOf`
- 0.1.4 added `mapOf`
- 0.1.3 updated package.json to support React v0.11.0+ (including 0.13.1). Thanks [Andrey Okonetchnikov](https://github.com/okonet)!

141

dist/__tests__/ImmutablePropTypes-test.js

@@ -33,21 +33,28 @@ "use strict";

describe("PropTypes config", function () {
it("should fail if typeChecker is not a function", function () {
typeCheckFail(PropTypes.listOf({ x: React.PropTypes.string }), Immutable.List([Immutable.Map({ x: "y" })]), "Invalid typeChecker supplied to " + "`testComponent` for propType `testProp`, expected a function.");
typeCheckPass(PropTypes.listOf(PropTypes.contains({ x: React.PropTypes.string })), Immutable.List([Immutable.Map({ x: "y" })]));
});
});
describe("Primitive Types", function () {
it("should not warn for valid values", function () {
typeCheckPass(PropTypes.list, new Immutable.List());
typeCheckPass(PropTypes.map, new Immutable.Map());
typeCheckPass(PropTypes.map, new Immutable.OrderedMap());
typeCheckPass(PropTypes.orderedMap, new Immutable.OrderedMap());
typeCheckPass(PropTypes.set, new Immutable.Set());
typeCheckPass(PropTypes.set, new Immutable.OrderedSet());
typeCheckPass(PropTypes.orderedSet, new Immutable.OrderedSet());
typeCheckPass(PropTypes.stack, new Immutable.Stack());
typeCheckPass(PropTypes.seq, new Immutable.Seq());
typeCheckPass(PropTypes.iterable, new Immutable.Iterable());
typeCheckPass(PropTypes.iterable, new Immutable.List());
typeCheckPass(PropTypes.iterable, new Immutable.Map());
typeCheckPass(PropTypes.iterable, new Immutable.OrderedMap());
typeCheckPass(PropTypes.iterable, new Immutable.Set());
typeCheckPass(PropTypes.iterable, new Immutable.OrderedSet());
typeCheckPass(PropTypes.iterable, new Immutable.Stack());
typeCheckPass(PropTypes.iterable, new Immutable.Seq());
typeCheckPass(PropTypes.list, Immutable.List());
typeCheckPass(PropTypes.map, Immutable.Map());
typeCheckPass(PropTypes.map, Immutable.OrderedMap());
typeCheckPass(PropTypes.orderedMap, Immutable.OrderedMap());
typeCheckPass(PropTypes.set, Immutable.Set());
typeCheckPass(PropTypes.set, Immutable.OrderedSet());
typeCheckPass(PropTypes.orderedSet, Immutable.OrderedSet());
typeCheckPass(PropTypes.stack, Immutable.Stack());
typeCheckPass(PropTypes.seq, Immutable.Seq());
typeCheckPass(PropTypes.iterable, Immutable.Iterable());
typeCheckPass(PropTypes.iterable, Immutable.List());
typeCheckPass(PropTypes.iterable, Immutable.Map());
typeCheckPass(PropTypes.iterable, Immutable.OrderedMap());
typeCheckPass(PropTypes.iterable, Immutable.Set());
typeCheckPass(PropTypes.iterable, Immutable.OrderedSet());
typeCheckPass(PropTypes.iterable, Immutable.Stack());
typeCheckPass(PropTypes.iterable, Immutable.Seq());
});

@@ -60,4 +67,4 @@ it("should warn for invalid lists", function () {

typeCheckFail(PropTypes.list, 0, "Invalid prop `testProp` of type `number` supplied to " + "`testComponent`, expected `List`.");
typeCheckFail(PropTypes.list, new Immutable.Map(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `List`.");
typeCheckFail(PropTypes.list, new Immutable.Iterable(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `List`.");
typeCheckFail(PropTypes.list, Immutable.Map(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `List`.");
typeCheckFail(PropTypes.list, Immutable.Iterable(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `List`.");
});

@@ -70,4 +77,4 @@ it("should warn for invalid maps", function () {

typeCheckFail(PropTypes.map, 0, "Invalid prop `testProp` of type `number` supplied to " + "`testComponent`, expected `Map`.");
typeCheckFail(PropTypes.map, new Immutable.List(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `Map`.");
typeCheckFail(PropTypes.map, new Immutable.Iterable(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `Map`.");
typeCheckFail(PropTypes.map, Immutable.List(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `Map`.");
typeCheckFail(PropTypes.map, Immutable.Iterable(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `Map`.");
});

@@ -86,9 +93,9 @@ it("should be implicitly optional and not warn without values", function () {

it("should support the listOf propTypes", function () {
typeCheckPass(PropTypes.listOf(React.PropTypes.number), new Immutable.List([1, 2, 3]));
typeCheckPass(PropTypes.listOf(React.PropTypes.string), new Immutable.List(["a", "b", "c"]));
typeCheckPass(PropTypes.listOf(React.PropTypes.oneOf(["a", "b"])), new Immutable.List(["a", "b"]));
typeCheckPass(PropTypes.listOf(React.PropTypes.number), Immutable.List([1, 2, 3]));
typeCheckPass(PropTypes.listOf(React.PropTypes.string), Immutable.List(["a", "b", "c"]));
typeCheckPass(PropTypes.listOf(React.PropTypes.oneOf(["a", "b"])), Immutable.List(["a", "b"]));
});
it("should support listOf with complex types", function () {
typeCheckPass(PropTypes.listOf(React.PropTypes.shape({ a: React.PropTypes.number.isRequired })), new Immutable.List([{ a: 1 }, { a: 2 }]));
typeCheckPass(PropTypes.listOf(React.PropTypes.shape({ a: React.PropTypes.number.isRequired })), Immutable.List([{ a: 1 }, { a: 2 }]));

@@ -98,7 +105,7 @@ typeCheckPass(PropTypes.listOf(PropTypes.shape({ a: React.PropTypes.number.isRequired })), Immutable.fromJS([{ a: 1 }, { a: 2 }]));

function Thing() {}
typeCheckPass(PropTypes.listOf(React.PropTypes.instanceOf(Thing)), new Immutable.List([new Thing(), new Thing()]));
typeCheckPass(PropTypes.listOf(React.PropTypes.instanceOf(Thing)), Immutable.List([new Thing(), new Thing()]));
});
it("should warn with invalid items in the list", function () {
typeCheckFail(PropTypes.listOf(React.PropTypes.number), new Immutable.List([1, 2, "b"]), "Invalid prop `2` of type `string` supplied to `testComponent`, " + "expected `number`.");
typeCheckFail(PropTypes.listOf(React.PropTypes.number), Immutable.List([1, 2, "b"]), "Invalid prop `2` of type `string` supplied to `testComponent`, " + "expected `number`.");
});

@@ -110,3 +117,3 @@

typeCheckFail(PropTypes.listOf(React.PropTypes.instanceOf(Thing)), new Immutable.List([new Thing(), "xyz"]), "Invalid prop `1` supplied to `testComponent`, expected instance of `" + name + "`.");
typeCheckFail(PropTypes.listOf(React.PropTypes.instanceOf(Thing)), Immutable.List([new Thing(), "xyz"]), "Invalid prop `1` supplied to `testComponent`, expected instance of `" + name + "`.");
});

@@ -122,4 +129,4 @@

it("should not warn when passing an empty array", function () {
typeCheckPass(PropTypes.listOf(PropTypes.number), new Immutable.List());
typeCheckPass(PropTypes.listOf(PropTypes.number), new Immutable.List([]));
typeCheckPass(PropTypes.listOf(PropTypes.number), Immutable.List());
typeCheckPass(PropTypes.listOf(PropTypes.number), Immutable.List([]));
});

@@ -140,9 +147,9 @@

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" }));
typeCheckPass(PropTypes.mapOf(React.PropTypes.number), Immutable.Map({ 1: 1, 2: 2, 3: 3 }));
typeCheckPass(PropTypes.mapOf(React.PropTypes.string), Immutable.Map({ 1: "a", 2: "b", 3: "c" }));
typeCheckPass(PropTypes.mapOf(React.PropTypes.oneOf(["a", "b"])), 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(React.PropTypes.shape({ a: React.PropTypes.number.isRequired })), Immutable.Map({ 1: { a: 1 }, 2: { a: 2 } }));

@@ -152,7 +159,7 @@ 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() }));
typeCheckPass(PropTypes.mapOf(React.PropTypes.instanceOf(Thing)), Immutable.Map({ 1: new Thing(), 2: new Thing() }));
});
it("should warn with invalid items in the map", 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`.");
typeCheckFail(PropTypes.mapOf(React.PropTypes.number), Immutable.Map({ 1: 1, 2: 2, 3: "b" }), "Invalid prop `2` of type `string` supplied to `testComponent`, " + "expected `number`.");
});

@@ -164,3 +171,3 @@

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 + "`.");
typeCheckFail(PropTypes.mapOf(React.PropTypes.instanceOf(Thing)), Immutable.Map({ 1: new Thing(), 2: "xyz" }), "Invalid prop `1` supplied to `testComponent`, expected instance of `" + name + "`.");
});

@@ -176,4 +183,4 @@

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({}));
typeCheckPass(PropTypes.mapOf(PropTypes.number), Immutable.Map());
typeCheckPass(PropTypes.mapOf(PropTypes.number), Immutable.Map({}));
});

@@ -194,16 +201,16 @@

it("should support the setOf propTypes", function () {
typeCheckPass(PropTypes.setOf(React.PropTypes.number), new Immutable.Set([1, 2, 3]));
typeCheckPass(PropTypes.setOf(React.PropTypes.string), new Immutable.Set(["a", "b", "c"]));
typeCheckPass(PropTypes.setOf(React.PropTypes.oneOf(["a", "b"])), new Immutable.Set(["a", "b"]));
typeCheckPass(PropTypes.setOf(React.PropTypes.number), Immutable.Set([1, 2, 3]));
typeCheckPass(PropTypes.setOf(React.PropTypes.string), Immutable.Set(["a", "b", "c"]));
typeCheckPass(PropTypes.setOf(React.PropTypes.oneOf(["a", "b"])), Immutable.Set(["a", "b"]));
});
it("should support setOf with complex types", function () {
typeCheckPass(PropTypes.setOf(React.PropTypes.shape({ a: React.PropTypes.number.isRequired })), new Immutable.Set([{ a: 1 }, { a: 2 }]));
typeCheckPass(PropTypes.setOf(React.PropTypes.shape({ a: React.PropTypes.number.isRequired })), Immutable.Set([{ a: 1 }, { a: 2 }]));
function Thing() {}
typeCheckPass(PropTypes.setOf(React.PropTypes.instanceOf(Thing)), new Immutable.Set([new Thing(), new Thing()]));
typeCheckPass(PropTypes.setOf(React.PropTypes.instanceOf(Thing)), Immutable.Set([new Thing(), new Thing()]));
});
it("should warn with invalid items in the set", function () {
typeCheckFail(PropTypes.setOf(React.PropTypes.number), new Immutable.Set([1, 2, "b"]), "Invalid prop `2` of type `string` supplied to `testComponent`, " + "expected `number`.");
typeCheckFail(PropTypes.setOf(React.PropTypes.number), Immutable.Set([1, 2, "b"]), "Invalid prop `2` of type `string` supplied to `testComponent`, " + "expected `number`.");
});

@@ -215,3 +222,3 @@

typeCheckFail(PropTypes.setOf(React.PropTypes.instanceOf(Thing)), new Immutable.Set([new Thing(), "xyz"]), "Invalid prop `1` supplied to `testComponent`, expected instance of `" + name + "`.");
typeCheckFail(PropTypes.setOf(React.PropTypes.instanceOf(Thing)), Immutable.Set([new Thing(), "xyz"]), "Invalid prop `1` supplied to `testComponent`, expected instance of `" + name + "`.");
});

@@ -227,4 +234,4 @@

it("should not warn when passing an empty object", function () {
typeCheckPass(PropTypes.setOf(PropTypes.number), new Immutable.Set());
typeCheckPass(PropTypes.setOf(PropTypes.number), new Immutable.Set([]));
typeCheckPass(PropTypes.setOf(PropTypes.number), Immutable.Set());
typeCheckPass(PropTypes.setOf(PropTypes.number), Immutable.Set([]));
});

@@ -245,9 +252,9 @@

it("should support the iterableOf propTypes", function () {
typeCheckPass(PropTypes.iterableOf(React.PropTypes.number), new Immutable.List([1, 2, 3]));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.string), new Immutable.List(["a", "b", "c"]));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.oneOf(["a", "b"])), new Immutable.List(["a", "b"]));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.number), Immutable.List([1, 2, 3]));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.string), Immutable.List(["a", "b", "c"]));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.oneOf(["a", "b"])), Immutable.List(["a", "b"]));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.number), new Immutable.Map({ 1: 1, 2: 2, 3: 3 }));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.string), new Immutable.Map({ 1: "a", 2: "b", 3: "c" }));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.oneOf(["a", "b"])), new Immutable.Map({ 1: "a", 2: "b" }));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.number), Immutable.Map({ 1: 1, 2: 2, 3: 3 }));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.string), Immutable.Map({ 1: "a", 2: "b", 3: "c" }));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.oneOf(["a", "b"])), Immutable.Map({ 1: "a", 2: "b" }));
});

@@ -258,19 +265,19 @@

typeCheckPass(PropTypes.iterableOf(React.PropTypes.shape({ a: React.PropTypes.number.isRequired })), new Immutable.List([{ a: 1 }, { a: 2 }]));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.shape({ a: React.PropTypes.number.isRequired })), Immutable.List([{ a: 1 }, { a: 2 }]));
typeCheckPass(PropTypes.iterableOf(PropTypes.shape({ a: React.PropTypes.number.isRequired })), Immutable.fromJS([{ a: 1 }, { a: 2 }]));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.instanceOf(Thing)), new Immutable.List([new Thing(), new Thing()]));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.instanceOf(Thing)), Immutable.List([new Thing(), new Thing()]));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.shape({ a: React.PropTypes.number.isRequired })), new Immutable.Map({ 1: { a: 1 }, 2: { a: 2 } }));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.shape({ a: React.PropTypes.number.isRequired })), Immutable.Map({ 1: { a: 1 }, 2: { a: 2 } }));
typeCheckPass(PropTypes.iterableOf(PropTypes.shape({ a: React.PropTypes.number.isRequired })), Immutable.fromJS({ 1: { a: 1 }, 2: { a: 2 } }));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.instanceOf(Thing)), new Immutable.Map({ 1: new Thing(), 2: new Thing() }));
typeCheckPass(PropTypes.iterableOf(React.PropTypes.instanceOf(Thing)), Immutable.Map({ 1: new Thing(), 2: new Thing() }));
});
it("should warn with invalid items in the list", function () {
typeCheckFail(PropTypes.iterableOf(React.PropTypes.number), new Immutable.List([1, 2, "b"]), "Invalid prop `2` of type `string` supplied to `testComponent`, " + "expected `number`.");
typeCheckFail(PropTypes.iterableOf(React.PropTypes.number), Immutable.List([1, 2, "b"]), "Invalid prop `2` of type `string` supplied to `testComponent`, " + "expected `number`.");
typeCheckFail(PropTypes.iterableOf(React.PropTypes.number), new Immutable.Map({ 1: 1, 2: 2, 3: "b" }), "Invalid prop `2` of type `string` supplied to `testComponent`, " + "expected `number`.");
typeCheckFail(PropTypes.iterableOf(React.PropTypes.number), Immutable.Map({ 1: 1, 2: 2, 3: "b" }), "Invalid prop `2` of type `string` supplied to `testComponent`, " + "expected `number`.");
});

@@ -282,5 +289,5 @@

typeCheckFail(PropTypes.iterableOf(React.PropTypes.instanceOf(Thing)), new Immutable.List([new Thing(), "xyz"]), "Invalid prop `1` supplied to `testComponent`, expected instance of `" + name + "`.");
typeCheckFail(PropTypes.iterableOf(React.PropTypes.instanceOf(Thing)), Immutable.List([new Thing(), "xyz"]), "Invalid prop `1` supplied to `testComponent`, expected instance of `" + name + "`.");
typeCheckFail(PropTypes.iterableOf(React.PropTypes.instanceOf(Thing)), new Immutable.Map({ 1: new Thing(), 2: "xyz" }), "Invalid prop `1` supplied to `testComponent`, expected instance of `" + name + "`.");
typeCheckFail(PropTypes.iterableOf(React.PropTypes.instanceOf(Thing)), Immutable.Map({ 1: new Thing(), 2: "xyz" }), "Invalid prop `1` supplied to `testComponent`, expected instance of `" + name + "`.");
});

@@ -296,5 +303,5 @@

it("should not warn when passing an empty iterable", function () {
typeCheckPass(PropTypes.iterableOf(PropTypes.number), new Immutable.List());
typeCheckPass(PropTypes.iterableOf(PropTypes.number), new Immutable.List([]));
typeCheckPass(PropTypes.iterableOf(PropTypes.number), new Immutable.Map({}));
typeCheckPass(PropTypes.iterableOf(PropTypes.number), Immutable.List());
typeCheckPass(PropTypes.iterableOf(PropTypes.number), Immutable.List([]));
typeCheckPass(PropTypes.iterableOf(PropTypes.number), Immutable.Map({}));
});

@@ -373,3 +380,3 @@

};
typeCheckPass(PropTypes.shape(shape), new Immutable.List([1, "2"]));
typeCheckPass(PropTypes.shape(shape), Immutable.List([1, "2"]));
});

@@ -438,5 +445,5 @@ });

};
typeCheckPass(PropTypes.contains(contains), new Immutable.List([1, "2"]));
typeCheckPass(PropTypes.contains(contains), Immutable.List([1, "2"]));
});
});
});

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

function createIterableTypeChecker(typeChecker, immutableClassName, immutableClassTypeValidator) {
function validate(props, propName, componentName, location) {

@@ -87,2 +88,5 @@ var propValue = props[propName];

for (var i = 0, len = propValues.length; i < len; i++) {
if (typeof typeChecker !== "function") {
return new Error("Invalid typeChecker supplied to `" + componentName + "` " + ("for propType `" + propName + "`, expected a function."));
}
var error = typeChecker(propValues, i, componentName, location);

@@ -89,0 +93,0 @@ if (error instanceof Error) {

{
"name": "react-immutable-proptypes",
"version": "1.2.1",
"version": "1.2.2",
"description": "PropType validators that work with Immutable.js.",

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

@@ -7,12 +7,2 @@ # react-immutable-proptypes

## Version Updates
- 1.1.0 added `contains` to replace `shape` validator. `shape` is deprecated and will be removed in v 1.2.0
- 1.0.0 marked as stable, no other changes
- 0.1.8 added `setOf` checker. Thanks to [Don Abrams](https://github.com/donabrams)!
- 0.1.7 added convencience checkers for "primitive" immutable types (map, list, etc...)
- 0.1.6 added `iterableOf`
- 0.1.4 added `mapOf`
- 0.1.3 updated package.json to support React v0.11.0+ (including 0.13.1). Thanks [Andrey Okonetchnikov](https://github.com/okonet)!
## About

@@ -19,0 +9,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc