Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

check-prop-types

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-prop-types - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

13

index.js

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

/**
* Same as checkPropTypes but throws on error
*/
function assertPropTypes() {
if (process.env.NODE_ENV !== 'production') {
var error = checkPropTypes.apply(null, arguments);
if (error) {
throw new Error(error);
}
}
}
module.exports = checkPropTypes;
module.exports.assertPropTypes = assertPropTypes;

6

package.json
{
"name": "check-prop-types",
"version": "1.0.0",
"version": "1.1.0",
"description": "Check PropTypes, returning errors instead of logging them",

@@ -16,2 +16,6 @@ "main": "index.js",

"author": "uniphil",
"repository": {
"type": "git",
"url": "git@github.com:ratehub/check-prop-types.git"
},
"license": "MIT",

@@ -18,0 +22,0 @@ "devDependencies": {

@@ -38,2 +38,25 @@ # checkPropTypes

### assertPropTypes
To throw errors instead of returning them, a helper called `assertPropTypes` is included:
```js
import PropTypes from 'prop-types';
import { assertPropTypes } from 'check-prop-types';
const HelloComponent = ({ name }) => (
<h1>Hi, {name}</h1>
);
HelloComponent.propTypes = {
name: PropTypes.string.isRequired,
};
assertPropTypes(HelloComponent.propTypes, { name: 'Julia' }, 'prop', HelloComponent.name);
// fine...
assertPropTypes(HelloComponent.propTypes, { name: 123 }, 'prop', HelloComponent.name);
// throws Error: Failed prop type: Invalid prop `name` of type `number` supplied to `HelloComponent`, expected `string`.
```
See [test.js](./test.js) for more usage examples.

@@ -42,1 +42,14 @@ const test = require('tape');

});
test('assertPropTypes throws instead of returning error', function(assert) {
var assertPropTypes = checkPropTypes.assertPropTypes;
assert.plan(2);
assert.doesNotThrow(function() {
assertPropTypes({x: PropTypes.number}, {x: 1}, 'prop', 'c');
});
assert.throws(function() {
assertPropTypes({x: PropTypes.number}, {x: ''}, 'prop', 'c');
});
});
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