Browse Source

Optimize eslint

pull/491/head
Jerome Wu 4 years ago
parent
commit
920dd902f8
  1. 2
      .eslintrc
  2. 1263
      package-lock.json
  3. 9
      package.json
  4. 2
      src/createWorker.js
  5. 4
      src/worker-script/browser/cache.js
  6. 4
      src/worker-script/browser/index.js
  7. 4
      src/worker-script/index.js
  8. 6
      src/worker-script/node/cache.js
  9. 4
      src/worker-script/node/index.js
  10. 4
      src/worker-script/utils/dump.js
  11. 6
      src/worker/browser/loadImage.js

2
.eslintrc

@ -1,5 +1,5 @@
{ {
"extends": "airbnb", "extends": "airbnb-base",
"env": { "env": {
"browser": true, "browser": true,
"node": true, "node": true,

1263
package-lock.json generated

File diff suppressed because it is too large Load Diff

9
package.json

@ -23,6 +23,7 @@
"test:browser:scheduler": "npm run test:browser-tpl -- -f ./tests/scheduler.test.html", "test:browser:scheduler": "npm run test:browser-tpl -- -f ./tests/scheduler.test.html",
"test:browser:FS": "npm run test:browser-tpl -- -f ./tests/FS.test.html", "test:browser:FS": "npm run test:browser-tpl -- -f ./tests/FS.test.html",
"lint": "eslint src", "lint": "eslint src",
"lint:fix": "eslint --fix src",
"postinstall": "opencollective-postinstall || true" "postinstall": "opencollective-postinstall || true"
}, },
"browser": { "browser": {
@ -39,11 +40,9 @@
"acorn": "^6.4.0", "acorn": "^6.4.0",
"babel-loader": "^8.1.0", "babel-loader": "^8.1.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"eslint": "^5.16.0", "eslint": "^7.2.0",
"eslint-config-airbnb": "^17.1.1", "eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.19.1", "eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.17.0",
"expect.js": "^0.3.1", "expect.js": "^0.3.1",
"express": "^4.17.1", "express": "^4.17.1",
"mocha": "^5.2.0", "mocha": "^5.2.0",

2
src/createWorker.js

@ -53,7 +53,7 @@ module.exports = (_options = {}) => {
}) })
); );
const load = jobId => ( const load = (jobId) => (
startJob(createJob({ startJob(createJob({
id: jobId, action: 'load', payload: { options }, id: jobId, action: 'load', payload: { options },
})) }))

4
src/worker-script/browser/cache.js

@ -4,7 +4,7 @@ module.exports = {
readCache: get, readCache: get,
writeCache: set, writeCache: set,
deleteCache: del, deleteCache: del,
checkCache: path => ( checkCache: (path) => (
get(path).then(v => typeof v !== 'undefined') get(path).then((v) => typeof v !== 'undefined')
), ),
}; };

4
src/worker-script/browser/index.js

@ -8,7 +8,7 @@
* @author Jerome Wu <jeromewus@gmail.com> * @author Jerome Wu <jeromewus@gmail.com>
*/ */
const worker = require('../'); const worker = require('..');
const getCore = require('./getCore'); const getCore = require('./getCore');
const gunzip = require('./gunzip'); const gunzip = require('./gunzip');
const cache = require('./cache'); const cache = require('./cache');
@ -17,7 +17,7 @@ const cache = require('./cache');
* register message handler * register message handler
*/ */
global.addEventListener('message', ({ data }) => { global.addEventListener('message', ({ data }) => {
worker.dispatchHandlers(data, obj => postMessage(obj)); worker.dispatchHandlers(data, (obj) => postMessage(obj));
}); });
/* /*

4
src/worker-script/index.js

@ -154,7 +154,7 @@ const loadLanguage = async ({
const setParameters = ({ payload: { params: _params } }, res) => { const setParameters = ({ payload: { params: _params } }, res) => {
Object.keys(_params) Object.keys(_params)
.filter(k => !k.startsWith('tessjs_')) .filter((k) => !k.startsWith('tessjs_'))
.forEach((key) => { .forEach((key) => {
api.SetVariable(key, _params[key]); api.SetVariable(key, _params[key]);
}); });
@ -171,7 +171,7 @@ const initialize = ({
}, res) => { }, res) => {
const langs = (typeof _langs === 'string') const langs = (typeof _langs === 'string')
? _langs ? _langs
: _langs.map(l => ((typeof l === 'string') ? l : l.data)).join('+'); : _langs.map((l) => ((typeof l === 'string') ? l : l.data)).join('+');
try { try {
res.progress({ res.progress({

6
src/worker-script/node/cache.js

@ -4,13 +4,13 @@ const fs = require('fs');
module.exports = { module.exports = {
readCache: util.promisify(fs.readFile), readCache: util.promisify(fs.readFile),
writeCache: util.promisify(fs.writeFile), writeCache: util.promisify(fs.writeFile),
deleteCache: path => ( deleteCache: (path) => (
util.promisify(fs.unlink)(path) util.promisify(fs.unlink)(path)
.catch(() => {}) .catch(() => {})
), ),
checkCache: path => ( checkCache: (path) => (
util.promisify(fs.access)(path, fs.F_OK) util.promisify(fs.access)(path, fs.F_OK)
.then(err => (err === null)) .then((err) => (err === null))
.catch(() => false) .catch(() => false)
), ),
}; };

4
src/worker-script/node/index.js

@ -9,7 +9,7 @@
*/ */
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const worker = require('../'); const worker = require('..');
const getCore = require('./getCore'); const getCore = require('./getCore');
const gunzip = require('./gunzip'); const gunzip = require('./gunzip');
const cache = require('./cache'); const cache = require('./cache');
@ -18,7 +18,7 @@ const cache = require('./cache');
* register message handler * register message handler
*/ */
process.on('message', (packet) => { process.on('message', (packet) => {
worker.dispatchHandlers(packet, obj => process.send(obj)); worker.dispatchHandlers(packet, (obj) => process.send(obj));
}); });
worker.setAdapter({ worker.setAdapter({

4
src/worker-script/utils/dump.js

@ -61,8 +61,8 @@ module.exports = (TessModule, api, {
const enumToString = (value, prefix) => ( const enumToString = (value, prefix) => (
Object.keys(TessModule) Object.keys(TessModule)
.filter(e => (e.startsWith(`${prefix}_`) && TessModule[e] === value)) .filter((e) => (e.startsWith(`${prefix}_`) && TessModule[e] === value))
.map(e => e.slice(prefix.length + 1))[0] .map((e) => e.slice(prefix.length + 1))[0]
); );
ri.Begin(); ri.Begin();

6
src/worker/browser/loadImage.js

@ -8,7 +8,7 @@ const blueimpLoadImage = require('blueimp-load-image');
* @function * @function
* @access private * @access private
*/ */
const readFromBlobOrFile = blob => ( const readFromBlobOrFile = (blob) => (
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const fileReader = new FileReader(); const fileReader = new FileReader();
fileReader.onload = () => { fileReader.onload = () => {
@ -21,11 +21,11 @@ const readFromBlobOrFile = blob => (
}) })
); );
const fixOrientationFromUrlOrBlobOrFile = blob => ( const fixOrientationFromUrlOrBlobOrFile = (blob) => (
new Promise((resolve) => { new Promise((resolve) => {
blueimpLoadImage( blueimpLoadImage(
blob, blob,
img => img.toBlob(resolve), (img) => img.toBlob(resolve),
{ {
orientation: true, orientation: true,
canvas: true, canvas: true,

Loading…
Cancel
Save