🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

formalist-validation

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formalist-validation

Data validation library for Formalist based on predicate logic.

1.0.0
latest
Source
npm
Version published
Weekly downloads
335
142.75%
Maintainers
1
Weekly downloads
 
Created
Source

Formalist Validation

Data validation library for Formalist based on predicate logic.

The scope of the library is very simple. It tests a value against a given schema and returns an array of relevant error messages.

Usage

import validation from 'formalist-validation'

// Define a schema
const schema = {
  "filled": true,
  "min_size": 2,
  "max_size": 3,
}

// Curry validator with the schema
const validator = validation(schema)

// Test
validator([1])
// => ['size cannot be less than 2']
validator([1,2])
// => []
validator([1,2,3])
// => []
validator([1,2,3,4])
// => ['size cannot be greater than 3']

View the full list of available predicates to see what else you can test.

Caveats

  • Tests will only be run if there’s a value to test or the schema specifies that to test that the value is 'filled'.
  • All the predicate tests are run as logical ANDs. There’s no support for more complex logic at at the moment.

TODO

  • Allow custom validations to be injected
  • i18n support

FAQs

Package last updated on 23 Feb 2017

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