Skip to content

Commit

Permalink
refactor: use a function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed May 20, 2019
1 parent 85c448a commit f0c4d59
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ function Osom (schemaBlueprint, globalRules) {
if (isInvalidType) throwTypeError(name, value, expectedValue, isRequired)

let TypedValue
const defaultValue = rule.default

const defaultValue = isFunction(rule.default) ? rule.default : () => rule.default
if (hasValue) TypedValue = isCasting ? rule.type(value) : value
else if (defaultValue) TypedValue = !isFunction(defaultValue) ? defaultValue : defaultValue()
else if (defaultValue) TypedValue = defaultValue()

TypedValue = reduce(rule.transform, (acc, fn) => fn(acc), TypedValue)

Expand Down

0 comments on commit f0c4d59

Please sign in to comment.