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

policeman

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

policeman

Lightweight yet powerful schema validator

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-57.14%
Maintainers
1
Weekly downloads
 
Created
Source

policeman

CircleCI

Lightweight yet powerful schema validator


API Docs | Examples


  • Validate objects based on provided schemas
  • Build with mappet

Installation (npm)

npm i -S policeman

Built-in validators

All built-in validator are curried.

isRequired(() => message, value)

Validates presence. Fails on null, empty string or undefined.

isMinLength(min, () => message, value)

Passed value must be a string longer or with length equal to min.

isMaxLength(max, () => message, value)

Passed value must be a string shorther or with length equal to max.

isEqualLength(equal, () => message, value)

Passed value must be a string shorther or with length equal to max.

isEmail(() => message, value)

Passed value must be a valid email. It's a simple check, if you need more complex solution use isMatching or isPassing.

isMatching(regexp, () => message, value)

Passed value must pass regexp.

isPassing(predicate, () => message, value)

Passed predicate answers on "Is value valid?". When predicate returns true validator passes, when predicate returns false error message is returned.

It makes policeman compatible with all available validators i.e. validator.

import validator from "validator";
import { isPassing } from "policeman";

const isCreditCard = isPassing(validator.isCreditCard, () => "is invalid credit card");
const isUUID4 = isPassing(value => validator.isUUID(value, 4), () => "is invalid UUID v4");
const isFTP = isPassing(value => validator.isURL(value, { protocols: ["ftp"] }, () => "is invalid FTP address");

See tests for more examples.

Examples

TODO

See tests for more examples.

Roadmap

  • Improve importing validators
  • Maybe (monad) error?

Keywords

FAQs

Package last updated on 21 Aug 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