forked from public-transport/hafas-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
64 lines (56 loc) · 1.51 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// 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);
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';
// 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;
}
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),
};
}
return parsed;
};
eql(lineNameWithoutFahrtNr({
parsed: {name: 'THA 123', fahrtNr: '123'},
}).name, 'THA 123');
eql(lineNameWithoutFahrtNr({
parsed: {name: 'S1 123', fahrtNr: '123'},
}).name, 'S1');
eql(lineNameWithoutFahrtNr({
parsed: {name: 'S1-123', fahrtNr: '123'},
}).name, 'S1-123');
eql(lineNameWithoutFahrtNr({
parsed: {name: 'S1 123a', fahrtNr: '123'},
}).name, 'S1 123a');
const profile = {
...baseProfile,
locale: 'fr-BE',
timezone: 'Europe/Brussels',
products,
parseLine: parseHook(parseLine, lineNameWithoutFahrtNr),
trip: true,
refreshJourney: true,
radar: true,
reachableFrom: true,
};
export {
profile,
};