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

async-validate

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-validate - npm Package Compare versions

Comparing version 0.4.16 to 0.5.1

89

lib/schema.js

@@ -25,3 +25,2 @@ var iterator = require('./iterator')

this.rules = {};
this.keys = [];

@@ -52,35 +51,2 @@ var z, item;

/**
* Collates the errors arrays and maps field names to errors
* specific to the field.
*/
function complete(results, options, callback) {
var i
, field
, errors = []
, fields = {};
for(i = 0;i < results.length;i++) {
errors = errors.concat(results[i]);
}
if(!errors.length) {
errors = null, fields = null;
}else{
if(options.single) {
errors = errors.slice(0,1);
}
for(i = 0;i < errors.length;i++) {
field = errors[i].field;
fields[field] = fields[field] || [];
fields[field].push(errors[i]);
}
}
// clean up flags
delete options._root;
callback(errors, fields);
}
/**
* Validate an object against this schema.

@@ -124,3 +90,3 @@ *

keys = options.keys || Object.keys(this.rules);
keys = options.keys || this.keys;

@@ -256,2 +222,7 @@ // iterator function series/parallel

/**
* @private
*
* Get a validator with public fields.
*/
function getValidationOptions(rule, options) {

@@ -263,3 +234,2 @@ return Validator({

source: rule.source,
data: options.data,
errors: [],

@@ -272,4 +242,6 @@ options: options,

/**
* Infer the type of a rule when necessary.
* @private
*
* Infer the type of a rule.
*
* @param rule The validation rule.

@@ -283,2 +255,3 @@ */

// handle instanceof tests for object type
if(typeof rule.type === 'function') {

@@ -298,4 +271,6 @@ rule.Type = rule.type;

/**
* Retrieve a validation method from a rule.
* @private
*
* Retrieve a validation method for a rule.
*
* @param rule The validation rule.

@@ -312,2 +287,40 @@ */

/**
* @private
*
* Collates the errors arrays and maps field names to errors
* specific to the field.
*
* Invokes callback when done.
*/
function complete(results, options, callback) {
var i
, field
, errors = []
, fields = {};
for(i = 0;i < results.length;i++) {
errors = errors.concat(results[i]);
}
if(!errors.length) {
errors = null, fields = null;
}else{
if(options.single) {
errors = errors.slice(0,1);
}
for(i = 0;i < errors.length;i++) {
field = errors[i].field;
fields[field] = fields[field] || [];
fields[field].push(errors[i]);
}
}
// clean up flags
delete options._root;
callback(errors, fields);
}
/**
* Clone helper function.

@@ -314,0 +327,0 @@ */

{
"name": "async-validate",
"description": "Asynchronous validation for object properties.",
"version": "0.4.16",
"version": "0.5.1",
"author": "muji <noop@xpm.io>",

@@ -73,3 +73,2 @@ "license": "MIT",

"inc": [
"standard-rules.md",
"api.md",

@@ -76,0 +75,0 @@ "developer.md",

@@ -31,3 +31,2 @@ Table of Contents

* [Transform](#transform)
* [Standard Rules](#standard-rules)
* [API](#api)

@@ -480,13 +479,2 @@ * [Schema](#schema)

### Standard Rules
Some standard rules for common validation requirements are accessible, you may wish to reference these rules or copy and modify them.
These rules must be required to be used: `require('async-validate/std-rules')`, see [std rules](https://github.com/freeformsystems/async-validate/blob/master/std-rules.js).
* `field`: Typical required field.
* `email`: Basic email validation rule using a pattern, note validating email addresses with a regular expression is [fraught with pitfalls](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address/201378#201378), use this with caution.
* `url`: Simple http(s) URL rule.
* `hex`: Rule for hexadecimal color values with optional leading hash.
### API

@@ -493,0 +481,0 @@

@@ -1,4 +0,4 @@

var assert = require('chai').assert;
var schema = require('../../index');
var std = require('../../std-rules')
var assert = require('chai').assert
, schema = require('../../index')
, email = /^.+@.+\..+/;

@@ -10,3 +10,3 @@ describe("async-validate:", function(done) {

{type: "string", required: true},
{pattern: std.pattern.email, required: true}
{pattern: email, required: true}
]

@@ -19,4 +19,3 @@ }

assert.equal(errors[1].message,
"email value undefined does not match pattern "
+ std.pattern.email);
"email value undefined does not match pattern " + email);
done();

@@ -29,3 +28,3 @@ });

{type: "string", required: true},
{pattern: std.pattern.email}
{pattern: email}
]

@@ -37,4 +36,3 @@ }

assert.equal(errors[0].message,
"email value user@example does not match pattern "
+ std.pattern.email);
"email value user@example does not match pattern " + email);
done();

@@ -46,3 +44,3 @@ });

email: [
std.email,
{type: 'string', pattern: email, required: true},
function(cb) {

@@ -49,0 +47,0 @@ var email = "user@example.com";

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