Socket
Socket
Sign inDemoInstall

@zxing/library

Package Overview
Dependencies
Maintainers
3
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zxing/library - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

18

CONTRIBUTING.md

@@ -28,6 +28,6 @@ # Contributing

The java files are transformed using regexps for some obvious syntax transformation (see ./autotransform) and then modified manually.
The Java files are transformed using regexps for some obvious syntax transformation (see ./autotransform) and then modified manually.
Using http://www.jsweet.org was considered but rejected because of loosing type information early on (for example
number versus int is esential for bitwise operations), language style and older typescript version.
number versus int is essential for bitwise operations), language style and older TypeScript version.

@@ -40,3 +40,3 @@ ### Rules

- Use constructor property whenever possible.
- Take care of array initialisation with capacity, especially when using length and push later on. Basically only use when setting with index accesor only .
- Take care of array initialisation with capacity, especially when using length and push later on. Basically only use when setting with index accessor only .
- Use utility classes to implement platform dependencies (like `System` or `Arrays`), avoid inline implementation for anything that is not trivial.

@@ -46,3 +46,3 @@ - Use single class|enum|interface per module, export with default. Move internal classes to separate modules if used from other modules.

- Keep enum as similar with the original interface as possible (transform to class and use static fields for enum values).
- Allways use `===` for `==` to avoid gliches from type transforms.
- Always use `===` for `==` to avoid glitches from type transforms.

@@ -62,10 +62,10 @@ ### Cheat Sheet 💩

- `byte` has 8 bits, signed (eg -127 to 127), so `byte[]` would trasnforms to `Int8Array` however:
- `byte` has 8 bits, signed (e.g. -127 to 127), so `byte[]` would transforms to `Int8Array` however:
- `TextEncoder` will use `Uint8Array`.
- `canvas` image data will use `Uint8ClampedArray`.
- `int` has 32 bits, signed, so `int[]` transforms to `Int32Array`.
- `char` has 2 bytes, so `char[]` transfomrs to `Uint16Array`.
- `char` has 2 bytes, so `char[]` transforms to `Uint16Array`.
- `long` has 64 bit two's complement `integer`, can be signed or unsigned.
### JavasSript TypedArray
### JavaScript's TypedArray

@@ -76,5 +76,5 @@ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

- Take care of `int` -> `number` (integer to number) port when doing bitwise transformation expecially `<<`. Do a `& 0xFFFFFFFF` for ints, a &0xFF for bytes.
- Take care of `int` -> `number` (integer to number) port when doing bitwise transformation especially `<<`. Do a `& 0xFFFFFFFF` for ints, a &0xFF for bytes.
- Take care of array initialization, in Java `new Array(N)` initializes capacity NOT size/length.
- Use `Math.floor` for any divison of ints otherwise the `number` type is a floating point and keeps the numbers after the dot.
- Use `Math.floor` for any division of ints otherwise the `number` type is a floating point and keeps the numbers after the dot.

@@ -81,0 +81,0 @@ ## Encoding

@@ -149,3 +149,2 @@ "use strict";

if (mediaElement.nodeName.toLowerCase() !== type.toLowerCase()) {
console.log(mediaElement.nodeName);
throw new ArgumentException_1.default("element with id '" + mediaElementId + "' must be an " + type + " element");

@@ -234,9 +233,8 @@ }

