Skip to content

Commit b84a0ae

Browse files
committed
rebuild
1 parent 394f119 commit b84a0ae

7 files changed

+22
-16
lines changed

lib/boolean.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ function BooleanSchema() {
1111

1212
this.transforms.push(function (value) {
1313
if (this.isType(value)) return value;
14-
return /true|1/i.test(value);
14+
return (/true|1/i.test(value)
15+
);
1516
});
1617
}
1718

lib/mixed.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ SchemaType.prototype = {
4545
concat: function concat(schema) {
4646
if (!schema) return this;
4747

48-
if (schema._type !== this._type) throw new TypeError('You cannot `concat()` schema\'s of different types: ' + this._type + ' and ' + schema._type);
48+
if (schema._type !== this._type && this._type !== 'mixed') throw new TypeError('You cannot `concat()` schema\'s of different types: ' + this._type + ' and ' + schema._type);
4949

5050
var next = _.merge(this.clone(), schema.clone());
5151

@@ -57,6 +57,8 @@ SchemaType.prototype = {
5757
return next[fn.VALIDATION_KEY] ? fn.VALIDATION_KEY : idx;
5858
}).reverse();
5959

60+
next._type = schema._type;
61+
6062
return next;
6163
},
6264

@@ -215,7 +217,6 @@ SchemaType.prototype = {
215217
test: function test(name, message, _test, useCallback) {
216218
var opts = name,
217219
next = this.clone(),
218-
errorMsg,
219220
isExclusive;
220221

221222
if (typeof name === 'string') {

lib/number.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ function NumberSchema() {
2525
inherits(NumberSchema, SchemaObject, {
2626

2727
_typeCheck: function _typeCheck(v) {
28-
return typeof v === 'number' && !(v !== +v) //isNaN check
29-
;
28+
return typeof v === 'number' && !(v !== +v); //isNaN check
3029
},
3130

3231
min: function min(_min, msg) {

lib/object.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
44

55
var MixedSchema = require('./mixed');
6-
var Promise = require('promise/lib/es6-extensions')
6+
var Promise = require('promise/lib/es6-extensions');
77
//, Reference = require('./util/Reference')
8-
;var cloneDeep = require('./util/clone');
8+
var cloneDeep = require('./util/clone');
99
var toposort = require('toposort');
1010
var locale = require('./locale.js').object;
1111
var split = require('property-expr').split;
@@ -176,14 +176,18 @@ inherits(ObjectSchema, MixedSchema, {
176176

177177
from: function from(_from, to, alias) {
178178
return this.transform(function (obj) {
179+
var newObj = obj;
180+
179181
if (obj == null) return obj;
180182

181-
var newObj = transform(obj, function (o, val, key) {
182-
return key !== _from && (o[key] = val);
183-
}, {});
183+
if (has(obj, _from)) {
184+
newObj = transform(obj, function (o, val, key) {
185+
return key !== _from && (o[key] = val);
186+
}, {});
187+
newObj[to] = obj[_from];
184188

185-
newObj[to] = obj[_from];
186-
if (alias) newObj[_from] = obj[_from];
189+
if (alias) newObj[_from] = obj[_from];
190+
}
187191

188192
return newObj;
189193
});

lib/util/condition.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ var Conditional = (function () {
2828

2929
if (!options.then && !options.otherwise) throw new TypeError('either `then:` or `otherwise:` is required for `when()` conditions');
3030

31-
if (options.then && options.then._type !== type || options.otherwise && options.otherwise._type !== type) throw new TypeError('cannot create polymorphic conditionals, `then` and `otherwise` must be the same type: ' + type);
31+
// if( options.then && options.then._type !== type || options.otherwise && options.otherwise._type !== type)
32+
// throw new TypeError(`cannot create polymorphic conditionals, \`then\` and \`otherwise\` must be the same type: ${type}`)
3233

3334
is = typeof is === 'function' ? is : (function (is, value) {
3435
return is === value;

lib/util/isodate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function parseIsoDate(date) {
2424
struct[3] = +struct[3] || 1;
2525

2626
// allow arbitrary sub-second precision beyond milliseconds
27-
struct[7] = struct[7] ? +(struct[7] + '00').substr(0, 3) : 0;
27+
struct[7] = struct[7] ? +(struct[7] + "00").substr(0, 3) : 0;
2828

2929
// timestamps without timezone identifiers should be considered local time
3030
if ((struct[8] === undefined || struct[8] === '') && (struct[9] === undefined || struct[9] === '')) timestamp = +new Date(struct[1], struct[2], struct[3], struct[4], struct[5], struct[6], struct[7]);else {

lib/util/validation-error.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ ValidationError.prototype.toJSON = function () {
6262
var _ref;
6363

6464
if (this.inner.length) return this.inner.reduce(function (list, e) {
65-
list[e.path] = (list[e.path] || (list[e.path] = [])).concat({ errors: e.errors, path: e.path, type: e.type });
65+
list[e.path] = (list[e.path] || (list[e.path] = [])).concat(e.toJSON());
6666
return list;
6767
}, {});
6868

69-
if (this.path) return (_ref = {}, _ref[this.path] = err.errors, _ref);
69+
if (this.path) return _ref = {}, _ref[this.path] = { errors: this.errors, path: this.path, type: this.type }, _ref;
7070

7171
return err.errors;
7272
};

0 commit comments

Comments
 (0)