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

validator-runner

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validator-runner

Validate form asynchronous

  • 0.1.0
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

validator-runner

async form validator runner

Install

yarn add validator-runner

Usage

define descriptor => passing the descriptor => add callback

import Validator from 'validator-runner';

const descriptor = {
    name: [
        {
            validator: name => name,
            message: 'Please input something!',
        },
        {
        validator(name) {
            return new Promise((res, rej) => {
                setTimeout(() => {
                   name === 'loading' ? res(name) : rej(name);
                }, 0);
            });
        },
        message: name => `"${name}" is not my name!`,
        },
    ],
    birth: {
        validator(date) {
            return date === '1995';
        },
        message: 'Wrong Date!',
    },
};
const validator = new Validator(descriptor);
validator.validateItem({ name: 'loading' }, 'name').then(data => {
    // data:
    //    errors: an array of errors
    //    rule: the validation object that executed last
});
// or
validator.validateItem({ name: 'loading' }, 'name', (errors, data) => {
    // errors: an array of errors
    // data:
    //    errors: an array of errors
    //    rule: the validation object that executed last
});

⚠️⚠️⚠️

Note: All sync validators will be transformed to promises internally.

Apis

validateItem

validateItem(source, fieldName, callback, options = { traversal: false, retention: false, concurrent: false },customFieldDescriptor)

Arguments
  • source: object The data to validate
  • fieldName: string The name of field to validate
  • callback: function(errors, data)
  • option: object

option.traversal If true, every field will not stop validation at first failed rule

option.retention If true, the last pending validation will be not covered when a new validation begins

option.concurrent if true, all validator will be executed at the same time

Return
  • promise: A promise that will be rejected if the validation fail

validate

validate(source, callback, specificField, options = { traversal: false, retention: false, concurrent: false },customFieldDescriptor)

Arguments
  • source: object The data to validate
  • callback: function(errors, data)
  • specificField: array The names of field to validate. If null, all fields will be validated.
  • option: object
Return
  • promise: A promise that will be rejected if the validation fail

Keywords

FAQs

Package last updated on 26 Apr 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

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