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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gb-transit/feed-parser

v1.0.1

Published

Declarative fixed-width and CSV record parsing for the GB rail data feeds

Readme

@gb-transit/feed-parser

Declarative fixed-width and CSV record parsing for the GB rail data feeds.

npm install @gb-transit/feed-parser

The RSP feeds are flat text: fixed-width columns in the timetable and routeing files, delimited records in others, and a single file often holds several record types told apart by the first few characters. This library is how a layout is written down once, as data, instead of as a hand-rolled substring loop per file.

It knows nothing about any particular feed. The layouts themselves live in @gb-transit/dtd-schema.

Describing a record

A record names its fields, where each one sits, and which of them form its key:

import {FixedWidthRecord, IntField, TextField} from "@gb-transit/feed-parser";

const physicalStation = new FixedWidthRecord(
  "physical_station",
  ["tiploc_code"], {
    "station_name": new TextField(5, 26),
    "tiploc_code": new TextField(36, 7),
    "crs_code": new TextField(49, 3, true),
    "minimum_change_time": new IntField(63, 2, false, [])
  }
);

A delimited record is the same idea with positions counted in columns rather than characters:

import {CSVRecord, DateField, TextField} from "@gb-transit/feed-parser";

const newStation = new CSVRecord(
  "new_station",
  ["nfm64_station_code", "new_station_code"], {
    "nfm64_station_code": new TextField(0, 3),
    "new_station_code": new TextField(1, 3),
    "start_date": new DateField(2),
    "end_date": new DateField(3)
  }
);

Fields

TextField, VariableLengthText, IntField, ZeroFillIntField, DoubleField, BooleanField, DateField, ShortDateField, NullDateField, TimeField and ForeignKeyField.

The distinction the field types exist to make is between a value and an absence. A numeric column of all zeroes or all spaces usually means the feed has nothing to say, but not always — so IntField takes the list of strings that count as null for that column, and narrowing it is a decision about the data rather than a formatting detail:

// blank means "not an interchange", but 9 is a value this column takes
new IntField(35, 1, true, [" "])

Reading a field that will not parse raises ParseError, naming the record, the field and the text it was given, so a malformed line says which column is wrong.

Files

A file is one record type or several:

import {MultiRecordFile, SingleRecordFile} from "@gb-transit/feed-parser";

const RGX = new SingleRecordFile(newStation);

// the record type is read from character 0
const MSN = new MultiRecordFile({"A": physicalStation, "L": alias}, 0);

MultiRecordFile ignores a line whose identifier it has no record for, which is how trailer lines and record types a consumer does not care about are skipped.

Contributing

Issues, pull requests and the source live at planarnetwork/gb-transit. This is libs/feed-parser in that repository.

License

This software is licensed under GNU GPLv3.

Copyright 2017 Linus Norton.