Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

validate-prop-types

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validate-prop-types

Validate React Prop Types, return errors as an object.

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
40
-48.05%
Maintainers
1
Weekly downloads
 
Created
Source

Validate Prop Types

This package is a modified version of PropTypes.checkPropTypes(), the difference being that it returns errors as an object instead of issuing a console.error.

ExampleComponent.js

const PropTypes = require('prop-types')
const ExampleComponent = () => 'hello'

ExampleComponent.propTypes = {
  a: PropTypes.string.isRequired,
  b: PropTypes.number,
  c: PropTypes.object
}

ExampleComponent.test.js

const assert = require('assert')
const validatePropTypes = require('validate-prop-types')
const ExampleComponent = require('./ExampleComponent')

const data = {
  b: 'a string',
  c: 'another string'
}

assert.deepEqual(validatePropTypes(ExampleComponent.propTypes, data), {
  a: 'The prop `a` is marked as required in `Component`, but its value is `undefined`.',
  b: 'Invalid prop `b` of type `string` supplied to `Component`, expected `number`.',
  c: 'Invalid prop `c` of type `string` supplied to `Component`, expected `object`.'
})

FAQs

Package last updated on 06 Jun 2018

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