Skip to content

Latest commit

 

History

History
25 lines (18 loc) · 1.16 KB

README.md

File metadata and controls

25 lines (18 loc) · 1.16 KB

DOI Prop Type

Build npm GitHub

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
};