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": {
"commonjs": true,
"es6": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
@ -11,7 +10,8 @@
},
"ignorePatterns": ["node_modules", "*example.js"],
"parserOptions": {
"ecmaVersion": 2018
"ecmaVersion": 2021,
"sourceType": "module"
},
"rules": {
"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):
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} from 'hafas-client'
import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program')
// 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):
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} from 'hafas-client'
import {vbbProfile} from 'hafas-client/p/vbb.js'
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):
```js
const createClient = require('hafas-client')
const dbProfile = require('hafas-client/p/db')
import {createClient} from 'hafas-client'
import {dbProfile} from 'hafas-client/p/db.js'
const berlinSüdkreuz = '8011113'
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):
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} 'hafas-client'
import {vbbProfile} 'hafas-client/p/vbb.js'
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):
```js
const createClient = require('hafas-client')
const svvProfile = require('hafas-client/p/svv')
import {createClient} from 'hafas-client'
import {svvProfile} from 'hafas-client/p/svv.js'
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):
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} from 'hafas-client'
import {vbbProfile} from 'hafas-client/p/vbb.js'
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):
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} from 'hafas-client'
import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program')

View file

@ -1,4 +1,3 @@
'use strict'
// Refer to the the ./writing-a-profile.md guide.
const products = [
@ -41,4 +40,6 @@ const insaProfile = {
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):
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} from 'hafas-client'
import {vbbProfile} from 'hafas-client/p/vbb.js'
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):
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} from 'hafas-client'
import {vbbProfile} from 'hafas-client/p/vbb.js'
const client = createClient(vbbProfile, 'my-awesome-program')

View file

