New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

deku-prop-types

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deku-prop-types - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

30

lib/validate.js
'use strict';
/**
* Warns of missing propTypes
* @param {Object} propTypes - an object with values being checkers
* @param {Object} props - an object to check for missing propTypes
* @param {Number} warningLevel - should warn when missing propType discovered
* 0 - do not warn
* 1 - console.warn
*/
var warnOfMissingPropTypes = function warnOfMissingPropTypes(propTypes, props, warningLevel) {
if (!warningLevel) {
return;
}
var propTypeKeys = Object.keys(propTypes);
var propsKeys = Object.keys(props);
propsKeys.filter(function (prop) {
return propTypeKeys.indexOf(prop) === -1;
}).forEach(function (missingProp) {
console.warn('Missing `' + missingProp + '` propType');
});
};
/**
* Determine if the props are valid

@@ -11,3 +34,3 @@ * @param {Object} propTypes - an object with values being checkers

Object.keys(propTypes).forEach(function (key) {
var result = undefined;
var result = void 0;
if (typeof propTypes[key] === 'function') {

@@ -28,5 +51,8 @@ result = propTypes[key](props, key);

* @param {Function|Object} component - the component to add validation to
* @param {Number} [warningLevel=1] - should warn when missing propType discovered
* @return {Function|Object} -the modified component with validation added
*/
module.exports = function (component) {
var warningLevel = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1];
/* eslint-disable no-process-env */

@@ -39,2 +65,3 @@ if (process.env.NODE_ENV === 'production') {

return function (model) {
warnOfMissingPropTypes(component.propTypes, model.props, warningLevel);
validate(component.propTypes, model.props);

@@ -48,2 +75,3 @@ return component(model);

render: function render(model) {
warnOfMissingPropTypes(component.propTypes, model.props, warningLevel);
validate(component.propTypes, model.props);

@@ -50,0 +78,0 @@ return component.render(model);

13

package.json
{
"name": "deku-prop-types",
"version": "0.3.2",
"version": "0.4.0",
"description": "Prop type validation for Deku components",

@@ -24,12 +24,13 @@ "main": "lib/index.js",

"devDependencies": {
"ava": "^0.11.0",
"austin": "^0.1.1",
"ava": "^0.13.0",
"babel-cli": "^6.4.0",
"babel-eslint": "^5.0.0-beta6",
"babel-eslint": "^6.0.0-beta.6",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.4.3",
"coveralls": "^2.11.6",
"eslint": "^1.10.3",
"eslint-config-dustinspecker": "^0.3.1",
"eslint": "^2.4.0",
"eslint-config-dustinspecker": "^0.4.0",
"eslint-plugin-no-use-extend-native": "^0.3.4",
"nyc": "^5.3.0"
"nyc": "^6.0.0"
},

@@ -36,0 +37,0 @@ "ava": {

@@ -219,3 +219,3 @@ # deku-prop-types

## API
### validate(component)
### validate(component, [warningLevel])
#### component

@@ -226,3 +226,16 @@ type: `function` | `object`

#### warningLevel
type: `number`
default: 1
If a missing propType is discovered, validate will by default log a warning. This functionality may be configured.
`0` - Do not warn or throw error
`1` - Log a warning
`2` - Throw an error
## License
MIT © [Dustin Specker](https://github.com/dustinspecker)
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