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

ticket-parser

v0.1.0

Published

Parse the data contained in Deutsche Bahn's aztec codes

Downloads

22

Readme

ticket-parser

Have you ever travelled with an online ticket from Deutsche Bahn and wondered what information is inside the 2D code? This library tells you. (Note that it doesn't read the image of the Aztec code itself; wrapping around zxing is your best bet for that at the moment.)

The Aztec code on a home-printed ticket

npm install ticket-parser

API

const TicketParser = require('ticketparser');
TicketParser.parse(dataFromAztecCode)
	.then(ticket => { /* do something */ })

The API is asynchronous because TicketParser invokes zlib to decompress the payload. Parsing is currently done with the buffered payload, but the format lends itself very well to being parsed as a stream.

The returned Promise is rejected if no payload is found, otherwise it resolves with output like this:

{
  version: "01",
  pnr: "QW2A66",
  issueDate: new Date("2015-06-24T15:44:00.000Z"),
  primaryLanguage: "DE",
  secondaryLanguage: "DE",
  identification: {
    carrier: "0080",
    type: "BahnCard", // === TicketParser.IDENTIFICATION_TYPES.BAHNCARD
    lastDigits: "1234"
  },
  fareName: "Sparpreis Aktion",
  productClass: {
    overall: "IC/EC", // === TicketParser.PRODUCT_CLASSES.IC
    outbound: "IC/EC",
    inbound: "IC/EC"
  },
  adults: 2,
  bahnCards: [
    {
      count: 2,
      type: "BahnCard 25" // === TicketParser.BAHNCARD_TYPES.BC25
    }
  ],
  children: 0,
  fareClass: "2",
  outbound: {
    from: "Berlin+City",
    to: "Freiburg(Brsg)+City"
  },
  inbound: {
    from: "Freiburg(Brsg)+City",
    to: "Berlin+City"
  },
  via: "H: B-Hbf 22:14 CNL1258-IC61258 R: FR-Hbf 21:58 CNL40459",
  owner: {
    fullName: "Beispiel Sofie",
    firstName: "Sofie",
    lastName: "Beispiel"
  },
  fareType: "Sparpreis", // === TicketParser.FARE_TYPES.SAVER
  identificationNumber: "***************1234",
  valid: {
    from: new Date("2015-06-30T22:00:00.000Z"),
    until: new Date("2015-07-01T22:00:00.000Z")
  },
  stationIds: {
    from: "11160",
    to: "107"
  },
  carrier: "0080",
  certificates: [
    {
      id: "208XEFFLLM3",
      validFrom: new Date("2015-06-30T22:00:00.000Z"),
      validUntil: new Date("2015-07-01T22:00:00.000Z"),
      serialNumber: "1234567890"
    },
    {
      id: "208AQRNBBE4",
      validFrom: new Date("2015-07-02T22:00:00.000Z"),
      validUntil: new Date("2015-07-03T22:00:00.000Z"),
      serialNumber: "1234567890"
    }
  ]
}

Limitations

Because the specification is not public, all the information has been gained through reverse-engineering; mainly thanks to the efforts of rumpeltux. Most things work, nothing's guaranteed.

Some information is not contained in the Aztec code, notably prices and seat reservations. If you care about those, you'll have no choice but to parse the text in the PDF.

TicketParser currently ignores extensions such as the "+City Ticket" or "Ländertickets", even though that is part of the encoded information.

TicketParser does not and cannot check if a ticket is genuine. Each ticket is cryptographically signed (almost certainly using asymmetric encryption), but the public key is, well, not public. TicketParser currently throws away the signature – if you have the means of verifying it, you probably also have better means of parsing the ticket.