UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

65 lines 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createBitFlagsEnum = void 0; function orBitFlags(other) { return new BitFlagValueImpl(this.value | other.value); } function unionBitFlags(...other) { let ret = this.value; for (let i = 0; i < other.length; i++) { const val = other[i]; ret |= val.value; } return new BitFlagValueImpl(ret); } function hasBitFlag(other) { return (this.value & other.value) !== 0; } function intersectBitFlags(...other) { let union = 0; for (let i = 0; i < other.length; i++) { const val = other[i]; union |= val.value; } return new BitFlagValueImpl(this.value & union); } class BitFlagValueImpl { constructor(numberValue) { this.or = orBitFlags; this.union = unionBitFlags; this.hasFlag = hasBitFlag; this.intersect = intersectBitFlags; this.value = numberValue; } } class BitFlagEnumValueImpl extends BitFlagValueImpl { constructor(stringValue, numberValue) { super(numberValue); this.stringValue = stringValue; } } class BitFlagEnumImpl { constructor(values) { this.keys = values; for (let i = 0; i < values.length; i++) { const value = values[i]; const numValue = 1 << i; // @ts-expect-error this is valid for now... mostly. Would be ideal to // modify the return type to include the new 'number' values this[value] = new BitFlagEnumValueImpl(value, numValue); } } union(other) { let ret = 0; for (let i = 0; i < other.length; i++) { const val = other[i]; ret |= val.value; } return new BitFlagValueImpl(ret); } } const createBitFlagsEnum = (values) => { return new BitFlagEnumImpl(values); }; exports.createBitFlagsEnum = createBitFlagsEnum; //# sourceMappingURL=bitflags.js.map