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

  • 2.1.0
  • latest
  • 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')

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

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

const requiredString = checkerFactory('string').isRequired

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

const evenNumberChecker = checkerFactory((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

const checkerWithName = checkerFactory('number', 'dog')
checkerWithName.name
// => 'dog'

API

checkerFactory(validator[, name])

Returns a CheckerFactory with an isRequired getter and validate function.

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.

name

type: string

This is an optional value to retrieve a name for the checker factory.

License

MIT © Dustin Specker

Keywords

FAQs

Package last updated on 03 Feb 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