Skip to content

Commit 648269f

Browse files
committed
rebuild
1 parent 2bdb1d4 commit 648269f

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

lib/mixed.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ function runValidations(validations, endEarly, value, path) {
2020
return endEarly ? Promise.all(validations) : _.collectErrors(validations, value, path);
2121
}
2222

23+
function extractTestParams(name, message, test, useCallback) {
24+
var opts = name;
25+
26+
if (typeof message === 'function') test = message, message = locale.default;
27+
28+
if (typeof name === 'string' || name === null) opts = { name: name, test: test, message: message, useCallback: useCallback, exclusive: false };
29+
30+
if (typeof opts.test !== 'function') throw new TypeError('`test` is a required parameters');
31+
32+
return opts;
33+
}
34+
2335
module.exports = SchemaType;
2436

2537
function SchemaType() {
@@ -247,17 +259,9 @@ SchemaType.prototype = {
247259
* the previous tests are removed and further tests of the same name will replace each other.
248260
*/
249261
test: function test(name, message, _test, useCallback) {
250-
var opts = name,
262+
var opts = extractTestParams(name, message, _test, useCallback),
251263
next = this.clone();
252264

253-
if (typeof name === 'string') {
254-
if (typeof message === 'function') _test = message, message = name, name = null;
255-
256-
opts = { name: name, test: _test, message: message, useCallback: useCallback, exclusive: false };
257-
}
258-
259-
if (typeof opts.message !== 'string' || typeof opts.test !== 'function') throw new TypeError('`message` and `test` are required parameters');
260-
261265
var validate = createValidation(opts);
262266

263267
var isExclusive = opts.exclusive || opts.name && next._exclusive[opts.name] === true;

lib/util/createValidation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ function createErrorFactory(_ref) {
4040
var type = _ref2$type === undefined ? opts.name : _ref2$type;
4141
var params = _ref2.params;
4242

43-
params = resolveParams(opts.params, params, resolve);
43+
params = _extends({ path: path, value: value, label: label }, resolveParams(opts.params, params, resolve));
4444

45-
return _extends(new ValidationError(formatError(message, _extends({ path: path, value: value, label: label }, params)), value, path, type), { params: params });
45+
return _extends(new ValidationError(typeof message === 'string' ? formatError(message, params) : message, value, path, type), { params: params });
4646
};
4747
}
4848

lib/util/validation-error.js

-13
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,4 @@ ValidationError.formatError = function (message, params) {
5858
};
5959

6060
return arguments.length === 1 ? fn : fn(params);
61-
};
62-
63-
ValidationError.prototype.toJSON = function () {
64-
var _ref2;
65-
66-
if (this.inner.length) return this.inner.reduce(function (list, e) {
67-
list[e.path] = (list[e.path] || (list[e.path] = [])).concat(e.toJSON());
68-
return list;
69-
}, {});
70-
71-
if (this.path) return _ref2 = {}, _ref2[this.path] = { errors: this.errors, path: this.path, type: this.type }, _ref2;
72-
73-
return err.errors;
7461
};

0 commit comments

Comments
 (0)