custom.js 869 B

1234567891011121314151617181920212223242526
  1. import {getVerboseFunction} from './values.js';
  2. // Apply the `verbose` function on each line
  3. export const applyVerboseOnLines = (printedLines, verboseInfo, fdNumber) => {
  4. const verboseFunction = getVerboseFunction(verboseInfo, fdNumber);
  5. return printedLines
  6. .map(({verboseLine, verboseObject}) => applyVerboseFunction(verboseLine, verboseObject, verboseFunction))
  7. .filter(printedLine => printedLine !== undefined)
  8. .map(printedLine => appendNewline(printedLine))
  9. .join('');
  10. };
  11. const applyVerboseFunction = (verboseLine, verboseObject, verboseFunction) => {
  12. if (verboseFunction === undefined) {
  13. return verboseLine;
  14. }
  15. const printedLine = verboseFunction(verboseLine, verboseObject);
  16. if (typeof printedLine === 'string') {
  17. return printedLine;
  18. }
  19. };
  20. const appendNewline = printedLine => printedLine.endsWith('\n')
  21. ? printedLine
  22. : `${printedLine}\n`;