Comparing version 4.5.0 to 4.6.0
// Load modules | ||
var Hoek = require('hoek'); | ||
var Any = require('./any'); | ||
@@ -115,2 +116,10 @@ var Cast = require('./cast'); | ||
root.assert = function (value, schema) { | ||
var error = root.validate(value, schema).error; | ||
if (error) { | ||
throw new Error(error.annotate()); | ||
} | ||
}; | ||
return root; | ||
@@ -117,0 +126,0 @@ }; |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "4.5.0", | ||
"version": "4.6.0", | ||
"repository": "git://github.com/spumko/joi", | ||
@@ -17,3 +17,3 @@ "main": "index", | ||
"topo": "1.x.x", | ||
"isemail": "0.1.x" | ||
"isemail": "1.x.x" | ||
}, | ||
@@ -20,0 +20,0 @@ "devDependencies": { |
@@ -6,3 +6,3 @@ <a href="https://github.com/spumko"><img src="https://raw.github.com/spumko/spumko/master/images/from.png" align="right" /></a> | ||
Current version: **4.3.x** | ||
Current version: **4.6.x** | ||
@@ -20,2 +20,3 @@ [![Build Status](https://secure.travis-ci.org/spumko/joi.png)](http://travis-ci.org/spumko/joi) | ||
- [`compile(schema)`](#compileschema) | ||
- [`assert(value, schema)`](#assertvalue-schema) | ||
- [`any`](#any) | ||
@@ -36,3 +37,3 @@ - [`any.allow(value)`](#anyallowvalue) | ||
- [`any.strict()`](#anystrict) | ||
- [`any.default(value)`](#anydefault) | ||
- [`any.default(value)`](#anydefaultvalue) | ||
- [`any.concat(schema)`](#anyconcatschema) | ||
@@ -225,2 +226,12 @@ - [`any.when(ref, options)`](#anywhenref-options) | ||
### `assert(value, schema)` | ||
Validates a value against a schema and throws if validation fails where: | ||
- `value` - the value to validate. | ||
- `schema` - the schema object. | ||
```javascript | ||
Joi.assert('x', Joi.number()); | ||
``` | ||
### `any` | ||
@@ -227,0 +238,0 @@ |
@@ -1404,2 +1404,23 @@ // Load modules | ||
}); | ||
describe('#assert', function () { | ||
it('throws on invalid value', function (done) { | ||
expect(function () { | ||
Joi.assert('x', Joi.number()); | ||
}).to.throw('"x"\n\u001b[31m\n[1] value must be a number\u001b[0m'); | ||
done(); | ||
}); | ||
it('does not throw on valid value', function (done) { | ||
expect(function () { | ||
Joi.assert('4', Joi.number()); | ||
}).to.not.throw(); | ||
done(); | ||
}); | ||
}); | ||
}); |
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
461887
7247
1028
+ Addedisemail@1.2.0(transitive)
- Removedisemail@0.1.2(transitive)
Updatedisemail@1.x.x