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) => {
|
2017-12-28 17:12:46 +01:00
|
|
|
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
|