Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 20, 2022
1 parent bb19da3 commit 88b9da2
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/config/normalize/lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@ export const transformValue = async function (value, transform, opts) {
return getTransformMove(transformReturn, opts)
}

const commonMove = COMMON_MOVES.find(({ test }) =>
test(transformReturn, value),
)

if (commonMove === undefined) {
return { value: transformReturn }
}

const newPath = commonMove.getNewPath(transformReturn)
const newPathA = `${opts.funcOpts.name}.${newPath}`
return { value: transformReturn, newPath: newPathA }
const commonMoveReturn = applyCommonMoves(transformReturn, value, opts)
return commonMoveReturn === undefined
? { value: transformReturn }
: commonMoveReturn
}

// `transform()` can return a `{ newPath, value }` object to indicate the
Expand All @@ -43,6 +36,20 @@ const getTransformMove = function ({ newPath, value }, { funcOpts: { name } }) {
return { newPath: `${name}.${newPath}`, value }
}

const applyCommonMoves = function (transformReturn, value, opts) {
const commonMove = COMMON_MOVES.find(({ test }) =>
test(transformReturn, value),
)

if (commonMove === undefined) {
return
}

const newPath = commonMove.getNewPath(transformReturn)
const newPathA = `${opts.funcOpts.name}.${newPath}`
return { value: transformReturn, newPath: newPathA }
}

const COMMON_MOVES = [
{
test(newValue, oldValue) {
Expand Down

0 comments on commit 88b9da2

Please sign in to comment.