Skip to content

Commit ad4390c

Browse files
committed
Merge pull request #18 from alpacaaa/patch-string
String objects should be considered valid strings.
2 parents b84a0ae + 067500b commit ad4390c

File tree

6 files changed

+11
-5
lines changed

6 files changed

+11
-5
lines changed

src/boolean.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function BooleanSchema(){
1919
inherits(BooleanSchema, MixedSchema, {
2020

2121
_typeCheck(v){
22-
return typeof v === 'boolean'
22+
return (typeof v === 'boolean') || (typeof v === 'object' && v instanceof Boolean)
2323
}
2424
})
2525

src/number.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ function NumberSchema(){
2222
inherits(NumberSchema, SchemaObject, {
2323

2424
_typeCheck(v) {
25-
return typeof v === 'number' && !(v !== +v) //isNaN check
25+
if ( typeof v === 'number' && !(v !== +v) ) return true
26+
if ( typeof v === 'object' && v instanceof Number ) return true
27+
28+
return false
2629
},
2730

2831
min(min, msg) {

src/string.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function StringSchema(){
2424
inherits(StringSchema, MixedSchema, {
2525

2626
_typeCheck(value) {
27-
return typeof value === 'string'
27+
return (typeof value === 'string') || (typeof value === 'object' && value instanceof String)
2828
},
2929

3030
required(msg){
@@ -99,4 +99,4 @@ inherits(StringSchema, MixedSchema, {
9999
test: val => val == null || val === val.toUpperCase()
100100
})
101101
}
102-
})
102+
})

test/bool.js

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('Boolean types', function(){
4040
inst.isType('true').should.equal(false)
4141
inst.isType(NaN).should.equal(false)
4242
inst.isType(34545).should.equal(false)
43+
inst.isType(new Boolean(false)).should.equal(true)
4344
chai.expect(
4445
inst.isType(null)).to.equal(false)
4546
inst.nullable().isType(null).should.equal(true)

test/number.js

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe('Number types', function(){
4848
var inst = number()
4949

5050
inst.isType(5).should.equal(true)
51+
inst.isType(new Number(5)).should.equal(true)
5152
inst.isType(false).should.equal(false)
5253
inst.isType(null).should.equal(false)
5354
inst.isType(NaN).should.equal(false)

test/string.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe('String types', function(){
5252
var inst = string()
5353

5454
inst.isType('5').should.equal(true)
55+
inst.isType(new String('5')).should.equal(true)
5556
inst.isType(false).should.equal(false)
5657
inst.isType(null).should.equal(false)
5758
inst.nullable(false).isType(null).should.equal(false)
@@ -135,4 +136,4 @@ describe('String types', function(){
135136
.should.eventually.equal(false)
136137
])
137138
})
138-
})
139+
})

0 commit comments

Comments
 (0)