catch (re) {
console.log(retryIfChecksumOrFormatError, re);
if (retryIfNotFound && re instanceof NotFoundException_1.default) {
console.log('not found, trying again...');
// Not found, trying again
this.decodeOnceWithDelay(resolve, reject);
}
else if (retryIfChecksumOrFormatError && (re instanceof ChecksumException_1.default || re instanceof FormatException_1.default)) {
console.log('checksum or format error, trying again...', re);
// checksum or format error, trying again
this.decodeOnceWithDelay(resolve, reject);

@@ -243,0 +241,0 @@ }

@@ -20,2 +20,34 @@ "use strict";

var FormatException_1 = require("../FormatException");
/*import java.util.HashMap;*/
/*import java.util.Map;*/
var CharacterSetValueIdentifiers;
(function (CharacterSetValueIdentifiers) {
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["Cp437"] = 0] = "Cp437";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_1"] = 1] = "ISO8859_1";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_2"] = 2] = "ISO8859_2";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_3"] = 3] = "ISO8859_3";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_4"] = 4] = "ISO8859_4";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_5"] = 5] = "ISO8859_5";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_6"] = 6] = "ISO8859_6";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_7"] = 7] = "ISO8859_7";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_8"] = 8] = "ISO8859_8";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_9"] = 9] = "ISO8859_9";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_10"] = 10] = "ISO8859_10";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_11"] = 11] = "ISO8859_11";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_13"] = 12] = "ISO8859_13";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_14"] = 13] = "ISO8859_14";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_15"] = 14] = "ISO8859_15";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ISO8859_16"] = 15] = "ISO8859_16";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["SJIS"] = 16] = "SJIS";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["Cp1250"] = 17] = "Cp1250";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["Cp1251"] = 18] = "Cp1251";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["Cp1252"] = 19] = "Cp1252";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["Cp1256"] = 20] = "Cp1256";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["UnicodeBigUnmarked"] = 21] = "UnicodeBigUnmarked";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["UTF8"] = 22] = "UTF8";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["ASCII"] = 23] = "ASCII";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["Big5"] = 24] = "Big5";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["GB18030"] = 25] = "GB18030";
CharacterSetValueIdentifiers[CharacterSetValueIdentifiers["EUC_KR"] = 26] = "EUC_KR";
})(CharacterSetValueIdentifiers = exports.CharacterSetValueIdentifiers || (exports.CharacterSetValueIdentifiers = {}));
/**

@@ -22,0 +54,0 @@ * Encapsulates a Character Set ECI, according to "Extended Channel Interpretations" 5.3.1.1

@@ -18,2 +18,89 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
/*namespace com.google.zxing {*/
/**
* Encapsulates a type of hint that a caller may pass to a barcode reader to help it
* more quickly or accurately decode it. It is up to implementations to decide what,
* if anything, to do with the information that is supplied.
*
* @author Sean Owen
* @author dswitkin@google.com (Daniel Switkin)
* @see Reader#decode(BinaryBitmap,java.util.Map)
*/
var DecodeHintType;
(function (DecodeHintType) {
/**
* Unspecified, application-specific hint. Maps to an unspecified {@link Object}.
*/
DecodeHintType[DecodeHintType["OTHER"] = 0] = "OTHER"; /*(Object.class)*/
/**
* Image is a pure monochrome image of a barcode. Doesn't matter what it maps to;
* use {@link Boolean#TRUE}.
*/
DecodeHintType[DecodeHintType["PURE_BARCODE"] = 1] = "PURE_BARCODE"; /*(Void.class)*/
/**
* Image is known to be of one of a few possible formats.
* Maps to a {@link List} of {@link BarcodeFormat}s.
*/
DecodeHintType[DecodeHintType["POSSIBLE_FORMATS"] = 2] = "POSSIBLE_FORMATS"; /*(List.class)*/
/**
* Spend more time to try to find a barcode; optimize for accuracy, not speed.
* Doesn't matter what it maps to; use {@link Boolean#TRUE}.
*/
DecodeHintType[DecodeHintType["TRY_HARDER"] = 3] = "TRY_HARDER"; /*(Void.class)*/
/**
* Specifies what character encoding to use when decoding, where applicable (type String)
*/
DecodeHintType[DecodeHintType["CHARACTER_SET"] = 4] = "CHARACTER_SET"; /*(String.class)*/
/**
* Allowed lengths of encoded data -- reject anything else. Maps to an {@code Int32Array}.
*/
DecodeHintType[DecodeHintType["ALLOWED_LENGTHS"] = 5] = "ALLOWED_LENGTHS"; /*(Int32Array.class)*/
/**
* Assume Code 39 codes employ a check digit. Doesn't matter what it maps to;
* use {@link Boolean#TRUE}.
*/
DecodeHintType[DecodeHintType["ASSUME_CODE_39_CHECK_DIGIT"] = 6] = "ASSUME_CODE_39_CHECK_DIGIT"; /*(Void.class)*/
/**
* Assume the barcode is being processed as a GS1 barcode, and modify behavior as needed.
* For example this affects FNC1 handling for Code 128 (aka GS1-128). Doesn't matter what it maps to;
* use {@link Boolean#TRUE}.
*/
DecodeHintType[DecodeHintType["ASSUME_GS1"] = 7] = "ASSUME_GS1"; /*(Void.class)*/
/**
* If true, return the start and end digits in a Codabar barcode instead of stripping them. They
* are alpha, whereas the rest are numeric. By default, they are stripped, but this causes them
* to not be. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
*/
DecodeHintType[DecodeHintType["RETURN_CODABAR_START_END"] = 8] = "RETURN_CODABAR_START_END"; /*(Void.class)*/
/**
* The caller needs to be notified via callback when a possible {@link ResultPoint}
* is found. Maps to a {@link ResultPointCallback}.
*/
DecodeHintType[DecodeHintType["NEED_RESULT_POINT_CALLBACK"] = 9] = "NEED_RESULT_POINT_CALLBACK"; /*(ResultPointCallback.class)*/
/**
* Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this.
* Maps to an {@code Int32Array} of the allowed extension lengths, for example [2], [5], or [2, 5].
* If it is optional to have an extension, do not set this hint. If this is set,
* and a UPC or EAN barcode is found but an extension is not, then no result will be returned
* at all.
*/
DecodeHintType[DecodeHintType["ALLOWED_EAN_EXTENSIONS"] = 10] = "ALLOWED_EAN_EXTENSIONS"; /*(Int32Array.class)*/
// End of enumeration values.
/**
* Data type the hint is expecting.
* Among the possible values the {@link Void} stands out as being used for
* hints that do not expect a value to be supplied (flag hints). Such hints
* will possibly have their value ignored, or replaced by a
* {@link Boolean#TRUE}. Hint suppliers should probably use
* {@link Boolean#TRUE} as directed by the actual hint documentation.
*/
// private valueType: Class<?>
// DecodeHintType(valueType: Class<?>) {
// this.valueType = valueType
// }
// public getValueType(): Class<?> {
// return valueType
// }
})(DecodeHintType || (DecodeHintType = {}));
exports.default = DecodeHintType;
//# sourceMappingURL=DecodeHintType.js.map

