Skip to content

Commit

Permalink
fix: ensure transform is an array
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed May 26, 2019
1 parent 576826a commit aa970e7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
'use strict'

const { isNil, isFunction, isBoolean, merge, reduce } = require('lodash')
const {
isNil,
isFunction,
isBoolean,
merge,
reduce,
castArray
} = require('lodash')
const { format } = require('util')
const chaste = require('chaste')
const is = require('kind-of')
Expand Down Expand Up @@ -97,7 +104,11 @@ function Osom (schemaBlueprint, globalRules) {
if (hasValue) TypedValue = isCasting ? rule.type(value) : value
else if (defaultValue) TypedValue = defaultValue()

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

if (isRequired && validate) {
const validator = getValidator(rule)
Expand Down

0 comments on commit aa970e7

Please sign in to comment.