db-vendo-client/format/products-bitmask.js

17 lines
483 B
JavaScript
Raw Normal View History

2017-11-27 19:39:18 +01:00
'use strict'
2018-02-28 16:09:23 +01:00
const createFormatBitmask = (allProducts) => {
2017-11-27 19:39:18 +01:00
const formatBitmask = (products) => {
if(Object.keys(products).length === 0) throw new Error('products filter must not be empty')
2017-11-27 19:39:18 +01:00
let bitmask = 0
for (let product in products) {
2018-02-28 16:09:23 +01:00
if (!allProducts[product]) throw new Error('unknown product ' + product)
if (products[product] === true) bitmask += allProducts[product].bitmask
2017-11-27 19:39:18 +01:00
}
return bitmask
}
return formatBitmask
}
module.exports = createFormatBitmask