Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/derhuerst/db-stations-autocomplete
Search for stations of DB (data from DB station API).
https://github.com/derhuerst/db-stations-autocomplete
autocomplete deutsche-bahn public-transport search
Last synced: 5 days ago
JSON representation
Search for stations of DB (data from DB station API).
- Host: GitHub
- URL: https://github.com/derhuerst/db-stations-autocomplete
- Owner: derhuerst
- License: isc
- Created: 2017-11-07T01:27:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-28T13:07:08.000Z (almost 2 years ago)
- Last Synced: 2024-10-03T23:57:09.201Z (about 1 month ago)
- Topics: autocomplete, deutsche-bahn, public-transport, search
- Language: JavaScript
- Homepage: https://github.com/derhuerst/db-stations-autocomplete#db-stations-autocomplete
- Size: 60.5 KB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# db-stations-autocomplete
*db-stations-autocomplete* provides a **stations search for [Deutsche Bahn](https://en.wikipedia.org/wiki/Deutsche_Bahn)**. Pulls its data from [`db-stations@4`](https://github.com/derhuerst/db-stations) (There's also [`db-hafas-stations-autocomplete`](https://github.com/derhuerst/db-hafas-stations-autocomplete), which pulls its data from [`db-hafas-stations`](https://github.com/derhuerst/db-hafas-stations)).
[![npm version](https://img.shields.io/npm/v/db-stations-autocomplete.svg)](https://www.npmjs.com/package/db-stations-autocomplete)
![ISC-licensed](https://img.shields.io/github/license/derhuerst/db-stations-autocomplete.svg)
![minimum Node.js version](https://img.shields.io/node/v/db-stations-autocomplete.svg)
[![support me via GitHub Sponsors](https://img.shields.io/badge/support%20me-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)
[![chat with me on Twitter](https://img.shields.io/badge/chat%20with%20me-on%20Twitter-1da1f2.svg)](https://twitter.com/derhuerst)## Installing
```shell
npm install db-stations-autocomplete
```## Usage
```js
autocomplete(query, results = 3, fuzzy = false, completion = true)
``````javascript
import {autocomplete} from 'db-stations-autocomplete'autocomplete('Münch', 3)
```This returns stations in a reduced form of the [*Friendly Public Transport Format*](https://github.com/public-transport/friendly-public-transport-format). To get all details, pass use [`db-stations`](https://github.com/derhuerst/db-stations).
```javascript
[ {
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](https://en.wikipedia.org/wiki/Levenshtein_distance) `<= 3` will be taken into account. This is a lot slower though (Apple M1, Node v19.1):
test | performance
-----|------------
non-fuzzy – `berlin charlottenburg` | 704 ops/sec
fuzzy – `berlin charlottenbrug` (note the typo) | 204 ops/secSetting `completion` to `false` speeds things up:
test | performance
-----|------------
completion – `Münc Hbf` | 477 ops/sec
no completion – `Münc Hbf` | 2115 ops/sec## Contributing
If you have a question or need support using `db-stations-autocomplete`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use [the issues page](https://github.com/derhuerst/db-stations-autocomplete/issues).