New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@decisiv/prop-types

Package Overview
Dependencies
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@decisiv/prop-types

Decisiv's custom React PropType validators.

  • 1.6.6
  • npm
  • Socket score

Version published
Weekly downloads
21
decreased by-77.89%
Maintainers
3
Weekly downloads
 
Created
Source

PropTypes

This package exports a variety of useful proptype validators for use within the Key Design System.

Table of Contents

Installation

yarn add @decisiv/prop-types

Validators

forbiddenIf

Used inside of proptypes declaration object as the validator itself. Takes two arguments: a proptypes validator and a conditional. Allows you to conditionally forbid a prop value based on other props/ logic. The prop is forbidden if the condition returns true.

Example use:

import { forbiddenIf } from '@decisiv/prop-types';

const propTypes = {
  text: forbiddenIf(PropTypes.string, (props) => !!props.icon),
  icon: forbiddenIf(PropTypes.string, (props) => !!props.text),
};

YourComponent.propTypes = propTypes;

requireAllOrNoneOf

Takes an object containing valid proptypes. Will error if some props are defined, but not if either all or none of the props are defined.

Example use:

import { requireAllOrNoneOf } from '@decisiv/prop-types';

const propTypes = {
  action: PropTypes.string,
  actionIcon: PropTypes.string,
};

requireAllOfNoneOf(propTypes);

YourComponent.propTypes = propTypes;

requireAtLeastOneOf

Takes an object containing valid proptypes. Will error if none of the props are defined, but not if one or more are defined.

Example use:

import { requireAtLeastOneOf } from '@decisiv/prop-types';

const propTypes = {
  text: PropTypes.string,
  icon: PropTypes.string,
};

requireAtLeastOneOf(propTypes);

YourComponent.propTypes = propTypes;

requireIfDefined

Used to validate that one or more props are required if a different prop is defined.

Example use:

import { requireIfDefined } from '@decisiv/prop-types';

const propTypes = {
  text: PropTypes.string,
  icon: PropTypes.string,
};

requireIfDefined('foo', propTypes);

YourComponent.propTypes = propTypes;

requireIf

Used inside of proptypes declaration object as the validator itself. Takes two arguments: a proptypes validator and a function. Allows you to conditionally require a prop value based on other props/ logic. The prop is required if the condition return true.

Example use:

import { requireIf } from '@decisiv/prop-types';

const propTypes = {
  text: requireIf(PropTypes.string, (props) => !props.icon),
  icon: requireIf(PropTypes.string, (props) => !props.text),
};

YourComponent.propTypes = propTypes;

FAQs

Package last updated on 15 Nov 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc