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

@dhis2/prop-types

Package Overview
Dependencies
Maintainers
14
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dhis2/prop-types - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

build/cjs/__tests__/arrayWithLength.test.js

19

build/cjs/arrayWithLength.js

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

return function (props, propSelector, // normally a propName, but when wrapped in arrayOf an index
componentName, _location, propFullName // normally null but a string like "propName[index]" when wrapped in arrayOf
componentName, location, propFullName // normally null but a string like "propName[index]" when wrapped in arrayOf
) {

@@ -28,2 +28,3 @@ var arr = props[propSelector];

var baseMsg = "Invalid prop `".concat(propName, "` supplied to `").concat(componentName, "`,");
var insideArrayOf = !!propFullName;

@@ -47,7 +48,15 @@ if (isRequired && typeof arr === 'undefined') {

if (arr && propType) {
var len = arr.length;
var checkPropName = insideArrayOf ? location : propName;
var checkPropType = insideArrayOf ? // array should be array containing only the given type
_propTypes.default.arrayOf(_propTypes.default.arrayOf(propType)) : // array should contain only the given type
_propTypes.default.arrayOf(propType);
for (var i = 0; i < len; i++) {
_propTypes.default.checkPropTypes(_defineProperty({}, i, propType), arr, propName, componentName);
}
var checkPropTypes = _defineProperty({}, checkPropName, checkPropType);
var checkProps = insideArrayOf ? _defineProperty({}, location, props) : props; // When not inside an array, the error message only reads correctly
// when using "prop"
var checkProp = insideArrayOf ? propName : 'prop';
_propTypes.default.checkPropTypes(checkPropTypes, checkProps, checkProp, componentName);
}

@@ -54,0 +63,0 @@

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

var expectedComponentName = typeof Component === 'string' ? Component : Component.name || Component.displayName;
var foundComponentName = typeof child.type !== 'string' ? child.type : child.type && (child.type.name || child.type.displayName);
var foundComponentName = typeof child.type !== 'string' ? child.type && child.type.name ? child.type.name : child.type : child.type && (child.type.name || child.type.displayName);

@@ -33,0 +33,0 @@ if (!foundComponentName) {

@@ -15,7 +15,5 @@ "use strict";

var mutuallyExclusiveFactory = function mutuallyExclusiveFactory(exlusivePropNames, propType, isRequired) {
return function (props, propSelector, // normally a propName, but when wrapped in arrayOf an index
componentName, _location, propFullName // normally null but a string like "propName[index]" when wrapped in arrayOf
) {
var propName = propFullName || propSelector;
var baseMsg = "Invalid prop `".concat(propName, "` supplied to `").concat(componentName, "`,"); // Usage errors
return function (props, propName, componentName) {
var baseMsg = "Invalid prop `".concat(propName, "` supplied to `").concat(componentName, "`,");
var isDefined = typeof props[propName] !== 'undefined'; // Usage errors

@@ -27,3 +25,3 @@ if (exlusivePropNames.length === 0) {

if (isRequired && typeof props[propName] === 'undefined') {
if (isRequired && !isDefined) {
return new Error("".concat(baseMsg, " this prop is required but no value was found."));

@@ -34,3 +32,3 @@ } // This is how to programatically invoke a propTypes check

_propTypes.default.checkPropTypes(_defineProperty({}, propName, propType), props, propName, componentName);
_propTypes.default.checkPropTypes(_defineProperty({}, propName, propType), props, 'prop', componentName);

@@ -37,0 +35,0 @@ if (props[propName]) {

@@ -19,7 +19,4 @@ "use strict";

var requiredIfFactory = function requiredIfFactory(condition, propType, isRequired) {
return function (props, propSelector, // normally a propName, but when wrapped in arrayOf an index
componentName, _location, propFullName // normally null but a string like "propName[index]" when wrapped in arrayOf
) {
var propName = propFullName || propSelector;
var propValue = props[propSelector]; // Usage errors
return function (props, propName, componentName) {
var propValue = props[propName]; // Usage errors

@@ -45,3 +42,3 @@ if (isRequired) {

_propTypes.default.checkPropTypes(_defineProperty({}, propName, propType), props, propName, componentName);
_propTypes.default.checkPropTypes(_defineProperty({}, propName, propType), props, 'prop', componentName);

@@ -48,0 +45,0 @@ return null;

@@ -9,3 +9,3 @@ import propTypes from 'prop-types';

}) => (props, propSelector, // normally a propName, but when wrapped in arrayOf an index
componentName, _location, propFullName // normally null but a string like "propName[index]" when wrapped in arrayOf
componentName, location, propFullName // normally null but a string like "propName[index]" when wrapped in arrayOf
) => {

@@ -15,2 +15,3 @@ const arr = props[propSelector];

const baseMsg = `Invalid prop \`${propName}\` supplied to \`${componentName}\`,`;
const insideArrayOf = !!propFullName;

@@ -34,9 +35,16 @@ if (isRequired && typeof arr === 'undefined') {

if (arr && propType) {
const len = arr.length;
const checkPropName = insideArrayOf ? location : propName;
const checkPropType = insideArrayOf ? // array should be array containing only the given type
propTypes.arrayOf(propTypes.arrayOf(propType)) : // array should contain only the given type
propTypes.arrayOf(propType);
const checkPropTypes = {
[checkPropName]: checkPropType
};
const checkProps = insideArrayOf ? {
[location]: props
} : props; // When not inside an array, the error message only reads correctly
// when using "prop"
for (let i = 0; i < len; i++) {
propTypes.checkPropTypes({
[i]: propType
}, arr, propName, componentName);
}
const checkProp = insideArrayOf ? propName : 'prop';
propTypes.checkPropTypes(checkPropTypes, checkProps, checkProp, componentName);
}

@@ -43,0 +51,0 @@

@@ -22,3 +22,3 @@ const instanceOfComponentFactory = (Component, isRequired) => (props, propSelector, // normally a propName, but when wrapped in arrayOf an index

const expectedComponentName = typeof Component === 'string' ? Component : Component.name || Component.displayName;
const foundComponentName = typeof child.type !== 'string' ? child.type : child.type && (child.type.name || child.type.displayName);
const foundComponentName = typeof child.type !== 'string' ? child.type && child.type.name ? child.type.name : child.type : child.type && (child.type.name || child.type.displayName);

@@ -25,0 +25,0 @@ if (!foundComponentName) {

import propTypes from 'prop-types';
const mutuallyExclusiveFactory = (exlusivePropNames, propType, isRequired) => (props, propSelector, // normally a propName, but when wrapped in arrayOf an index
componentName, _location, propFullName // normally null but a string like "propName[index]" when wrapped in arrayOf
) => {
const propName = propFullName || propSelector;
const baseMsg = `Invalid prop \`${propName}\` supplied to \`${componentName}\`,`; // Usage errors
const mutuallyExclusiveFactory = (exlusivePropNames, propType, isRequired) => (props, propName, componentName) => {
const baseMsg = `Invalid prop \`${propName}\` supplied to \`${componentName}\`,`;
const isDefined = typeof props[propName] !== 'undefined'; // Usage errors

@@ -14,3 +12,3 @@ if (exlusivePropNames.length === 0) {

if (isRequired && typeof props[propName] === 'undefined') {
if (isRequired && !isDefined) {
return new Error(`${baseMsg} this prop is required but no value was found.`);

@@ -23,3 +21,3 @@ } // This is how to programatically invoke a propTypes check

[propName]: propType
}, props, propName, componentName);
}, props, 'prop', componentName);

@@ -26,0 +24,0 @@ if (props[propName]) {

@@ -5,7 +5,4 @@ import propTypes from 'prop-types';

const requiredIfFactory = (condition, propType, isRequired) => (props, propSelector, // normally a propName, but when wrapped in arrayOf an index
componentName, _location, propFullName // normally null but a string like "propName[index]" when wrapped in arrayOf
) => {
const propName = propFullName || propSelector;
const propValue = props[propSelector]; // Usage errors
const requiredIfFactory = (condition, propType, isRequired) => (props, propName, componentName) => {
const propValue = props[propName]; // Usage errors

@@ -33,3 +30,3 @@ if (isRequired) {

[propName]: propType
}, props, propName, componentName);
}, props, 'prop', componentName);
return null;

@@ -36,0 +33,0 @@ };

@@ -0,1 +1,14 @@

# [1.5.0](https://github.com/dhis2/prop-types/compare/v1.4.0...v1.5.0) (2019-12-04)
### Bug Fixes
* **array with length:** check prop type correctly & fix error message ([c465743](https://github.com/dhis2/prop-types/commit/c465743b535223549151b35560f7975b222edaaf))
* **required if:** remove duplicate prop name from error message ([f9f44b0](https://github.com/dhis2/prop-types/commit/f9f44b067d354a10fe28b89563cb0155cce649cc))
### Features
* **instance of component:** display name instead of the function body ([ede4312](https://github.com/dhis2/prop-types/commit/ede43124f83b10dd3d28e264ccbf7839a83fcad8))
# [1.4.0](https://github.com/dhis2/prop-types/compare/v1.3.0...v1.4.0) (2019-11-21)

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

{
"name": "@dhis2/prop-types",
"version": "1.4.0",
"version": "1.5.0",
"main": "./build/cjs/index.js",

@@ -15,4 +15,5 @@ "module": "./build/es/index.js",

"scripts": {
"test": "jest",
"docs": "jsdoc2md -t jsdoc2md/README.hbs src/*.js > README.md; echo",
"prebuild": "rm -rf ./build/**",
"prebuild": "rm -rf ./build/** && yarn test",
"build:commonjs": "BABEL_ENV=commonjs babel src --out-dir ./build/cjs --copy-files --verbose",

@@ -27,8 +28,12 @@ "build:modules": "BABEL_ENV=modules babel src --out-dir ./build/es --copy-files --verbose",

"devDependencies": {
"@babel/cli": "^7.7.0",
"@babel/core": "^7.7.2",
"@babel/preset-env": "^7.7.1",
"@dhis2/cli-style": "4.2.0",
"@babel/cli": "^7.7.4",
"@babel/core": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"@babel/preset-react": "^7.7.4",
"@dhis2/cli-style": "5.0.3",
"babel-eslint": "^10.0.3",
"jsdoc-to-markdown": "^5.0.2"
"jest": "^24.9.0",
"jsdoc-to-markdown": "^5.0.3",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},

@@ -35,0 +40,0 @@ "peerDependencies": {

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