npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@deviceflow/rxing-wasm

v0.3.1

Published

wasm bindings for rxing to provide commong barcode operations (decode/encode)

Downloads

110

Readme

rxing-wasm

WASM bindings for common rxing functions. The NPM link is https://www.npmjs.com/package/@deviceflow/rxing-wasm and the rust source is https://github.com/deviceflow/rxing-wasm.

This fork is identical to the upstream package, except wasm-pack is invoked with the --web flag.

Decode Multi Breaking Change with v0.3.0

Version 0.3.0 now returns BarcodeResult objects in a native javascript array. This fully deprecates the old method which returned a custom object with internal state.

Data

The convert_js_image_to_luma function is used to convert canvas image data to the luma 8 format that rxing expects. An example might look like to below.

function decodeBarcode(canvas) {
    let context = canvas.getContext('2d');
    let height = canvas.height;
    let width = canvas.width;
    let imageData = context.getImageData(0, 0, width, height);

    let data = imageData.data;
    let luma8Data = convert_js_image_to_luma(data);
    let parsedBarcode = decode_barcode(luma8Data, width, height);
    
    return parsedBarcode;
}

The convert_canvas_to_luma function is used to convert a canvas to the luma 8 format that rxing expects. An example might look like to below.

function decodeBarcode(canvas) {
    let height = canvas.height;
    let width = canvas.width;
    let luma8Data = convert_canvas_to_luma(canvas);
    let parsedBarcode = decode_barcode(luma8Data, width, height);
    
    return parsedBarcode;
}

The convert_imagedata_to_luma function is used to convert an ImageData object to the luma 8 format that rxing expects. An example might look like to below.

function decodeBarcode(canvas) {
    let context = canvas.getContext('2d');
    let height = canvas.height;
    let width = canvas.width;
    let imageData = context.getImageData(0, 0, width, height);

    let luma8Data = convert_imagedata_to_luma(imageData);
    let parsedBarcode = decode_barcode(luma8Data, width, height);
    
    return parsedBarcode;
}

Hints

Using the DecodeHintDictionary class

Add a hint with set_hint(hint: DecodeHintTypes, value: string). The function returns true if the hint was added and false if it was not. The value of hint must be a number representing on of the enum values for DecodeHintTypes. The easiest way to use this is to simply pass in one of the values from DecodeHintTypes.

Remove a hint using remove_hint(hint: DecodeHintTypes). The function returns true if the hint was present and removed, and false otherwise. The hint value is the same as in the add_hint function.

DecodeHintTypes Values

The following values are available for the DecodeHintTypes enum.

  • Other: Unspecified, application-specific hint. This can be any string, only some decoders care about this value.
  • PureBarcode: Image is a pure monochrome image of a barcode. Should be a string with either "true" or "false".
  • PossibleFormats: A comma separated list (no spaces between elements), with the names of barcode formats to search for. For example, looking for a QrCode and a Datamatrix, one would pass in the string "qrcode,datamatrix".
  • TryHarder: Spend more time to try to find a barcode; optimize for accuracy, not speed. String with either "true" or "false".
  • CharacterSet: Specifies what character encoding to use when decoding, where applicable. This should be a string mapping to a character encoding.
  • AllowedLengths: Allowed lengths of encoded data -- reject anything else. A comma separated list of integers.
  • AssumeCode39CheckDigit: Assume Code 39 codes employ a check digit. A string with either "true" or "false".
  • AssumeGs1: 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). A string with either "true" or "false".
  • ReturnCodabarStartEnd: 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. A string with either "true" or "false".
  • NeedResultPointCallback: The caller needs to be notified via callback when a possible ResultPoint is found. Currently unsupported. In future will map to a (x: number, y: number) = {} function.
  • AllowedEanExtensions: Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this. A comma separated list 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.
  • AlsoInverted: If true, also tries to decode as inverted image. All configured decoders are simply called a second time with an inverted image. A string with either "true" or "false".

Result Metadata

Result metadata is now available through the get_result_metadata_name method of the BarcodeResult class. The returned result is a javascript Map object representing availble decoded metadata. The possible keys are:

  • OTHER
  • Orientation
  • Byte_Segments
  • Error_Correction_Level
  • Issue_Number
  • Suggested_Price
  • Possible_Country
  • UPC/EAN_Extension
  • PDF417_Extra_MetaData
  • Structured_Append_Sequence
  • Structured_Append_Parity
  • Symbology_Identifier
  • Is_Mirrored
  • Content_Type

It is important to note that not all values will be set for all results.

Functions

pub fn convert_js_image_to_luma(data: &[u8]) -> Vec<u8>;
pub fn encode_barcode(
    data: &str,
    width: u32,
    height: u32,
    bc_type: BarcodeFormat,
) -> Result<String, String>;
pub fn decode_barcode(
    data: Vec<u8>,
    width: u32,
    height: u32,
    try_harder: Option<bool>,
) -> Result<BarcodeResult, String>;
pub fn decode_barcode_with_hints(
    data: Vec<u8>,
    width: u32,
    height: u32,
    hints: &mut decode_hints::DecodeHintDictionary,
) -> Result<BarcodeResult, String>;
pub fn decode_multi(
    data: Vec<u8>,
    width: u32,
    height: u32,
    hints: &mut decode_hints::DecodeHintDictionary,
    filter_image: Option<bool>,
) -> Result<Vec<BarcodeResult>, String>;
pub fn encode_barcode_with_hints(
    data: &str,
    width: u32,
    height: u32,
    bc_type: BarcodeFormat,
    hints: &mut EncodeHintDictionary,
) -> Result<String, String>;

Beta Features

encode_barcode_with_hints is currently in alpha. The output and behaviour is unexpected and poorly documented. Use at your own risk, feature may change, unstable interface.