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.9.9 to 0.9.12

plugin/multiple.js

6

doc/readme/developer.md
## Developer
Clone the repository, run `npm i` and install [mdp][] and [jshint][] globally.
Clone the repository, install project and global dependencies ([mdp][], [jshint][] and [jscs][]) globally:
```
npm i && npm i -g mdp jshint jscs
```
### Test

@@ -6,0 +10,0 @@

32

doc/readme/guide.md

@@ -211,5 +211,11 @@ ## Guide

To allow a field to be of multiple types you may declare an array of valid type identifiers, for example:
```javascript
{type: ['string', String, Number], required: true}
```
##### Test
The test function to use for rule validation.
The function to use for rule validation.

@@ -409,10 +415,2 @@ ##### Additional

##### required
```javascript
function required()
```
Validate a required field, typically invoked from a rule function, raises an error if a required field is not present.
##### pattern

@@ -434,2 +432,18 @@

##### required
```javascript
function required()
```
Validate a required field, typically invoked from a rule function, raises an error if a required field is not present.
##### type
```javascript
function type()
```
Validate a value is one of the expected type(s), typically invoked from a rule function, raises an error if the value is not one of the declared types.
### Validation

@@ -436,0 +450,0 @@

@@ -6,2 +6,3 @@ [node]: http://nodejs.org

[jshint]: http://jshint.com/
[jscs]: http://jscs.info/
[zephyr]: https://github.com/socialally/zephyr

@@ -34,3 +34,3 @@ function mapSeries(list, cb, complete) {

e = err;
return complete(err, out);
return complete(err, out);
}

@@ -45,3 +45,3 @@ out[index] = result;

run(item, index);
})
});
}

@@ -48,0 +48,0 @@

@@ -23,3 +23,3 @@ function Reason(id, meta) {

min: new Reason('min'),
max: new Reason('max'),
max: new Reason('max')
}

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

@@ -10,3 +10,3 @@ var plugin = require('zephyr')

if(!(this instanceof Rule)) {
return new Rule(opts);
return new Rule(opts);
}

