doi-prop-type
v1.1.0
Published
React Prop Types DOI Validator
Downloads
6
Readme
DOI Prop Type
This package is used to validate if a React Prop value is a valid DOI, e.g. 10.11647/obp.0229
. To do so we compare the input against this regex: /^10.\d{4,9}\/[-._\;\(\)\/:a-zA-Z0-9]+$/g
.
The prop-types
package does not support a DOI prop type, therefore you can use this package to validate them, instead of using the permissive PropType.string
.
Installation
npm install --save doi-prop-type
Example Usage
import React from 'react';
import doiPropType from 'doi-prop-type';
// Create a generic component
const Doi = props => ( <a href={`https://doi.org/${props.doi}`}>{props.doi}</a> );
Doi.propTypes = {
doi: doiPropType.isRequired, // can also specify doiPropType if it is not required
};