Skip to content
Search for stations of DB (data from DB station API).
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig
.gitignore
.travis.yml
benchmark.js
build.js
example.js
index.js
license.md
package.json
readme.md
test.js

readme.md

db-stations-autocomplete

db-stations-autocomplete provides a stations search for Deutsche Bahn. Pulls its data from db-stations (There's also db-hafas-stations-autocomplete, which pulls its data from db-hafas-stations).

npm version build status ISC-licensed chat on Gitter support me on Patreon

Installing

npm install db-stations-autocomplete

Usage

autocomplete(query, results = 3, fuzzy = false, completion = true)
const autocomplete = require('vbb-stations-autocomplete')
autocomplete('Münch', 3)

This returns stations in a reduced form of the Friendly Public Transport Format. To get all details, pass use db-stations.

[ {
	id: '8000261', // München Hbf
	relevance: 0.8794466403162056,
	score: 11.763480191996974,
	weight: 2393.2
}, {
	id: '8004128', // München Donnersbergerbrücke
	relevance: 0.8794466403162056,
	score: 9.235186720706798,
	weight: 1158
}, {
	id: '8004132', // München Karlsplatz
	relevance: 0.8794466403162056,
	score: 9.144716179768407,
	weight: 1124.3
} ]

If you set fuzzy to true, words with a Levenshtein distance <= 3 will be taken into account. This is a lot slower though:

test performance
non-fuzzy – berlin charlottenburg 626 ops/sec
fuzzy – berlin charlottenbrug (note the typo) 108 ops/sec

Setting completion to false speeds things up:

test performance
completion – Münc Hbf 592 ops/sec
no completion – Münc Hbf 12635 ops/sec

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.

You can’t perform that action at this time.