I was trying to use the standard example from ansi-to-html
npm
packae.
var Convert = require('ansi-to-html');
var convert = new Convert();
console.log(convert.toHtml('\x1b[30mblack\x1b[37mwhite'));
And while trying to wrap the example into an Observable Cell, I’ve got the TypeError: Convert is not a constructor
. The Cell.
ansitohtml = {
let Convert = require('https://bundle.run/ansi-to-html@0.6.14');
let convert = new Convert();
return convert
}
The Error.
The error here happens because Observable require
is asynchronous (returns a promise) and constructors in JavaScript are not - new
operation doesn’t understand what a promise is. The solution is to await
until the promise resolves.
ansitohtml = {
let Convert = await require('https://bundle.run/ansi-to-html@0.6.14');
let convert = new Convert();
return convert
}
ansitohtml.toHtml('\x1b[94mRunning number: \x1b[96mtest_line\e[0m')
Or maybe Observable language can make new
operation understand asynchronous objects as well?