Socket
Socket
Sign inDemoInstall

@nativescript/mlkit-barcode-scanning

Package Overview
Dependencies
0
Maintainers
18
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @nativescript/mlkit-barcode-scanning

NativeScript MLKit Barcode Scanner module


Version published
Weekly downloads
1.4K
increased by13.66%
Maintainers
18
Install size
24.7 kB
Created
Weekly downloads
 

Readme

Source

@nativescript/mlkit-barcode-scanning

This plugin is used with @nativescript/mlkit-core. It enables barcode scanning and provides the BarcodeResult type for the barcode-scanned data.

Contents

Installation

npm install @nativescript/mlkit-barcode-scanning

Use @nativescript/mlkit-barcode-scanning

Follow these steps to scan a barcode:

  1. Add MLKitView to your page and set the detectionType property to "barcode".
<StackLayout>
    <MLKitView
    detectionType="barcode" 
    detection="{{ onDetection }}"
    />
    <Label row="6">
        <FormattedString>
            <Span text="Barcode: "/>
            <Span text="{{ barcode }}" class="text-green-500"/>
        </FormattedString>
    </Label>
</StackLayout>
  1. To receive the scanned barcode data, handle the detection event and get the data if the event's type is "barcode".
import { Observable } from "@nativescript/core"
import { DetectionEvent, DetectionType } from "@nativescript/mlkit-core";
import { BarcodeResult } from "@nativescript/mlkit-barcode-scanning";

export class BarcodeScannerViewModel extends Observable {
    barcode = ""
...
    onDetection(event: DetectionEvent){

        if(event.type == DetectionType.Barcode){
            const barcodeData: BarcodeResult = event.data[0] as BarcodeResult;
            this.set("barcode", barcodeData?.rawValue)
        }
}
}

Demo app

You can try a demo app at StackBlitz with the NativeScript Preview app.

API

Interfaces

BarcodeResult

The scanned barcode data object has the following properties:

PropertyTypeOptional
formatBarcodeFormatsNo
calendarEventCalenderEventYes
contactInfoContactInfoYes
boundsBoundsYes
pointsPoint[]Yes
displayValuestringYes
driverLicenseDriverLicenseYes
emailEmailYes
geoPointGeoPointYes
phonePhoneYes
rawBytesany[]Yes
rawValuestringYes
smsSmsYes
urlUrlBookmarkYes
valueTypeValueTypeYes
wifiWiFiYes
WiFi
PropertyTypeOptional
encryptionTypestringNo
passwordstringNo
ssidstringNo
UrlBookmark
PropertyTypeOptional
titlestringYes
urlstringYes
Sms
PropertyTypeOptional
messagestringNo
honeNumberstringNo
Phone
PropertyTypeOptional
numberstringNo
typePhoneTypeNo
Email
PropertyTypeOptional
addressstringNo
subjectstringNo
bodystringNo
typeEmailType
DriverLicense
PropertyTypeOptional
documentTypestringNo
firstNamestringNo
middleNamestringNo
lastNamestringNo
genderstringNo
addressStreetstringNo
addressCitystringNo
addressStatestringNo
addressZipstringNo
licenseNumberstringNo
issueDatestringNo
expiryDatestringNo
birthDatestringNo
issuingCountrystringNo
CalenderEvent
PropertyTypeOptional
descriptionstringYes
locationstringYes
organizerstringYes
statusstringYes
summarystringYes
startstringYes
endstringYes
Address
PropertyTypeOptional
addressLinesstring[]No
typeAddressTypeNo
ContactInfo
PropertyTypeOptional
addressesAddress[]No
Origin
PropertyTypeOptional
xnumberNo
ynumberNo
Size
PropertyTypeOptional
widthnumberNo
heightnumberNo
Bounds
PropertyTypeOptional
originOriginNo
sizeSizeNo
Point
PropertyTypeOptional
xnumberNo
ynumberNo
GeoPoint
PropertyTypeOptional
latnumberNo
lngnumberNo

Enums

EncryptionType
  • Open = 'open'
  • WPA = 'wpa'
  • WEP = 'wep'
  • Unknown = 'unknown'
PhoneType
  • Unknown = "unknown"
  • Home = "home"
  • Work = "work"
  • Fax = "fax"
  • Mobile = "mobile"
EmailType
  • Unknown = "unknown"
  • Home = "home"
  • Work = "work"
AddressType
  • Unknown = "unknown"
  • Home = "home"
  • Work = "work"
ValueType
  • ContactInfo= "contactInfo"
  • Email= "email"
  • ISBN= "isbn"
  • Phone= "phone"
  • Product= "product"
  • Text= "text"
  • Sms= "sms"
  • URL= "url"
  • WiFi= "wifi"
  • Geo= "geo"
  • CalenderEvent= "calender"
  • DriverLicense= "driverLicense"
  • Unknown= "unknown"
BarcodeFormats
  • ALL = 'all'
  • CODE_128 = 'code_128'
  • CODE_39 = 'code_39'
  • CODE_93 = 'code_93'
  • CODABAR = 'codabar'
  • DATA_MATRIX = 'data_matrix'
  • EAN_13 = 'ean_13'
  • EAN_8 = 'ean_8'
  • ITF = 'itf'
  • QR_CODE = 'qr_code'
  • UPC_A = 'upc_a'
  • UPC_E = 'upc_e'
  • PDF417 = 'pdf417'
  • AZTEC = 'aztec'
  • UNKOWN = 'unknown'

License

Apache License Version 2.0

Keywords

FAQs

Last updated on 21 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc