Skip to content
Myr

custom.js

This file

Path

lib/verbose/custom.js

26 lines · 869 bytes · JavaScript

Last changed by

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

History of this file

Take it

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 1–26why, one step back
1import {getVerboseFunction} from './values.js';
23// Apply the `verbose` function on each line4export const applyVerboseOnLines = (printedLines, verboseInfo, fdNumber) => {5 const verboseFunction = getVerboseFunction(verboseInfo, fdNumber);6 return printedLines7 .map(({verboseLine, verboseObject}) => applyVerboseFunction(verboseLine, verboseObject, verboseFunction))8 .filter(printedLine => printedLine !== undefined)9 .map(printedLine => appendNewline(printedLine))10 .join('');11};1213const applyVerboseFunction = (verboseLine, verboseObject, verboseFunction) => {14 if (verboseFunction === undefined) {15 return verboseLine;16 }1718 const printedLine = verboseFunction(verboseLine, verboseObject);19 if (typeof printedLine === 'string') {20 return printedLine;21 }22};2324const appendNewline = printedLine => printedLine.endsWith('\n')25 ? printedLine26 : `${printedLine}\n`;