Comparing version 0.7.5 to 0.8.0
@@ -143,3 +143,3 @@ 'use strict'; | ||
var result = schema.tests.map(function (fn) { | ||
return fn.call(schema, value, path); | ||
return fn.call(schema, value, path, context); | ||
}); | ||
@@ -263,7 +263,7 @@ | ||
function validate(value, path) { | ||
function validate(value, path, context) { | ||
var _this2 = this; | ||
return new Promise(function (resolve, reject) { | ||
!opts.useCallback ? resolve(opts.test.call(_this2, value)) : opts.test.call(_this2, value, function (err, valid) { | ||
!opts.useCallback ? resolve(opts.test.call(_this2, value, context)) : opts.test.call(_this2, value, context, function (err, valid) { | ||
return err ? reject(err) : resolve(valid); | ||
@@ -270,0 +270,0 @@ }); |
{ | ||
"name": "yup", | ||
"version": "0.7.5", | ||
"version": "0.8.0", | ||
"description": "Dead simple Object schema validation", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -138,3 +138,3 @@ 'use strict'; | ||
let result = schema.tests.map(fn => fn.call(schema, value, path)) | ||
let result = schema.tests.map(fn => fn.call(schema, value, path, context)) | ||
@@ -252,7 +252,7 @@ result = endEarly | ||
function validate(value, path) { | ||
function validate(value, path, context) { | ||
return new Promise((resolve, reject) => { | ||
!opts.useCallback | ||
? resolve(opts.test.call(this, value)) | ||
: opts.test.call(this, value, (err, valid) => err ? reject(err) : resolve(valid)) | ||
? resolve(opts.test.call(this, value, context)) | ||
: opts.test.call(this, value, context, (err, valid) => err ? reject(err) : resolve(valid)) | ||
}) | ||
@@ -259,0 +259,0 @@ .then(valid => { |
@@ -129,3 +129,20 @@ 'use strict'; | ||
it.only('tests should receive context', function(done){ | ||
var inst = object({ | ||
other: mixed(), | ||
test: mixed().test({ | ||
message: 'invalid', | ||
exclusive: true, | ||
name: 'max', | ||
test: function(v, context){ | ||
context.should.eql({ other: 5, test : 'hi' }) | ||
done() | ||
} | ||
}) | ||
}) | ||
inst.validate({ other: 5, test : 'hi' }) | ||
}) | ||
it('should allow custom validation of either style', function(){ | ||
@@ -136,3 +153,3 @@ var inst = string() | ||
}) | ||
.test('name', 'test b', function(val, done){ | ||
.test('name', 'test b', function(val, context, done){ | ||
process.nextTick(function(){ | ||
@@ -139,0 +156,0 @@ done(null, val !== 'jim') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
152171
3302