Skip to content

Commit

Permalink
Setup default value under nill values
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Apr 3, 2016
1 parent 1618956 commit 0b8083a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ var assign = require('lodash/assign')
var flow = require('lodash/flow')
var chaste = require('chaste')

function exists (value) {
return value != null
}

function createSchemaRule (rule) {
var blueprint = { filter: [] }
var schema = typeof rule === 'function' ? { type: rule } : rule
Expand All @@ -51,7 +55,7 @@ function Ardent (schemaBlueprint) {

return reduce(schema, function applyRule (objSchema, rule, name) {
var applyFilters = flow(rule.filter)
var value = obj[name] ? rule.type(obj[name]) : rule.default
var value = exists(obj[name]) ? rule.type(obj[name]) : rule.default
objSchema[name] = applyFilters(value)
return objSchema
}, {})
Expand Down

0 comments on commit 0b8083a

Please sign in to comment.