Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@dhis2/prop-types
Advanced tools
This package contains common prop types used across dhis2 apps and libraries.
This package contains common prop types used across dhis2 apps and libraries.
yarn add @dhis2/prop-types
Error
| null
Ensure the prop value is an array with a length between a minimum and maximum.
If a third propType
argument is passed each item in the array needs to be of that prop-type
Error
| null
Conditionally determines a prop type bases on the passed props
Error
| null
Ensure the prop value is an instance of a certain component
Error
| null
Ensure that only one property within a specified list is thruthy This function will also check if the current property value is of the specified type
Error
| null
Ensure the prop has a value (i.e. treat it as required) when a given sibling prop also has a value, and ensure the prop is of the correct prop-type
Error
| null
Ensure the prop value is an array with a length between a minimum and maximum.
If a third propType
argument is passed each item in the array needs to be of that prop-type
Kind: global function
Returns: Error
| null
- Returns null if all conditions are met, or an error
Param | Type | Default | Description |
---|---|---|---|
[min] | number | 0 | The minimal array length |
[max] | number | Infinity | The maximal array length |
[propType] | function | The prop-type that each array item needs to conform to |
Example
import React from 'react'
import { arrayWithLength } from '@dhis2/prop-types'
const LotsOfLists = (props) => <div {...props}>Does nothing</div>
LotsOfLists.propTypes = {
arrayWithMaxThreeNumbers: arrayWithLength(0, 3, propTypes.number),
arrayWithAtLeastSixStrings: arrayWithLength(6, undefined, propTypes.string),
arrayWithAtLeastTenItems: arrayWithLength(10),
mandatoryArrayBetweenOneAndTen: arrayWithLength(1, 10).isRequired,
}
Error
| null
Determine the prop type of a prop by the value(s) of a/several passed prop(s).
This will restrict the propType in contrast to oneOfType
.
Kind: global function
Returns: Error
| null
- Returns null if all conditions are met, or an error
Param | Type | Default | Description |
---|---|---|---|
propsToPropType | Function | The function that will determine the actual prop type |
Example
import React from 'react'
import { conditional } from '@dhis2/prop-types'
const Select = ({ multiple, selected: _selected, options }) => {
const selected = multiple ? _selected : [ _selected ]
return (
// ...
)
}
const option = propTypes.shape({
value: propTypes.string.isReuqired,
labe: propTypes.string.isReuqired,
})
LotsOfLists.propTypes = {
// ...
options: propTypes.arrayOf(option).isRequired,
selected: conditional(
props => props.multiple ? propTypes.arrayOf(option) : option
).isRequired,
// ...
}
Error
| null
Ensure the prop value is an instance of a certain component
Kind: global function
Returns: Error
| null
- Returns null if all conditions are met, or an error
Param | Type | Description |
---|---|---|
Component | function | string | The component that is expected. Can either be a React component, or a string for built-in components, such as 'span', 'div', etc. |
Example
import React from 'react'
import { instanceOfComponent } from '@dhis2/prop-types'
import { Button } from './Button'
const ButtonWrap = ({ children }) => <div>{children}</div>
// This would allow the ButtonWrap to be empty
ButtonWrap.propTypes = {
children: instanceOfComponent(Button),
}
// Enforce presence of a Button instance
ButtonWrap.propTypes = {
children: instanceOfComponent(Button).isRequired,
}
// Enforce presence of a multiple children, all Button instances
ButtonWrap.propTypes = {
children: proptypes.arrayOf(instanceOfComponent(Button)).isRequired,
}
Error
| null
Ensure that only one property within a specified list is thruthy This function will also check if the current property value is of the specified type
Kind: global function
Returns: Error
| null
- Returns null if all conditions are met, or an error
Param | Type | Description |
---|---|---|
exlusivePropNames | array.<string> | The prop names to be checked |
propType | function | The prop-type that the current prop-value needs to conform to |
Example
import React from 'react'
import cx from 'classnames'
import propTypes from 'prop-types'
import { mutuallyExclusive } from '@dhis2/prop-types'
const Alert = ({ danger, warning, success, children }) => (
<div className={cx({ danger, warning, success })}>{children}</div>
)
const statusPropType = mutuallyExclusive(
['danger', 'warning', 'success'],
propTypes.bool
)
Alert.propTypes = {
children: propTypes.node,
danger: statusPropType,
warning: statusPropType,
success: statusPropType,
}
Error
| null
Ensure the prop has a value (i.e. treat it as required) when a given sibling prop also has a value, and ensure the prop is of the correct prop-type
Kind: global function
Returns: Error
| null
- Returns null if all conditions are met, or an error
Param | Type | Description |
---|---|---|
siblingPropName | function | The name of the sibling prop |
Example
import React from 'react'
import { requiredIf } from '@dhis2/prop-types'
const Test = ({ someBool, someString }) => (
<div>
<h1>someBool: {someBool ? 'true' : 'false'}</h1>
<h1>someString: {someString}</h1>
</div>
)
Test.propTypes = {
someBool: propTypes.bool,
someString: requiredIf((props) => props.someBool, propTypes.string),
}
@dhis2/prop-types
V3@dhis2/prop-types
previously had a direct dependency on the prop-types
library and also re-exported its exports:
PropTypes
exportprop-types
package anymore. Instead we simply expose our own custom prop-types functions as named exports.These are the steps to take:
yarn upgrade @dhis2/prop-types --latest
. Ensure the package.json
has an entry for "@dhis2/prop-types": "^3.x.x"
@dhis2/cli
is installed.d2 utils codemod list
You should see @dhis2/prop-types:prop-types-v1-v3.js
listed.d2 utils codemod apply @dhis2/prop-types:prop-types-v1-v3.js **/*.js`
prop-types
package is listed as a regular dependency in package.json
.@dhis2/prop-types
(doing a global search for from '@dhis2/prop-types'
will do the trick).
@dhis2/prop-types
dependency should be removed.No codemod is available to transform the component files, but this should be fairly straightforward:
import { PropTypes } from '@dhis2/prop-types'
with import PropTypes from 'prop-types'
.@dhis2/prop-types
, then probably these are actually using DHIS2 custom prop-types and these files should be addressed individually.Once the component files have been updated, the dependencies in package.json
need to be updated in eaxtly the same way as illustrated in step 3 and 4 of the v1 -> 3 migration section.
The issue tracker can be found in DHIS2 JIRA under the LIBS project.
Deep links:
FAQs
This package contains common prop types used across dhis2 apps and libraries.
The npm package @dhis2/prop-types receives a total of 2,463 weekly downloads. As such, @dhis2/prop-types popularity was classified as popular.
We found that @dhis2/prop-types demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.