How to use the hafas-client/lib/profile-hooks.parseHook function in hafas-client

To help you get started, we’ve selected a few hafas-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github derhuerst / vbb-hafas / index.js View on Github external
const colors = require('vbb-line-colors')

const addTransferInfoToJourney = require('./lib/add-transfer-info')

const {parseLine: _parseLine} = vbbProfile
const parseLineWithColor = ({parsed}, l) => {
	const {product, name} = parsed
	const c = colors[product] && colors[product][name]
	if (c) parsed.color = c

	return parsed
}

const customVbbProfile = {
	...vbbProfile,
	parseLine: parseHook(_parseLine, parseLineWithColor)
}

const defaults = {
	profile: customVbbProfile
}

const createVbbHafas = (userAgent, opt = {}) => {
	const {profile} = {...defaults, ...opt}

	const hafas = createClient(profile, userAgent)

	const origJourneys = hafas.journeys
	const journeysWithTransfers = (from, to, opt = {}) => {
		if (opt && opt.transferInfo) opt.stopovers = true
		const p = origJourneys(from, to, opt)