@ -11,9 +11,9 @@
There's opt-in support for throttling requests to the endpoint.
```js
const createClient = require('hafas-client')
const withThrottling = require('hafas-client/throttle')
const dbProfile = require('hafas-client/p/db')
import {createClient} from 'hafas-client'
import {withThrottling} from 'hafas-client/throttle.js'
import {dbProfile} from 'hafas-client/p/db.js'
// create a throttled HAFAS client with Deutsche Bahn profile
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.
```js
const createClient = require('hafas-client')
const withRetrying = require('hafas-client/retry')
const dbProfile = require('hafas-client/p/db')
import {createClient} from 'hafas-client'
import {withRetrying} from 'hafas-client/retry.js'
import {dbProfile} from 'hafas-client/p/db.js'
// create a client with Deutsche Bahn profile that will retry on HAFAS errors
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:
```js
const createClient('hafas-client')
import {createClient} from 'hafas-client'
// …
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`**:
```js
const {HafasError} = require('hafas-client/lib/errors')
import {HafasError} from 'hafas-client/lib/errors.js'
try {
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):
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} from 'hafas-client'
import {vbbProfile} from 'hafas-client/p/vbb.js'
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):
```js
const createClient = require('hafas-client')
const svvProfile = require('hafas-client/p/svv')
import {createClient} from 'hafas-client'
import {svvProfile} from 'hafas-client/p/svv.js'
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):
```js
const createClient = require('hafas-client')
const svvProfile = require('hafas-client/p/svv')
import {createClient} from 'hafas-client'
import {svvProfile} from 'hafas-client/p/svv.js'
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):
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} from 'hafas-client'
import {vbbProfile} from 'hafas-client/p/vbb.js'
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:
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} from 'hafas-client'
import {vbbProfile} from 'hafas-client/p/vbb.js'
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):
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} from 'hafas-client'
import {vbbProfile} from 'hafas-client/p/vbb/index.js'
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):
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
import {createClient} from 'hafas-client'
import {vbbProfile} from 'hafas-client/p/vbb.js'
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
// 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
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:
```js
const {parseHook} = require('hafas-client/lib/profile-hooks')
import {parseHook} from 'hafas-client/lib/profile-hooks.js'
const removeFoo = (ctx, rawLine) => ({
...ctx.parsed,

View file

@ -1,7 +1,5 @@
'use strict'
const formatLocationIdentifier = require('./location-identifier')
const formatCoord = require('./coord')
import {formatLocationIdentifier} from './location-identifier.js'
import {formatCoord} from './coord.js'
const formatAddress = (a) => {
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)
module.exports = formatCoord
export {
formatCoord,
}

View file

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

View file

@ -1,5 +1,3 @@
'use strict'
const bike = {type: 'BC', mode: 'INC'}
const accessibility = {
@ -8,4 +6,7 @@ const accessibility = {
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) => {
return {
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) => {
if (stops && addresses && poi) return 'ALL'
return (stops ? 'S' : '') + (addresses ? 'A' : '') + (poi ? 'P' : '')
}
module.exports = formatLocationFilter
export {
formatLocationFilter,
}

View file

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

View file

@ -1,5 +1,3 @@
'use strict'
const formatLocation = (profile, l, name = 'location') => {
if ('string' === typeof l) return profile.formatStation(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.')
}
module.exports = formatLocation
export {
formatLocation,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatLocationsReq = (ctx, query) => {
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 nearbyReq = (ctx, location) => {
const formatNearbyReq = (ctx, location) => {
const {profile, opt} = ctx
return {
@ -25,4 +23,6 @@ const nearbyReq = (ctx, location) => {
}
}
module.exports = nearbyReq
export {
formatNearbyReq,
}

View file

@ -1,7 +1,5 @@
'use strict'
const formatLocationIdentifier = require('./location-identifier')
const formatCoord = require('./coord')
import {formatLocationIdentifier} from './location-identifier.js'
import {formatCoord} from './coord.js'
const formatPoi = (p) => {
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'
const isObj = require('lodash/isObject')
import isObj from 'lodash/isObject.js'
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 {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 {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) => {
return {
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) => {
// eslint-disable-next-line no-unused-vars
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 {profile, opt} = ctx
@ -31,4 +29,6 @@ const formatRemarksReq = (ctx) => {
return {meth: 'HimSearch', req}
}
module.exports = formatRemarksReq
export {
formatRemarksReq,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatStationBoardReq = (ctx, station, type) => {
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'
const formatLocationIdentifier = require('./location-identifier')
import {formatLocationIdentifier} from './location-identifier.js'
const formatStation = (id) => {
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) => {
return {
// 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'
const {DateTime, IANAZone} = require('luxon')
import {DateTime, IANAZone} from 'luxon'
const timezones = new WeakMap()
@ -19,4 +17,6 @@ const formatTime = (profile, when) => {
}).toFormat('HHmmss')
}
module.exports = formatTime
export {
formatTime,
}

View file

@ -1,5 +1,3 @@
'use strict'
const formatTripReq = ({opt}, id) => {
return {
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')
const sortBy = require('lodash/sortBy')
const omit = require('lodash/omit')
const defaultProfile = require('./lib/default-profile')
const validateProfile = require('./lib/validate-profile')
const {INVALID_REQUEST} = require('./lib/errors')
const sliceLeg = require('./lib/slice-leg')
const {HafasError} = require('./lib/errors')
import {defaultProfile} from './lib/default-profile.js'
import {validateProfile} from './lib/validate-profile.js'
import {INVALID_REQUEST} from './lib/errors.js'
import {sliceLeg} from './lib/slice-leg.js'
import {HafasError} from './lib/errors.js'
const isNonEmptyString = str => 'string' === typeof str && str.length > 0
@ -795,4 +793,6 @@ const createClient = (profile, userAgent, opt = {}) => {
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')
const formatLocationsReq = require('../format/locations-req')
const formatStopReq = require('../format/stop-req')
const formatNearbyReq = require('../format/nearby-req')
const formatTripReq = require('../format/trip-req')
const formatRadarReq = require('../format/radar-req')
const formatReachableFromReq = require('../format/reachable-from-req')
const formatRefreshJourneyReq = require('../format/refresh-journey-req')
const formatRemarksReq = require('../format/remarks-req')
const formatLinesReq = require('../format/lines-req')
import {parseDateTime} from '../parse/date-time.js'
import {parsePlatform} from '../parse/platform.js'
import {parseBitmask as parseProductsBitmask} from '../parse/products-bitmask.js'
import {parseIcon} from '../parse/icon.js'
import {parseWhen} from '../parse/when.js'
import {parsePrognosisType} from '../parse/prognosis-type.js'
import {parseScheduledDays} from '../parse/scheduled-days.js'
import {parseDeparture} from '../parse/departure.js'
import {parseArrival} from '../parse/arrival.js'
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')
const parsePlatform = require('../parse/platform')
const parseProductsBitmask = require('../parse/products-bitmask')
const parseIcon = require('../parse/icon')
const parseWhen = require('../parse/when')
const parsePrognosisType = require('../parse/prognosis-type')
const parseScheduledDays = require('../parse/scheduled-days')
const parseDeparture = require('../parse/departure')
const parseArrival = require('../parse/arrival')
const parseTrip = require('../parse/trip')
const parseJourneyLeg = require('../parse/journey-leg')
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')
import {formatAddress} from '../format/address.js'
import {formatCoord} from '../format/coord.js'
import {formatDate} from '../format/date.js'
import {formatLocationFilter} from '../format/location-filter.js'
import {formatProductsFilter} from '../format/products-filter.js'
import {formatPoi} from '../format/poi.js'
import {formatStation} from '../format/station.js'
import {formatTime} from '../format/time.js'
import {formatLocation} from '../format/location.js'
import {formatRectangle} from '../format/rectangle.js'
import * as filters from '../format/filters.js'
const DEBUG = /(^|,)hafas-client(,|$)/.test(process.env.DEBUG || '')
const logRequest = DEBUG
@ -137,4 +135,6 @@ const defaultProfile = {
lines: true,
}
module.exports = defaultProfile
export {
defaultProfile,
}

View file

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

View file

@ -1,6 +1,4 @@
'use strict'
const objectScan = require('object-scan')
import objectScan from 'object-scan'
const createFindInTree = (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.
// By composing custom parse function(s) with the default ones, one
// can customize the behaviour of hafas-client. Profiles extensively
@ -20,6 +18,6 @@ const parseHook = (oldParse, newParse) => {
}
}
module.exports = {
parseHook
export {
parseHook,
}

View file

@ -1,16 +1,13 @@
'use strict'
const ProxyAgent = require('https-proxy-agent')
const {isIP} = require('net')
const {Agent: HttpsAgent} = require('https')
const roundRobin = require('@derhuerst/round-robin-scheduler')
const {randomBytes} = require('crypto')
const createHash = require('create-hash')
const {stringify} = require('qs')
const {Request, fetch} = require('cross-fetch')
const {parse: parseContentType} = require('content-type')
const {HafasError} = require('./errors')
const checkIfResponseIsOk = require('./check-if-res-is-ok')
import ProxyAgent from 'https-proxy-agent'
import {isIP} from 'net'
import {Agent as HttpsAgent} from 'https'
import roundRobin from '@derhuerst/round-robin-scheduler'
import {randomBytes} from 'crypto'
import createHash from 'create-hash'
import {stringify} from 'qs'
import {Request, fetch} from 'cross-fetch'
import {parse as parseContentType} from 'content-type'
import {HafasError, byErrorCode} from './errors.js'
const proxyAddress = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || null
const localAddresses = process.env.LOCAL_ADDRESS || null
@ -62,6 +59,45 @@ const randomizeUserAgent = (userAgent) => {
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 {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 needleStopId = needle.id
const needleStationId = needle.station ? needle.station.id : null
@ -44,4 +42,6 @@ const sliceLeg = (leg, from, to) => {
return newLeg
}
module.exports = sliceLeg
export {
sliceLeg,
}

View file

@ -1,5 +1,3 @@
'use strict'
const types = {
locale: '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 vosProfile = require('.')
const client = createClient(vosProfile, 'hafas-client-example')
const client = createClient(profile, 'hafas-client-example')
const rwth = '1057'
const kronenberg = '1397'
@ -48,6 +47,6 @@ client.locations('kronenberg', {results: 3})
// })
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.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')
@ -81,7 +84,7 @@ const products = [{
default: true,
}]
const avvProfile = {
const profile = {
...baseProfile,
locale: 'de-DE',
timezone: 'Europe/Berlin',
@ -97,4 +100,6 @@ const avvProfile = {
remarksGetPolyline: false,
}
module.exports = avvProfile
export {
profile,
}

View file

@ -5,8 +5,8 @@
## Usage
```js
const createClient = require('hafas-client')
const avvProfile = require('hafas-client/p/AVV')
import {createClient} from 'hafas-client'
import {avvProfile} from 'hafas-client/p/avv/index.js'
// create a client with AVV profile
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 vosProfile = require('.')
const client = createClient(vosProfile, 'hafas-client-example')
const client = createClient(profile, 'hafas-client-example')
const fremont = '100013296'
const embarcadero = '100013295'
@ -48,6 +47,6 @@ client.locations('embarcadero', {results: 3})
// })
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.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')
@ -46,7 +49,7 @@ const products = [{
default: true,
}]
const bartProfile = {
const profile = {
...baseProfile,
locale: 'en-US',
timezone: 'America/Los_Angeles',
@ -61,4 +64,6 @@ const bartProfile = {
refreshJourneyUseOutReconL: true,
}
module.exports = bartProfile
export {
profile,
}

View file

@ -5,8 +5,8 @@
## Usage
```js
const createClient = require('hafas-client')
const bartProfile = require('hafas-client/p/BART')
import {createClient} from 'hafas-client'
import {bartProfile} from 'hafas-client/p/bart/index.js'
// create a client with BART profile
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 blsProfile = require('.')
const client = createClient(blsProfile, 'hafas-client-example')
const client = createClient(profile, 'hafas-client-example')
const bernDennigkofengässli = '8590093'
const münsingenSpital = '8578932'
@ -48,6 +47,6 @@ client.journeys(bernDennigkofengässli, münsingenSpital, {results: 1, stopovers
// })
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.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')
@ -74,7 +77,7 @@ const products = [{
default: true,
}]
const blsProfile = {
const profile = {
...baseProfile,
locale: 'de-DE',
timezone: 'Europe/Berlin',
@ -88,4 +91,6 @@ const blsProfile = {
reachableFrom: true,
}
module.exports = blsProfile
export {
profile,
}

View file

@ -5,8 +5,8 @@
## Usage
```js
const createClient = require('hafas-client')
const blsProfile = require('hafas-client/p/BLS')
import {createClient} from 'hafas-client'
import {blsProfile} from 'hafas-client/p/bls/index.js'
// create a client with BLS profile
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 bvgProfile = require('.')
const client = createClient(bvgProfile, 'hafas-client-example')
const client = createClient(profile, 'hafas-client-example')
// Hauptbahnhof to Charlottenburg
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})
// })
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.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 {
parseLocation: _parseLocation,
parseArrival: _parseArrival,
parseDeparture: _parseDeparture,
parseStopover: _parseStopover,
parseJourneyLeg: _parseJourneyLeg,
} = require('../../lib/default-profile')
import {parseLocation as _parseLocation} from '../../parse/location.js'
import {parseArrival as _parseArrival} from '../../parse/arrival.js'
import {parseDeparture as _parseDeparture} from '../../parse/departure.js'
import {parseStopover as _parseStopover} from '../../parse/stopover.js'
import {parseJourneyLeg as _parseJourneyLeg} from '../../parse/journey-leg.js'
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}"}`
const addOccupancy = (item, occupancyCodes) => {
@ -131,7 +132,7 @@ const requestJourneysWithBerlkoenig = ({opt}, query) => {
// todo: adapt/extend `vbb-parse-ticket` to support the BVG markup
const bvgProfile = {
const profile = {
...baseProfile,
locale: 'de-DE',
timezone: 'Europe/Berlin',
@ -162,4 +163,6 @@ const bvgProfile = {
reachableFrom: true
}
module.exports = bvgProfile
export {
profile,
}

View file

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

View file

@ -5,8 +5,8 @@
## Usage
```js
const createClient = require('hafas-client')
const bvgProfile = require('hafas-client/p/bvg')
import {createClient} from 'hafas-client'
import {bvgProfile} from 'hafas-client/p/bvg/index.js'
// create a client with BVG profile
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 cflProfile = require('.')
const client = createClient(cflProfile, 'hafas-client-example')
const client = createClient(profile, 'hafas-client-example')
const mersch = '9864348'
const bruxellesCentral = '8800003'
@ -47,6 +46,6 @@ client.journeys(mersch, bruxellesCentral, {results: 1})
// })
.then(data => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.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 products = require('./products')
import {products} from './products.js'
const cflProfile = {
const profile = {
...baseProfile,
locale: 'de-LU',
timezone: 'Europe/Luxembourg',
@ -18,4 +21,6 @@ const cflProfile = {
remarksGetPolyline: false,
}
module.exports = cflProfile;
export {
profile,
}

View file

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

View file

@ -5,8 +5,8 @@ The [*Société Nationale des Chemins de Fer Luxembourgeois (CFL)*](https://en.w
## Usage
```js
const createClient = require('hafas-client')
const cflProfile = require('hafas-client/p/cfl')
import {createClient} from 'hafas-client'
import {cflProfile} from 'hafas-client/p/cfl/index.js'
// create a client with CFL profile
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 cmtaProfile = require('.')
const client = createClient(cmtaProfile, 'hafas-client-example')
const client = createClient(profile, 'hafas-client-example')
// Broadie Oaks to Domain
client.journeys('000002370', '000005919', {results: 1, polylines: true})
@ -43,6 +42,6 @@ client.journeys('000002370', '000005919', {results: 1, polylines: true})
// })
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.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 products = require('./products')
import {products} from './products.js'
const cmtaProfile = {
const profile = {
...baseProfile,
locale: 'en-US',
timezone: 'America/Chicago',
@ -18,4 +21,6 @@ const cmtaProfile = {
remarks: true, // `.svcResL[0].res.msgL[]` is missing though 🤔
}
module.exports = cmtaProfile
export {
profile,
}

View file

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

View file

@ -5,8 +5,8 @@
## Usage
```js
const createClient = require('hafas-client')
const cmtaProfile = require('hafas-client/p/cmta')
import {createClient} from 'hafas-client'
import {cmtaProfile} from 'hafas-client/p/cmta/index.js'
// create a client with CMTA profile
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 dartProfile = require('.')
const client = createClient(dartProfile, 'hafas-client example')
const client = createClient(profile, 'hafas-client example')
const mlkJrPkwyAdamsAveDsm2055 = '100002702'
const se5thStEHackleyAveDsm2294 = '100004972'
@ -49,6 +48,6 @@ client.locations('adams ave', {results: 3})
// })
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.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')
@ -11,7 +14,7 @@ const products = [{
default: true,
}]
const dartProfile = {
const profile = {
...baseProfile,
locale: 'en-US',
timezone: 'America/Chicago',
@ -24,4 +27,6 @@ const dartProfile = {
radar: true,
}
module.exports = dartProfile
export {
profile,
}

View file

@ -7,8 +7,8 @@
## Usage
```js
const createClient = require('hafas-client')
const dartProfile = require('hafas-client/p/dart')
import {createClient} from 'hafas-client'
import {dartProfile} from 'hafas-client/p/dart/index.js'
// create a client with DART profile
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 dbbusradarnrwProfile = require('.')
const client = createClient(dbbusradarnrwProfile, 'hafas-client-example')
const client = createClient(profile, 'hafas-client-example')
// Hagen Bauhaus to Schwerte Bahnhof
// returns hafas error PARSE
@ -36,6 +35,6 @@ client.journeys('3307002', '3357026', {results: 1})
// }, {results: 10})
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
}, 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')
@ -75,7 +78,7 @@ const products = [
}
]
const dbBusradarNrwProfile = {
const profile = {
...baseProfile,
locale: 'de-DE',
timezone: 'Europe/Berlin',
@ -90,5 +93,6 @@ const dbBusradarNrwProfile = {
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
```js
const createClient = require('hafas-client')
const dbbusradarnrwProfile = require('hafas-client/p/db-busradar-nrw')
import {createClient} from 'hafas-client'
import {dbbusradarnrwProfile} from 'hafas-client/p/db-busradar-nrw/index.js'
// create a client with DB Busradar NRW profile
const client = createClient(dbbusradarnrwProfile, 'my-awesome-program')

View file

@ -1,5 +1,3 @@
'use strict'
const ageGroup = {
BABY: 'B',
CHILD: 'K',
@ -30,7 +28,7 @@ const ageGroupFromAge = (age) => {
throw new TypeError(`Invalid age '${age}'`)
}
module.exports = {
export {
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 dbProfile = require('.')
const client = createClient(dbProfile, 'hafas-client-example')
const client = createClient(profile, 'hafas-client-example')
// Berlin Jungfernheide to München Hbf
client.journeys('8011167', '8000261', {results: 1, tickets: true})
@ -55,5 +54,5 @@ client.journeys('8011167', '8000261', {results: 1, tickets: true})
// })
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
}, 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')
const uniqBy = require('lodash/uniqBy')
const slugg = require('slugg')
const without = require('lodash/without')
const {parseHook} = require('../../lib/profile-hooks')
import trim from 'lodash/trim.js'
import uniqBy from 'lodash/uniqBy.js'
import slugg from 'slugg'
import without from 'lodash/without.js'
import {parseHook} from '../../lib/profile-hooks.js'
const _parseJourney = require('../../parse/journey')
const _parseJourneyLeg = require('../../parse/journey-leg')
const _parseLine = require('../../parse/line')
const _parseArrival = require('../../parse/arrival')
const _parseDeparture = require('../../parse/departure')
const _parseHint = require('../../parse/hint')
const _parseLocation = require('../../parse/location')
const _formatStation = require('../../format/station')
const {bike} = require('../../format/filters')
import {parseJourney as _parseJourney} from '../../parse/journey.js'
import {parseJourneyLeg as _parseJourneyLeg} from '../../parse/journey-leg.js'
import {parseLine as _parseLine} from '../../parse/line.js'
import {parseArrival as _parseArrival} from '../../parse/arrival.js'
import {parseDeparture as _parseDeparture} from '../../parse/departure.js'
import {parseHint as _parseHint} from '../../parse/hint.js'
import {parseLocation as _parseLocation} from '../../parse/location.js'
import {formatStation as _formatStation} from '../../format/station.js'
import {bike} from '../../format/filters.js'
const products = require('./products')
const baseProfile = require('./base.json')
const formatLoyaltyCard = require('./loyalty-cards').format
const {ageGroup, ageGroupFromAge} = require('./ageGroup')
import {products} from './products.js'
import {formatLoyaltyCard} from './loyalty-cards.js'
import {ageGroup, ageGroupFromAge} from './ageGroup.js'
const transformReqBody = (ctx, body) => {
const req = body.svcReqL[0] || {}
@ -483,7 +486,7 @@ const formatStation = (id) => {
// todo: find option for absolute number of results
const dbProfile = {
const profile = {
...baseProfile,
locale: 'de-DE',
timezone: 'Europe/Berlin',
@ -512,4 +515,6 @@ const dbProfile = {
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 ?
const c = {
NONE: Symbol('no loyalty card'),
@ -25,7 +23,7 @@ const formatLoyaltyCard = (data) => {
return 0
}
module.exports = {
data: c,
format: formatLoyaltyCard
export {
c as data,
formatLoyaltyCard,
}

View file

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

View file

@ -5,8 +5,8 @@
## Usage
```js
const createClient = require('hafas-client')
const dbProfile = require('hafas-client/p/db')
import {createClient} from 'hafas-client'
import {dbProfile} from 'hafas-client/p/db/index.js'
// create a client with DB profile
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
```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, {
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 hvvProfile = require('.')
const client = createClient(hvvProfile, 'hafas-client-example')
const client = createClient(profile, 'hafas-client-example')
// client.journeys('116', '5900', {results: 1, polylines: true})
// client.departures('116', {duration: 1})
@ -42,6 +41,6 @@ client.locations('dammtor', {results: 2})
// return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true})
// })
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.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 products = require('./products')
import {products} from './products.js'
const hvvProfile = {
const profile = {
...baseProfile,
locale: 'de-DE',
timezone: 'Europe/Berlin',
@ -23,4 +26,6 @@ const hvvProfile = {
lines: false, // fails with `FAIL` "HCI Service: request failed"
}
module.exports = hvvProfile
export {
profile,
}

View file

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

View file

@ -5,8 +5,8 @@
## Usage
```js
const createClient = require('hafas-client')
const hvvProfile = require('hafas-client/p/hvv')
import {createClient} from 'hafas-client'
import {hvvProfile} from 'hafas-client/p/hvv/index.js'
// create a client with HVV profile
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 insaProfile = require('.')
const client = createClient(insaProfile, 'hafas-client-example')
const client = createClient(profile, 'hafas-client-example')
const hellestr1 = {
type: 'location',
@ -41,6 +40,6 @@ client.journeys('008010226', '008013456', {results: 1})
// })
.then(data => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.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 products = require('./products')
import {products} from './products.js'
const insaProfile = {
const profile = {
...baseProfile,
locale: 'de-DE',
timezone: 'Europe/Berlin',
@ -16,4 +19,6 @@ const insaProfile = {
reachableFrom: true,
}
module.exports = insaProfile;
export {
profile,
}

View file

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

View file

@ -5,8 +5,8 @@ The [Nahverkehr Sachsen-Anhalt (NASA)](https://de.wikipedia.org/wiki/Nahverkehrs
## Usage
```js
const createClient = require('hafas-client')
const insaProfile = require('hafas-client/p/insa')
import {createClient} from 'hafas-client'
import {insaProfile} from 'hafas-client/p/insa/index.js'
// create a client with INSA profile
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 cmtaProfile = require('.')
const client = createClient(cmtaProfile, 'hafas-client-example')
const client = createClient(profile, 'hafas-client-example')
const ingolstadtHbf = '8000183'
const audiParkplatz = '84999'
@ -40,6 +39,6 @@ client.journeys(ingolstadtHbf, audiParkplatz, {results: 1})
// todo: `reachableFrom` with `Ingolstadt, Tillystraße 1` 48.745769 | 11.432814
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.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 products = require('./products')
import {products} from './products.js'
const invgProfile = {
const profile = {
...baseProfile,
locale: 'de-DE',
timezone: 'Europe/Berlin',
@ -16,4 +19,6 @@ const invgProfile = {
refreshJourney: true,
}
module.exports = invgProfile
export {
profile,
}

View file

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

View file

@ -5,8 +5,8 @@
## Usage
```js
const createClient = require('hafas-client')
const invgProfile = require('hafas-client/p/invg')
import {createClient} from 'hafas-client'
import {invgProfile} from 'hafas-client/p/invg/index.js'
// create a client with INVG profile
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 irishProfile = require('.')
const client = createClient(irishProfile, 'hafas-client example')
const client = createClient(profile, 'hafas-client example')
// from Dublin to Belfast Central
client.journeys('9909002', '9990840', {results: 1})
@ -31,6 +30,6 @@ client.journeys('9909002', '9990840', {results: 1})
// }, {results: 10})
.then(data => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.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 products = require('./products')
import {products} from './products.js'
const irishRailProfile = {
const profile = {
...baseProfile,
locale: 'en-IE',
timezone: 'Europe/Dublin',
@ -18,4 +21,6 @@ const irishRailProfile = {
radar: true,
}
module.exports = irishRailProfile;
export {
profile,
}

View file

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

View file

@ -5,8 +5,8 @@ The [*Iarnród Éireann* (Irish Rail)](https://en.wikipedia.org/wiki/Iarnród_É
## Usage
```js
const createClient = require('hafas-client')
const irishProfile = require('hafas-client/p/irish-rail')
import {createClient} from 'hafas-client'
import {irishProfile} from 'hafas-client/p/irish-rail/index.js'
// create a client with Irish Rail profile
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 ivbProfile = require('.')
const client = createClient(ivbProfile, 'hafas-client example')
const client = createClient(profile, 'hafas-client example')
const innsbruckGriesauweg = '476162400'
const völsWest = '476431800'
@ -44,6 +43,6 @@ client.locations('griesauweg', {results: 3})
// })
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
console.log(inspect(data, {depth: null, colors: true}))
})
.catch(console.error)

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