From bbb68d86d52fe99676db5908d657fae84861a4eb Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 16 Mar 2018 17:03:13 +0100 Subject: [PATCH] validate products in lib/validate-profile --- lib/validate-profile.js | 16 ++++++++++++++++ parse/line.js | 9 --------- parse/products-bitmask.js | 10 ---------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/validate-profile.js b/lib/validate-profile.js index 2a8ac81b..8c05ebdb 100644 --- a/lib/validate-profile.js +++ b/lib/validate-profile.js @@ -52,6 +52,22 @@ const validateProfile = (profile) => { throw new Error('profile.products must be an array.') } 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 diff --git a/parse/line.js b/parse/line.js index 99e8c293..36da3f26 100644 --- a/parse/line.js +++ b/parse/line.js @@ -5,16 +5,7 @@ const slugg = require('slugg') const createParseLine = (profile, operators) => { const byBitmask = [] 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) { - if ('number' !== typeof bitmask) { - throw new Error(product.product + '.bitmasks[] must be a number.') - } byBitmask[bitmask] = product } } diff --git a/parse/products-bitmask.js b/parse/products-bitmask.js index f8522dc6..3ebdb7d7 100644 --- a/parse/products-bitmask.js +++ b/parse/products-bitmask.js @@ -4,18 +4,8 @@ const createParseBitmask = (profile) => { const defaultProducts = {} let withBitmask = [] 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 - 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.') - } withBitmask.push([bitmask, product]) } }