Skip to content

Commit

Permalink
rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Nov 8, 2015
1 parent 394f119 commit b84a0ae
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
3 changes: 2 additions & 1 deletion lib/boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function BooleanSchema() {

this.transforms.push(function (value) {
if (this.isType(value)) return value;
return /true|1/i.test(value);
return (/true|1/i.test(value)
);
});
}

Expand Down
5 changes: 3 additions & 2 deletions lib/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SchemaType.prototype = {
concat: function concat(schema) {
if (!schema) return this;

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

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

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

next._type = schema._type;

return next;
},

Expand Down Expand Up @@ -215,7 +217,6 @@ SchemaType.prototype = {
test: function test(name, message, _test, useCallback) {
var opts = name,
next = this.clone(),
errorMsg,
isExclusive;

if (typeof name === 'string') {
Expand Down
3 changes: 1 addition & 2 deletions lib/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ function NumberSchema() {
inherits(NumberSchema, SchemaObject, {

_typeCheck: function _typeCheck(v) {
return typeof v === 'number' && !(v !== +v) //isNaN check
;
return typeof v === 'number' && !(v !== +v); //isNaN check
},

min: function min(_min, msg) {
Expand Down
18 changes: 11 additions & 7 deletions lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
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; };

var MixedSchema = require('./mixed');
var Promise = require('promise/lib/es6-extensions')
var Promise = require('promise/lib/es6-extensions');
//, Reference = require('./util/Reference')
;var cloneDeep = require('./util/clone');
var cloneDeep = require('./util/clone');
var toposort = require('toposort');
var locale = require('./locale.js').object;
var split = require('property-expr').split;
Expand Down Expand Up @@ -176,14 +176,18 @@ inherits(ObjectSchema, MixedSchema, {

from: function from(_from, to, alias) {
return this.transform(function (obj) {
var newObj = obj;

if (obj == null) return obj;

var newObj = transform(obj, function (o, val, key) {
return key !== _from && (o[key] = val);
}, {});
if (has(obj, _from)) {
newObj = transform(obj, function (o, val, key) {
return key !== _from && (o[key] = val);
}, {});
newObj[to] = obj[_from];

newObj[to] = obj[_from];
if (alias) newObj[_from] = obj[_from];
if (alias) newObj[_from] = obj[_from];
}

return newObj;
});
Expand Down
3 changes: 2 additions & 1 deletion lib/util/condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ var Conditional = (function () {

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

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);
// 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}`)

is = typeof is === 'function' ? is : (function (is, value) {
return is === value;
Expand Down
2 changes: 1 addition & 1 deletion lib/util/isodate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function parseIsoDate(date) {
struct[3] = +struct[3] || 1;

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

// timestamps without timezone identifiers should be considered local time
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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/util/validation-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ ValidationError.prototype.toJSON = function () {
var _ref;

if (this.inner.length) return this.inner.reduce(function (list, e) {
list[e.path] = (list[e.path] || (list[e.path] = [])).concat({ errors: e.errors, path: e.path, type: e.type });
list[e.path] = (list[e.path] || (list[e.path] = [])).concat(e.toJSON());
return list;
}, {});

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

return err.errors;
};

0 comments on commit b84a0ae

Please sign in to comment.