Ported (basically 1 to 1) the powerful tess2.js (https://github.com/memononen/tess2.js)