Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request jquense#18 from alpacaaa/patch-string
Browse files Browse the repository at this point in the history
String objects should be considered valid strings.
  • Loading branch information
jquense committed Dec 14, 2015
2 parents b84a0ae + 067500b commit ad4390c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

5 changes: 4 additions & 1 deletion src/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -99,4 +99,4 @@ inherits(StringSchema, MixedSchema, {
test: val => val == null || val === val.toUpperCase()
})
}
})
})
1 change: 1 addition & 0 deletions test/bool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion test/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -135,4 +136,4 @@ describe('String types', function(){
.should.eventually.equal(false)
])
})
})
})

0 comments on commit ad4390c

Please sign in to comment.