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.12.1 to 0.12.2

35

doc/readme/api.md

@@ -66,12 +66,2 @@ ### API

#### Reason
```javascript
function Reason(id, [opts])
```
Represents the reason for a validation error, may be created using `reason()`.
You must supply a reason `id`; if `opts` are passed they are assigned as properties of the reason instance. When `toString()` is called on a `Reason` instance the `id` is returned.
#### Rule

@@ -86,4 +76,5 @@

* `rule`: The validation rule in the schema descriptor.
* `value`: The value of the source object property being validated.
* `field`: The name of the field being validated.
* `value`: The value of the property being validated.
* `field`: The name of the property being validated.
* `parent`: The parent object that declares the property.
* `source`: The source object passed to `validate()`.

@@ -148,1 +139,21 @@ * `messages`: Reference to the schema messages.

Compare two arrays, return `false` if they are equal otherwise return an array that is the difference between the supplied arrays.
#### Error
The errors created by [raise](#raise) are assigned the following public fields:
* `field`: The name of the property that failed validation.
* `value`: The value of the property.
* `parent`: The parent object that declares the property.
* `reason`: A [Reason](#reason) for the error when available.
#### Reason
```javascript
function Reason(id, [opts])
```
Represents the reason for a validation error, may be created using `reason()`.
You must supply a reason `id`; if `opts` are passed they are assigned as properties of the reason instance. When `toString()` is called on a `Reason` instance the `id` is returned.

@@ -80,2 +80,5 @@ var plugin = require('zephyr')

err.field = this.field;
err.value = this.value;
err.parent = this.parent;
if(reason) {

@@ -82,0 +85,0 @@ err.reason = reason;

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

rule.parent = opts.parent || source;
rule.value = value;

@@ -174,0 +175,0 @@ rule.source = opts._source || source;

{
"name": "async-validate",
"description": "Asynchronous validation for node and the browser",
"version": "0.12.1",
"version": "0.12.2",
"author": "muji <noop@xpm.io>",

@@ -6,0 +6,0 @@ "license": "MIT",

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

* [Schema.clone](#schemaclone)
* [Reason](#reason)
* [Rule](#rule)

@@ -65,2 +64,4 @@ * [isRoot](#isroot)

* [diff](#diff)
* [Error](#error)
* [Reason](#reason)
* [Developer](#developer)

@@ -837,12 +838,2 @@ * [Test](#test-1)

#### Reason
```javascript
function Reason(id, [opts])
```
Represents the reason for a validation error, may be created using `reason()`.
You must supply a reason `id`; if `opts` are passed they are assigned as properties of the reason instance. When `toString()` is called on a `Reason` instance the `id` is returned.
#### Rule

@@ -857,4 +848,5 @@

* `rule`: The validation rule in the schema descriptor.
* `value`: The value of the source object property being validated.
* `field`: The name of the field being validated.
* `value`: The value of the property being validated.
* `field`: The name of the property being validated.
* `parent`: The parent object that declares the property.
* `source`: The source object passed to `validate()`.

@@ -920,2 +912,21 @@ * `messages`: Reference to the schema messages.

#### Error
The errors created by [raise](#raise) are assigned the following public fields:
* `field`: The name of the property that failed validation.
* `value`: The value of the property.
* `parent`: The parent object that declares the property.
* `reason`: A [Reason](#reason) for the error when available.
#### Reason
```javascript
function Reason(id, [opts])
```
Represents the reason for a validation error, may be created using `reason()`.
You must supply a reason `id`; if `opts` are passed they are assigned as properties of the reason instance. When `toString()` is called on a `Reason` instance the `id` is returned.
## Developer

@@ -922,0 +933,0 @@

@@ -5,3 +5,5 @@ var schema = {

name: function(cb) {
this.raise('%s is a required field', this.field);
this.raise(
this.reasons.required,
'%s is a required field', this.field);
cb();

@@ -8,0 +10,0 @@ }

@@ -8,6 +8,13 @@ var expect = require('chai').expect

it('should use raise() helper method', function(done) {
var schema = new Schema(descriptor);
schema.validate({}, function(err, res) {
var schema = new Schema(descriptor)
, source = {};
schema.validate(source, function(err, res) {
expect(res.errors.length).to.eql(1);
expect(res.errors[0].message).to.eql('name is a required field');
expect(res.errors[0].field).to.be.a('string');
expect(res.errors[0].value).to.eql(undefined);
expect(res.errors[0].parent).to.be.an('object');
expect(res.errors[0].parent).to.equal(source);
expect(res.errors[0].reason).to.be.an('object');
done();

@@ -14,0 +21,0 @@ });

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