@@ -47,3 +47,3 @@

}
if(typeof(this.rule.message) === 'function') {

@@ -55,3 +55,3 @@ // allow calls to error() so that message functions

this.rule.message = null;
res = tmp.call(this, message, args);
res = tmp.call(this, message, args);
this.rule.message = tmp;

@@ -61,3 +61,3 @@ if(res instanceof Error) {

}else{
msg = '' + res;
msg = '' + res;
}

@@ -103,3 +103,3 @@ }else{

if(arguments.length > 1) {
parameters = Array.prototype.slice.call(arguments, 1);
parameters = Array.prototype.slice.call(arguments, 1);
}

@@ -138,3 +138,3 @@ var err = this.error.apply(this, [message].concat(parameters));

if(results.length === 0) {
return false;
return false;
}

@@ -141,0 +141,0 @@ // return diff array

@@ -113,2 +113,7 @@ var iterator = require('./iterator')

if(typeof(rule.test) !== 'function'
&& Array.isArray(rule.type)) {
rule.test = Rule.types;
}
if(typeof rule === 'function') {

@@ -115,0 +120,0 @@ rule.test = rule;

@@ -11,4 +11,4 @@ /**

date: {
format: "%s date %s is invalid for format %s",
invalid: "%s date %s is invalid"
format: '%s date %s is invalid for format %s',
invalid: '%s date %s is invalid'
},

@@ -26,3 +26,4 @@ types: {

float: '%s is not a %s',
regexp: '%s is not a valid %s'
regexp: '%s is not a valid %s',
multiple: '%s is not one of the allowed types %s'
},

@@ -56,3 +57,4 @@ function: {

}
}
};
module.exports = messages;
{
"name": "async-validate",
"description": "Asynchronous validation for node and the browser",
"version": "0.9.9",
"version": "0.9.12",
"author": "muji <noop@xpm.io>",

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

"istanbul": "~0.3.17",
"jscs": "~2.1.1",
"mocha": "~2.3.2",

@@ -30,0 +29,0 @@ "moment": "~2.10.6"

@@ -11,8 +11,3 @@ module.exports = function() {

this.required();
if(!Array.isArray(this.value)) {
this.raise(
this.reasons.type,
this.messages.types[this.rule.type],
this.field, this.rule.type);
}
this.type();
this.range();

@@ -19,0 +14,0 @@ }

@@ -11,10 +11,3 @@ module.exports = function() {

this.required();
// straight typeof check
if(typeof(this.value) !== this.rule.type) {
this.raise(
this.reasons.type,
this.messages.types[this.rule.type],
this.field, this.rule.type);
}
this.type();
}

@@ -21,0 +14,0 @@ cb();

@@ -11,11 +11,3 @@ module.exports = function() {

this.required();
if(typeof(this.value) !== 'number'
|| Number(this.value) === parseInt(this.value)) {
this.raise(
this.reasons.type,
this.messages.types[this.rule.type],
this.field, this.rule.type);
}
this.type();
this.range();

@@ -22,0 +14,0 @@ }

@@ -11,11 +11,3 @@ module.exports = function() {

this.required();
if(typeof(this.value) !== 'number'
|| Number(this.value) !== parseInt(this.value)) {
this.raise(
this.reasons.type,
this.messages.types[this.rule.type],
this.field, this.rule.type);
}
this.type();
this.range();

@@ -22,0 +14,0 @@ }

@@ -11,9 +11,4 @@ module.exports = function() {

this.required();
this.type();
this.range();
if(typeof this.value !== 'function') {
this.raise(
this.reasons.type,
this.messages.types[this.rule.type],
this.field, this.rule.type);
}
}

@@ -20,0 +15,0 @@ cb();

@@ -11,8 +11,3 @@ module.exports = function() {

this.required();
if(this.value !== null) {
this.raise(
this.reasons.type,
this.messages.types[this.rule.type],
this.field, this.rule.type);
}
this.type();
}

@@ -19,0 +14,0 @@ cb();

@@ -11,9 +11,3 @@ module.exports = function() {

this.required();
// straight typeof check
if(typeof(this.value) !== this.rule.type) {
this.raise(
this.reasons.type,
this.messages.types[this.rule.type],
this.field, this.rule.type);
}
this.type();
this.range();

@@ -20,0 +14,0 @@ }

@@ -10,26 +10,9 @@ module.exports = function() {

var expected
, additional
, Type = this.rule.Type;
, additional;
if(this.validates()) {
this.required();
this.type();
// instanceof comparison on `type` as function
if(typeof Type === 'function'
&& !(this.value instanceof Type)) {
this.raise(
this.reasons.instance,
this.messages.types.instance,
this.field, Type.name || 'function (anonymous)');
// plain object
}else if(typeof(this.value) !== 'object' || Array.isArray(this.value)) {
this.raise(
this.reasons.type,
this.messages.types[this.rule.type],
this.field, this.rule.type);
}
// nested deep properties
if(this.rule.additional === false) {
// NOTE: Object.keys() will throw if you declare `additional`

@@ -36,0 +19,0 @@ // NOTE: for the `object` type but do not declare nested `fields` object

@@ -1,12 +0,1 @@

function isRegExp(value) {
if(value instanceof RegExp) {
return true;
}
try {
new RegExp(value);
return true;
}catch(e) {}
return false;
}
module.exports = function() {

@@ -22,7 +11,3 @@

this.required();
if(!isRegExp(this.value)) {
this.raise(
this.reasons.type,
this.messages.types[this.rule.type], this.field, this.rule.type);
}
this.type();
}

@@ -29,0 +14,0 @@ cb();

@@ -13,18 +13,12 @@ module.exports = function() {

// if value is required and value is undefined
// no need to add this error message
// no need to add other error messages
if(this.rule.required && this.value === undefined) {
return cb();
return cb();
}
if(typeof this.value !== 'string' && this.validates()) {
this.raise(
this.reasons.type,
this.messages.types[this.rule.type],
this.field, this.rule.type);
}
this.type();
this.range();
this.pattern();
if(this.rule.whitespace === true) {
if(this.rule.whitespace) {
if(/^\s+$/.test(this.value) || this.value === '') {

@@ -31,0 +25,0 @@ this.raise(

@@ -6,5 +6,6 @@ module.exports = function() {

require('./util/range'),
require('./util/required')
require('./util/required'),
require('./util/type')
]
)
}

@@ -39,5 +39,6 @@ Table of Contents

* [Helper Plugins](#helper-plugins)
* [required](#required)
* [pattern](#pattern)
* [range](#range)
* [required](#required)
* [type](#type)
* [Validation](#validation)

@@ -327,5 +328,11 @@ * [Bail](#bail)

To allow a field to be of multiple types you may declare an array of valid type identifiers, for example:
```javascript
{type: ['string', String, Number], required: true}
```
##### Test
The test function to use for rule validation.
The function to use for rule validation.

@@ -525,10 +532,2 @@ ##### Additional

##### required
```javascript
function required()
```
Validate a required field, typically invoked from a rule function, raises an error if a required field is not present.
##### pattern

@@ -550,2 +549,18 @@

##### required
```javascript
function required()
```
Validate a required field, typically invoked from a rule function, raises an error if a required field is not present.
##### type
```javascript
function type()
```
Validate a value is one of the expected type(s), typically invoked from a rule function, raises an error if the value is not one of the declared types.
### Validation

@@ -806,4 +821,8 @@

Clone the repository, run `npm i` and install [mdp](https://github.com/freeformsystems/mdp) and [jshint](http://jshint.com/) globally.
Clone the repository, install project and global dependencies ([mdp](https://github.com/freeformsystems/mdp), [jshint](http://jshint.com/) and [jscs](http://jscs.info/)) globally:
```
npm i && npm i -g mdp jshint jscs
```
### Test

@@ -892,2 +911,3 @@

[jshint]: http://jshint.com/
[jscs]: http://jscs.info/
[zephyr]: https://github.com/socialally/zephyr

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