diff --git a/.eslintrc b/.eslintrc index 0283e5f..fa01611 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,6 +6,7 @@ }, "rules": { "no-underscore-dangle": 0, - "no-console": 0 + "no-console": 0, + "global-require": 0 } } diff --git a/src/node/worker.js b/src/node/worker.js index bea5d5c..1531d34 100644 --- a/src/node/worker.js +++ b/src/node/worker.js @@ -1,19 +1,20 @@ -const workerUtils = require('../common/worker.js') +const check = require('check-types'); +const workerUtils = require('../common/worker'); -process.on('message', function(packet){ - workerUtils.dispatchHandlers(packet, obj => process.send(obj)) -}) +let TesseractCore = null; -var TesseractCore; -exports.getCore = function(req, res){ - if(!TesseractCore){ - res.progress({ status: 'loading tesseract core' }) - TesseractCore = require('tesseract.js-core') - res.progress({ status: 'loaded tesseract core' }) - } - return TesseractCore -} - -exports.getLanguageData = require('./lang.js') +process.on('message', (packet) => { + workerUtils.dispatchHandlers(packet, obj => process.send(obj)); +}); -workerUtils.setAdapter(module.exports); +workerUtils.setAdapter({ + getCore: (req, res) => { + if (check.null(TesseractCore)) { + res.progress({ status: 'loading tesseract core' }); + TesseractCore = require('tesseract.js-core'); + res.progress({ status: 'loaded tesseract core' }); + } + return TesseractCore; + }, + getLanguageData: require('./lang'), +});