MCPcopy
hub / github.com/lfb/nodejs-koa-blog / validate

Method validate

core/lin-validator-v2.js:207–230  ·  view source on GitHub ↗
(field)

Source from the content-addressed store, hash-verified

205 }
206
207 validate(field) {
208 if (field == null) {
209 // 如果字段为空
210 const allowEmpty = this._allowEmpty()
211 const defaultValue = this._hasDefault()
212 if (allowEmpty) {
213 return new RuleFieldResult(true, '', defaultValue)
214 } else {
215 return new RuleFieldResult(false, '字段是必填参数')
216 }
217 }
218
219 const filedResult = new RuleFieldResult(false)
220 for (let rule of this.rules) {
221 let result = rule.validate(field)
222 if (!result.pass) {
223 filedResult.msg = result.msg
224 filedResult.legalValue = null
225 // 一旦一条校验规则不通过,则立即终止这个字段的验证
226 return filedResult
227 }
228 }
229 return new RuleFieldResult(true, '', this._convert(field))
230 }
231
232 _convert(value) {
233 for (let rule of this.rules) {

Callers 1

_checkMethod · 0.95

Calls 4

_allowEmptyMethod · 0.95
_hasDefaultMethod · 0.95
_convertMethod · 0.95
validateMethod · 0.45

Tested by

no test coverage detected