async-validator
Advanced tools
Comparing version 1.9.0 to 1.10.0
import _extends from 'babel-runtime/helpers/extends'; | ||
import _typeof from 'babel-runtime/helpers/typeof'; | ||
import { format, complementError, asyncMap, warning, deepMerge, convertFieldsError } from './util'; | ||
import { format, complementError, asyncMap, warning, deepMerge } from './util'; | ||
import validators from './validator/'; | ||
@@ -47,3 +47,3 @@ import { messages as defaultMessages, newMessages } from './messages'; | ||
var o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var oc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {}; | ||
var oc = arguments[2]; | ||
@@ -61,6 +61,7 @@ var source = source_; | ||
} | ||
return Promise.resolve(); | ||
return; | ||
} | ||
function complete(results) { | ||
var i = void 0; | ||
var field = void 0; | ||
var errors = []; | ||
@@ -84,3 +85,7 @@ var fields = {}; | ||
} else { | ||
fields = convertFieldsError(errors); | ||
for (i = 0; i < errors.length; i++) { | ||
field = errors[i].field; | ||
fields[field] = fields[field] || []; | ||
fields[field].push(errors[i]); | ||
} | ||
} | ||
@@ -139,3 +144,3 @@ callback(errors, fields); | ||
var errorFields = {}; | ||
return asyncMap(series, options, function (data, doIt) { | ||
asyncMap(series, options, function (data, doIt) { | ||
var rule = data.rule; | ||
@@ -142,0 +147,0 @@ var deep = (rule.type === 'object' || rule.type === 'array') && (_typeof(rule.fields) === 'object' || _typeof(rule.defaultField) === 'object'); |
@@ -20,13 +20,2 @@ import _extends from 'babel-runtime/helpers/extends'; | ||
export function convertFieldsError(errors) { | ||
if (!errors || !errors.length) return null; | ||
var fields = {}; | ||
errors.forEach(function (error) { | ||
var field = error.field; | ||
fields[field] = fields[field] || []; | ||
fields[field].push(error); | ||
}); | ||
return fields; | ||
} | ||
export function format() { | ||
@@ -156,19 +145,16 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
var results = []; | ||
return new Promise(function (resolve, reject) { | ||
var next = function next(errors) { | ||
results.push.apply(results, errors); | ||
total++; | ||
if (total === objArrLength) { | ||
callback(results); | ||
return results.length ? reject({ errors: results, fields: convertFieldsError(results) }) : resolve(); | ||
} | ||
}; | ||
objArrKeys.forEach(function (key) { | ||
var arr = objArr[key]; | ||
if (firstFields.indexOf(key) !== -1) { | ||
asyncSerialArray(arr, func, next); | ||
} else { | ||
asyncParallelArray(arr, func, next); | ||
} | ||
}); | ||
var next = function next(errors) { | ||
results.push.apply(results, errors); | ||
total++; | ||
if (total === objArrLength) { | ||
callback(results); | ||
} | ||
}; | ||
objArrKeys.forEach(function (key) { | ||
var arr = objArr[key]; | ||
if (firstFields.indexOf(key) !== -1) { | ||
asyncSerialArray(arr, func, next); | ||
} else { | ||
asyncParallelArray(arr, func, next); | ||
} | ||
}); | ||
@@ -175,0 +161,0 @@ } |
# History | ||
---- | ||
## 1.10.0 / 2018-10-17 | ||
- revert promise | ||
## 1.9.0 / 2018-10-10 | ||
@@ -5,0 +9,0 @@ |
@@ -65,3 +65,3 @@ 'use strict'; | ||
var o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var oc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {}; | ||
var oc = arguments[2]; | ||
@@ -79,6 +79,7 @@ var source = source_; | ||
} | ||
return Promise.resolve(); | ||
return; | ||
} | ||
function complete(results) { | ||
var i = void 0; | ||
var field = void 0; | ||
var errors = []; | ||
@@ -102,3 +103,7 @@ var fields = {}; | ||
} else { | ||
fields = (0, _util.convertFieldsError)(errors); | ||
for (i = 0; i < errors.length; i++) { | ||
field = errors[i].field; | ||
fields[field] = fields[field] || []; | ||
fields[field].push(errors[i]); | ||
} | ||
} | ||
@@ -157,3 +162,3 @@ callback(errors, fields); | ||
var errorFields = {}; | ||
return (0, _util.asyncMap)(series, options, function (data, doIt) { | ||
(0, _util.asyncMap)(series, options, function (data, doIt) { | ||
var rule = data.rule; | ||
@@ -160,0 +165,0 @@ var deep = (rule.type === 'object' || rule.type === 'array') && ((0, _typeof3['default'])(rule.fields) === 'object' || (0, _typeof3['default'])(rule.defaultField) === 'object'); |
@@ -16,3 +16,2 @@ 'use strict'; | ||
exports.convertFieldsError = convertFieldsError; | ||
exports.format = format; | ||
@@ -44,13 +43,2 @@ exports.isEmptyValue = isEmptyValue; | ||
function convertFieldsError(errors) { | ||
if (!errors || !errors.length) return null; | ||
var fields = {}; | ||
errors.forEach(function (error) { | ||
var field = error.field; | ||
fields[field] = fields[field] || []; | ||
fields[field].push(error); | ||
}); | ||
return fields; | ||
} | ||
function format() { | ||
@@ -180,19 +168,16 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
var results = []; | ||
return new Promise(function (resolve, reject) { | ||
var next = function next(errors) { | ||
results.push.apply(results, errors); | ||
total++; | ||
if (total === objArrLength) { | ||
callback(results); | ||
return results.length ? reject({ errors: results, fields: convertFieldsError(results) }) : resolve(); | ||
} | ||
}; | ||
objArrKeys.forEach(function (key) { | ||
var arr = objArr[key]; | ||
if (firstFields.indexOf(key) !== -1) { | ||
asyncSerialArray(arr, func, next); | ||
} else { | ||
asyncParallelArray(arr, func, next); | ||
} | ||
}); | ||
var next = function next(errors) { | ||
results.push.apply(results, errors); | ||
total++; | ||
if (total === objArrLength) { | ||
callback(results); | ||
} | ||
}; | ||
objArrKeys.forEach(function (key) { | ||
var arr = objArr[key]; | ||
if (firstFields.indexOf(key) !== -1) { | ||
asyncSerialArray(arr, func, next); | ||
} else { | ||
asyncParallelArray(arr, func, next); | ||
} | ||
}); | ||
@@ -199,0 +184,0 @@ } |
{ | ||
"name": "async-validator", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "validate form asynchronous", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -50,19 +50,2 @@ # async-validator | ||
}); | ||
// PROMISE USAGE | ||
validator.validate({name: "muji"}, (errors, fields) => { | ||
if(errors) { | ||
// validation failed, errors is an array of all errors | ||
// fields is an object keyed by field name with an array of | ||
// errors per field | ||
return handleErrors(errors, fields); | ||
} | ||
// validation passed | ||
}) | ||
.then(() => { | ||
// validation passed | ||
}) | ||
.catch(({ errors, fields }) => { | ||
return handleErrors(errors, fields); | ||
}) | ||
``` | ||
@@ -80,6 +63,2 @@ | ||
The method will return a Promise object like: | ||
* `then()`,validation passed | ||
* `catch({ errors, fields })`,validation failed, errors is an array of all errors, fields is an object keyed by field name with an array of | ||
### Options | ||
@@ -86,0 +65,0 @@ |
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
97617
2374
366