Socket
Socket
Sign inDemoInstall

react-immutable-proptypes

Package Overview
Dependencies
4
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

66

dist/__tests__/ImmutablePropTypes-test.js

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

describe("Shape Types", function () {
describe("Shape Types [deprecated]", function () {
it("should warn for non objects", function () {

@@ -359,2 +359,66 @@ typeCheckFail(PropTypes.shape({}), "some string", "Invalid prop `testProp` of type `string` supplied to " + "`testComponent`, expected an Immutable.js Iterable.");

});
describe("Contains Types", function () {
it("should warn for non objects", function () {
typeCheckFail(PropTypes.contains({}), "some string", "Invalid prop `testProp` of type `string` supplied to " + "`testComponent`, expected an Immutable.js Iterable.");
typeCheckFail(PropTypes.contains({}), ["array"], "Invalid prop `testProp` of type `array` supplied to " + "`testComponent`, expected an Immutable.js Iterable.");
typeCheckFail(PropTypes.contains({}), { a: 1 }, "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected an Immutable.js Iterable.");
});
it("should not warn for empty values", function () {
typeCheckPass(PropTypes.contains({}), undefined);
typeCheckPass(PropTypes.contains({}), null);
typeCheckPass(PropTypes.contains({}), Immutable.fromJS({}));
});
it("should not warn for an empty Immutable object", function () {
typeCheckPass(PropTypes.contains({}).isRequired, Immutable.fromJS({}));
});
it("should not warn for non specified types", function () {
typeCheckPass(PropTypes.contains({}), Immutable.fromJS({ key: 1 }));
});
it("should not warn for valid types", function () {
typeCheckPass(PropTypes.contains({ key: React.PropTypes.number }), Immutable.fromJS({ key: 1 }));
});
it("should ignore null keys", function () {
typeCheckPass(PropTypes.contains({ key: null }), Immutable.fromJS({ key: 1 }));
});
it("should warn for required valid types", function () {
typeCheckFail(PropTypes.contains({ key: React.PropTypes.number.isRequired }), Immutable.fromJS({}), "Required prop `key` was not specified in `testComponent`.");
});
it("should warn for the first required type", function () {
typeCheckFail(PropTypes.contains({
key: React.PropTypes.number.isRequired,
secondKey: React.PropTypes.number.isRequired
}), Immutable.fromJS({}), "Required prop `key` was not specified in `testComponent`.");
});
it("should warn for invalid key types", function () {
typeCheckFail(PropTypes.contains({ key: React.PropTypes.number }), Immutable.fromJS({ key: "abc" }), "Invalid prop `key` of type `string` supplied to `testComponent`, " + "expected `number`.");
});
it("should be implicitly optional and not warn without values", function () {
typeCheckPass(PropTypes.contains(PropTypes.contains({ key: React.PropTypes.number })), null);
typeCheckPass(PropTypes.contains(PropTypes.contains({ key: React.PropTypes.number })), undefined);
});
it("should warn for missing required values", function () {
typeCheckFail(PropTypes.contains({ key: React.PropTypes.number }).isRequired, null, requiredMessage);
typeCheckFail(PropTypes.contains({ key: React.PropTypes.number }).isRequired, undefined, requiredMessage);
});
it("should probably not validate a list, but does", function () {
var contains = {
0: React.PropTypes.number.isRequired,
1: React.PropTypes.string.isRequired,
2: React.PropTypes.string
};
typeCheckPass(PropTypes.contains(contains), new Immutable.List([1, "2"]));
});
});
});

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

shape: createShapeTypeChecker,
contains: createShapeTypeChecker,
// Primitive Types

@@ -21,0 +22,0 @@ list: createImmutableTypeChecker("List", Immutable.List.isList),

2

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

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

@@ -8,2 +8,3 @@ # 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

@@ -19,3 +20,3 @@ - 0.1.8 added `setOf` checker. Thanks to [Don Abrams](https://github.com/donabrams)!

I got tired of seeing `React.PropTypes.instanceOf(Immutable.List)` or `React.PropTypes.instanceOf(Immutable.Map)` as PropTypes for components that should be specifying an `Immutable.List` **_of_** something or an `Immutable.Map` **shape**. A little *"googling"* came up empty, unless you want to use Flow, which I do not. So, I wrote `react-immutable-proptypes`.
I got tired of seeing `React.PropTypes.instanceOf(Immutable.List)` or `React.PropTypes.instanceOf(Immutable.Map)` as PropTypes for components that should be specifying an `Immutable.List` **_of_** something or that an `Immutable.Map` **contains** some keys. A little *"googling"* came up empty, unless you want to use Flow, which I do not. So, I wrote `react-immutable-proptypes`.

@@ -29,3 +30,3 @@ Usage is simple, they work with and like any `React.PropType.*` validator.

myRequiredImmutableList: ImmutablePropTypes.listOf(
ImmutablePropTypes.shape({
ImmutablePropTypes.contains({
someNumberProp: React.PropTypes.number.isRequired

@@ -78,6 +79,6 @@ })

* `ImmutablePropTypes.shape` is based on `React.PropTypes.shape` and will try to work with any `Immutable.Iterable`. In practice, I would recommend limiting this to `Immutable.Map` or `Immutable.OrderedMap`. However, it is possible to abuse `shape` to validate an array via `Immutable.List`.
* `ImmutablePropTypes.contains` (formerly `shape`) is based on `React.PropTypes.shape` and will try to work with any `Immutable.Iterable`. In practice, I would recommend limiting this to `Immutable.Map` or `Immutable.OrderedMap`. However, it is possible to abuse `contains` to validate an array via `Immutable.List`.
// ...
aList: ImmutablePropTypes.shape({
aList: ImmutablePropTypes.contains({
0: React.PropTypes.number.isRequired,

@@ -84,0 +85,0 @@ 1: React.PropTypes.string.isRequired,

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