mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
validate products in lib/validate-profile
This commit is contained in:
parent
08357dfa9d
commit
bbb68d86d5
3 changed files with 16 additions and 19 deletions
|
@ -52,6 +52,22 @@ const validateProfile = (profile) => {
|
||||||
throw new Error('profile.products must be an array.')
|
throw new Error('profile.products must be an array.')
|
||||||
}
|
}
|
||||||
if (profile.products.length === 0) throw new Error('profile.products is empty.')
|
if (profile.products.length === 0) throw new Error('profile.products is empty.')
|
||||||
|
for (let product of profile.products) {
|
||||||
|
if ('string' !== typeof product.product) {
|
||||||
|
throw new Error('profile.products[].product must be a string.')
|
||||||
|
}
|
||||||
|
if ('boolean' !== typeof product.default) {
|
||||||
|
throw new Error('profile.products[].default must be a boolean.')
|
||||||
|
}
|
||||||
|
if (!Array.isArray(product.bitmasks)) {
|
||||||
|
throw new Error(product.product + '.bitmasks must be an array.')
|
||||||
|
}
|
||||||
|
for (let bitmask of product.bitmasks) {
|
||||||
|
if ('number' !== typeof bitmask) {
|
||||||
|
throw new Error(product.product + '.bitmasks[] must be a number.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = validateProfile
|
module.exports = validateProfile
|
||||||
|
|
|
@ -5,16 +5,7 @@ const slugg = require('slugg')
|
||||||
const createParseLine = (profile, operators) => {
|
const createParseLine = (profile, operators) => {
|
||||||
const byBitmask = []
|
const byBitmask = []
|
||||||
for (let product of profile.products) {
|
for (let product of profile.products) {
|
||||||
if ('string' !== typeof product.product) {
|
|
||||||
throw new Error('profile.products[].product must be a string.')
|
|
||||||
}
|
|
||||||
if (!Array.isArray(product.bitmasks)) {
|
|
||||||
throw new Error(product.product + '.bitmasks must be an array.')
|
|
||||||
}
|
|
||||||
for (let bitmask of product.bitmasks) {
|
for (let bitmask of product.bitmasks) {
|
||||||
if ('number' !== typeof bitmask) {
|
|
||||||
throw new Error(product.product + '.bitmasks[] must be a number.')
|
|
||||||
}
|
|
||||||
byBitmask[bitmask] = product
|
byBitmask[bitmask] = product
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,18 +4,8 @@ const createParseBitmask = (profile) => {
|
||||||
const defaultProducts = {}
|
const defaultProducts = {}
|
||||||
let withBitmask = []
|
let withBitmask = []
|
||||||
for (let product of profile.products) {
|
for (let product of profile.products) {
|
||||||
if ('string' !== typeof product.product) {
|
|
||||||
throw new Error('profile.products[].product must be a string.')
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultProducts[product.product] = false
|
defaultProducts[product.product] = false
|
||||||
if (!Array.isArray(product.bitmasks)) {
|
|
||||||
throw new Error(product.product + '.bitmasks must be an array.')
|
|
||||||
}
|
|
||||||
for (let bitmask of product.bitmasks) {
|
for (let bitmask of product.bitmasks) {
|
||||||
if ('number' !== typeof bitmask) {
|
|
||||||
throw new Error(product.product + '.bitmasks[] must be a number.')
|
|
||||||
}
|
|
||||||
withBitmask.push([bitmask, product])
|
withBitmask.push([bitmask, product])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue