New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.1.5 to 0.1.6

85

lib/index.js

@@ -124,24 +124,43 @@ var util = require('util');

}
validator = function(callback) {
var data = arguments.callee.data;
var cb = function(errors) {
//delete data.rule.validator;
if(options.first) {
return complete(errors);
}
callback(null, errors);
series.push({rule: rule, value: value, source: source});
}
}
async.mapSeries( series, function(data, callback) {
var rule = data.rule;
var deep = (rule.type == 'object' || rule.type == 'array')
&& typeof(rule.fields) == 'object';
deep = deep && (rule.required || (!rule.required && data.value));
var cb = function(errors) {
if(options.first) {
return complete(errors);
}
if(!deep) {
callback(null, errors);
}else{
errors = errors || [];
// if rule is required but the target object
// does not exist fail at the rule level and don't
// go deeper
if(rule.required && !data.value) {
return callback(null, [
options.error(
rule, util.format(options.messages.required, rule.field))
]);
}
//console.log("calling validator with messages %s", messages);
data.rule.validator(
data.rule, data.value, cb, data.source, options);
var schema = new Schema(data.rule.fields);
schema.messages(options.messages);
if(data.rule.options) {
data.rule.options.messages = options.messages;
data.rule.options.exception = options.exception;
data.rule.options.error = options.error;
}
schema.validate(
data.value, data.rule.options || options, function(errs, fields) {
callback(null, errs && errs.length ? errors.concat(errs) : errs);
});
}
validator.data = {rule: rule, value: value, source: source};
series.push(validator);
if((rule.type == 'object' || rule.type == 'array')
&& typeof(rule.fields) == 'object') {
this.getDeepValidator(series, rule, value, options);
}
}
}
async.series(series, function(err, results) {
rule.validator(
rule, data.value, cb, data.source, options);
}, function(err, results) {
complete(results);

@@ -188,30 +207,2 @@ });

/**
* Handles creating deep validation rules.
*
* @param series The array of asynchronous functions.
* @param rule The validation rule.
* @param value The value on the source object.
* @param options The options passed to validate the object.
*
* @api private
*/
Schema.prototype.getDeepValidator = function(series, rule, value, options) {
if(value === undefined) {
return false;
}
var messages = this.messages();
var deep = function(callback) {
var data = arguments.callee.data;
var schema = new Schema(data.rule.fields);
schema.messages(messages);
schema.validate(
data.value, data.rule.options || data.options, function(errors, fields) {
callback(null, errors);
});
}
deep.data = {rule: rule, value: value, options: options};
series.push(deep);
}
/**
* Register a validator function for a type.

@@ -218,0 +209,0 @@ *

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

@@ -6,0 +6,0 @@ "repository": {

@@ -159,5 +159,5 @@ var util = require('util');

validator.validate({name: "user"}, function(errors, fields) {
console.log("after revalidation %j", errors);
//assert.isNull(errors);
//assert.isNull(fields);
//console.log("after revalidation %j", errors);
assert.isNull(errors);
assert.isNull(fields);
});

@@ -164,0 +164,0 @@ });

Sorry, the diff of this file is not supported yet

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