mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
31 lines
575 B
JavaScript
31 lines
575 B
JavaScript
import slugg from 'slugg';
|
|
|
|
const parseOperator = (ctx, zugattrib) => {
|
|
if (zugattrib?.operatorName) {
|
|
return {
|
|
type: 'operator',
|
|
id: zugattrib.operatorCode,
|
|
name: zugattrib.operatorName,
|
|
};
|
|
}
|
|
if (!zugattrib || !Array.isArray(zugattrib)) {
|
|
return null;
|
|
}
|
|
const bef = zugattrib.find(z => z.key == 'BEF' || z.key == 'OP');
|
|
if (!bef) {
|
|
return null;
|
|
}
|
|
const name = bef.value || bef.text;
|
|
if (!name) {
|
|
return null;
|
|
}
|
|
return {
|
|
type: 'operator',
|
|
id: slugg(name.trim()), // todo: find a more reliable way
|
|
name,
|
|
};
|
|
};
|
|
|
|
export {
|
|
parseOperator,
|
|
};
|