Skip to content

Commit

Permalink
Support for empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajaxy committed Aug 30, 2018
1 parent 18e2d5b commit 12d0b79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -12,7 +12,7 @@ function castWithSchema(query, schema) {
}

function castProp(value, propertyDef) {
if (!value || !propertyDef) {
if (!propertyDef || value === undefined) {
return value;
}

Expand Down
24 changes: 22 additions & 2 deletions tests/all.test.js
Expand Up @@ -30,7 +30,11 @@ describe('All', () => {
s: ['777', '7.77', 'invalid-number'],
t: {}, // invalid array
u: 'value', // missing schema type
v: 'value', // missing type
v: 'value', // missing type,
w: '',
x: '', // `NaN` with integer
y: '', // `0` with number
z: '', // `true` with boolean
}, {
type: 'object',
properties: {
Expand Down Expand Up @@ -123,8 +127,20 @@ describe('All', () => {
type: 'number',
},
},
u: {
u: {},
w: {
type: 'string',
},
x: {
type: 'integer',
},
y: {
type: 'number',
},
z: {
type: 'boolean',
},

},
})).toEqual({
a: 'value',
Expand Down Expand Up @@ -155,6 +171,10 @@ describe('All', () => {
t: undefined,
u: 'value',
v: 'value',
w: '',
x: NaN,
y: 0,
z: true,
});
});
});

0 comments on commit 12d0b79

Please sign in to comment.