@tmlmobilidade/types
Version:
24 lines (23 loc) • 675 B
JavaScript
/* * */
/* * */
export function createGtfsMapper(map) {
const forward = map;
const reverse = Object.entries(map).reduce((acc, [key, value]) => {
acc[value] = key;
return acc;
}, {});
return {
fromGtfs: (value) => {
const mapped = reverse[value];
if (mapped === undefined)
throw new Error(`No GTFS→Our mapping for: ${value}`);
return mapped;
},
toGtfs: (value) => {
const mapped = forward[value];
if (mapped === undefined)
throw new Error(`No Our→GTFS mapping for: ${value}`);
return mapped;
},
};
}