added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
+118
View File
@@ -0,0 +1,118 @@
'use strict'
const spaces = /\s+/g
const leadingProduct = /^(BUS|TRAM)\s+/g
const symbolOnly = /^[a-z]{1,3}$/i
const numberOnly = /^[\d]+$/i
const twoNumbers = /^([\d]+)[^\w]([\d]+)$/i
const symbolAndNumber = /^(([a-z]{1,3})[^\w]?([\d]+)|([\d]+)[^\w]?([a-z]{1,3}))/i
const modes = {
'ICE': 'train',
'IC': 'train',
'EC': 'train',
'EN': 'train',
'LOC': 'train',
'RE': 'train',
'RB': 'train',
'OE': 'train',
'U': 'train',
'S': 'train',
'F': 'watercraft',
'E': 'bus',
'H': 'bus',
'N': 'bus',
'X': 'bus'
}
const products = {
'ICE': 'express',
'IC': 'express',
'EC': 'express',
'EN': 'express',
'LOC': 'express',
'RE': 'regional',
'RB': 'regional',
'OE': 'regional',
'U': 'subway',
'S': 'suburban',
'F': 'ferry',
'E': 'bus',
'H': 'bus',
'N': 'bus',
'X': 'bus'
}
const parse = (name) => {
name = name.toUpperCase().replace(leadingProduct, '').replace(spaces, '')
let r = {_: name,
mode: null, product: null, symbol: null, nr: null,
metro: false, express: false, night: false
}
// weird buses in Berlin
if (name === 'TXL') return {_: name,
mode: 'bus', product: 'bus', symbol: 'TXL', nr: null,
metro: true, express: true, night: true
}
if (name === 'SXF2') return {_: name,
mode: 'bus', product: 'bus', symbol: 'SXF', nr: 2,
metro: false, express: true, night: false
}
if (name === 'SEV') return {_: name,
mode: 'bus', product: 'bus', symbol: null, nr: null,
metro: true, express: false, night: false
}
if (name === 'IRE') return {_: name,
mode: 'train', product: 'regional', symbol: 'IRE', nr: null,
metro: false, express: true, night: false
}
if (symbolOnly.test(name)) {
r.symbol = name
r.mode = r.product = 'bus'
} else if (numberOnly.test(name)) { // bus & tram lines
r.nr = parseInt(name)
} else if (twoNumbers.test(name)) { // weird buses in Brandenburg
const matches = twoNumbers.exec(name)
r.mode = r.product = 'bus'
r.nr = parseInt(matches[1])
} else {
const matches = symbolAndNumber.exec(name)
if (matches && matches[2] && matches[3]) {
r.symbol = matches[2]
r.nr = parseInt(matches[3])
} else if (matches && matches[4] && matches[5]) { // night bus somewhere else
r.nr = parseInt(matches[4])
r.symbol = matches[5]
}
}
if (Number.isNaN(r.nr)) r.nr = null
// handle bus & tram lines with symbol
if (r.symbol === 'M') r.metro = true
else if (r.symbol === 'X') r.express = true
else if (r.symbol === 'N') r.night = true
// handle weird metro bus & metro tram naming
if (!r.product) {
if (r.symbol === 'M') {
r.product = (r.nr <= 17 && r.nr !== 11) ? 'tram' : 'bus'
r.mode = (r.nr <= 17 && r.nr !== 11) ? 'train' : 'bus'
} else if (r.symbol) {
r.mode = modes[r.symbol]
r.product = products[r.symbol]
} else {
r.product = r.nr < 100 ? 'tram' : 'bus'
r.mode = r.nr < 100 ? 'train' : 'bus'
}
}
if (r.symbol === 'RE') r.express = true // regional express trains
else if (r.symbol === 'EN') r.night = true // national night trains
return r
}
module.exports = parse
@@ -0,0 +1,5 @@
Copyright (c) 2019, Jannis R
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,66 @@
{
"_from": "vbb-parse-line@^1.0.0",
"_id": "vbb-parse-line@1.0.0",
"_inBundle": false,
"_integrity": "sha512-/xtFJAWmoulUD3kWX9kPQyn9tDMncuGu22Bfe1C1/Pwf/pJAGd7zKA1IpRf9rrdEP+AN1ECD6SHsGbNcqLbR5w==",
"_location": "/vbb-parse-line",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "vbb-parse-line@^1.0.0",
"name": "vbb-parse-line",
"escapedName": "vbb-parse-line",
"rawSpec": "^1.0.0",
"saveSpec": null,
"fetchSpec": "^1.0.0"
},
"_requiredBy": [
"/hafas-client"
],
"_resolved": "https://registry.npmjs.org/vbb-parse-line/-/vbb-parse-line-1.0.0.tgz",
"_shasum": "be307bbe7968aae2f35576117abd7f64e948d25c",
"_spec": "vbb-parse-line@^1.0.0",
"_where": "/home/pi/MagicMirror/modules/MMM-PublicTransportHafas/node_modules/hafas-client",
"author": {
"name": "Jannis R",
"email": "mail@jannisr.de"
},
"bugs": {
"url": "https://github.com/derhuerst/vbb-parse-line/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Parse VBB lines like M4, TXL, S42.",
"engines": {
"node": ">=8"
},
"files": [
"index.js"
],
"homepage": "https://github.com/derhuerst/vbb-parse-line",
"keywords": [
"vbb",
"parse",
"line",
"gtfs",
"suburban",
"subway",
"regional",
"tram",
"bus",
"ferry"
],
"license": "ISC",
"main": "index.js",
"name": "vbb-parse-line",
"repository": {
"type": "git",
"url": "git+https://github.com/derhuerst/vbb-parse-line.git"
},
"scripts": {
"prepublishOnly": "npm test",
"test": "node test.js"
},
"version": "1.0.0"
}
+45
View File
@@ -0,0 +1,45 @@
# *vbb-parse-line*
**Parses the names of VBB lines like `M4`, `TXL`, `S42`.**
[![npm version](https://img.shields.io/npm/v/vbb-parse-line.svg)](https://www.npmjs.com/package/vbb-parse-line)
[![build status](https://img.shields.io/travis/derhuerst/vbb-parse-line.svg)](https://travis-ci.org/derhuerst/vbb-parse-line)
![ISC-licensed](https://img.shields.io/github/license/derhuerst/vbb-parse-line.svg)
[![chat on gitter](https://badges.gitter.im/derhuerst.svg)](https://gitter.im/derhuerst)
[![support me on Patreon](https://img.shields.io/badge/support%20me-on%20patreon-fa7664.svg)](https://patreon.com/derhuerst)
Because this module tries to guess the mode of transport from line names, it is doomed to have conflicts. Right now, it is primarily focused on Berlin, until we have a more robust solution to find out more about lines.
## Installing
```shell
npm install vbb-parse-line
```
## Usage
```js
const parse = require('vbb-parse-line')
parse('M4')
```
This will return the following.
```js
{
mode: 'train',
product: 'tram',
symbol: 'M',
nr: 4
metro: true // buses & trams that run frequently & all day
express: false // buses that skip stations
night: false // buses replacing other lines in the night
}
```
## Contributing
If you have a question or have difficulties using `vbb-parse-line`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to [the issues page](https://github.com/derhuerst/vbb-parse-line/issues).