New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vbb-find-stations

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vbb-find-stations - npm Package Compare versions

Comparing version 1.7.0 to 3.0.0

79

index.js
'use strict'
const fs = require('fs')
const path = require('path')
const filter = require('stream-filter')
const through = require('through2')
const leven = require('leven')
const tokenize = require('vbb-tokenize-station')
const ndjson = require('ndjson')
const stream = require('stream')
const autocomplete = require('vbb-stations-autocomplete')
let rawData = require('vbb-stations/simple')
const stations = Object.create(null)
for (let s of rawData) stations[s.id] = s
rawData = null
const exact = (query) => through.obj(function (station, _, cb) {
const tokens = Array.from(station.tokens)
for (let fragment of query) {
const i = tokens.indexOf(fragment)
if (i < 0) {
tokens.splice(i, 1)
return cb()
}
}
station = Object.assign({type: 'station'}, station)
this.push(station)
cb()
})
const fuzzy = (query) => through.obj(function (station, _, cb) {
const tokens = Array.from(station.tokens)
let relevance = .5 / station.name.length
for (let fragment of query) {
let i = tokens.indexOf(fragment) // try exact matching
if (i >= 0) {relevance += 1; tokens.splice(i, 1); continue}
let distance = 3
for (let j = 0; j < tokens.length; j++) {
const d = leven(tokens[j], fragment)
if (d < distance) {distance = d; i = j}
}
if (i >= 0) {
relevance += 1 / (distance + 1)
tokens.splice(i, 1)
continue
}
return cb() // fragment not found in tokens
}
station = Object.assign({type: 'station', relevance}, station)
this.push(station)
cb()
})
const find = (query, filter = exact) => {
query = tokenize(query)
if (query.length === 0) return empty()
return fs.createReadStream(path.join(__dirname, 'stations.ndjson'))
.pipe(ndjson.parse())
.pipe(filter(query))
const findStations = (query, fuzzy = false) => {
return autocomplete(query, 100, fuzzy, false)
.filter(res => !!stations[res.id])
.map(res => ({...res, ...stations[res.id]}))
}
const empty = () => {
const s = new stream.PassThrough({objectMode: true})
s.end()
return s
}
module.exports = Object.assign(find, {exact, fuzzy})
module.exports = findStations

52

package.json
{
"name": "vbb-find-stations",
"description": "Search for stations of VBB.",
"version": "1.7.0",
"main": "index.js",
"files": ["index.js", "stations.ndjson"],
"keywords": ["vbb", "stations", "search", "berlin", "public transport", "open data"],
"author": "Jannis R <mail@jannisr.de>",
"homepage": "https://github.com/derhuerst/vbb-find-stations",
"repository": "git://github.com/derhuerst/vbb-find-stations.git",
"license": "ISC",
"engines": {"node": ">=6"},
"name": "vbb-find-stations",
"description": "Search for stations of VBB.",
"version": "3.0.0",
"main": "index.js",
"files": [
"index.js"
],
"keywords": [
"vbb",
"stations",
"search",
"berlin",
"public transport",
"open data"
],
"author": "Jannis R <mail@jannisr.de>",
"homepage": "https://github.com/derhuerst/vbb-find-stations",
"repository": "git://github.com/derhuerst/vbb-find-stations.git",
"license": "ISC",
"engines": {
"node": ">=8"
},
"dependencies": {
"stream-filter": "^2.1",
"through2": "^2.0.1",
"leven": "^2.1.0",
"vbb-tokenize-station": "^0.3.0",
"ndjson": "^1.4.3"
"vbb-stations-autocomplete": "^4.0.0"
},
"devDependencies": {
"vbb-common-places": "^1.1.0",
"vbb-stations": "^5.1.0",
"blue-tape": "^1.0.0",
"so": "^1.0.1",
"tap-min": "^1.2.1"
"tap-min": "^2.0.0",
"tape": "^4.6.3",
"vbb-stations": "^7.0.0"
},
"scripts": {
"build": "node build.js",
"test": "tape test.js | tap-min",
"prepublish": "npm run build; npm test"
"test": "tape test.js | tap-min",
"prepublish": "npm test"
}
}
# vbb-find-stations
*vbb-find-stations* provides a **stations search for the Berlin Brandenburg public transport service (VBB)**. It pulls its data from [`vbb-static`](https://github.com/derhuerst/vbb-static).
**Find stations of Berlin Brandenburg public transport service (VBB).** This module is only a wrapper around [`vbb-stations-autocomplete`](https://github.com/derhuerst/vbb-stations-autocomplete).
*Note*: [*vbb-stations-autocomplete*](https://github.com/derhuerst/vbb-stations-autocomplete) delivers the `n` most relevant stations for a query, this module returns all that match the query.
[![npm version](https://img.shields.io/npm/v/vbb-find-stations.svg)](https://www.npmjs.com/package/vbb-find-stations)

@@ -11,2 +9,3 @@ [![build status](https://img.shields.io/travis/derhuerst/vbb-find-stations.svg)](https://travis-ci.org/derhuerst/vbb-find-stations)

[![gitter channel](https://badges.gitter.im/derhuerst/vbb-rest.svg)](https://gitter.im/derhuerst/vbb-rest)
[![support me on Patreon](https://img.shields.io/badge/support%20me-on%20patreon-fa7664.svg)](https://patreon.com/derhuerst)

@@ -25,44 +24,70 @@

const findStations = require('vbb-find-stations')
```
This module accepts a filter function (that filters all stations by the first argument) as the second argument. `findStations.exact` and `findStations.fuzzy` are included, with `findStations.exact` being the default one.
```javascript
findStations('U Steglitz')
.on('data', console.log)
console.log(findStations('U Steglitz'))
```
The stream emits stations in the [*Friendly Public Transport Format*](https://github.com/public-transport/friendly-public-transport-format).
`findStations` returns [*Friendly Public Transport Format* 1.2.1](https://github.com/public-transport/friendly-public-transport-format/blob/1.2.1/spec/readme.md) `station`s.
```js
{
[ {
type: 'station',
id: '900000062202',
name: 'S+U Rathaus Steglitz (Berlin)',
tokens: ['sbahn', 'ubahn', 'rathaus', 'steglitz', 'berlin']
}
{
location: {
type: 'location',
latitude: 52.455066,
longitude: 13.322152
},
weight: 2736,
relevance: 3.1185246962418125,
score: 43.61687553989209
}, {
type: 'station',
id: '900000062282',
name: 'S+U Rathaus Steglitz/Kreisel (Berlin)',
tokens: ['sbahn', 'ubahn', 'rathaus', 'steglitz', 'kreisel', 'berlin']
}
{
type: 'station',
id: '900000062781',
name: 'S+U Rathaus Steglitz (Berlin) [U9]',
tokens: ['sbahn', 'ubahn', 'rathaus', 'steglitz', 'berlin', 'u9']
}
{
location: {
type: 'location',
latitude: 52.456438,
longitude: 13.319986
},
weight: 2831.5,
relevance: 2.4948197569934503,
score: 35.294851852317365
}, {
type: 'station',
id: '900000062782',
name: 'S+U Rathaus Steglitz (Berlin) [Bus Schloßstr.]',
tokens: ['sbahn', 'ubahn', 'rathaus', 'steglitz', 'berlin', 'bus', 'schloss', 'strasse']
}
{
location: {
type: 'location',
latitude: 52.456755,
longitude: 13.320584
},
weight: 4831.25,
relevance: 2.0790164641612083,
score: 35.14615060514675
}, {
type: 'station',
id: '900000062282',
name: 'S+U Rathaus Steglitz/Kreisel (Berlin)',
location: {
type: 'location',
latitude: 52.455889,
longitude: 13.320852
},
weight: 2563.75,
relevance: 2.4948197569934503,
score: 34.14531045766747
}, {
type: 'station',
id: '900000062784',
name: 'S+U Rathaus Steglitz (Berlin) [Bus Albrechtstr.]',
tokens: ['sbahn', 'ubahn', 'rathaus', 'steglitz', 'berlin', 'bus', 'albrecht', 'strasse']
}
location: {
type: 'location',
latitude: 52.45668,
longitude: 13.321685
},
weight: 2834,
relevance: 2.0790164641612083,
score: 29.421030297346405
} ]
```

@@ -69,0 +94,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc