Coder Social home page Coder Social logo

baao / ngx-scanner-detection Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 3.0 1.36 MB

Detects barcode scanning on document, validates it and emits the scanned barcode. For Angular 7 (should work with former versions too)

JavaScript 14.45% TypeScript 82.17% HTML 2.97% CSS 0.41%
barcode barcode-scanner angular7 angular6 angular5 angular barcode-scanning

ngx-scanner-detection's Introduction

NgxScannerDetection

Detects barcode scanning on document, validates it and emits the scanned barcode. For Angular 7+ (should work with former versions too)

Installation

npm install ngx-scanner-detection

app.module

import {ScannerDetectionModule} from 'ngx-scanner-detection';

And add ScannerDetectionModule to imports

Config

interface ScannerConfiguration {
  minLength?: number; // 7
  maxLength?: number; //  14
  scannerStartsWith?: string; // '' - characters to trim before the code
  scannerEndsWith?: string; // '' - characters to trim after the code
  scanTimeout?: number; // 100 - timeout for detection in ms
  replaceNotNumber?: boolean; // true - allowes numbers only [0-9], replace everything else
  allowNotNumber?: boolean; // false  - allowes numbers only [0-9], replace everything else
  ignoreOverElement?: string[]; // ['INPUT'] - array of tag names that should disable emit
  barcodeType?: string; // ean13 - gtin[d] or ean[\]
}

Usage

<ngx-sw-scanner-detection
  (scan)="handle($event)"
  [config]="{scannerEndsWith: 'Enter'}"
>
  <input #input> ### not needed, only for showing the code
</ngx-sw-scanner-detection>

<button (click)="simulateScanner()">Scanner Simulation</button>

Example Component

  @ViewChild('input') input: ElementRef;

  handle(event: ScanDetected) {
    console.log(event);
    this.input.nativeElement.value = event.barcode;
  }

  // dummy
  simulateScanner() {
    const s = '1234567890123';
    for (let i = 0; i < s.length; i++) {
      const e = new KeyboardEvent('keyup', {bubbles : true, cancelable : true, key : s[i], shiftKey : false});
      setTimeout(() => document.dispatchEvent(e));
    }
    const xe = new KeyboardEvent('keyup', {bubbles : true, cancelable : true, key : 'Enter', shiftKey : false});
    setTimeout(() => document.dispatchEvent(xe));
  }

This project was generated with Angular CLI version 7.3.3.

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the --prod flag for a production build.

Running unit tests

Run ng test to execute the unit tests via Karma.

Running end-to-end tests

Run ng e2e to execute the end-to-end tests via Protractor.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI README.

ngx-scanner-detection's People

Contributors

baao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ngx-scanner-detection's Issues

Cannot set barcodeType or Max Length

Hello Everybody... I am trying to integrate the barcode scanner but somehow it is stuck with 'ean12' type. I have tried to do everything I could understand but no luck. I will describe the issue below and what I have tried and let me know what I am missing.

Modal which is having the scanning component

<div class="modal-body">
            <ngx-sw-scanner-detection
            (scan)="barcodeScanned($event)"
            [config]="{scannerEndsWith: 'Enter'}"
            >
          </ngx-sw-scanner-detection>
           <!-- <input type="text" #barcode ngbAutofocus (keydown)="barcodeScanned($event)"> -->
	<img src="assets/media/modals/scanner.png" class="img-fluid mx-auto d-block" />
</div>

This configuration results in the following response in my handler:

barcode: "295642975221"
length: 12
valid: false
__proto__: Object

If I change the configuration to:

<div class="modal-body">
            <ngx-sw-scanner-detection
            (scan)="barcodeScanned($event)"
            [config]="{scannerEndsWith: 'Enter', barcodeType: 'ean14', maxLength: 14}"
            >
          </ngx-sw-scanner-detection>
           <!-- <input type="text" #barcode ngbAutofocus (keydown)="barcodeScanned($event)"> -->
	<img src="assets/media/modals/scanner.png" class="img-fluid mx-auto d-block" />
</div>

Nothing happens....

I even went and hardcoded the type in the library's config model instead of 'ean13' but still it doesn't pick 14 characters. It will always pick 12 characters.

Please let me know what wrong I am doing. I am badly stuck right now. Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.