UNPKG

@envelop/core

Version:

This is the core package for Envelop. You can find a complete documentation here: https://github.com/n1ru4l/envelop

18 lines (17 loc) 560 B
import { handleStreamOrSingleExecutionResult } from '../utils.js'; const makeHandleResult = (formatter) => ({ args, result, setResult, }) => { const modified = formatter(result, args); if (modified !== false) { setResult(modified); } }; export const usePayloadFormatter = (formatter) => ({ onExecute() { const handleResult = makeHandleResult(formatter); return { onExecuteDone(payload) { return handleStreamOrSingleExecutionResult(payload, handleResult); }, }; }, });