Comparing version 2.2.3 to 2.3.0
2.3.0 / 2018-06-19 | ||
================== | ||
**features** | ||
* [[`a5c1721`](http://github.com/node-modules/parameter/commit/a5c172179071aaaafb6fac604bc6bf4ebb0c8d98)] - feat: Add option.validateRoot to enable validate the root object (#41) (paranoidjk <<hust2012jiangkai@gmail.com>>) | ||
2.2.3 / 2018-05-16 | ||
@@ -3,0 +9,0 @@ ================== |
12
index.js
@@ -32,2 +32,6 @@ 'use strict'; | ||
} | ||
if (opts.validateRoot) { | ||
this.validateRoot = true; | ||
} | ||
} | ||
@@ -56,2 +60,10 @@ | ||
if (this.validateRoot && (typeof obj !== 'object' || !obj)) { | ||
return [{ | ||
message: 'the validated value should be a object', | ||
code: this.t('invalid'), | ||
field: undefined, | ||
}]; | ||
} | ||
var self = this; | ||
@@ -58,0 +70,0 @@ |
{ | ||
"name": "parameter", | ||
"version": "2.2.3", | ||
"version": "2.3.0", | ||
"description": "A parameter verify tools.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -35,2 +35,3 @@ parameter | ||
- `options.translate` - translate function | ||
- `options.validateRoot` - config whether to validate the passed in value must be a object. | ||
- `validate(rule, value)` - validate the `value` conforms to `rule`. return an array of errors if break rule. | ||
@@ -51,3 +52,4 @@ - `addRule(type, check)` - add custom rules. | ||
return I18n.t.apply(I18n, args); | ||
} | ||
}, | ||
validateRoot: true, // restrict the being validate value must be a object | ||
}); | ||
@@ -54,0 +56,0 @@ |
21609
451
219