diff --git a/src/utils/getResultsFromFnsList.ts b/src/utils/getResultsFromFnsList.ts index 9b4bcce..5ad94c3 100644 --- a/src/utils/getResultsFromFnsList.ts +++ b/src/utils/getResultsFromFnsList.ts @@ -1,33 +1,12 @@ +import { orange } from './cliColors'; +import { shouldShortCircuit } from './shouldShortCircuit'; import type { AnyObject, Context, MergePropsOptions, MergePropsOptionsSequential, PropsResult, - ShortCircuitType, } from '../types'; -import { orange } from './cliColors'; - -const shouldShortCircuit = ( - result: PropsResult, - shortCircuit?: ShortCircuitType -) => { - if (!shortCircuit || shortCircuit === 'never') { - return false; - } - - const hasRedirect: boolean = 'redirect' in result && !!result?.redirect; - const hasNotFound: boolean = 'notFound' in result && !!result?.notFound; - - switch (shortCircuit) { - case 'redirect-and-notfound': - return hasRedirect || hasNotFound; - case 'redirect-only': - return hasRedirect; - case 'notfound-only': - return hasNotFound; - } -}; export const getResultsFromFnsList = async

( ctx: Context, diff --git a/src/utils/shouldShortCircuit.ts b/src/utils/shouldShortCircuit.ts new file mode 100644 index 0000000..b3bacb9 --- /dev/null +++ b/src/utils/shouldShortCircuit.ts @@ -0,0 +1,22 @@ +import type { PropsResult, ShortCircuitType } from '../types'; + +export const shouldShortCircuit = ( + result: PropsResult, + shortCircuit?: ShortCircuitType +) => { + if (!shortCircuit || shortCircuit === 'never') { + return false; + } + + const hasRedirect: boolean = 'redirect' in result && !!result?.redirect; + const hasNotFound: boolean = 'notFound' in result && !!result?.notFound; + + switch (shortCircuit) { + case 'redirect-and-notfound': + return hasRedirect || hasNotFound; + case 'redirect-only': + return hasRedirect; + case 'notfound-only': + return hasNotFound; + } +};