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

uic-918-3

v1.0.5

Published

Package for decoding and parsing barcodes according to UIC-918.3 specification, which are used commonly on public transport online tickets.

Downloads

49

Readme

uic-918-3.js

TypeScript Build Status Coverage Status Maintainability npm version code style: prettier

A Node.js package written in Typescript for decoding and parsing barcodes according to the "UIC 918.3" specification, which is commonly used on Print and Mobile Tickets from public transport companies (e.g. Deutsche Bahn).

Installation

To install the latest released version:

npm install uic-918-3

Or checkout the master branch on GitHub:

git clone https://github.com/justusjonas74/uic-918-3.git
cd uic-918-3
npm install

Usage

import { readBarcode } from 'uic-918-3';

// Input could be a string with path to image...
const image = '/path/to/your/file.png';
// ... or a Buffer object with an image
const image_as_buffer = fs.readFileSync('/path/to/your/file.png');

readBarcode('foo.png')
  .then((ticket) => console.log(ticket))
  .catch((error) => console.error(error));

Options

Following options are available:

import { readBarcode } from 'uic-918-3';

const image = '/path/to/your/file.png';
const options = {
  verifySignature: true // Verify the signature included in the ticket barcode with a public key set from a Public Key Infrastructure (PKI). The PKI url is set inside './lib/cert_url.json'. Default is 'false'.
};

uic.readBarcode(image, options).then((ticket) => {
  console.log(ticket.validityOfSignature); // Returns "VALID", "INVALID" or "Public Key not found"
  // ticket.isSignatureValid is deprecated. Use validityOfSignature instead.
});
//

Returning object

The returning object consists of (among other things) one or more TicketDataContainers which hold ticket data for different purposes. The most interesting containers are:

  • **U_HEAD** The ticket header ...
  • **U_TLAY** A representation of the informations which are printed on the ticket.
  • **0080BL** A specific container on tickets from Deutsche Bahn. Consists of all relevant information which will be used for proof-of-payment checks on the train.
  • **0080VU** A specific container on (some) tickets from Deutsche Bahn. This container is used on products, which are also accepted by other carriers, especially (local) public transport companies. Get more information about this container here.

Optimize your files

Actually the barcode reader is very dump, so the ticket you want to read, should be optimised before using this package. A better reading logic will be added in future versions.

Images

Actually the package only supports images with a "nice to read" barcode. So it's best to crop the image to the dimensions of the barcode and save it as a monochrome image (1 bit colour depth).

Extract barcode images from PDF files

You have to extract the barcode image from your PDF. The fastest (but not the best) way is to make a screen shot and save it as described before. If you're using Linux or Mac OS X a much better way is to use poppler-utils and imagemagick:

# Extract images from pdf to .ppm or .pbm images. The last argument is a prefix for the extracted image file names.
pdfimages your-ticket.pdf your-ticket
# convert .ppm/.pbm to a readable format (png)
convert your-ticket-00x.ppm your-ticket-00x.png;

Expected Quality

The UIC 913.3 specifications aren't available for free, so the whole underlying logic is build upon third party sources, particularly the Python script onlineticket from Hagen Fritzsch, the diploma thesis from Roman Waitz and the Wikipedia discussion about Online-Tickets. Therefore results from this package (especially the parsing logic) should be taken with care. Please feel free to open an issue, if you guess there's a wrong interpretation of data fields or corresponding values.

Contributing

Feel free to contribute.