mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
26 lines
491 B
JavaScript
26 lines
491 B
JavaScript
const parseBitmask = ({profile}, bitmask) => {
|
|
const res = {};
|
|
for (let product of profile.products) {
|
|
res[product.id] = false;
|
|
}
|
|
|
|
const bits = bitmask.toString(2)
|
|
.split('')
|
|
.map(i => parseInt(i))
|
|
.reverse();
|
|
for (let i = 0; i < bits.length; i++) {
|
|
if (!bits[i]) {
|
|
continue;
|
|
} // ignore `0`
|
|
|
|
const product = profile.products.find(p => p.bitmasks.includes(Math.pow(2, i)));
|
|
if (product) {
|
|
res[product.id] = true;
|
|
}
|
|
}
|
|
return res;
|
|
};
|
|
|
|
export {
|
|
parseBitmask,
|
|
};
|