New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

prop-types-plus

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prop-types-plus

Another library of custom PropType validators. It is greatly inspired by [`airbnb/prop-types`](https://github.com/airbnb/prop-types), which probably already offers the same custom types and more. I just wanted to create my own. 🙃

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

prop-types-plus

Another library of custom PropType validators. It is greatly inspired by airbnb/prop-types, which probably already offers the same custom types and more. I just wanted to create my own. 🙃

Installation

yarn add prop-types-plus

Validators

[!NOTE] Since PropTypes are only useful for developement, when NODE_ENV is set to production mock functions are exported instead of the real validators.

arrayOfShape

Validates the type of the entries in an array in the given order.

Signature

arrayOfShape(shape: PropTypes[])

Usage

import { string, number } from "prop-type";
import { arrayOfShape } from "prop-types-plus";

const propTypes = {
  foo: arrayOfShape([string, number.isRequired]),
  fooRequired: arrayOfShape([string, number.isRequired]).isRequired
};

requiredIf

Tests whether a prop is required based on a given condition.

Signature

requiredIf(
  type: PropTypes,
  condition: (props: object) => boolean,
  errorMessage?: string
)

Usage

import { string } from "prop-type";
import { requiredIf } from "prop-types-plus";

const propTypes = {
  foo: requiredIf(
    string,
    (props) => props.bar
    "The prop `foo` is required when there is `bar`."
  )
};

stringOfShape

Tests whether a string match the given regex.

Signature

stringOfShape(regex: RegExp)

Usage

import { stringOfShape } from "prop-types-plus";

const propTypes = {
  foo: stringOfShape(/^#.+/),
  fooRequired: stringOfShape(/^#.+/).isRequired
};

unnecessaryWhen

Tests whether a prop is unnecessary based on a given condition.

Signature

unnecessaryWhen(
  type: PropTypes,
  condition: (props: object) => boolean,
  errorMessage?: string
)

Usage

import { string } from "prop-type";
import { unnecessaryWhen } from "prop-types-plus";

const propTypes = {
  foo: requiredIf(
    string,
    (props) => props.bar
    "The prop `foo` is unnecessary when there is `bar`."
  )
};

Keywords

react

FAQs

Package last updated on 21 Feb 2024

Did you know?

Socket

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.

Install

Related posts