@@ -166,3 +166,3 @@ "use strict";

var reader = _a[_i];
// console.log(`Trying to decode with ${reader.constructor.name} reader.`);
// Trying to decode with ${reader} reader.
try {

@@ -175,5 +175,3 @@ return reader.decode(image, this.hints);

}
// Uncomment for test outputting.
// const extra = !ex.message ? '.' : ` with the message: \n\n\t${ex.message}\n\n`;
// console.error('[decodeInternal]', `Exception of type \`${ex.constructor.name}\` was thrown${extra}`);
// Bad Exception.
}

@@ -180,0 +178,0 @@ }

@@ -18,2 +18,13 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var DataMaskValues;
(function (DataMaskValues) {
DataMaskValues[DataMaskValues["DATA_MASK_000"] = 0] = "DATA_MASK_000";
DataMaskValues[DataMaskValues["DATA_MASK_001"] = 1] = "DATA_MASK_001";
DataMaskValues[DataMaskValues["DATA_MASK_010"] = 2] = "DATA_MASK_010";
DataMaskValues[DataMaskValues["DATA_MASK_011"] = 3] = "DATA_MASK_011";
DataMaskValues[DataMaskValues["DATA_MASK_100"] = 4] = "DATA_MASK_100";
DataMaskValues[DataMaskValues["DATA_MASK_101"] = 5] = "DATA_MASK_101";
DataMaskValues[DataMaskValues["DATA_MASK_110"] = 6] = "DATA_MASK_110";
DataMaskValues[DataMaskValues["DATA_MASK_111"] = 7] = "DATA_MASK_111";
})(DataMaskValues = exports.DataMaskValues || (exports.DataMaskValues = {}));
/**

@@ -20,0 +31,0 @@ * <p>Encapsulates data masks for the data bits in a QR code, per ISO 18004:2006 6.8. Implementations

@@ -21,2 +21,9 @@ "use strict";

var IllegalArgumentException_1 = require("../../IllegalArgumentException");
var ErrorCorrectionLevelValues;
(function (ErrorCorrectionLevelValues) {
ErrorCorrectionLevelValues[ErrorCorrectionLevelValues["L"] = 0] = "L";
ErrorCorrectionLevelValues[ErrorCorrectionLevelValues["M"] = 1] = "M";
ErrorCorrectionLevelValues[ErrorCorrectionLevelValues["Q"] = 2] = "Q";
ErrorCorrectionLevelValues[ErrorCorrectionLevelValues["H"] = 3] = "H";
})(ErrorCorrectionLevelValues = exports.ErrorCorrectionLevelValues || (exports.ErrorCorrectionLevelValues = {}));
/**

@@ -23,0 +30,0 @@ * <p>See ISO 18004:2006, 6.5.1. This enum encapsulates the four error correction levels

@@ -19,2 +19,16 @@ "use strict";

var IllegalArgumentException_1 = require("../../IllegalArgumentException");
var ModeValues;
(function (ModeValues) {
ModeValues[ModeValues["TERMINATOR"] = 0] = "TERMINATOR";
ModeValues[ModeValues["NUMERIC"] = 1] = "NUMERIC";
ModeValues[ModeValues["ALPHANUMERIC"] = 2] = "ALPHANUMERIC";
ModeValues[ModeValues["STRUCTURED_APPEND"] = 3] = "STRUCTURED_APPEND";
ModeValues[ModeValues["BYTE"] = 4] = "BYTE";
ModeValues[ModeValues["ECI"] = 5] = "ECI";
ModeValues[ModeValues["KANJI"] = 6] = "KANJI";
ModeValues[ModeValues["FNC1_FIRST_POSITION"] = 7] = "FNC1_FIRST_POSITION";
ModeValues[ModeValues["FNC1_SECOND_POSITION"] = 8] = "FNC1_SECOND_POSITION";
/** See GBT 18284-2000; "Hanzi" is a transliteration of this mode name. */
ModeValues[ModeValues["HANZI"] = 9] = "HANZI";
})(ModeValues = exports.ModeValues || (exports.ModeValues = {}));
/**

@@ -21,0 +35,0 @@ * <p>See ISO 18004:2006, 6.4.1, Tables 2 and 3. This enum encapsulates the various modes in which

@@ -46,2 +46,4 @@ "use strict";

exports.BinaryBitmap = BinaryBitmap_1.default;
var DecodeHintType_1 = require("./core/DecodeHintType");
exports.DecodeHintType = DecodeHintType_1.default;
var InvertedLuminanceSource_1 = require("./core/InvertedLuminanceSource");

@@ -48,0 +50,0 @@ exports.InvertedLuminanceSource = InvertedLuminanceSource_1.default;

{
"name": "@zxing/library",
"version": "0.7.0",
"version": "0.8.0",
"description": "TypeScript port of ZXing multi-format 1D/2D barcode image processing library.",

@@ -108,3 +108,3 @@ "keywords": [

"tslint": "^5.10.0",
"typescript": "^2.8",
"typescript": "^2.9.2",
"uglify-js": "^3.3.25",

@@ -111,0 +111,0 @@ "uglifyjs-webpack-plugin": "^1.1.8",

@@ -44,7 +44,7 @@ [<img align="right" src="https://raw.github.com/wiki/zxing/zxing/zxing-logo.png"/>][1]

**Note:** All the examples are using ES6, be sure is supported in your browser or modify as needed, Chrome recomended.
**Note:** All the examples are using ES6, be sure is supported in your browser or modify as needed, Chrome recommended.
## Usage
### Instalation
### Installation

@@ -59,3 +59,3 @@ `npm i @zxing/library --save`

Examples below are for QR barcode, all other supported barcodes work similary.
Examples below are for QR barcode, all other supported barcodes work similarly.

@@ -70,3 +70,3 @@ #### Browser

_You can use external polyfills like [WebRTC adapter](https://github.com/webrtc/adapter) to increase browser compatiblity._
_You can use external polyfills like [WebRTC adapter](https://github.com/webrtc/adapter) to increase browser compatibility._

@@ -125,3 +125,3 @@ Also, note that the library is using the [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) (`Int32Array`, `Uint8ClampedArray`, etc.) which are not available in older browsers (e.g. Android 4 default browser).

You can also provide `undefined` for the device id parameter in which case the library will automatically choose the camera, prefering the main (environment facing) camera if more are available:
You can also provide `undefined` for the device id parameter in which case the library will automatically choose the camera, preferring the main (environment facing) camera if more are available:

@@ -166,3 +166,3 @@ ```javascript

```html
<img id="img" src="qrcode-image.png" width="200" height="300" style="border: 1px solid gray"></img>
<img id="img" src="qrcode-image.png" width="200" height="300" style="border: 1px solid gray">
```

@@ -194,3 +194,3 @@

```html
<img id="img" width="200" height="300" style="border: 1px solid gray"></img>
<img id="img-to-decode" width="200" height="300" style="border: 1px solid gray">
```

@@ -197,0 +197,0 @@

@@ -167,3 +167,2 @@ import { HTMLCanvasElementLuminanceSource } from './HTMLCanvasElementLuminanceSource';

if (mediaElement.nodeName.toLowerCase() !== type.toLowerCase()) {
console.log(mediaElement.nodeName);
throw new ArgumentException(`element with id '${mediaElementId}' must be an ${type} element`);

@@ -246,2 +245,3 @@ }

private decodeOnce(resolve: (result: Result) => any, reject: (error: any) => any, retryIfNotFound: boolean = true, retryIfChecksumOrFormatError: boolean = true): void {
if (undefined === this.canvasElementContext) {

@@ -255,2 +255,3 @@ this.prepareCaptureCanvas();

const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
try {

@@ -260,8 +261,7 @@ const result = this.readerDecode(binaryBitmap);

} catch (re) {
console.log(retryIfChecksumOrFormatError, re);
if (retryIfNotFound && re instanceof NotFoundException) {
console.log('not found, trying again...');
// Not found, trying again
this.decodeOnceWithDelay(resolve, reject);
} else if (retryIfChecksumOrFormatError && (re instanceof ChecksumException || re instanceof FormatException)) {
console.log('checksum or format error, trying again...', re);
// checksum or format error, trying again
this.decodeOnceWithDelay(resolve, reject);

@@ -268,0 +268,0 @@ } else {

@@ -185,3 +185,3 @@ /*

// console.log(`Trying to decode with ${reader.constructor.name} reader.`);
// Trying to decode with ${reader} reader.

@@ -195,5 +195,3 @@ try {

// Uncomment for test outputting.
// const extra = !ex.message ? '.' : ` with the message: \n\n\t${ex.message}\n\n`;
// console.error('[decodeInternal]', `Exception of type \`${ex.constructor.name}\` was thrown${extra}`);
// Bad Exception.
}

@@ -200,0 +198,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc