Socket
Socket
Sign inDemoInstall

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 1.2.3 to 1.3.0

1

CHANGELOG.md
## 1.2.x
- 1.3.0 added support for record and recordOf type checkers.
- 1.2.3 [Nik Butenko](http://butenko.me/) provided a better .npmignore file

@@ -3,0 +4,0 @@ - allows devs who want to compile the code to do so

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

iterableOf: createIterableOfTypeChecker,
recordOf: createRecordOfTypeChecker,
shape: createShapeTypeChecker,

@@ -29,2 +30,5 @@ contains: createShapeTypeChecker,

seq: createImmutableTypeChecker("Seq", Immutable.Seq.isSeq),
record: createImmutableTypeChecker("Record", function (isRecord) {
return isRecord instanceof Immutable.Record;
}),
iterable: createImmutableTypeChecker("Iterable", Immutable.Iterable.isIterable)

@@ -117,2 +121,25 @@ };

function createRecordOfTypeChecker(recordKeys) {
function validate(props, propName, componentName, location) {
var propValue = props[propName];
var propType = getPropType(propValue);
if (!(propValue instanceof Immutable.Record)) {
var locationName = location;
return new Error("Invalid " + locationName + " `" + propName + "` of type `" + propType + "` " + ("supplied to `" + componentName + "`, expected an Immutable.js Record."));
}
for (var key in recordKeys) {
var checker = recordKeys[key];
if (!checker) {
continue;
}
var mutablePropValue = propValue.toObject();
var error = checker(mutablePropValue, key, componentName, location);
if (error) {
return error;
}
}
}
return createChainableTypeChecker(validate);
}
// there is some irony in the fact that shapeTypes is a standard hash and not an immutable collection

@@ -119,0 +146,0 @@ function createShapeTypeChecker(shapeTypes) {

8

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

@@ -41,6 +41,6 @@ "main": "dist/ImmutablePropTypes.js",

"istanbul": "~0.3.7",
"mocha": "^2.0.1",
"react": "0.14.0-beta3",
"react-dom": "^0.14.0-beta3"
"mocha": "^2.3.3",
"react": "^0.14.0",
"react-dom": "^0.14.0"
}
}

@@ -57,2 +57,3 @@ # react-immutable-proptypes

ImmutablePropTypes.iterable // Immutable.Iterable.isIterable
ImmutablePropTypes.record // instanceof Record

@@ -67,2 +68,11 @@ * `ImmutablePropTypes.listOf` is based on `React.PropTypes.array` and is specific to `Immutable.List`.

* `ImmutablePropTypes.recordOf` is like `contains`, except it operates on Record properties.
// ...
aRecord: ImmutablePropTypes.recordOf({
keyA: React.PropTypes.string,
keyB: ImmutablePropTypes.list.isRequired
})
// ...
* `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`.

@@ -69,0 +79,0 @@

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

iterableOf: createIterableOfTypeChecker,
recordOf: createRecordOfTypeChecker,
shape: createShapeTypeChecker,

@@ -27,2 +28,3 @@ contains: createShapeTypeChecker,

seq: createImmutableTypeChecker('Seq', Immutable.Seq.isSeq),
record: createImmutableTypeChecker('Record', function(isRecord) { return isRecord instanceof Immutable.Record; }),
iterable: createImmutableTypeChecker('Iterable', Immutable.Iterable.isIterable)

@@ -127,2 +129,28 @@ };

function createRecordOfTypeChecker(recordKeys) {
function validate(props, propName, componentName, location) {
var propValue = props[propName];
var propType = getPropType(propValue);
if (!(propValue instanceof Immutable.Record)) {
var locationName = location;
return new Error(
`Invalid ${locationName} \`${propName}\` of type \`${propType}\` ` +
`supplied to \`${componentName}\`, expected an Immutable.js Record.`
);
}
for (var key in recordKeys) {
var checker = recordKeys[key];
if (!checker) {
continue;
}
var mutablePropValue = propValue.toObject();
var error = checker(mutablePropValue, key, componentName, location);
if (error) {
return error;
}
}
}
return createChainableTypeChecker(validate);
}
// there is some irony in the fact that shapeTypes is a standard hash and not an immutable collection

@@ -129,0 +157,0 @@ function createShapeTypeChecker(shapeTypes) {

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc