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

anchor

Package Overview
Dependencies
Maintainers
4
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.11.2 to 0.11.3

65

lib/match/errorFactory.js

@@ -23,3 +23,6 @@ /**

module.exports = function errorFactory(value, ruleName, keyName, customMessage) {
// Avoid throwing errors by defaulting the `ruleName` value
if (_.isUndefined(ruleName)) {
ruleName = 'unknown';
}
// Construct error message

@@ -34,10 +37,56 @@ var errMsg;

else {
// errMsg = 'Validation error: "' + value + '" ';
// errMsg += keyName ? '(' + keyName + ') ' : '';
// errMsg += 'is not of type "' + ruleName + '"';
errMsg = util.format(
'`%s` should be a %s (instead of "%s", which is a %s)',
keyName, ruleName, value, typeof value
);
// Get the type of the value that was passed here.
var actualType = typeof value;
// In the case of a NaN, don't bother saying "instead of NaN which is a NaN",
// since it doesn't give you any more information.
if (typeof value === 'number' && isNaN(value)) {
errMsg = util.format(
// Template:
'%s should be a%s %s',
// Token replacements:
// -------------------
// Default to just saying 'Value' if we don't have the property name of the value.
keyName ? ('`' + keyName + '`') : 'Value',
// Adjust the article ("a" or "an") based on whether the next word starts with a vowel.
_.contains(['a','e','i','o','u'], ruleName[0]) ? 'n' : '',
// Output the name of the expected data type (e.g. "string" or "boolean").
ruleName
);
}
// In all other cases, make a nicer error message comparing what was expected
// to what was actually received.
else {
// Attempt to stringify the passed value.
var stringifiedValue;
try {
stringifiedValue = JSON.stringify(value);
}
// Fall back to just displaying the `toString()` version of the value.
catch(e) {
stringifiedValue = value;
}
errMsg = util.format(
// Template:
'%s should be a%s %s (instead of %s, which is a%s %s)',
// Token replacements:
// -------------------
// Default to just saying 'Value' if we don't have the property name of the value.
keyName ? ('`' + keyName + '`') : 'Value',
// Adjust the article ("a" or "an") based on whether the next word starts with a vowel.
_.contains(['a','e','i','o','u'], ruleName[0]) ? 'n' : '',
// Output the name of the expected data type (e.g. "string" or "boolean").
ruleName,
// Output the actual value that was passed in here.
stringifiedValue,
// Adjust the article ("a" or "an") based on whether the next word starts with a vowel.
_.contains(['a','e','i','o','u'], actualType[0]) ? 'n' : '',
// Output the type of the value that was passed in.
actualType
);
}
}

@@ -44,0 +93,0 @@

@@ -24,2 +24,10 @@ /**

return !validator.isNull(x);
// Note that this (^^) is probably not the expected behavior!
//
// Because:
// ```
// require('validator').isNull([]) >> true
// ```
//
// This will change in a future release of anchor.
},

@@ -26,0 +34,0 @@

2

package.json
{
"name": "anchor",
"version": "0.11.2",
"version": "0.11.3",
"description": "Recursive validation library with support for objects and lists",

@@ -5,0 +5,0 @@ "homepage": "http://sailsjs.org",

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