Skip to content

Commit

Permalink
Fix globalRules shallow copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jul 8, 2016
1 parent e207650 commit ade0966
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -22,7 +22,7 @@ var DEFAULT = {

function createSchemaRule (rule, globalRules) {
var schema = typeof rule === 'function' ? { type: rule } : rule
var fields = merge(globalRules, schema)
var fields = merge({}, globalRules, schema)
return assign({}, DEFAULT.BLUEPRINT, fields)
}

Expand Down Expand Up @@ -61,13 +61,13 @@ function Osom (schemaBlueprint, globalRules) {
obj = obj || {}

return reduce(schema, function applyRule (objSchema, rule, name) {
var hasValue = exists(obj[name])
var value = obj[name]
var hasValue = exists(value)

if ((rule.required && !hasValue) || (hasValue && !rule.casting && type(value !== schemaTypes[name]))) {
if ((rule.required && !hasValue) || (hasValue && !rule.casting && type(value) !== schemaTypes[name])) {
throwTypeError(name, schemaTypes[name], rule.required)
}

var value
if (rule.casting && hasValue) value = rule.type(obj[name])
else if (rule.default) value = !isFunction(rule.default) ? rule.default : rule.default()

Expand Down

0 comments on commit ade0966

Please sign in to comment.