Socket
Socket
Sign inDemoInstall

flix

Package Overview
Dependencies
15
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.1 to 4.0.2

lib/index.js

20

lib/fetch.js
'use strict'
const {fetch} = require('fetch-ponyfill')({Promise: require('pinkie-promise')})
const { fetch } = require('fetch-ponyfill')({ Promise: require('pinkie-promise') })
const qs = require('querystring')

@@ -15,14 +15,14 @@

query = qs.stringify(query)
return fetch(endpoint + route + '?' + query, {headers})
.then((res) => {
if (!res.ok) {
const err = new Error(res.statusText)
err.statusCode = res.status
throw err
}
return fetch(endpoint + route + '?' + query, { headers })
.then((res) => {
if (!res.ok) {
const err = new Error(res.statusText)
err.statusCode = res.status
throw err
}
return res.json()
})
return res.json()
})
}
module.exports = request
'use strict'
const moment = require('moment-timezone')
const fill = require('lodash.fill')
const isString = require('lodash.isstring')
const isObject = require('lodash.isobject')
const fill = require('lodash/fill')
const isString = require('lodash/isString')
const slug = require('slugg')

@@ -11,3 +10,3 @@

const isType = (t) => ['region', 'station'].indexOf(t)>=0
const isType = (t) => ['region', 'station'].indexOf(t) >= 0

@@ -18,17 +17,17 @@ const formatInputDate = (date) => moment(date).tz('Europe/Berlin').format('DD.MM.YYYY')

const createOperator = (o) => ({
type: 'operator',
id: o.key,
name: o.label,
url: o.url,
address: o.address
type: 'operator',
id: o.key,
name: o.label,
url: o.url,
address: o.address
})
// const formatDuration = (duration) => (+duration.hour*60)+(+duration.minutes)
const m = (a) => ((a===undefined) ? null : a)
const m = (a) => ((a === undefined) ? null : a)
const createStation = (s) => ({
type: 'station',
id: s.id + '',
name: s.name,
importance: Number.isInteger(s.importance_order) ? s.importance_order : null
type: 'station',
id: s.id + '',
name: s.name,
importance: Number.isInteger(s.importance_order) ? s.importance_order : null
})

@@ -49,74 +48,73 @@

const extractLegs = (origin, destination, departure, arrival, operators, transfers, transferType) => {
const legs = []
operators = operators.map(createOperator)
if(operators.length === 1) operators = fill(Array((transfers.length || 0)+1), operators[0])
else if(operators.length !== (transfers.length || 0)+1) operators = null
if(transfers && transfers.length){
// first leg
legs.push({
origin: createStation(origin),
destination: createStation({id: transfers[0].station_id, name: transfers[0].station_name}),
departure: formatOutputDate(departure),
arrival: formatOutputDate(transfers[0].arrival),
// shuttle: transfers[0].shuttle_transfer,
hint: transfers[0].message || null,
operator: operators ? operators[0] : null
})
const legs = []
operators = operators.map(createOperator)
if (operators.length === 1) operators = fill(Array((transfers.length || 0) + 1), operators[0])
else if (operators.length !== (transfers.length || 0) + 1) operators = null
if (transfers && transfers.length) {
// first leg
legs.push({
origin: createStation(origin),
destination: createStation({ id: transfers[0].station_id, name: transfers[0].station_name }),
departure: formatOutputDate(departure),
arrival: formatOutputDate(transfers[0].arrival),
// shuttle: transfers[0].shuttle_transfer,
hint: transfers[0].message || null,
operator: operators ? operators[0] : null
})
// middle legs
// middle legs
for (let i = 1; i < transfers.length - 1; i++) {
legs.push({
origin: createStation({ id: transfers[i].station_id, name: transfers[i].station_name }),
destination: createStation({ id: transfers[i + 1].station_id, name: transfers[i + 1].station_name }),
departure: formatOutputDate(transfers[i].departure),
arrival: formatOutputDate(transfers[i + 1].arrival),
hint: transfers[i].message || null,
operator: operators ? operators[i] : null
})
}
for(let i = 1; i < transfers.length-1; i++) legs.push({
origin: createStation({id: transfers[i].station_id, name: transfers[i].station_name}),
destination: createStation({id: transfers[i+1].station_id, name: transfers[i+1].station_name}),
departure: formatOutputDate(transfers[i].departure),
arrival: formatOutputDate(transfers[i+1].arrival),
hint: transfers[i].message || null,
operator: operators ? operators[i] : null
})
// last legs
legs.push({
origin: createStation({ id: transfers[transfers.length - 1].station_id, name: transfers[transfers.length - 1].station_name }),
destination: createStation(destination),
departure: formatOutputDate(transfers[transfers.length - 1].departure),
arrival: formatOutputDate(arrival),
// shuttle: transfers[transfers.length-1].shuttle_transfer,
hint: transfers[transfers.length - 1].message || null,
operator: operators ? operators[transfers.length - 1] : null
})
} else {
legs.push({
origin: createStation(origin),
destination: createStation(destination),
departure: formatOutputDate(departure),
arrival: formatOutputDate(arrival),
operator: operators ? operators[0] : null
})
}
// last legs
legs.push({
origin: createStation({id: transfers[transfers.length-1].station_id, name: transfers[transfers.length-1].station_name}),
destination: createStation(destination),
departure: formatOutputDate(transfers[transfers.length-1].departure),
arrival: formatOutputDate(arrival),
// shuttle: transfers[transfers.length-1].shuttle_transfer,
hint: transfers[transfers.length-1].message || null,
operator: operators ? operators[transfers.length-1] : null
})
}
else{
legs.push({
origin: createStation(origin),
destination: createStation(destination),
departure: formatOutputDate(departure),
arrival: formatOutputDate(arrival),
operator: operators ? operators[0] : null
})
}
for(let leg of legs){
leg.schedule = slug(hashLeg(leg))
leg.mode = (transferType && transferType === 'train') ? 'train' : 'bus'
leg.public = true
}
return legs
for (let leg of legs) {
leg.schedule = slug(hashLeg(leg))
leg.mode = (transferType && transferType === 'train') ? 'train' : 'bus'
leg.public = true
}
return legs
}
const createJourney = (origin, destination, links) => (trip) => ({
type: 'journey',
type: 'journey',
id: slug(m(trip.uid)),
legs: extractLegs(origin, destination, trip.departure, trip.arrival, trip.operated_by, trip.interconnection_transfers, trip.transfer_type_key),
legs: extractLegs(origin, destination, trip.departure, trip.arrival, trip.operated_by, trip.interconnection_transfers, trip.transfer_type_key),
status: m(trip.status),
borders: m(trip.transborder),
price: {
amount: m(trip.price_total_sum) || null, // bad hack
currency: 'EUR',
discounts: m(trip.discounts), // ???
saleRestriction: m(trip.sale_restriction), // ???
available: (trip.available && trip.status !== 'full'), // is this correct?
url: (links.find(l => l.rel === 'shop:search') || {}).href || null
},
price: {
amount: m(trip.price_total_sum) || null, // bad hack
currency: 'EUR',
discounts: m(trip.discounts), // ???
saleRestriction: m(trip.sale_restriction), // ???
available: (trip.available && trip.status !== 'full'), // is this correct?
url: (links.find(l => l.rel === 'shop:search') || {}).href || null
},
info: {

@@ -126,4 +124,4 @@ title: m(trip.info_title),

message: m(trip.info_message),
warnings: m(trip.warnings)
},
warnings: m(trip.warnings)
}
})

