db-vendo-client/lib/validate-profile.js
2017-12-28 17:13:02 +01:00

48 lines
1.1 KiB
JavaScript

'use strict'
const types = {
locale: 'string',
timezone: 'string',
transformReq: 'function',
transformReqBody: 'function',
transformJourneysQuery: 'function',
products: 'object',
parseDateTime: 'function',
parseDeparture: 'function',
parseJourneyLeg: 'function',
parseJourney: 'function',
parseLine: 'function',
parseStationName: 'function',
parseLocation: 'function',
parseMovement: 'function',
parseNearby: 'function',
parseOperator: 'function',
parseRemark: 'function',
parseStopover: 'function',
formatAddress: 'function',
formatCoord: 'function',
formatDate: 'function',
formatLocationFilter: 'function',
formatPoi: 'function',
formatStation: 'function',
formatTime: 'function',
formatLocation: 'function',
formatRectangle: 'function'
}
const validateProfile = (profile) => {
for (let key of Object.keys(types)) {
const type = types[key]
if (type !== typeof profile[key]) {
throw new Error(`profile.${key} must be a ${type}.`)
}
if (type === 'object' && profile[key] === null) {
throw new Error(`profile.${key} must not be null.`)
}
}
}
module.exports = validateProfile