Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

checker-factory

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

checker-factory

Checker Factory used by Deku Prop Type Validators

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Checker Factory

NPM version Build Status Coverage Status

Code Climate Dependencies DevDependencies

Checker Factory used by Deku Prop Type Validators

Install

npm install --save checker-factory

Usage

import checkerFactory from 'checker-factory'

const numberChecker = checkerFactory('number', 'number')

numberChecker.validate('hello', 'age')
// => TypeError: Expected age to be of type `number`, but got `string`

numberChecker.validate(3, 'age')
// => undefined

const requiredString = checkerFactory('string', 'string').isRequired

requiredString.validate(undefined, 'name')
// => Error: name is required

const evenNumberChecker = checkerFactory('evenNumber', (prop, key) => {
  if (prop % 2 === 1) {
    return new Error(`Expected ${key} to be an even number`)
  }
})

evenNumberChecker.validate(3, 'id')
// => Error: Expected id to be an even number

API

checkerFactory(name, validator)

Returns a CheckerFactory with an isRequired getter and validate function.

name

type: string

The name of the CheckerFactory. This name is how users will reference the checker. For example, a name of string will have users using propTypes.string.

validator

type: function | string

If validator is a string, then a typeof check will be performed. If validator is a function, then the function will be execution. The function is passed the prop value and the key name.

License

MIT © Dustin Specker

Keywords

FAQs

Package last updated on 24 Jan 2016

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