Neanderthals Paint Mammals

    props-validator

    0.1.0 • Public • Published

    props-validator

    React Props Validators 🏥

    Installation

    npm i props-validator

    or

    yarn add props-validator

    Usage

    Importing

    Either

    import { isLength } from 'props-validator';

    or

    const { isLength } = require('props-validator');

    Implementation

    ...
     
    MyReactComponent.propTypes = {
      name: isLength(5) // checks for the length of the prop value
    }
     
    ...

    Validators

    Validator Description Example
    isLength(max, min) matches the length isLength(5, 1)

    Options

    All the validators accepts options as the last argument. Options include -

    param description
    errorMessage Error message to show on failure

    Example

    ...
     
    MyReactComponent.propTypes = {
      name: isLength(5, 1, {
        errorMessage: 'MyReactComponent accepts prop name of max and min length of 5, 1 respectively'
      })
    }
     
    ...

    TypeScript

    props-validator is not written in TypeScript, so while using it with TypeScript, you might face an error for missing type declaration file. Please add a global.d.ts file to your project and add this content to it

    declare module 'props-validator'

    Install

    npm i props-validator

    DownloadsWeekly Downloads

    7

    Version

    0.1.0

    License

    ISC

    Unpacked Size

    6.19 kB

    Total Files

    10

    Last publish

    Collaborators

    • maddhruv
    • cleartax