convert to ESM 💥📝

This commit is contained in:
Jannis R 2022-05-07 16:17:37 +02:00
parent 28f1316a51
commit 339d64e901
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
361 changed files with 2412 additions and 2169 deletions

View file

@ -1,7 +1,6 @@
{ {
"env": { "env": {
"commonjs": true, "es2021": true,
"es6": true,
"node": true "node": true
}, },
"extends": "eslint:recommended", "extends": "eslint:recommended",
@ -11,7 +10,8 @@
}, },
"ignorePatterns": ["node_modules", "*example.js"], "ignorePatterns": ["node_modules", "*example.js"],
"parserOptions": { "parserOptions": {
"ecmaVersion": 2018 "ecmaVersion": 2021,
"sourceType": "module"
}, },
"rules": { "rules": {
"no-unused-vars": [ "no-unused-vars": [

View file

@ -43,8 +43,9 @@ With `opt`, you can override the default options, which look like this:
If you pass an object `opt.products`, its fields will partially override the default products defined in the profile. An example with the [BVG profile](../p/bvg): If you pass an object `opt.products`, its fields will partially override the default products defined in the profile. An example with the [BVG profile](../p/bvg):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program') const client = createClient(vbbProfile, 'my-awesome-program')
// will query with these products: suburban, subway, bus, express, regional // will query with these products: suburban, subway, bus, express, regional
@ -60,8 +61,8 @@ You may pass a departure's `tripId` into [`trip(id, lineName, [opt])`](trip.md)
As an example, we're going to use the [VBB profile](../p/vbb): As an example, we're going to use the [VBB profile](../p/vbb):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program') const client = createClient(vbbProfile, 'my-awesome-program')

View file

@ -22,8 +22,8 @@ With `opt`, you can override the default options, which look like this:
As an example, we're going to use the [*Deutsche Bahn* profile](../p/db): As an example, we're going to use the [*Deutsche Bahn* profile](../p/db):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const dbProfile = require('hafas-client/p/db') import {dbProfile} from 'hafas-client/p/db.js'
const berlinSüdkreuz = '8011113' const berlinSüdkreuz = '8011113'
const münchenHbf = '8000261' const münchenHbf = '8000261'

View file

@ -85,8 +85,8 @@ With `opt`, you can override the default options, which look like this:
As an example, we're going to use the [VBB profile](../p/vbb): As an example, we're going to use the [VBB profile](../p/vbb):
```js ```js
const createClient = require('hafas-client') import {createClient} 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program') const client = createClient(vbbProfile, 'my-awesome-program')

View file

@ -7,8 +7,8 @@
As an example, we're going to use the [SVV profile](../p/svv): As an example, we're going to use the [SVV profile](../p/svv):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const svvProfile = require('hafas-client/p/svv') import {svvProfile} from 'hafas-client/p/svv.js'
const client = createClient(svvProfile, 'my-awesome-program') const client = createClient(svvProfile, 'my-awesome-program')

View file

@ -23,8 +23,8 @@ With `opt`, you can override the default options, which look like this:
As an example, we're going to use the [VBB profile](../p/vbb): As an example, we're going to use the [VBB profile](../p/vbb):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program') const client = createClient(vbbProfile, 'my-awesome-program')

View file

@ -24,8 +24,8 @@ With `opt`, you can override the default options, which look like this:
As an example, we're going to use the [VBB profile](../p/vbb): As an example, we're going to use the [VBB profile](../p/vbb):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program') const client = createClient(vbbProfile, 'my-awesome-program')

View file

@ -1,4 +1,3 @@
'use strict'
// Refer to the the ./writing-a-profile.md guide. // Refer to the the ./writing-a-profile.md guide.
const products = [ const products = [
@ -41,4 +40,6 @@ const insaProfile = {
radar: false radar: false
} }
module.exports = insaProfile export {
insaProfile,
}

View file

@ -25,8 +25,8 @@ With `opt`, you can override the default options, which look like this:
As an example, we're going to use the [VBB profile](../p/vbb): As an example, we're going to use the [VBB profile](../p/vbb):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program') const client = createClient(vbbProfile, 'my-awesome-program')

View file

@ -31,8 +31,8 @@ With `opt`, you can override the default options, which look like this:
As an example, we're going to use the [VBB profile](../p/vbb): As an example, we're going to use the [VBB profile](../p/vbb):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program') const client = createClient(vbbProfile, 'my-awesome-program')

View file

@ -11,9 +11,9 @@
There's opt-in support for throttling requests to the endpoint. There's opt-in support for throttling requests to the endpoint.
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const withThrottling = require('hafas-client/throttle') import {withThrottling} from 'hafas-client/throttle.js'
const dbProfile = require('hafas-client/p/db') import {dbProfile} from 'hafas-client/p/db.js'
// create a throttled HAFAS client with Deutsche Bahn profile // create a throttled HAFAS client with Deutsche Bahn profile
const client = createClient(withThrottling(dbProfile), 'my-awesome-program') const client = createClient(withThrottling(dbProfile), 'my-awesome-program')
@ -35,9 +35,9 @@ const client = createClient(throttledDbProfile, 'my-awesome-program')
There's opt-in support for retrying failed requests to the endpoint. There's opt-in support for retrying failed requests to the endpoint.
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const withRetrying = require('hafas-client/retry') import {withRetrying} from 'hafas-client/retry.js'
const dbProfile = require('hafas-client/p/db') import {dbProfile} from 'hafas-client/p/db.js'
// create a client with Deutsche Bahn profile that will retry on HAFAS errors // create a client with Deutsche Bahn profile that will retry on HAFAS errors
const client = createClient(withRetrying(dbProfile), 'my-awesome-program') const client = createClient(withRetrying(dbProfile), 'my-awesome-program')
@ -65,7 +65,7 @@ const client = createClient(retryingDbProfile, 'my-awesome-program')
By default, `hafas-client` randomizes the client name that you pass into `createClient`, and sends it as [`User-Agent`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent) in a randomized form: By default, `hafas-client` randomizes the client name that you pass into `createClient`, and sends it as [`User-Agent`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent) in a randomized form:
```js ```js
const createClient('hafas-client') import {createClient} from 'hafas-client'
// … // …
const client = createClient(someProfile, 'my-awesome-program') const client = createClient(someProfile, 'my-awesome-program')
@ -158,7 +158,7 @@ Each error has the following properties:
To check **if an error from `hafas-client` is HAFAS-specific, use `error instanceof HafasError`**: To check **if an error from `hafas-client` is HAFAS-specific, use `error instanceof HafasError`**:
```js ```js
const {HafasError} = require('hafas-client/lib/errors') import {HafasError} from 'hafas-client/lib/errors.js'
try { try {
await client.journeys(/* … */) await client.journeys(/* … */)

View file

@ -21,8 +21,8 @@ With `opt`, you can override the default options, which look like this:
As an example, we're going to use the [VBB profile](../p/vbb): As an example, we're going to use the [VBB profile](../p/vbb):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile) const client = createClient(vbbProfile)

View file

@ -20,8 +20,8 @@ With `opt`, you can override the default options, which look like this:
As an example, we're going to use the [SVV profile](../p/svv): As an example, we're going to use the [SVV profile](../p/svv):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const svvProfile = require('hafas-client/p/svv') import {svvProfile} from 'hafas-client/p/svv.js'
const client = createClient(svvProfile, 'my-awesome-program') const client = createClient(svvProfile, 'my-awesome-program')

View file

@ -16,8 +16,8 @@ With `opt`, you can override the default options, which look like this:
As an example, we're going to use the [SVV profile](../p/svv): As an example, we're going to use the [SVV profile](../p/svv):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const svvProfile = require('hafas-client/p/svv') import {svvProfile} from 'hafas-client/p/svv.js'
const client = createClient(svvProfile, 'my-awesome-program') const client = createClient(svvProfile, 'my-awesome-program')

View file

@ -35,8 +35,8 @@ With `opt`, you can override the default options, which look like this:
As an example, we're going to use the [VBB profile](../p/vbb): As an example, we're going to use the [VBB profile](../p/vbb):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program') const client = createClient(vbbProfile, 'my-awesome-program')

View file

@ -7,8 +7,8 @@ This method can be used to refetch information about a trip  a vehicle stopp
Let's say you used [`journeys`](journeys.md) and now want to get more up-to-date data about the arrival/departure of a leg. You'd pass in the trip ID from `leg.tripId`, e.g. `'1|24983|22|86|18062017'`, and the name of the line from `leg.line.name` like this: Let's say you used [`journeys`](journeys.md) and now want to get more up-to-date data about the arrival/departure of a leg. You'd pass in the trip ID from `leg.tripId`, e.g. `'1|24983|22|86|18062017'`, and the name of the line from `leg.line.name` like this:
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program') const client = createClient(vbbProfile, 'my-awesome-program')
@ -39,8 +39,8 @@ With `opt`, you can override the default options, which look like this:
As an example, we're going to use the [VBB profile](../p/vbb): As an example, we're going to use the [VBB profile](../p/vbb):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} from 'hafas-client/p/vbb/index.js'
const client = createClient(vbbProfile) const client = createClient(vbbProfile)

View file

@ -7,8 +7,8 @@ Get all trips matching one or more criteria, e.g. a specific name.
As an example, we're going to use the [VBB profile](../p/vbb): As an example, we're going to use the [VBB profile](../p/vbb):
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const vbbProfile = require('hafas-client/p/vbb') import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program') const client = createClient(vbbProfile, 'my-awesome-program')

View file

@ -35,7 +35,7 @@ Assuming their HAFAS endpoint returns all line names prefixed with `foo `, we ca
```js ```js
// get the default line parser // get the default line parser
const parseLine = require('hafas-client/parse/line') import {parseLine} from 'hafas-client/parse/line.js'
// wrapper function with additional logic // wrapper function with additional logic
const parseLineWithoutFoo = (ctx, rawLine) => { const parseLineWithoutFoo = (ctx, rawLine) => {
@ -52,7 +52,7 @@ If you pass this profile into `hafas-client`, the `parseLine` method will overri
You can also use the `parseHook` helper to reduce boilerplate: You can also use the `parseHook` helper to reduce boilerplate:
```js ```js
const {parseHook} = require('hafas-client/lib/profile-hooks') import {parseHook} from 'hafas-client/lib/profile-hooks.js'
const removeFoo = (ctx, rawLine) => ({ const removeFoo = (ctx, rawLine) => ({
...ctx.parsed, ...ctx.parsed,

View file

@ -1,7 +1,5 @@
'use strict' import {formatLocationIdentifier} from './location-identifier.js'
import {formatCoord} from './coord.js'
const formatLocationIdentifier = require('./location-identifier')
const formatCoord = require('./coord')
const formatAddress = (a) => { const formatAddress = (a) => {
if (a.type !== 'location' || !a.latitude || !a.longitude || !a.address) { if (a.type !== 'location' || !a.latitude || !a.longitude || !a.address) {
@ -22,4 +20,6 @@ const formatAddress = (a) => {
} }
} }
module.exports = formatAddress export {
formatAddress,
}

View file

@ -1,5 +1,5 @@
'use strict'
const formatCoord = x => Math.round(x * 1000000) const formatCoord = x => Math.round(x * 1000000)
module.exports = formatCoord export {
formatCoord,
}

View file

@ -1,6 +1,4 @@
'use strict' import {DateTime, IANAZone} from 'luxon'
const {DateTime, IANAZone} = require('luxon')
const timezones = new WeakMap() const timezones = new WeakMap()
@ -19,4 +17,6 @@ const formatDate = (profile, when) => {
}).toFormat('yyyyMMdd') }).toFormat('yyyyMMdd')
} }
module.exports = formatDate export {
formatDate,
}

View file

@ -1,5 +1,3 @@
'use strict'
const bike = {type: 'BC', mode: 'INC'} const bike = {type: 'BC', mode: 'INC'}
const accessibility = { const accessibility = {
@ -8,4 +6,7 @@ const accessibility = {
complete: {type: 'META', mode: 'INC', meta: 'completeBarrierfree'} complete: {type: 'META', mode: 'INC', meta: 'completeBarrierfree'}
} }
module.exports = {bike, accessibility} export {
bike,
accessibility,
}

View file

@ -1,13 +0,0 @@
'use strict'
module.exports = {
date: require('./date'),
time: require('./time'),
filters: require('./filters'),
station: require('./station'),
address: require('./address'),
poi: require('./poi'),
location: require('./location'),
locationFilter: require('./location-filter'),
rectangle: require('./rectangle')
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatLinesReq = (ctx, query) => { const formatLinesReq = (ctx, query) => {
return { return {
meth: 'LineMatch', meth: 'LineMatch',
@ -9,4 +7,6 @@ const formatLinesReq = (ctx, query) => {
} }
} }
module.exports = formatLinesReq export {
formatLinesReq,
}

View file

@ -1,8 +1,8 @@
'use strict'
const formatLocationFilter = (stops, addresses, poi) => { const formatLocationFilter = (stops, addresses, poi) => {
if (stops && addresses && poi) return 'ALL' if (stops && addresses && poi) return 'ALL'
return (stops ? 'S' : '') + (addresses ? 'A' : '') + (poi ? 'P' : '') return (stops ? 'S' : '') + (addresses ? 'A' : '') + (poi ? 'P' : '')
} }
module.exports = formatLocationFilter export {
formatLocationFilter,
}

View file

@ -1,5 +1,3 @@
'use strict'
const sep = '@' const sep = '@'
const formatLocationIdentifier = (data) => { const formatLocationIdentifier = (data) => {
@ -13,4 +11,6 @@ const formatLocationIdentifier = (data) => {
return str return str
} }
module.exports = formatLocationIdentifier export {
formatLocationIdentifier,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatLocation = (profile, l, name = 'location') => { const formatLocation = (profile, l, name = 'location') => {
if ('string' === typeof l) return profile.formatStation(l) if ('string' === typeof l) return profile.formatStation(l)
if ('object' === typeof l && !Array.isArray(l)) { if ('object' === typeof l && !Array.isArray(l)) {
@ -14,4 +12,6 @@ const formatLocation = (profile, l, name = 'location') => {
throw new TypeError(name + ': valid station, address or poi required.') throw new TypeError(name + ': valid station, address or poi required.')
} }
module.exports = formatLocation export {
formatLocation,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatLocationsReq = (ctx, query) => { const formatLocationsReq = (ctx, query) => {
const {profile, opt} = ctx const {profile, opt} = ctx
@ -17,4 +15,6 @@ const formatLocationsReq = (ctx, query) => {
} }
} }
module.exports = formatLocationsReq export {
formatLocationsReq,
}

View file

@ -1,6 +1,4 @@
'use strict' const formatNearbyReq = (ctx, location) => {
const nearbyReq = (ctx, location) => {
const {profile, opt} = ctx const {profile, opt} = ctx
return { return {
@ -25,4 +23,6 @@ const nearbyReq = (ctx, location) => {
} }
} }
module.exports = nearbyReq export {
formatNearbyReq,
}

View file

@ -1,7 +1,5 @@
'use strict' import {formatLocationIdentifier} from './location-identifier.js'
import {formatCoord} from './coord.js'
const formatLocationIdentifier = require('./location-identifier')
const formatCoord = require('./coord')
const formatPoi = (p) => { const formatPoi = (p) => {
if (p.type !== 'location' || !p.latitude || !p.longitude || !p.id || !p.name) { if (p.type !== 'location' || !p.latitude || !p.longitude || !p.id || !p.name) {
@ -21,4 +19,6 @@ const formatPoi = (p) => {
} }
} }
module.exports = formatPoi export {
formatPoi,
}

View file

@ -1,6 +1,4 @@
'use strict' import isObj from 'lodash/isObject.js'
const isObj = require('lodash/isObject')
const hasProp = (o, k) => Object.prototype.hasOwnProperty.call(o, k) const hasProp = (o, k) => Object.prototype.hasOwnProperty.call(o, k)
@ -32,4 +30,6 @@ const formatProductsFilter = (ctx, filter) => {
} }
} }
module.exports = formatProductsFilter export {
formatProductsFilter,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatRadarReq = (ctx, north, west, south, east) => { const formatRadarReq = (ctx, north, west, south, east) => {
const {profile, opt} = ctx const {profile, opt} = ctx
@ -26,4 +24,6 @@ const formatRadarReq = (ctx, north, west, south, east) => {
} }
} }
module.exports = formatRadarReq export {
formatRadarReq,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatReachableFromReq = (ctx, address) => { const formatReachableFromReq = (ctx, address) => {
const {profile, opt} = ctx const {profile, opt} = ctx
@ -19,4 +17,6 @@ const formatReachableFromReq = (ctx, address) => {
} }
} }
module.exports = formatReachableFromReq export {
formatReachableFromReq,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatRectangle = (profile, north, west, south, east) => { const formatRectangle = (profile, north, west, south, east) => {
return { return {
llCrd: { llCrd: {
@ -13,4 +11,6 @@ const formatRectangle = (profile, north, west, south, east) => {
} }
} }
module.exports = formatRectangle export {
formatRectangle,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatRefreshJourneyReq = (ctx, refreshToken) => { const formatRefreshJourneyReq = (ctx, refreshToken) => {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const {profile, opt} = ctx const {profile, opt} = ctx
@ -22,4 +20,6 @@ const formatRefreshJourneyReq = (ctx, refreshToken) => {
} }
} }
module.exports = formatRefreshJourneyReq export {
formatRefreshJourneyReq,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatRemarksReq = (ctx) => { const formatRemarksReq = (ctx) => {
const {profile, opt} = ctx const {profile, opt} = ctx
@ -31,4 +29,6 @@ const formatRemarksReq = (ctx) => {
return {meth: 'HimSearch', req} return {meth: 'HimSearch', req}
} }
module.exports = formatRemarksReq export {
formatRemarksReq,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatStationBoardReq = (ctx, station, type) => { const formatStationBoardReq = (ctx, station, type) => {
const {profile, opt} = ctx const {profile, opt} = ctx
@ -31,4 +29,6 @@ const formatStationBoardReq = (ctx, station, type) => {
} }
} }
module.exports = formatStationBoardReq export {
formatStationBoardReq,
}

View file

@ -1,6 +1,4 @@
'use strict' import {formatLocationIdentifier} from './location-identifier.js'
const formatLocationIdentifier = require('./location-identifier')
const formatStation = (id) => { const formatStation = (id) => {
return { return {
@ -13,4 +11,6 @@ const formatStation = (id) => {
} }
} }
module.exports = formatStation export {
formatStation,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatStopReq = (ctx, stopRef) => { const formatStopReq = (ctx, stopRef) => {
return { return {
// todo: there's also `StationDetails`, are there differences? // todo: there's also `StationDetails`, are there differences?
@ -10,4 +8,6 @@ const formatStopReq = (ctx, stopRef) => {
} }
} }
module.exports = formatStopReq export {
formatStopReq,
}

View file

@ -1,6 +1,4 @@
'use strict' import {DateTime, IANAZone} from 'luxon'
const {DateTime, IANAZone} = require('luxon')
const timezones = new WeakMap() const timezones = new WeakMap()
@ -19,4 +17,6 @@ const formatTime = (profile, when) => {
}).toFormat('HHmmss') }).toFormat('HHmmss')
} }
module.exports = formatTime export {
formatTime,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatTripReq = ({opt}, id) => { const formatTripReq = ({opt}, id) => {
return { return {
cfg: {polyEnc: 'GPA'}, cfg: {polyEnc: 'GPA'},
@ -15,4 +13,6 @@ const formatTripReq = ({opt}, id) => {
} }
} }
module.exports = formatTripReq export {
formatTripReq,
}

View file

@ -1,14 +1,12 @@
'use strict' import isObj from 'lodash/isObject.js'
import sortBy from 'lodash/sortBy.js'
import omit from 'lodash/omit.js'
const isObj = require('lodash/isObject') import {defaultProfile} from './lib/default-profile.js'
const sortBy = require('lodash/sortBy') import {validateProfile} from './lib/validate-profile.js'
const omit = require('lodash/omit') import {INVALID_REQUEST} from './lib/errors.js'
import {sliceLeg} from './lib/slice-leg.js'
const defaultProfile = require('./lib/default-profile') import {HafasError} from './lib/errors.js'
const validateProfile = require('./lib/validate-profile')
const {INVALID_REQUEST} = require('./lib/errors')
const sliceLeg = require('./lib/slice-leg')
const {HafasError} = require('./lib/errors')
const isNonEmptyString = str => 'string' === typeof str && str.length > 0 const isNonEmptyString = str => 'string' === typeof str && str.length > 0
@ -795,4 +793,6 @@ const createClient = (profile, userAgent, opt = {}) => {
return client return client
} }
module.exports = createClient export {
createClient,
}

View file

@ -1,44 +0,0 @@
'use strict'
const {HafasError, byErrorCode} = require('./errors')
const checkIfResponseIsOk = (_) => {
const {
body,
errProps: baseErrProps,
} = _
const errProps = {
...baseErrProps,
}
if (body.id) errProps.hafasResponseId = body.id
// Because we want more accurate stack traces, we don't construct the error here,
// but only return the constructor & error message.
const getError = (_) => {
// mutating here is ugly but pragmatic
if (_.errTxt) errProps.hafasMessage = _.errTxt
if (_.errTxtOut) errProps.hafasDescription = _.errTxtOut
if (_.err in byErrorCode) return byErrorCode[_.err]
return {
Error: HafasError,
message: body.errTxt || 'unknown error',
props: {},
}
}
if (body.err && body.err !== 'OK') {
const {Error: HafasError, message, props} = getError(body)
throw new HafasError(message, body.err, {...errProps, ...props})
}
if (!body.svcResL || !body.svcResL[0]) {
throw new HafasError('invalid/unsupported response structure', null, errProps)
}
if (body.svcResL[0].err !== 'OK') {
const {Error: HafasError, message, props} = getError(body.svcResL[0])
throw new HafasError(message, body.svcResL[0].err, {...errProps, ...props})
}
}
module.exports = checkIfResponseIsOk

View file

@ -1,52 +1,50 @@
'use strict' import {request} from '../lib/request.js'
const request = require('../lib/request') import {formatStationBoardReq} from '../format/station-board-req.js'
import {formatLocationsReq} from '../format/locations-req.js'
import {formatStopReq} from '../format/stop-req.js'
import {formatNearbyReq} from '../format/nearby-req.js'
import {formatTripReq} from '../format/trip-req.js'
import {formatRadarReq} from '../format/radar-req.js'
import {formatReachableFromReq} from '../format/reachable-from-req.js'
import {formatRefreshJourneyReq} from '../format/refresh-journey-req.js'
import {formatRemarksReq} from '../format/remarks-req.js'
import {formatLinesReq} from '../format/lines-req.js'
const formatStationBoardReq = require('../format/station-board-req') import {parseDateTime} from '../parse/date-time.js'
const formatLocationsReq = require('../format/locations-req') import {parsePlatform} from '../parse/platform.js'
const formatStopReq = require('../format/stop-req') import {parseBitmask as parseProductsBitmask} from '../parse/products-bitmask.js'
const formatNearbyReq = require('../format/nearby-req') import {parseIcon} from '../parse/icon.js'
const formatTripReq = require('../format/trip-req') import {parseWhen} from '../parse/when.js'
const formatRadarReq = require('../format/radar-req') import {parsePrognosisType} from '../parse/prognosis-type.js'
const formatReachableFromReq = require('../format/reachable-from-req') import {parseScheduledDays} from '../parse/scheduled-days.js'
const formatRefreshJourneyReq = require('../format/refresh-journey-req') import {parseDeparture} from '../parse/departure.js'
const formatRemarksReq = require('../format/remarks-req') import {parseArrival} from '../parse/arrival.js'
const formatLinesReq = require('../format/lines-req') import {parseTrip} from '../parse/trip.js'
import {parseJourneyLeg} from '../parse/journey-leg.js'
import {parseJourney} from '../parse/journey.js'
import {parseLine} from '../parse/line.js'
import {parseLocation} from '../parse/location.js'
import {parseCommonData as parseCommon} from '../parse/common.js'
import {parsePolyline} from '../parse/polyline.js'
import {parseMovement} from '../parse/movement.js'
import {parseNearby} from '../parse/nearby.js'
import {parseOperator} from '../parse/operator.js'
import {parseHint} from '../parse/hint.js'
import {parseWarning} from '../parse/warning.js'
import {parseStopover} from '../parse/stopover.js'
const parseDateTime = require('../parse/date-time') import {formatAddress} from '../format/address.js'
const parsePlatform = require('../parse/platform') import {formatCoord} from '../format/coord.js'
const parseProductsBitmask = require('../parse/products-bitmask') import {formatDate} from '../format/date.js'
const parseIcon = require('../parse/icon') import {formatLocationFilter} from '../format/location-filter.js'
const parseWhen = require('../parse/when') import {formatProductsFilter} from '../format/products-filter.js'
const parsePrognosisType = require('../parse/prognosis-type') import {formatPoi} from '../format/poi.js'
const parseScheduledDays = require('../parse/scheduled-days') import {formatStation} from '../format/station.js'
const parseDeparture = require('../parse/departure') import {formatTime} from '../format/time.js'
const parseArrival = require('../parse/arrival') import {formatLocation} from '../format/location.js'
const parseTrip = require('../parse/trip') import {formatRectangle} from '../format/rectangle.js'
const parseJourneyLeg = require('../parse/journey-leg') import * as filters from '../format/filters.js'
const parseJourney = require('../parse/journey')
const parseLine = require('../parse/line')
const parseLocation = require('../parse/location')
const parseCommon = require('../parse/common')
const parsePolyline = require('../parse/polyline')
const parseMovement = require('../parse/movement')
const parseNearby = require('../parse/nearby')
const parseOperator = require('../parse/operator')
const parseHint = require('../parse/hint')
const parseWarning = require('../parse/warning')
const parseStopover = require('../parse/stopover')
const formatAddress = require('../format/address')
const formatCoord = require('../format/coord')
const formatDate = require('../format/date')
const formatLocationFilter = require('../format/location-filter')
const formatProductsFilter = require('../format/products-filter')
const formatPoi = require('../format/poi')
const formatStation = require('../format/station')
const formatTime = require('../format/time')
const formatLocation = require('../format/location')
const formatRectangle = require('../format/rectangle')
const filters = require('../format/filters')
const DEBUG = /(^|,)hafas-client(,|$)/.test(process.env.DEBUG || '') const DEBUG = /(^|,)hafas-client(,|$)/.test(process.env.DEBUG || '')
const logRequest = DEBUG const logRequest = DEBUG
@ -137,4 +135,6 @@ const defaultProfile = {
lines: true, lines: true,
} }
module.exports = defaultProfile export {
defaultProfile,
}

View file

@ -1,5 +1,3 @@
'use strict'
const ACCESS_DENIED = 'ACCESS_DENIED' const ACCESS_DENIED = 'ACCESS_DENIED'
const INVALID_REQUEST = 'INVALID_REQUEST' const INVALID_REQUEST = 'INVALID_REQUEST'
const NOT_FOUND = 'NOT_FOUND' const NOT_FOUND = 'NOT_FOUND'
@ -283,7 +281,7 @@ const byErrorCode = Object.assign(Object.create(null), {
} }
}) })
module.exports = { export {
ACCESS_DENIED, ACCESS_DENIED,
INVALID_REQUEST, INVALID_REQUEST,
NOT_FOUND, NOT_FOUND,

View file

@ -1,6 +1,4 @@
'use strict' import objectScan from 'object-scan'
const objectScan = require('object-scan')
const createFindInTree = (needles) => { const createFindInTree = (needles) => {
const scanner = objectScan(needles, { const scanner = objectScan(needles, {
@ -20,4 +18,6 @@ const createFindInTree = (needles) => {
} }
} }
module.exports = createFindInTree export {
createFindInTree,
}

View file

@ -1,5 +1,3 @@
'use strict'
// For any type of "thing to parse", there's >=1 parse functions. // For any type of "thing to parse", there's >=1 parse functions.
// By composing custom parse function(s) with the default ones, one // By composing custom parse function(s) with the default ones, one
// can customize the behaviour of hafas-client. Profiles extensively // can customize the behaviour of hafas-client. Profiles extensively
@ -20,6 +18,6 @@ const parseHook = (oldParse, newParse) => {
} }
} }
module.exports = { export {
parseHook parseHook,
} }

View file

@ -1,16 +1,13 @@
'use strict' import ProxyAgent from 'https-proxy-agent'
import {isIP} from 'net'
const ProxyAgent = require('https-proxy-agent') import {Agent as HttpsAgent} from 'https'
const {isIP} = require('net') import roundRobin from '@derhuerst/round-robin-scheduler'
const {Agent: HttpsAgent} = require('https') import {randomBytes} from 'crypto'
const roundRobin = require('@derhuerst/round-robin-scheduler') import createHash from 'create-hash'
const {randomBytes} = require('crypto') import {stringify} from 'qs'
const createHash = require('create-hash') import {Request, fetch} from 'cross-fetch'
const {stringify} = require('qs') import {parse as parseContentType} from 'content-type'
const {Request, fetch} = require('cross-fetch') import {HafasError, byErrorCode} from './errors.js'
const {parse: parseContentType} = require('content-type')
const {HafasError} = require('./errors')
const checkIfResponseIsOk = require('./check-if-res-is-ok')
const proxyAddress = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || null const proxyAddress = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || null
const localAddresses = process.env.LOCAL_ADDRESS || null const localAddresses = process.env.LOCAL_ADDRESS || null
@ -62,6 +59,45 @@ const randomizeUserAgent = (userAgent) => {
const md5 = input => createHash('md5').update(input).digest() const md5 = input => createHash('md5').update(input).digest()
const checkIfResponseIsOk = (_) => {
const {
body,
errProps: baseErrProps,
} = _
const errProps = {
...baseErrProps,
}
if (body.id) errProps.hafasResponseId = body.id
// Because we want more accurate stack traces, we don't construct the error here,
// but only return the constructor & error message.
const getError = (_) => {
// mutating here is ugly but pragmatic
if (_.errTxt) errProps.hafasMessage = _.errTxt
if (_.errTxtOut) errProps.hafasDescription = _.errTxtOut
if (_.err in byErrorCode) return byErrorCode[_.err]
return {
Error: HafasError,
message: body.errTxt || 'unknown error',
props: {},
}
}
if (body.err && body.err !== 'OK') {
const {Error: HafasError, message, props} = getError(body)
throw new HafasError(message, body.err, {...errProps, ...props})
}
if (!body.svcResL || !body.svcResL[0]) {
throw new HafasError('invalid/unsupported response structure', null, errProps)
}
if (body.svcResL[0].err !== 'OK') {
const {Error: HafasError, message, props} = getError(body.svcResL[0])
throw new HafasError(message, body.svcResL[0].err, {...errProps, ...props})
}
}
const request = async (ctx, userAgent, reqData) => { const request = async (ctx, userAgent, reqData) => {
const {profile, opt} = ctx const {profile, opt} = ctx
@ -163,4 +199,7 @@ const request = async (ctx, userAgent, reqData) => {
} }
} }
module.exports = request export {
checkIfResponseIsOk,
request,
}

View file

@ -1,5 +1,3 @@
'use strict'
const findById = (needle) => { const findById = (needle) => {
const needleStopId = needle.id const needleStopId = needle.id
const needleStationId = needle.station ? needle.station.id : null const needleStationId = needle.station ? needle.station.id : null
@ -44,4 +42,6 @@ const sliceLeg = (leg, from, to) => {
return newLeg return newLeg
} }
module.exports = sliceLeg export {
sliceLeg,
}

View file

@ -1,5 +1,3 @@
'use strict'
const types = { const types = {
locale: 'string', locale: 'string',
timezone: 'string', timezone: 'string',
@ -92,4 +90,6 @@ const validateProfile = (profile) => {
} }
} }
module.exports = validateProfile export {
validateProfile,
}

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client-example')
const vosProfile = require('.')
const client = createClient(vosProfile, 'hafas-client-example')
const rwth = '1057' const rwth = '1057'
const kronenberg = '1397' const kronenberg = '1397'
@ -48,6 +47,6 @@ client.locations('kronenberg', {results: 3})
// }) // })
.then((data) => { .then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

View file

@ -1,4 +1,7 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
@ -81,7 +84,7 @@ const products = [{
default: true, default: true,
}] }]
const avvProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'de-DE', locale: 'de-DE',
timezone: 'Europe/Berlin', timezone: 'Europe/Berlin',
@ -97,4 +100,6 @@ const avvProfile = {
remarksGetPolyline: false, remarksGetPolyline: false,
} }
module.exports = avvProfile export {
profile,
}

View file

@ -5,8 +5,8 @@
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const avvProfile = require('hafas-client/p/AVV') import {avvProfile} from 'hafas-client/p/avv/index.js'
// create a client with AVV profile // create a client with AVV profile
const client = createClient(avvProfile, 'my-awesome-program') const client = createClient(avvProfile, 'my-awesome-program')

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client-example')
const vosProfile = require('.')
const client = createClient(vosProfile, 'hafas-client-example')
const fremont = '100013296' const fremont = '100013296'
const embarcadero = '100013295' const embarcadero = '100013295'
@ -48,6 +47,6 @@ client.locations('embarcadero', {results: 3})
// }) // })
.then((data) => { .then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

View file

@ -1,4 +1,7 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
@ -46,7 +49,7 @@ const products = [{
default: true, default: true,
}] }]
const bartProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'en-US', locale: 'en-US',
timezone: 'America/Los_Angeles', timezone: 'America/Los_Angeles',
@ -61,4 +64,6 @@ const bartProfile = {
refreshJourneyUseOutReconL: true, refreshJourneyUseOutReconL: true,
} }
module.exports = bartProfile export {
profile,
}

View file

@ -5,8 +5,8 @@
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const bartProfile = require('hafas-client/p/BART') import {bartProfile} from 'hafas-client/p/bart/index.js'
// create a client with BART profile // create a client with BART profile
const client = createClient(bartProfile, 'my-awesome-program') const client = createClient(bartProfile, 'my-awesome-program')

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client-example')
const blsProfile = require('.')
const client = createClient(blsProfile, 'hafas-client-example')
const bernDennigkofengässli = '8590093' const bernDennigkofengässli = '8590093'
const münsingenSpital = '8578932' const münsingenSpital = '8578932'
@ -48,6 +47,6 @@ client.journeys(bernDennigkofengässli, münsingenSpital, {results: 1, stopovers
// }) // })
.then((data) => { .then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

View file

@ -1,4 +1,7 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
@ -74,7 +77,7 @@ const products = [{
default: true, default: true,
}] }]
const blsProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'de-DE', locale: 'de-DE',
timezone: 'Europe/Berlin', timezone: 'Europe/Berlin',
@ -88,4 +91,6 @@ const blsProfile = {
reachableFrom: true, reachableFrom: true,
} }
module.exports = blsProfile export {
profile,
}

View file

@ -5,8 +5,8 @@
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const blsProfile = require('hafas-client/p/BLS') import {blsProfile} from 'hafas-client/p/bls/index.js'
// create a client with BLS profile // create a client with BLS profile
const client = createClient(blsProfile, 'my-awesome-program') const client = createClient(blsProfile, 'my-awesome-program')

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client-example')
const bvgProfile = require('.')
const client = createClient(bvgProfile, 'hafas-client-example')
// Hauptbahnhof to Charlottenburg // Hauptbahnhof to Charlottenburg
client.journeys('900000003201', '900000024101', {results: 1, polylines: true}) client.journeys('900000003201', '900000024101', {results: 1, polylines: true})
@ -43,6 +42,6 @@ client.journeys('900000003201', '900000024101', {results: 1, polylines: true})
// return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) // return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true})
// }) // })
.then((data) => { .then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

View file

@ -1,19 +1,20 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const {parseHook} = require('../../lib/profile-hooks') import {parseHook} from '../../lib/profile-hooks.js'
const parseAndAddLocationDHID = require('../vbb/parse-loc-dhid') import {parseAndAddLocationDHID} from '../vbb/parse-loc-dhid.js'
const { import {parseLocation as _parseLocation} from '../../parse/location.js'
parseLocation: _parseLocation, import {parseArrival as _parseArrival} from '../../parse/arrival.js'
parseArrival: _parseArrival, import {parseDeparture as _parseDeparture} from '../../parse/departure.js'
parseDeparture: _parseDeparture, import {parseStopover as _parseStopover} from '../../parse/stopover.js'
parseStopover: _parseStopover, import {parseJourneyLeg as _parseJourneyLeg} from '../../parse/journey-leg.js'
parseJourneyLeg: _parseJourneyLeg,
} = require('../../lib/default-profile')
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
const products = require('./products') import {products} from './products.js'
// todo: there's also a referenced icon `{"res":"occup_fig_{low,mid}"}` // todo: there's also a referenced icon `{"res":"occup_fig_{low,mid}"}`
const addOccupancy = (item, occupancyCodes) => { const addOccupancy = (item, occupancyCodes) => {
@ -131,7 +132,7 @@ const requestJourneysWithBerlkoenig = ({opt}, query) => {
// todo: adapt/extend `vbb-parse-ticket` to support the BVG markup // todo: adapt/extend `vbb-parse-ticket` to support the BVG markup
const bvgProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'de-DE', locale: 'de-DE',
timezone: 'Europe/Berlin', timezone: 'Europe/Berlin',
@ -162,4 +163,6 @@ const bvgProfile = {
reachableFrom: true reachableFrom: true
} }
module.exports = bvgProfile export {
profile,
}

View file

@ -1,6 +1,4 @@
'use strict' const products = [
module.exports = [
{ {
id: 'suburban', id: 'suburban',
mode: 'train', mode: 'train',
@ -58,3 +56,7 @@ module.exports = [
default: true default: true
} }
] ]
export {
products,
}

View file

@ -5,8 +5,8 @@
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const bvgProfile = require('hafas-client/p/bvg') import {bvgProfile} from 'hafas-client/p/bvg/index.js'
// create a client with BVG profile // create a client with BVG profile
const client = createClient(bvgProfile, 'my-awesome-program') const client = createClient(bvgProfile, 'my-awesome-program')

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client-example')
const cflProfile = require('.')
const client = createClient(cflProfile, 'hafas-client-example')
const mersch = '9864348' const mersch = '9864348'
const bruxellesCentral = '8800003' const bruxellesCentral = '8800003'
@ -47,6 +46,6 @@ client.journeys(mersch, bruxellesCentral, {results: 1})
// }) // })
.then(data => { .then(data => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

View file

@ -1,9 +1,12 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
const products = require('./products') import {products} from './products.js'
const cflProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'de-LU', locale: 'de-LU',
timezone: 'Europe/Luxembourg', timezone: 'Europe/Luxembourg',
@ -18,4 +21,6 @@ const cflProfile = {
remarksGetPolyline: false, remarksGetPolyline: false,
} }
module.exports = cflProfile; export {
profile,
}

View file

@ -1,6 +1,4 @@
'use strict' const products = [
module.exports = [
// todo: other bits // todo: other bits
{ {
id: 'express-train', id: 'express-train',
@ -43,3 +41,7 @@ module.exports = [
default: true default: true
} }
] ]
export {
products,
}

View file

@ -5,8 +5,8 @@ The [*Société Nationale des Chemins de Fer Luxembourgeois (CFL)*](https://en.w
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const cflProfile = require('hafas-client/p/cfl') import {cflProfile} from 'hafas-client/p/cfl/index.js'
// create a client with CFL profile // create a client with CFL profile
const client = createClient(cflProfile) const client = createClient(cflProfile)

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client-example')
const cmtaProfile = require('.')
const client = createClient(cmtaProfile, 'hafas-client-example')
// Broadie Oaks to Domain // Broadie Oaks to Domain
client.journeys('000002370', '000005919', {results: 1, polylines: true}) client.journeys('000002370', '000005919', {results: 1, polylines: true})
@ -43,6 +42,6 @@ client.journeys('000002370', '000005919', {results: 1, polylines: true})
// }) // })
.then((data) => { .then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

View file

@ -1,9 +1,12 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
const products = require('./products') import {products} from './products.js'
const cmtaProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'en-US', locale: 'en-US',
timezone: 'America/Chicago', timezone: 'America/Chicago',
@ -18,4 +21,6 @@ const cmtaProfile = {
remarks: true, // `.svcResL[0].res.msgL[]` is missing though 🤔 remarks: true, // `.svcResL[0].res.msgL[]` is missing though 🤔
} }
module.exports = cmtaProfile export {
profile,
}

View file

@ -1,6 +1,4 @@
'use strict' const products = [
module.exports = [
{ {
id: 'bus', id: 'bus',
mode: 'bus', mode: 'bus',
@ -26,3 +24,7 @@ module.exports = [
default: true default: true
} }
] ]
export {
products,
}

View file

@ -5,8 +5,8 @@
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const cmtaProfile = require('hafas-client/p/cmta') import {cmtaProfile} from 'hafas-client/p/cmta/index.js'
// create a client with CMTA profile // create a client with CMTA profile
const client = createClient(cmtaProfile, 'my-awesome-program') const client = createClient(cmtaProfile, 'my-awesome-program')

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client example')
const dartProfile = require('.')
const client = createClient(dartProfile, 'hafas-client example')
const mlkJrPkwyAdamsAveDsm2055 = '100002702' const mlkJrPkwyAdamsAveDsm2055 = '100002702'
const se5thStEHackleyAveDsm2294 = '100004972' const se5thStEHackleyAveDsm2294 = '100004972'
@ -49,6 +48,6 @@ client.locations('adams ave', {results: 3})
// }) // })
.then((data) => { .then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

View file

@ -1,4 +1,7 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
@ -11,7 +14,7 @@ const products = [{
default: true, default: true,
}] }]
const dartProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'en-US', locale: 'en-US',
timezone: 'America/Chicago', timezone: 'America/Chicago',
@ -24,4 +27,6 @@ const dartProfile = {
radar: true, radar: true,
} }
module.exports = dartProfile export {
profile,
}

View file

@ -7,8 +7,8 @@
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const dartProfile = require('hafas-client/p/dart') import {dartProfile} from 'hafas-client/p/dart/index.js'
// create a client with DART profile // create a client with DART profile
const client = createClient(dartProfile, 'my-awesome-program') const client = createClient(dartProfile, 'my-awesome-program')

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../../') const client = createClient(profile, 'hafas-client-example')
const dbbusradarnrwProfile = require('.')
const client = createClient(dbbusradarnrwProfile, 'hafas-client-example')
// Hagen Bauhaus to Schwerte Bahnhof // Hagen Bauhaus to Schwerte Bahnhof
// returns hafas error PARSE // returns hafas error PARSE
@ -36,6 +35,6 @@ client.journeys('3307002', '3357026', {results: 1})
// }, {results: 10}) // }, {results: 10})
.then((data) => { .then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}, console.error) }, console.error)

View file

@ -1,4 +1,7 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
@ -75,7 +78,7 @@ const products = [
} }
] ]
const dbBusradarNrwProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'de-DE', locale: 'de-DE',
timezone: 'Europe/Berlin', timezone: 'Europe/Berlin',
@ -90,5 +93,6 @@ const dbBusradarNrwProfile = {
lines: false, // `.svcResL[0].res.lineL[]` is missing 🤔 lines: false, // `.svcResL[0].res.lineL[]` is missing 🤔
} }
module.exports = dbBusradarNrwProfile export {
profile,
}

View file

@ -11,8 +11,8 @@ This profile adapts `hafas-client` to the HAFAS endpoint used by the application
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const dbbusradarnrwProfile = require('hafas-client/p/db-busradar-nrw') import {dbbusradarnrwProfile} from 'hafas-client/p/db-busradar-nrw/index.js'
// create a client with DB Busradar NRW profile // create a client with DB Busradar NRW profile
const client = createClient(dbbusradarnrwProfile, 'my-awesome-program') const client = createClient(dbbusradarnrwProfile, 'my-awesome-program')

View file

@ -1,5 +1,3 @@
'use strict'
const ageGroup = { const ageGroup = {
BABY: 'B', BABY: 'B',
CHILD: 'K', CHILD: 'K',
@ -30,7 +28,7 @@ const ageGroupFromAge = (age) => {
throw new TypeError(`Invalid age '${age}'`) throw new TypeError(`Invalid age '${age}'`)
} }
module.exports = { export {
ageGroup, ageGroup,
ageGroupFromAge ageGroupFromAge,
} }

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../../') const client = createClient(profile, 'hafas-client-example')
const dbProfile = require('.')
const client = createClient(dbProfile, 'hafas-client-example')
// Berlin Jungfernheide to München Hbf // Berlin Jungfernheide to München Hbf
client.journeys('8011167', '8000261', {results: 1, tickets: true}) client.journeys('8011167', '8000261', {results: 1, tickets: true})
@ -55,5 +54,5 @@ client.journeys('8011167', '8000261', {results: 1, tickets: true})
// }) // })
.then((data) => { .then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}, console.error) }, console.error)

View file

@ -1,25 +1,28 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const trim = require('lodash/trim') import trim from 'lodash/trim.js'
const uniqBy = require('lodash/uniqBy') import uniqBy from 'lodash/uniqBy.js'
const slugg = require('slugg') import slugg from 'slugg'
const without = require('lodash/without') import without from 'lodash/without.js'
const {parseHook} = require('../../lib/profile-hooks') import {parseHook} from '../../lib/profile-hooks.js'
const _parseJourney = require('../../parse/journey') import {parseJourney as _parseJourney} from '../../parse/journey.js'
const _parseJourneyLeg = require('../../parse/journey-leg') import {parseJourneyLeg as _parseJourneyLeg} from '../../parse/journey-leg.js'
const _parseLine = require('../../parse/line') import {parseLine as _parseLine} from '../../parse/line.js'
const _parseArrival = require('../../parse/arrival') import {parseArrival as _parseArrival} from '../../parse/arrival.js'
const _parseDeparture = require('../../parse/departure') import {parseDeparture as _parseDeparture} from '../../parse/departure.js'
const _parseHint = require('../../parse/hint') import {parseHint as _parseHint} from '../../parse/hint.js'
const _parseLocation = require('../../parse/location') import {parseLocation as _parseLocation} from '../../parse/location.js'
const _formatStation = require('../../format/station') import {formatStation as _formatStation} from '../../format/station.js'
const {bike} = require('../../format/filters') import {bike} from '../../format/filters.js'
const products = require('./products')
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
const formatLoyaltyCard = require('./loyalty-cards').format import {products} from './products.js'
const {ageGroup, ageGroupFromAge} = require('./ageGroup') import {formatLoyaltyCard} from './loyalty-cards.js'
import {ageGroup, ageGroupFromAge} from './ageGroup.js'
const transformReqBody = (ctx, body) => { const transformReqBody = (ctx, body) => {
const req = body.svcReqL[0] || {} const req = body.svcReqL[0] || {}
@ -483,7 +486,7 @@ const formatStation = (id) => {
// todo: find option for absolute number of results // todo: find option for absolute number of results
const dbProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'de-DE', locale: 'de-DE',
timezone: 'Europe/Berlin', timezone: 'Europe/Berlin',
@ -512,4 +515,6 @@ const dbProfile = {
lines: false, // `.svcResL[0].res.lineL[]` is missing 🤔 lines: false, // `.svcResL[0].res.lineL[]` is missing 🤔
} }
module.exports = dbProfile export {
profile,
}

View file

@ -1,5 +1,3 @@
'use strict'
// todo: generate from https://reiseauskunft.bahn.de/addons/fachkonfig-utf8.cfg ? // todo: generate from https://reiseauskunft.bahn.de/addons/fachkonfig-utf8.cfg ?
const c = { const c = {
NONE: Symbol('no loyalty card'), NONE: Symbol('no loyalty card'),
@ -25,7 +23,7 @@ const formatLoyaltyCard = (data) => {
return 0 return 0
} }
module.exports = { export {
data: c, c as data,
format: formatLoyaltyCard formatLoyaltyCard,
} }

View file

@ -1,7 +1,5 @@
'use strict'
// todo: https://gist.github.com/anonymous/d3323a5d2d6e159ed42b12afd0380434#file-haf_products-properties-L1-L95 // todo: https://gist.github.com/anonymous/d3323a5d2d6e159ed42b12afd0380434#file-haf_products-properties-L1-L95
module.exports = [ const products = [
{ {
id: 'nationalExpress', id: 'nationalExpress',
mode: 'train', mode: 'train',
@ -83,3 +81,7 @@ module.exports = [
default: true default: true
} }
] ]
export {
products,
}

View file

@ -5,8 +5,8 @@
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const dbProfile = require('hafas-client/p/db') import {dbProfile} from 'hafas-client/p/db/index.js'
// create a client with DB profile // create a client with DB profile
const client = createClient(dbProfile, 'my-awesome-program') const client = createClient(dbProfile, 'my-awesome-program')
@ -74,7 +74,7 @@ With the `db` profile, `hafas-client` will return more station information whene
## Using the `loyaltyCard` option ## Using the `loyaltyCard` option
```js ```js
const {data: loyaltyCards} = require('hafas-client/p/db/loyalty-cards') import {data as loyaltyCards} from 'hafas-client/p/db/loyalty-cards.js'
hafas.journeys(from, to, { hafas.journeys(from, to, {
loyaltyCard: {type: data.BAHNCARD, discount: 25} loyaltyCard: {type: data.BAHNCARD, discount: 25}

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client-example')
const hvvProfile = require('.')
const client = createClient(hvvProfile, 'hafas-client-example')
// client.journeys('116', '5900', {results: 1, polylines: true}) // client.journeys('116', '5900', {results: 1, polylines: true})
// client.departures('116', {duration: 1}) // client.departures('116', {duration: 1})
@ -42,6 +41,6 @@ client.locations('dammtor', {results: 2})
// return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) // return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true})
// }) // })
.then((data) => { .then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

View file

@ -1,9 +1,12 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
const products = require('./products') import {products} from './products.js'
const hvvProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'de-DE', locale: 'de-DE',
timezone: 'Europe/Berlin', timezone: 'Europe/Berlin',
@ -23,4 +26,6 @@ const hvvProfile = {
lines: false, // fails with `FAIL` "HCI Service: request failed" lines: false, // fails with `FAIL` "HCI Service: request failed"
} }
module.exports = hvvProfile export {
profile,
}

View file

@ -1,6 +1,4 @@
'use strict' const products = [ // todo: what is `512`?
module.exports = [ // todo: what is `512`?
{ {
id: 'subway', id: 'subway',
mode: 'train', mode: 'train',
@ -90,3 +88,7 @@ module.exports = [ // todo: what is `512`?
default: false default: false
} }
] ]
export {
products,
}

View file

@ -5,8 +5,8 @@
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const hvvProfile = require('hafas-client/p/hvv') import {hvvProfile} from 'hafas-client/p/hvv/index.js'
// create a client with HVV profile // create a client with HVV profile
const client = createClient(hvvProfile, 'my-awesome-program') const client = createClient(hvvProfile, 'my-awesome-program')

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client-example')
const insaProfile = require('.')
const client = createClient(insaProfile, 'hafas-client-example')
const hellestr1 = { const hellestr1 = {
type: 'location', type: 'location',
@ -41,6 +40,6 @@ client.journeys('008010226', '008013456', {results: 1})
// }) // })
.then(data => { .then(data => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

View file

@ -1,9 +1,12 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
const products = require('./products') import {products} from './products.js'
const insaProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'de-DE', locale: 'de-DE',
timezone: 'Europe/Berlin', timezone: 'Europe/Berlin',
@ -16,4 +19,6 @@ const insaProfile = {
reachableFrom: true, reachableFrom: true,
} }
module.exports = insaProfile; export {
profile,
}

View file

@ -1,6 +1,4 @@
'use strict' const products = [
module.exports = [
{ {
id: 'nationalExpress', id: 'nationalExpress',
mode: 'train', mode: 'train',
@ -58,3 +56,7 @@ module.exports = [
default: true default: true
} }
] ]
export {
products,
}

View file

@ -5,8 +5,8 @@ The [Nahverkehr Sachsen-Anhalt (NASA)](https://de.wikipedia.org/wiki/Nahverkehrs
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const insaProfile = require('hafas-client/p/insa') import {insaProfile} from 'hafas-client/p/insa/index.js'
// create a client with INSA profile // create a client with INSA profile
const client = createClient(insaProfile, 'my-awesome-program') const client = createClient(insaProfile, 'my-awesome-program')

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client-example')
const cmtaProfile = require('.')
const client = createClient(cmtaProfile, 'hafas-client-example')
const ingolstadtHbf = '8000183' const ingolstadtHbf = '8000183'
const audiParkplatz = '84999' const audiParkplatz = '84999'
@ -40,6 +39,6 @@ client.journeys(ingolstadtHbf, audiParkplatz, {results: 1})
// todo: `reachableFrom` with `Ingolstadt, Tillystraße 1` 48.745769 | 11.432814 // todo: `reachableFrom` with `Ingolstadt, Tillystraße 1` 48.745769 | 11.432814
.then((data) => { .then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

View file

@ -1,9 +1,12 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
const products = require('./products') import {products} from './products.js'
const invgProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'de-DE', locale: 'de-DE',
timezone: 'Europe/Berlin', timezone: 'Europe/Berlin',
@ -16,4 +19,6 @@ const invgProfile = {
refreshJourney: true, refreshJourney: true,
} }
module.exports = invgProfile export {
profile,
}

View file

@ -1,6 +1,4 @@
'use strict' const products = [
module.exports = [
// https://github.com/public-transport/hafas-client/issues/93#issuecomment-437868265 // https://github.com/public-transport/hafas-client/issues/93#issuecomment-437868265
{ {
id: 'bus', id: 'bus',
@ -67,3 +65,7 @@ module.exports = [
default: false default: false
} }
] ]
export {
products,
}

View file

@ -5,8 +5,8 @@
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const invgProfile = require('hafas-client/p/invg') import {invgProfile} from 'hafas-client/p/invg/index.js'
// create a client with INVG profile // create a client with INVG profile
const client = createClient(invgProfile, 'my-awesome-program') const client = createClient(invgProfile, 'my-awesome-program')

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client example')
const irishProfile = require('.')
const client = createClient(irishProfile, 'hafas-client example')
// from Dublin to Belfast Central // from Dublin to Belfast Central
client.journeys('9909002', '9990840', {results: 1}) client.journeys('9909002', '9990840', {results: 1})
@ -31,6 +30,6 @@ client.journeys('9909002', '9990840', {results: 1})
// }, {results: 10}) // }, {results: 10})
.then(data => { .then(data => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

View file

@ -1,9 +1,12 @@
'use strict' // todo: use import assertions once they're supported by Node.js & ESLint
// https://github.com/tc39/proposal-import-assertions
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
const products = require('./products') import {products} from './products.js'
const irishRailProfile = { const profile = {
...baseProfile, ...baseProfile,
locale: 'en-IE', locale: 'en-IE',
timezone: 'Europe/Dublin', timezone: 'Europe/Dublin',
@ -18,4 +21,6 @@ const irishRailProfile = {
radar: true, radar: true,
} }
module.exports = irishRailProfile; export {
profile,
}

View file

@ -1,6 +1,4 @@
'use strict' const products = [
module.exports = [
{ {
id: 'national-train', id: 'national-train',
mode: 'train', mode: 'train',
@ -36,3 +34,7 @@ module.exports = [
default: true default: true
} }
] ]
export {
products,
}

View file

@ -5,8 +5,8 @@ The [*Iarnród Éireann* (Irish Rail)](https://en.wikipedia.org/wiki/Iarnród_É
## Usage ## Usage
```js ```js
const createClient = require('hafas-client') import {createClient} from 'hafas-client'
const irishProfile = require('hafas-client/p/irish-rail') import {irishProfile} from 'hafas-client/p/irish-rail/index.js'
// create a client with Irish Rail profile // create a client with Irish Rail profile
const client = createClient(irishProfile, 'my-awesome-program') const client = createClient(irishProfile, 'my-awesome-program')

View file

@ -1,9 +1,8 @@
'use strict' import {inspect} from 'util'
import {createClient} from '../../index.js'
import {profile} from './index.js'
const createClient = require('../..') const client = createClient(profile, 'hafas-client example')
const ivbProfile = require('.')
const client = createClient(ivbProfile, 'hafas-client example')
const innsbruckGriesauweg = '476162400' const innsbruckGriesauweg = '476162400'
const völsWest = '476431800' const völsWest = '476431800'
@ -44,6 +43,6 @@ client.locations('griesauweg', {results: 3})
// }) // })
.then((data) => { .then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true})) console.log(inspect(data, {depth: null, colors: true}))
}) })
.catch(console.error) .catch(console.error)

Some files were not shown because too many files have changed in this diff Show more