UNPKG

map-transform

Version:

Map and transform objects with mapping definitions

17 lines 791 B
import { getStateValue, setStateValue, revFromState, } from '../utils/stateHelpers.js'; export default function transform(fn, revFn) { return (options) => { if (typeof fn !== 'function') { throw new Error('Transform operation was called without a valid transformer function'); } const fwdPipeline = fn(options); const revPipeline = typeof revFn === 'function' ? revFn(options) : fwdPipeline; return (next) => async (state) => { const nextState = await next(state); const fn = revFromState(nextState) ? revPipeline : fwdPipeline; const value = await fn(getStateValue(nextState), nextState); return setStateValue(nextState, value); }; }; } //# sourceMappingURL=transform.js.map