2019-10-20 00:19:11 +02:00
|
|
|
const parseBitmask = ({profile}, bitmask) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
const res = {};
|
|
|
|
for (let product of profile.products) {
|
|
|
|
res[product.id] = false;
|
|
|
|
}
|
2018-03-13 03:23:03 +01:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
const bits = bitmask.toString(2)
|
|
|
|
.split('')
|
|
|
|
.map(i => parseInt(i))
|
|
|
|
.reverse();
|
2019-10-20 00:19:11 +02:00
|
|
|
for (let i = 0; i < bits.length; i++) {
|
2024-02-06 22:58:49 +01:00
|
|
|
if (!bits[i]) {
|
|
|
|
continue;
|
|
|
|
} // ignore `0`
|
2018-03-13 03:23:03 +01:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
const product = profile.products.find(p => p.bitmasks.includes(Math.pow(2, i)));
|
|
|
|
if (product) {
|
|
|
|
res[product.id] = true;
|
|
|
|
}
|
2017-11-27 19:39:18 +01:00
|
|
|
}
|
2024-02-06 22:58:49 +01:00
|
|
|
return res;
|
|
|
|
};
|
2017-11-27 19:39:18 +01:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
parseBitmask,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|