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

hafas-osm-line-colours

v0.2.0

Published

Match HAFAS legs or departures/arrivals with OpenStreetMap transit line colours.

Downloads

15

Readme

hafas-osm-line-colours

Match legs or departures/arrivals found with hafas-client with OpenStreetMap transit line colours from datasets generated using osm-transit-lines.

npm version Build Status Greenkeeper badge dependency status license chat on gitter

Installation

npm install hafas-osm-line-colours

Usage

// the actual methods are wrapped in this creator method because we only want the search tree to be created once, not every time we actually search for a line
// takes a couple of seconds to create the client, depending on the size of your line dataset, but can then handle up to 250.000 queries per second
// note that the data will be stored in-memory, so double-check your hardware before loading a dataset that covers the entire planet
const createTransitLineColourClient = require('hafas-osm-line-colours')
const hafas = require('db-hafas')('user-agent')
const osmTransitLines = require('osm-transit-lines')

const main = async () => {
	const berlinBbox = { south: 52.3418234221, north: 52.6697240587, west: 13.0882097323, east: 13.7606105539 }
	const berlinTransitLines = await osmTransitLines(berlinBbox, { wikidata: true }) // see `osm-transit-lines` docs

	const { legLineColour, departureOrArrivalLineColour } = createTransitLineColourClient(berlinTransitLines) // methods exposed by this module

	// departures/arrivals
	const virchowKlinikumBerlin = '000730855'
	const [departure] = await hafas.departures(virchowKlinikumBerlin) // next train is a tram 50
	const departureLineColour = departureOrArrivalLineColour(departure) // { backgroundColour: '#36ab94', textColour: null } (colour of tram 50), null if no matching background colour was found
	const [arrival] = await hafas.arrivals(virchowKlinikumBerlin) // next train is a tram M13
	const arrivalLineColour = departureOrArrivalLineColour(arrival) // { backgroundColour: '#00cc00', textColour: null } (colour of tram M13), null if no matching background colour was found

	const zehlendorf = '008089098'
	const mexikoplatz = '008089023'
	const [journey] = await hafas.journeys(zehlendorf, mexikoplatz) // only leg is an S1 train
	const lineColour = legLineColour(journey.legs[0]) // { backgroundColour: '#d474ae', textColour: null } (colour of S1), null if no matching background colour was found
}

Since the lines list returned by osm-transit-lines tends to be quite large, the module also exposes two helper methods that allow you to transform the lines list into a more memory-efficient array (that can also be stored) from which you can create a line colour client as well:

const { linesToPoints, createLineColourClientFromPoints } = require('hafas-osm-line-colours')

const main = async () => {
	const berlinBbox = { south: 52.3418234221, north: 52.6697240587, west: 13.0882097323, east: 13.7606105539 }
	const berlinTransitLines = await osmTransitLines(berlinBbox, { wikidata: true }) // see `osm-transit-lines` docs

	const berlinTransitLinePoints = linesToPoints(berlinTransitLines)
	const { legLineColour, departureOrArrivalLineColour } = createLineColourClientFromPoints(berlinTransitLines)
}

Contributing

If you found a bug or want to propose a feature, feel free to visit the issues page.