Socket
Socket
Sign inDemoInstall

anchor

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anchor - npm Package Compare versions

Comparing version 0.9.3 to 0.9.4

2

index.js

@@ -279,2 +279,2 @@ /**

throw new Error('Not implemented yet! If you\'d like to contribute, tweet @mikermcneil.');
}
}

@@ -68,14 +68,9 @@ /**

// remove data from the front
args.shift();
// Construct error message
var errMsg = '';
var argStr = _.reduce(args, function (memo, arg, i) {
// Prepend w/ comma if this isn't the first argument
return ( (i > 0) ? ',' : '' ) + arg;
}, '');
// If for some reasons the first argument was empty
if(argStr[0] === ',') argStr = argStr.slice(1);
errMsg += 'Validation error: "'+data+'" ';
errMsg += 'Rule "' + ruleName + '(' + argStr + ')" failed.';
errMsg += 'Rule "' + ruleName + '(' + args.join(',') + ')" failed.';

@@ -124,17 +119,23 @@ // Construct error object

// If this is a schema rule, check each item in the data collection
if (_.isArray(ruleset) && ruleset.length !== 0) {
if (ruleset.length > 1) {
throw new Error ('[] (or schema) rules can contain only one item.');
if (_.isArray(ruleset)) {
if (ruleset.length !== 0) {
if (ruleset.length > 1) {
throw new Error ('[] (or schema) rules can contain only one item.');
}
// Handle plurals (arrays with a schema rule)
// Match each object in data array against ruleset until error is detected
_.each(data, function (model) {
errors = errors.concat(deepMatchType(model, ruleset[0], depth+1, keyName));
});
return errors;
}
// Handle plurals (arrays with a schema rule)
// Match each object in data array against ruleset until error is detected
_.each(data, function (model) {
errors = errors.concat(deepMatchType(model, ruleset[0], depth+1, keyName));
});
return errors;
// Leaf rules land here and execute the iterator
else return matchType(data, ruleset, keyName);
}
// If the current rule is an object, check each key
else if (!_.isArray(ruleset) && _.isObject(ruleset)) {
// && _.isObject(ruleset) is a redundant test (already tested aboved), always true at this point
// !_.isArray(ruleset) is also redundant test, just need to refactor if else
else {

@@ -154,5 +155,2 @@ // Don't treat empty object as a ruleset

}
// Leaf rules land here and execute the iterator
else return matchType(data, ruleset, keyName);
}

@@ -159,0 +157,0 @@

{
"name": "anchor",
"version": "0.9.3",
"version": "0.9.4",
"description": "Recursive validation library with support for objects and lists",

@@ -20,6 +20,6 @@ "main": "index.js",

"dependencies": {
"validator": "0.4.22",
"underscore": "1.4.4",
"async": "0.2.6"
"validator": "1.5.0",
"underscore": "1.5.1",
"async": "0.2.9"
}
}
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