All files / src/lib scanResult.ts

100% Statements 9/9
100% Branches 0/0
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58            15x                                                               77x 77x 77x 77x                       15x 5x   15x  
import { Barcode } from "./barcode";
import { ImageSettings } from "./imageSettings";
 
/**
 * A result of a scanning operation on an image.
 */
export class ScanResult {
  /**
   * The list of barcodes found in the image (can be empty).
   */
  public readonly barcodes: Barcode[];
  /**
   * The image data given as a byte array, formatted accordingly to the set settings ([[imageSettings]]).
   */
  public readonly imageData: Uint8Array;
 
  /**
   * The configuration object defining the properties of the processed image ([[imageData]]).
   */
  public readonly imageSettings: ImageSettings;
 
  /**
   * @hidden
   *
   * The list of manually rejected barcodes.
   */
  public readonly rejectedCodes: Set<Barcode>;
 
  /**
   * @hidden
   *
   * Create a ScanResult instance.
   *
   * @param barcodes The list of barcodes found in the image.
   * @param imageData The image data given as a byte array, formatted accordingly to the set settings.
   * @param imageSettings The configuration object defining the properties of the processed image.
   */
  constructor(barcodes: Barcode[], imageData: Uint8Array, imageSettings: ImageSettings) {
    this.barcodes = barcodes;
    this.imageData = imageData;
    this.imageSettings = imageSettings;
    this.rejectedCodes = new Set();
  }
 
  /**
   * Prevent playing a sound, vibrating or flashing the GUI for a particular code.
   * If all codes in the result are rejected (or no barcode is present), sound, vibration and GUI flashing will be
   * suppressed.
   *
   * Rejected codes will still be part of the [[ScanResult.barcodes]] property like all other codes.
   *
   * @param barcode The barcode to be rejected.
   */
  public rejectCode(barcode: Barcode): void {
    this.rejectedCodes.add(barcode);
  }
}