@@ -137,24 +135,21 @@

const journeys = (origin, destination, date, opt) => {
opt = Object.assign({}, defaults, opt || {})
if(isString(origin)) origin = {id: origin, type: 'station'}
if(isString(destination)) destination = {id: destination, type: 'station'}
if (isString(origin)) origin = { id: origin, type: 'station' }
if (isString(destination)) destination = { id: destination, type: 'station' }
if(origin.type !== destination.type) throw new Error('origin and destination objects must have the same type')
if(!isString(origin.id)) throw new Error('invalid or missing origin id')
if(!isType(origin.type)) throw new Error('invalid or missing origin type')
if(!isString(destination.id)) throw new Error('invalid or missing destination id')
if(!isType(destination.type)) throw new Error('invalid or missing destination type')
if (origin.type !== destination.type) throw new Error('origin and destination objects must have the same type')
if (!isString(origin.id)) throw new Error('invalid or missing origin id')
if (!isType(origin.type)) throw new Error('invalid or missing origin type')
if (!isString(destination.id)) throw new Error('invalid or missing destination id')
if (!isType(destination.type)) throw new Error('invalid or missing destination type')
if(origin.type === 'station'){
opt.searchBy = 'stations'
}
else{
opt.searchBy = 'cities'
}
origin = origin.id
destination = destination.id
if (origin.type === 'station') {
opt.searchBy = 'stations'
} else {
opt.searchBy = 'cities'
}
origin = origin.id
destination = destination.id

@@ -177,6 +172,6 @@ return fetch('trip/search.json', {

})
.then((data) => data.trips)
.then((data) => createJourneys(data))
.then((data) => data.trips)
.then((data) => createJourneys(data))
}
module.exports = journeys

@@ -5,3 +5,3 @@ 'use strict'

const m = (a) => ((a===undefined) ? null : a)
const m = (a) => ((a === undefined) ? null : a)

