diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..9498e50b Binary files /dev/null and b/.DS_Store differ diff --git a/.babelrc b/.babelrc index 09b5e3c3..feccf134 100644 --- a/.babelrc +++ b/.babelrc @@ -1,33 +1,31 @@ { + "presets": [ + "@babel/env", + "@babel/typescript" + ], "plugins": [ - "check-es2015-constants", - "transform-es2015-arrow-functions", - "transform-es2015-block-scoped-functions", - "transform-es2015-block-scoping", - ["transform-es2015-classes", { "loose": true }], - ["transform-es2015-computed-properties", { "loose": true }], - ["transform-es2015-destructuring", { "loose": true }], - ["transform-es2015-for-of", { "loose": true }], - "transform-es2015-function-name", - "transform-es2015-literals", - - "transform-es2015-object-super", - "transform-es2015-parameters", - "transform-es2015-shorthand-properties", - ["transform-es2015-spread", { "loose": true }], - "transform-es2015-sticky-regex", - ["transform-es2015-template-literals", { "loose": true }], - "transform-es2015-unicode-regex", - "transform-es2015-typeof-symbol", - "transform-object-rest-spread", - "lodash" -], -"env": { - "commonjs": { + "@babel/proposal-class-properties", + "@babel/proposal-object-rest-spread", + "@babel/transform-runtime" + ], + "env": { + "node": { "plugins": [ - ["transform-es2015-modules-commonjs", { "loose": true }], - "add-module-exports" + "add-module-exports" + ] + }, + "test": { + "plugins": [ + "add-module-exports", + [ + "istanbul", + { + "exclude": [ + "**/*.spec.js" + ] + } + ] ] } } -} +} \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index 628f4846..623e6d00 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,35 +1,21 @@ { - "settings" : { - "ecmascript": 6, - "jsx": true + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 2018, + "sourceType": "module" }, "env": { "browser": true, + "es6": true, "node": true }, - "ecmaFeatures": { - "blockBindings": true, - "forOf": true, - "defaultParams": true, - "globalReturn": false, - "modules": true, - "objectLiteralShorthandMethods": true, - "objectLiteralShorthandProperties": true, - "templateStrings": true, - "spread": true, - "jsx": true, - "arrowFunctions": true, - "classes": true, - "destructuring": true, - "objectLiteralComputedProperties": true - }, "globals": { - "ENV": true, - "beforeEach": true, - "describe": true, - "it": true, - "expect": true, - "sinon": true + "ENV": "readonly", + "beforeEach": "readonly", + "describe": "readonly", + "it": "readonly", + "expect": "readonly", + "sinon": "readonly" }, "rules": { "no-unused-expressions": 1, @@ -42,7 +28,10 @@ "eqeqeq": 2, "guard-for-in": 2, "wrap-iife": 0, - "no-use-before-define": [1, "nofunc"], + "no-use-before-define": [ + 1, + "nofunc" + ], "new-cap": 2, "quotes": 0, "strict": 0, @@ -52,18 +41,44 @@ "no-plusplus": 0, "no-unused-vars": 1, "no-trailing-spaces": 2, - // STYLE - "max-params": [2, 7], - "key-spacing": [1, { - beforeColon: false, - afterColon: true - }], - "indent": [2, 4], - "brace-style": [2, "1tbs"], - "comma-spacing": [2, {before: false, after: true}], - "comma-style": [2, "last"], - "consistent-this": [1, "self"], + "max-params": [ + 2, + 7 + ], + "key-spacing": [ + 1, + { + "beforeColon": false, + "afterColon": true + } + ], + "indent": [ + "error", + 4, + { + "SwitchCase": 1 + } + ], + "brace-style": [ + 2, + "1tbs" + ], + "comma-spacing": [ + 2, + { + "before": false, + "after": true + } + ], + "comma-style": [ + 2, + "last" + ], + "consistent-this": [ + 1, + "self" + ], "eol-last": 0, "new-parens": 2, "no-array-constructor": 2, @@ -74,12 +89,20 @@ "no-spaced-func": 1, "no-shadow": 2, "no-undef": 2, - "padded-blocks": [2, "never"], - "semi": [2, "always"], - "space-after-keywords": [2, "always"], + "padded-blocks": [ + 2, + "never" + ], + "semi": [ + 2, + "always" + ], "space-infix-ops": 2, - "max-len" : [1, 120], + "max-len": [ + 1, + 120 + ], "consistent-return": 2, "yoda": 2 } -} +} \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index a57c82d8..00000000 --- a/Gruntfile.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = function(grunt) { - // Project configuration. - grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), - karma: { - unit: { - configFile: 'karma.conf.js' - }, - integration: { - configFile: 'karma-integration.conf.js' - } - } - }); - - grunt.loadNpmTasks('grunt-karma'); - - grunt.loadTasks('tasks'); - - grunt.registerTask('test', ['karma']); - grunt.registerTask('integrationtest', ['karma:integration']); -}; diff --git a/README.md b/README.md index b14c8cf2..00b086b8 100644 --- a/README.md +++ b/README.md @@ -91,12 +91,11 @@ The above condition evaluates to: | Chrome | `true` | | Firefox | `true` | | IE 11 | `false` | -| Safari iOS | `true` | +| Safari iOS | `true` | ## Installing -QuaggaJS can be installed using __npm__, __bower__, or by including it with -the __script__ tag. +QuaggaJS can be installed using __npm__ or by including it with the __script__ tag. ### NPM @@ -115,14 +114,6 @@ Currently, the full functionality is only available through the browser. When using QuaggaJS within __node__, only file-based decoding is available. See the example for [node_examples](#node-example). -### Bower - -You can also install QuaggaJS through __bower__: - -```console -> bower install quagga -``` - ### Script-Tag Anno 1998 You can simply include `dist/quagga.min.js` in your project and you are ready @@ -181,19 +172,19 @@ node. ```javascript Quagga.init({ inputStream : { - name : "Live", - type : "LiveStream", + name : 'Live', + type : 'LiveStream', target: document.querySelector('#yourElement') // Or '#yourElement' (optional) }, decoder : { - readers : ["code_128_reader"] + readers : ['code_128_reader'] } - }, function(err) { + }, function (err) { if (err) { console.log(err); return } - console.log("Initialization finished. Ready to start"); + console.log('Initialization finished. Ready to start'); Quagga.start(); }); ``` @@ -475,7 +466,7 @@ supplements you have to provide them in the configuration as followed: ```javascript decoder: { readers: [{ - format: "ean_reader", + format: 'ean_reader', config: { supplements: [ 'ean_5_reader', 'ean_2_reader' @@ -508,7 +499,7 @@ Only two properties are relevant for the use in Quagga (`halfSample` and ```javascript { halfSample: true, - patchSize: "medium", // x-small, small, medium, large, x-large + patchSize: 'medium', // x-small, small, medium, large, x-large debug: { showCanvas: false, showPatches: false, @@ -552,43 +543,43 @@ locating-mechanism for more robust results. ```javascript Quagga.decodeSingle({ decoder: { - readers: ["code_128_reader"] // List of active readers + readers: ['code_128_reader'] // List of active readers }, locate: true, // try to locate the barcode in the image src: '/test/fixtures/code_128/image-001.jpg' // or 'data:image/jpg;base64,' + data -}, function(result){ - if(result.codeResult) { - console.log("result", result.codeResult.code); +}, function (result) { + if (result.codeResult) { + console.log('result', result.codeResult.code); } else { - console.log("not detected"); + console.log('not detected'); } }); ``` ### Using node -The following example illustrates the use of QuaggaJS within a node -environment. It's almost identical to the browser version with the difference -that node does not support web-workers out of the box. Therefore the config +The following example illustrates the use of QuaggaJS within a node environment. +It's almost identical to the browser version with the difference +that node does not support web workers out of the box. Therefore the config property `numOfWorkers` must be explicitly set to `0`. ```javascript var Quagga = require('quagga').default; Quagga.decodeSingle({ - src: "image-abc-123.jpg", + src: 'image-abc-123.jpg', numOfWorkers: 0, // Needs to be 0 when used within node inputStream: { - size: 800 // restrict input-size to be 800px in width (long-side) + size: 800 // restrict input size to be 800px in width (long side) }, decoder: { - readers: ["code_128_reader"] // List of active readers + readers: ['code_128_reader'] // List of active readers }, }, function(result) { if(result.codeResult) { - console.log("result", result.codeResult.code); + console.log('result', result.codeResult.code); } else { - console.log("not detected"); + console.log('not detected'); } }); ``` @@ -601,11 +592,11 @@ A growing collection of tips & tricks to improve the various aspects of Quagga. Barcodes too far away from the camera, or a lens too close to the object result in poor recognition rates and Quagga might respond with a lot of -false-positives. +false positives. Starting in Chrome 59 you can now make use of `capabilities` and directly control the zoom of the camera. Head over to the -[web-cam demo](https://serratus.github.io/quaggaJS/examples/live_w_locator.html) +[web cam demo](https://serratus.github.io/quaggaJS/examples/live_w_locator.html) and check out the __Zoom__ feature. You can read more about those `capabilities` in @@ -618,7 +609,7 @@ recognition logic. Since Chrome 59 you can turn on/off the __Torch__ of our device and vastly improve the quality of the images. Head over to the -[web-cam demo](https://serratus.github.io/quaggaJS/examples/live_w_locator.html) +[web cam demo](https://serratus.github.io/quaggaJS/examples/live_w_locator.html) and check out the __Torch__ feature. To find out more about this feature [read on](https://www.oberhofer.co/mediastreamtrack-and-its-capabilities). @@ -626,8 +617,8 @@ To find out more about this feature [read on](https://www.oberhofer.co/mediastre ## Tests Unit Tests can be run with [Karma][karmaUrl] and written using -[Mocha][mochaUrl], [Chai][chaiUrl] and [SinonJS][sinonUrl]. Coverage reports are -automatically generated in the coverage/ folder. +[Mocha][mochaUrl], [Chai][chaiUrl] and [SinonJS][sinonUrl]. +Coverage reports are automatically generated in the coverage/ folder. ```console > npm install @@ -639,7 +630,7 @@ In case you want to take a deeper dive into the inner workings of Quagga, get to know the _debugging_ capabilities of the current implementation. The various flags exposed through the `config` object give you the abilily to visualize almost every step in the processing. Because of the introduction of the -web-workers, and their restriction not to have access to the DOM, the +web workers, and their restriction not to have access to the DOM, the configuration must be explicitly set to `config.numOfWorkers = 0` in order to work. @@ -652,19 +643,19 @@ bugs in the implementation. ### Creating a ``ResultCollector`` -You can easily create a new ``ResultCollector`` by calling its ``create`` -method with a configuration. +You can easily create a new ``ResultCollector`` by calling its constructor +with a configuration. ```javascript -var resultCollector = Quagga.ResultCollector.create({ +const resultCollector = new Quagga.ResultCollector({ capture: true, // keep track of the image producing this result capacity: 20, // maximum number of results to store blacklist: [ // list containing codes which should not be recorded - {code: "3574660239843", format: "ean_13"}], - filter: function(codeResult) { + {code: '3574660239843', format: 'ean_13'}], + filter: function (codeResult) { // only store results which match this constraint // returns true/false - // e.g.: return codeResult.format === "ean_13"; + // e.g.: return codeResult.format === 'ean_13'; return true; } }); @@ -684,7 +675,7 @@ do not fit into a certain schema. Calling ``getResults`` on the ```javascript { codeResult: {}, // same as in onDetected event - frame: "data:image/png;base64,iVBOR..." // dataURL of the gray-scaled image + frame: 'data:image/png;base64,iVBOR...' // dataURL of the gray-scaled image } ``` @@ -705,6 +696,18 @@ on the ``singleChannel`` flag in the configuration when using ``decodeSingle``. ## Changelog +### 2019-07-31 +- Internal Changes + - Converted to TypeScript + - Upgraded tooling to Webpack 4.38, Babel 7.5, Karma 4.2, Chai 4.2, Sinon 7.3 + - Removed redundant files +- Improvements + - Removed all 3rd party dependencies for Web version + - Changed ImageDebug API + - Changed ``Box`` interface to be ``[Point, Point, Point, Point]`` + - Improved performance by utilizing ES2015+ features, bitwise operators, etc. + - Added support for ``area`` measured in pixels (px) + ### 2017-06-07 - Improvements - added `muted` and `playsinline` to `