Files
discordeno/transformers/toggles/ToggleBitfield.ts
ITOH 03996c5f58 refactor: revert "feat: base plugin lib idea (#2308)" (#2336)
* Revert "feat: base plugin lib idea (#2308)"

This reverts commit ffe7cdbc6f.

* fmt
2022-07-02 14:24:43 +01:00

50 lines
1.0 KiB
TypeScript

export class ToggleBitfield {
bitfield = 0;
constructor(bitfield?: number) {
if (bitfield) this.bitfield = bitfield;
}
/** Tests whether or not this bitfield has the permission requested. */
contains(bits: number) {
return Boolean(this.bitfield & bits);
}
/** Adds some bits to the bitfield. */
add(bits: number) {
this.bitfield |= bits;
return this;
}
/** Removes some bits from the bitfield. */
remove(bits: number) {
this.bitfield &= ~bits;
return this;
}
}
export class ToggleBitfieldBigint {
bitfield = 0n;
constructor(bitfield?: bigint) {
if (bitfield) this.bitfield = bitfield;
}
/** Tests whether or not this bitfield has the permission requested. */
contains(bits: bigint) {
return Boolean(this.bitfield & bits);
}
/** Adds some bits to the bitfield. */
add(bits: bigint) {
this.bitfield |= bits;
return this;
}
/** Removes some bits from the bitfield. */
remove(bits: bigint) {
this.bitfield &= ~bits;
return this;
}
}