diff --git a/src/boolean.js b/src/boolean.js index 935b44143..aa9af89ea 100644 --- a/src/boolean.js +++ b/src/boolean.js @@ -19,7 +19,7 @@ function BooleanSchema(){ inherits(BooleanSchema, MixedSchema, { _typeCheck(v){ - return typeof v === 'boolean' + return (typeof v === 'boolean') || (typeof v === 'object' && v instanceof Boolean) } }) diff --git a/src/number.js b/src/number.js index 12f835b67..355076070 100644 --- a/src/number.js +++ b/src/number.js @@ -22,7 +22,10 @@ function NumberSchema(){ inherits(NumberSchema, SchemaObject, { _typeCheck(v) { - return typeof v === 'number' && !(v !== +v) //isNaN check + if ( typeof v === 'number' && !(v !== +v) ) return true + if ( typeof v === 'object' && v instanceof Number ) return true + + return false }, min(min, msg) { diff --git a/src/string.js b/src/string.js index 83be11495..7a6c45ddd 100644 --- a/src/string.js +++ b/src/string.js @@ -24,7 +24,7 @@ function StringSchema(){ inherits(StringSchema, MixedSchema, { _typeCheck(value) { - return typeof value === 'string' + return (typeof value === 'string') || (typeof value === 'object' && value instanceof String) }, required(msg){ @@ -99,4 +99,4 @@ inherits(StringSchema, MixedSchema, { test: val => val == null || val === val.toUpperCase() }) } -}) \ No newline at end of file +}) diff --git a/test/bool.js b/test/bool.js index fef55bd3b..addc01c82 100644 --- a/test/bool.js +++ b/test/bool.js @@ -40,6 +40,7 @@ describe('Boolean types', function(){ inst.isType('true').should.equal(false) inst.isType(NaN).should.equal(false) inst.isType(34545).should.equal(false) + inst.isType(new Boolean(false)).should.equal(true) chai.expect( inst.isType(null)).to.equal(false) inst.nullable().isType(null).should.equal(true) diff --git a/test/number.js b/test/number.js index 0897286d8..de5b47748 100644 --- a/test/number.js +++ b/test/number.js @@ -48,6 +48,7 @@ describe('Number types', function(){ var inst = number() inst.isType(5).should.equal(true) + inst.isType(new Number(5)).should.equal(true) inst.isType(false).should.equal(false) inst.isType(null).should.equal(false) inst.isType(NaN).should.equal(false) diff --git a/test/string.js b/test/string.js index 420afb040..ad9ee4779 100644 --- a/test/string.js +++ b/test/string.js @@ -52,6 +52,7 @@ describe('String types', function(){ var inst = string() inst.isType('5').should.equal(true) + inst.isType(new String('5')).should.equal(true) inst.isType(false).should.equal(false) inst.isType(null).should.equal(false) inst.nullable(false).isType(null).should.equal(false) @@ -135,4 +136,4 @@ describe('String types', function(){ .should.eventually.equal(false) ]) }) -}) \ No newline at end of file +})