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

@clocklimited/validity-validate-if-set

Package Overview
Dependencies
Maintainers
7
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clocklimited/validity-validate-if-set

Validity validator which calls a subsequent validator if a value is truthy

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
85
increased by51.79%
Maintainers
7
Weekly downloads
 
Created
Source

validity-validate-if-set

Build Status

Validity validator which calls a subsequent validator if a value is truthy. E.g you have a URL property of a schema, which is not a required field. You only want to apply validation to that field if there is a value to validate.

Installation

npm install validity-validate-if-set --save

Usage

Below is a simple example for usage with schemata and save:

var validity = require('validity')
  , schemata = require('schemata')
  , save = require('save')
  , collection = save('author')
  , validateIfSet = require('validity-validate-if-set')

var schema = schemata(
    { url:
      { type: String
      , validators: { all: [ validateIfSet(validity.url) ] }
      }
    })

API

var validate = createValidator(Function: validityFunction)

Create a validate function by passing in the subsequent validator to be called if the value is set.

validate(String:key, String:keyDisplayName, Object:object, Function:cb)

This is a validity compatible function, which in turn is used by schemata for schema validation.

The callback signature cb(err, errorMessage).

err is an Error object if something bad happened and null otherwise. errorMessage is a String if a validation error happened and undefined otherwise.

Licence

Licensed under the New BSD License

Keywords

FAQs

Package last updated on 04 Apr 2022

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