Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
prop-type-conditionals
Advanced tools
A React PropType utility library that consists of various custom proptype validators.
$ npm install --save prop-type-conditionals
You may import the individual validators as needed or you can import the entire module:
// Import individual validator
import { isValidIf } from 'prop-type-conditionals'
// Import entire module
import conditionals from 'prop-type-conditionals'
isAllowedIfNone
Returns a function that validates that the prop is not defined if any of the exclusive props are already defined. The .isRequired
chained validator specifies that the prop is required if none of the exclusive props are defined.
@param {Array[String]} exclusivePropNames
@param {PropTypes.validator} validator
import { isAllowedIfNone } from 'prop-type-conditionals'
Component.propTypes = {
foo: PropTypes.string,
bar: PropTypes.string,
baz: isAllowedIfNone(['foo', 'bar'], PropTypes.string),
}
isOneOfType
Returns a function that validates that the prop's type matches one of the component constructors or element type specified. If this validator is used on the children
prop, it validates that all child components pass validation.
@param {Array} allowedTypes
import { isOneOfType } from 'prop-type-conditionals'
import Foo from 'components/foo'
import Bar from 'components/bar'
Component.propTypes = {
children: isOneOfType([Foo, Bar])
}
isRequiredIf
Returns a function that validates that a prop is required if the condition function returns true
.
@param {Function} condition
@param {Function} validator
import { isRequiredIf } from 'prop-type-conditionals'
const condition = (props, propName) => true
Component.propTypes = {
foo: isRequiredIf(condition, PropTypes.string)
}
isValidIf
Returns a function that validates that the prop passes the user defined condition.
@param {Function} condition
@param {PropTypes.validator} defaultValidator
import { isValidIf } from 'prop-type-conditionals'
const condition = (props, propName) => true
Component.propTypes = {
foo: isValidIf(condition, PropTypes.string)
}
isWholeNumber
Returns a function that validates that the prop is a whole number
import { isWholeNumber } from 'prop-type-conditionals'
Component.propTypes = {
foo: isWholeNumber()
}
FAQs
React proptype utility library
We found that prop-type-conditionals demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.