console-table-printer
console-table-printer copied to clipboard
Render raw string
Hey!
I really appreciate your fantastic package!
I use render()
to get a string but it has come with ANSI escape codes like [37m
. Is there any way to get the raw text?
I want to use the output in a Telegram message so I need the raw text.
P.S. I can create a pull request if it's approved! Something like render(raw: boolean) => string
with the false
default value for raw
to have backward compatibility
Interesting idea! Lets create a function called renderRaw and get output from that. Feel free to open a PR
Been trying every RegEx I can think of / find and still can't get the control characters stripped from the output such that it renders as raw text. Bummer.
This could be a good regex to use to strip all special chars. Needs some testing though https://github.com/ayonious/console-table-printer/blob/master/src/utils/console-utils.ts#L5
After stripping all the ansii using that regex mentioned here This is how it looks like: To me its looking very much usable.
// Find the latest regex from [the code](https://github.com/ayonious/console-table-printer/blob/master/src/utils/console-utils.ts#L5)
const colorRegex = /\x1b\[\d{1,3}(;\d{1,3})*m/g; // \x1b[30m \x1b[305m \x1b[38;5m
export const stripAnsi = (str: string): string => str.replace(colorRegex, '');
// Create table and add rows.....
// render, strip and print
const rendered = stripAnsi(p.render());
console.log(rendered);
This has been included in this feature: https://console-table.netlify.app/docs/doc-no-ascii
If its not yet resolved feel free to open again