Skip to content

Commit ff0e327

Browse files
authored
Add strict mode directive (#1003)
1 parent 4389040 commit ff0e327

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+122
-0
lines changed

.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
"mocha": true,
88
"worker": true
99
},
10+
"parserOptions": {
11+
// airbnb-base sets this to "modules" for ESM but CJS is being used
12+
"sourceType": "script"
13+
},
1014
"rules": {
15+
"strict": ["error", "global"],
1116
"no-underscore-dangle": 0,
1217
"no-console": 0,
1318
"global-require": 0,

benchmarks/node/memory-benchmark.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env node
22

3+
'use strict';
4+
35
// Note: getting replicable results from this script requires:
46
// (1) Running with the `--expose-gc` flag,
57
// (2) adding `global.gc()` within the `index.js` file

benchmarks/node/speed-benchmark.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env node
2+
3+
'use strict';
4+
25
const path = require('path');
36
const { createWorker } = require('../..');
47

examples/node/download-pdf.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env node
2+
3+
'use strict';
4+
25
const path = require('path');
36
const fs = require('fs');
47
const { createWorker } = require('../..');

examples/node/image-processing.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env node
2+
3+
'use strict';
4+
25
const path = require('path');
36
const fs = require('fs');
47
const { createWorker } = require('../..');

examples/node/recognize.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env node
2+
3+
'use strict';
4+
25
const path = require('path');
36
const { createWorker } = require('../..');
47

examples/node/scheduler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const path = require('path');
24
const { createWorker, createScheduler } = require('../..');
35

scripts/server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const webpack = require('webpack');
24
const middleware = require('webpack-dev-middleware');
35
const express = require('express');

scripts/test-helper.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const constants = require('../tests/constants');
24
global.expect = require('expect.js');
35
global.fs = require('fs');

scripts/webpack.config.common.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
module.exports = {
24
resolve: {
35
fallback: {

scripts/webpack.config.prod.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const path = require('path');
24
const common = require('./webpack.config.common');
35
const webpack = require('webpack');

src/Tesseract.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const createWorker = require('./createWorker');
24

35
const recognize = async (image, langs, options) => {

src/constants/OEM.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/*
24
* OEM = OCR Engine Mode, and there are 4 possible modes.
35
*

src/constants/PSM.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/*
24
* PSM = Page Segmentation Mode
35
*/

src/constants/defaultOptions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
module.exports = {
24
/*
35
* Use BlobURL for worker script by default

src/constants/imageType.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
module.exports = {
24
COLOR: 0,
35
GREY: 1,

src/constants/languages.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/*
24
* languages with existing tesseract traineddata
35
* https://tesseract-ocr.github.io/tessdoc/Data-Files#data-files-for-version-400-november-29-2016

src/createJob.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const getId = require('./utils/getId');
24

35
let jobCounter = 0;

src/createScheduler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const createJob = require('./createJob');
24
const { log } = require('./utils/log');
35
const getId = require('./utils/getId');

src/createWorker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const resolvePaths = require('./utils/resolvePaths');
24
const createJob = require('./createJob');
35
const { log } = require('./utils/log');

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
*
35
* Entry point for tesseract.js, should be the entry when bundling.

src/utils/getEnvironment.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
module.exports = (key) => {
24
const env = {};
35

src/utils/getId.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
module.exports = (prefix, cnt) => (
24
`${prefix}-${cnt}-${Math.random().toString(16).slice(3, 8)}`
35
);

src/utils/log.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
let logging = false;
24

35
exports.logging = logging;

src/utils/resolvePaths.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const isBrowser = require('./getEnvironment')('type') === 'browser';
24

35
const resolveURL = isBrowser ? s => (new URL(s, window.location.href)).href : s => s; // eslint-disable-line

src/worker-script/browser/cache.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const { set, get, del } = require('idb-keyval');
24

35
module.exports = {

src/worker-script/browser/getCore.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const { simd } = require('wasm-feature-detect');
24
const coreVersion = require('../../../package.json').dependencies['tesseract.js-core'];
35

src/worker-script/browser/gunzip.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
'use strict';
2+
13
module.exports = require('zlibjs').gunzipSync;

src/worker-script/browser/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
*
35
* Browser worker scripts

src/worker-script/constants/defaultOutput.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/*
24
* default output formats for tesseract.js
35
*/

src/worker-script/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
*
35
* Worker script for browser and node

src/worker-script/node/cache.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const util = require('util');
24
const fs = require('fs');
35

src/worker-script/node/getCore.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const { simd } = require('wasm-feature-detect');
24
const OEM = require('../../constants/OEM');
35

src/worker-script/node/gunzip.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
'use strict';
2+
13
module.exports = require('zlib').gunzipSync;

src/worker-script/node/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
*
35
* Tesseract Worker Script for Node

src/worker-script/utils/arrayBufferToBase64.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
// Copied from https://gist.github.com/jonleighton/958841
24
// Copyright 2011 Jon Leighton, MIT LICENSE
35

src/worker-script/utils/dump.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
*
35
* Dump data to a big JSON tree

src/worker-script/utils/setImage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const bmp = require('bmp-js');
24

35
/**

src/worker/browser/defaultOptions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const version = require('../../../package.json').version;
24
const defaultOptions = require('../../constants/defaultOptions');
35

src/worker/browser/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
*
35
* Tesseract Worker adapter for browser

src/worker/browser/loadImage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
* readFromBlobOrFile
35
*

src/worker/browser/onMessage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
module.exports = (worker, handler) => {
24
worker.onmessage = ({ data }) => { // eslint-disable-line
35
handler(data);

src/worker/browser/send.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
* send
35
*

src/worker/browser/spawnWorker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
* spawnWorker
35
*

src/worker/browser/terminateWorker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
* terminateWorker
35
*

src/worker/node/defaultOptions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const path = require('path');
24
const defaultOptions = require('../../constants/defaultOptions');
35

src/worker/node/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
*
35
* Tesseract Worker impl. for node (using child_process)

src/worker/node/loadImage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const util = require('util');
24
const fs = require('fs');
35
const fetch = require('node-fetch');

src/worker/node/onMessage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
module.exports = (worker, handler) => {
24
worker.on('message', handler);
35
};

src/worker/node/send.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
* send
35
*

src/worker/node/spawnWorker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const { Worker } = require('worker_threads');
24

35
/**

src/worker/node/terminateWorker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
/**
24
* terminateWorker
35
*

tests/FS.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const { createWorker } = Tesseract;
24
const FS_WAIT = 500;
35
let worker;

tests/constants.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/detect.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const { createWorker } = Tesseract;
24
let worker;
35
before(async function cb() {

tests/recognize.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
'use strict';
2+
13
const { createWorker, PSM } = Tesseract;
24
let worker;
5+
let workerLegacy;
36
before(async function cb() {
47
this.timeout(0);
58
worker = await createWorker('eng', 1, OPTIONS);

tests/scheduler.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const { createScheduler, createWorker } = Tesseract;
24

35
let workers = [];

0 commit comments

Comments
 (0)