mindee
Version:
Mindee Client Library for Node.js
42 lines (41 loc) • 1.12 kB
JavaScript
export 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
*/
export 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
*/
export 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.
*/
export function floatToString(value) {
if (value === null) {
return "";
}
return value.toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 5,
useGrouping: false,
});
}