@@ -13,6 +13,6 @@ const defaults = {

const formatCountry = (country) => (country ? {name: m(country.name), code: m(country.alpha2_code)} : null)
const formatCountry = (country) => (country ? { name: m(country.name), code: m(country.alpha2_code) } : null)
const createRegion = (city) => ({
type: 'region',
type: 'region',
id: city.id + '',

@@ -24,6 +24,6 @@ name: m(city.name),

latitude: m(city.coordinates.latitude),
country: formatCountry(city.country),
country: formatCountry(city.country)
},
class: m(city.classes),
stations: (m(city.stations) || []).map(s => s+''),
stations: (m(city.stations) || []).map(s => s + ''),
connections: m(city.pairs),

@@ -34,3 +34,3 @@ slug: m(city.slugs)

const regions = (opt) => {
opt = Object.assign({}, defaults, opt || {})
opt = Object.assign({}, defaults, opt || {})

@@ -41,6 +41,6 @@ return fetch('network.json', {

})
.then((data) => data.cities)
.then((regions) => regions.map(createRegion))
.then((data) => data.cities)
.then((regions) => regions.map(createRegion))
}
module.exports = regions

@@ -7,3 +7,3 @@ 'use strict'

const m = (a) => ((a===undefined) ? null : a)
const m = (a) => ((a === undefined) ? null : a)

@@ -15,6 +15,6 @@ const defaults = {

const formatCountry = (country) => (country ? {name: m(country.name), code: m(country.alpha2_code)} : null)
const formatCountry = (country) => (country ? { name: m(country.name), code: m(country.alpha2_code) } : null)
const createStation = (station) => ({
type: 'station',
type: 'station',
id: station.id + '',

@@ -33,3 +33,3 @@ name: m(station.name),

aliases: (station.aliases ? csv(station.aliases) : null),
regions: [m(station.city_id+'')].filter((x) => !!x),
regions: [m(station.city_id + '')].filter((x) => !!x),
connections: m(station.pairs),

@@ -46,6 +46,6 @@ importance: m(+station.importance_order)

})
.then((data) => data.stations)
.then((stations) => stations.map(createStation))
.then((data) => data.stations)
.then((stations) => stations.map(createStation))
}
module.exports = stations
{
"name": "flix",
"version": "4.0.2",
"description": "JavaScript client for the FlixBus (Meinfernbus) / FlixTrain API.",
"version": "4.0.1",
"keywords": [
"api",
"bus",
"client",
"coach",
"travel",
"transport",
"flixbus",
"meinfernbus",
"flixtrain",
"deutschland",
"europe",
"flix",
"flixbus",
"flixmobility",
"flixtrain",
"fptf",
"germany",
"meinfernbus",
"mobility",
"railway",
"train",
"railway",
"germany",
"deutschland",
"api",
"client",
"fptf"
"transport",
"travel"
],
"author": "Julius Tens <mail@juliustens.eu>",
"homepage": "https://github.com/juliuste/flix",
"bugs": "https://github.com/juliuste/flix/issues",
"repository": "juliuste/flix",
"bugs": "https://github.com/juliuste/flix/issues",
"main": "index.js",
"license": "ISC",
"author": "Julius Tens <mail@juliustens.eu>",
"files": [
"index.js",
"lib/*"
],
"main": "lib/index.js",
"scripts": {
"check-deps": "depcheck",
"fix": "eslint --fix lib",
"lint": "eslint lib",
"prepublishOnly": "npm test",
"test": "npm run lint && npm run check-deps && node test"
},
"dependencies": {
"fetch-ponyfill": "^6.0.2",
"lodash.fill": "^3.4.0",
"lodash.isobject": "^3.0.2",
"lodash.isstring": "^4.0.1",
"moment-timezone": "^0.5.16",
"lodash": "^4.17.10",
"moment-timezone": "^0.5.21",
"pinkie-promise": "^2.0.1",

@@ -45,15 +50,16 @@ "slugg": "^1.2.1",

"devDependencies": {
"depcheck": "^0.6.11",
"eslint": "^5.8.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"is-url-superb": "^2.0.0",
"lodash.isequal": "^4.5.0",
"tape": "^4.9.0",
"validate-fptf": "^2.0.1"
"tape": "^4.9.1",
"validate-fptf": "^2.1.1"
},
"scripts": {
"test": "node test.js",
"prepare": "npm test"
},
"engine": {
"engines": {
"node": ">=8"
},
"license": "ISC"
}
}

@@ -33,9 +33,9 @@ # flix

- [search-meinfernbus-locations](https://github.com/derhuerst/search-meinfernbus-locations/) - "Search for FlixBus (Meinfernbus) / FlixTrain cities & stations."
- [db-meinfernbus-cities](https://github.com/juliuste/db-meinfernbus-cities/) – "Get all DB stations located in the same city as the given FlixBus / FlixTrain location, and vice versa."
- [db-hafas](https://github.com/derhuerst/db-hafas/) - "JavaScript client for the DB Hafas API."
- [db-stations](https://github.com/derhuerst/db-stations/) - "A list of DB stations."
- [search-flix-locations](https://github.com/derhuerst/search-flix-locations/) - Search for FlixBus (Meinfernbus) / FlixTrain cities & stations.
- [db-flix-cities](https://github.com/juliuste/db-flix-cities/) – Get all DB stations located in the same city as the given FlixBus / FlixTrain location, and vice versa.
- [db-hafas](https://github.com/derhuerst/db-hafas/) - JavaScript client for the DB Hafas API.
- [db-stations](https://github.com/derhuerst/db-stations/) - A list of DB stations.
## Contributing
If you found a bug, want to propose a feature or feel the urge to complain about your life, feel free to visit [the issues page](https://github.com/juliuste/flix/issues).
If you found a bug or want to propose a feature, feel free to visit [the issues page](https://github.com/juliuste/flix/issues).
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc