mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
extract parseIcon from parseCommon
This commit is contained in:
parent
9318007455
commit
6c5409fbce
3 changed files with 20 additions and 12 deletions
|
@ -1,6 +1,9 @@
|
|||
'use strict'
|
||||
|
||||
const parseDateTime = require('../parse/date-time')
|
||||
const parsePlatform = require('../parse/platform')
|
||||
const parseIcon = require('../parse/icon')
|
||||
const parseWhen = require('../parse/when')
|
||||
const parseDeparture = require('../parse/departure')
|
||||
const parseArrival = require('../parse/arrival')
|
||||
const parseJourneyLeg = require('../parse/journey-leg')
|
||||
|
@ -40,6 +43,9 @@ const defaultProfile = {
|
|||
transformJourneysQuery: id,
|
||||
|
||||
parseDateTime,
|
||||
parsePlatform,
|
||||
parseIcon,
|
||||
parseWhen,
|
||||
parseDeparture,
|
||||
parseArrival,
|
||||
parseJourneyLeg,
|
||||
|
|
|
@ -3,17 +3,6 @@
|
|||
const get = require('lodash/get')
|
||||
const findInTree = require('../lib/find-in-tree')
|
||||
|
||||
// todo: move to separate file
|
||||
const parseIcon = (i) => {
|
||||
const res = {
|
||||
type: i.res || null,
|
||||
title: i.text || null
|
||||
}
|
||||
if (i.fg) res.fgColor = i.fg
|
||||
if (i.bg) res.bgColor = i.bg
|
||||
return res
|
||||
}
|
||||
|
||||
const parseCommonData = (profile, opt, res) => {
|
||||
const c = res.common || {}
|
||||
|
||||
|
@ -27,7 +16,7 @@ const parseCommonData = (profile, opt, res) => {
|
|||
|
||||
res.icons = []
|
||||
if (Array.isArray(c.icoL)) {
|
||||
res.icons = c.icoL.map(parseIcon)
|
||||
res.icons = c.icoL.map(icon => profile.parseIcon(profile, icon))
|
||||
findInTree(res, '**.icoX', (idx, parent) => {
|
||||
if ('number' === typeof idx) parent.icon = res.icons[idx]
|
||||
})
|
||||
|
|
13
parse/icon.js
Normal file
13
parse/icon.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
'use strict'
|
||||
|
||||
const parseIcon = (profile, i) => {
|
||||
const res = {
|
||||
type: i.res || null,
|
||||
title: i.text || null
|
||||
}
|
||||
if (i.fg) res.fgColor = i.fg
|
||||
if (i.bg) res.bgColor = i.bg
|
||||
return res
|
||||
}
|
||||
|
||||
module.exports = parseIcon
|
Loading…
Add table
Reference in a new issue