UNPKG

mindee

Version:

Mindee Client Library for Node.js

48 lines (47 loc) 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cleanOutString = cleanOutString; exports.lineSeparator = lineSeparator; exports.cleanSpecialChars = cleanSpecialChars; exports.floatToString = floatToString; function cleanOutString(outStr) { const lines = / \n/gm; return outStr.replace(lines, "\n"); } /** * * @param columnSizes Size of each column in the table * @param separator character for a separator * @returns A separator for table lines */ function lineSeparator(columnSizes, separator) { let outStr = " +"; columnSizes.forEach((size) => { outStr += separator.repeat(size) + "+"; }); return outStr; } /** * Replaces all special characters like \n, \r, \t, with an equivalent that can be displayed on a single line. * Also trims line breaks at the end of the string. * @param outStr */ function cleanSpecialChars(outStr) { return outStr .replace(/\n/g, "\\n") .replace(/\r/g, "\\r") .replace(/\t/g, "\\t"); } /** * Return a float as a string with at least 2 levels of precision. */ function floatToString(value) { if (value === null) { return ""; } return value.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 5, useGrouping: false, }); }