db-vendo-client/p/sncb/index.js

67 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-05-07 16:17:37 +02:00
// 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);
2020-03-18 03:08:13 +01:00
import {readFileSync} from 'fs';
import {Agent} from 'https';
import {strictEqual as eql} from 'assert';
import {parseHook} from '../../lib/profile-hooks.js';
import {parseLine} from '../../parse/line.js';
const baseProfile = require('./base.json');
import {products} from './products.js';
2020-03-18 03:08:13 +01:00
2020-03-19 00:18:32 +01:00
// todo: this is ugly
const lineNameWithoutFahrtNr = ({parsed}) => {
const {name, fahrtNr} = parsed;
if (!name || !fahrtNr || !(/s\d/i).test(name)) {
return parsed;
}
const i = name.indexOf(fahrtNr);
if (i < 0) {
return parsed;
}
2020-03-19 00:18:32 +01:00
if (
(/\s/).test(name[i - 1] || '') // space before
&& name.length === i + fahrtNr.length // nothing behind
) {
return {
...parsed,
name: name.slice(0, i - 1) + name.slice(i + fahrtNr.length + 1),
};
2020-03-19 00:18:32 +01:00
}
return parsed;
};
2020-03-19 00:18:32 +01:00
eql(lineNameWithoutFahrtNr({
parsed: {name: 'THA 123', fahrtNr: '123'},
}).name, 'THA 123');
2020-03-19 00:18:32 +01:00
eql(lineNameWithoutFahrtNr({
parsed: {name: 'S1 123', fahrtNr: '123'},
}).name, 'S1');
2020-03-19 00:18:32 +01:00
eql(lineNameWithoutFahrtNr({
parsed: {name: 'S1-123', fahrtNr: '123'},
}).name, 'S1-123');
2020-03-19 00:18:32 +01:00
eql(lineNameWithoutFahrtNr({
parsed: {name: 'S1 123a', fahrtNr: '123'},
}).name, 'S1 123a');
2020-03-19 00:18:32 +01:00
2022-05-07 16:17:37 +02:00
const profile = {
...baseProfile,
2020-03-18 03:08:13 +01:00
locale: 'fr-BE',
timezone: 'Europe/Brussels',
products,
2020-03-19 00:18:32 +01:00
parseLine: parseHook(parseLine, lineNameWithoutFahrtNr),
2020-03-18 03:08:13 +01:00
trip: true,
refreshJourney: true,
radar: true,
2022-11-09 21:22:49 +01:00
reachableFrom: true,
};
2020-03-18 03:08:13 +01:00
2022-05-07 16:17:37 +02:00
export {
profile,
};