summary refs log tree commit diff
path: root/dist/server-util/src/util/BitField.js
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-14 00:30:07 +0100
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-14 00:30:07 +0100
commit8e84d39c7f2531e81eed3a9d01bf4030b19a2c88 (patch)
treeeb89f194780f903388cf968e9073cab4aed75ccc /dist/server-util/src/util/BitField.js
parent:art: Channel + Member + Message + Role in separate collection (diff)
downloadserver-8e84d39c7f2531e81eed3a9d01bf4030b19a2c88.tar.xz
:sparkles: getPermission util function
Diffstat (limited to 'dist/server-util/src/util/BitField.js')
-rw-r--r--dist/server-util/src/util/BitField.js127
1 files changed, 0 insertions, 127 deletions
diff --git a/dist/server-util/src/util/BitField.js b/dist/server-util/src/util/BitField.js
deleted file mode 100644

index 97d76f3a..00000000 --- a/dist/server-util/src/util/BitField.js +++ /dev/null
@@ -1,127 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.BitField = void 0; -/** - * Data structure that makes it easy to interact with a bitfield. - */ -class BitField { - constructor(bits = 0) { - this.bitfield = BigInt(0); - this.bitfield = BitField.resolve(bits); - } - /** - * Checks whether the bitfield has a bit, or any of multiple bits. - */ - any(bit) { - return (this.bitfield & BitField.resolve(bit)) !== 0n; - } - /** - * Checks if this bitfield equals another - */ - equals(bit) { - return this.bitfield === BitField.resolve(bit); - } - /** - * Checks whether the bitfield has a bit, or multiple bits. - */ - has(bit) { - if (Array.isArray(bit)) - return bit.every((p) => this.has(p)); - const BIT = BitField.resolve(bit); - return (this.bitfield & BIT) === BIT; - } - /** - * Gets all given bits that are missing from the bitfield. - */ - missing(bits) { - if (!Array.isArray(bits)) - bits = new BitField(bits).toArray(); - return bits.filter((p) => !this.has(p)); - } - /** - * Freezes these bits, making them immutable. - */ - freeze() { - return Object.freeze(this); - } - /** - * Adds bits to these ones. - * @param {...BitFieldResolvable} [bits] Bits to add - * @returns {BitField} These bits or new BitField if the instance is frozen. - */ - add(...bits) { - let total = 0n; - for (const bit of bits) { - total |= BitField.resolve(bit); - } - if (Object.isFrozen(this)) - return new BitField(this.bitfield | total); - this.bitfield |= total; - return this; - } - /** - * Removes bits from these. - * @param {...BitFieldResolvable} [bits] Bits to remove - */ - remove(...bits) { - let total = 0n; - for (const bit of bits) { - total |= BitField.resolve(bit); - } - if (Object.isFrozen(this)) - return new BitField(this.bitfield & ~total); - this.bitfield &= ~total; - return this; - } - /** - * Gets an object mapping field names to a {@link boolean} indicating whether the - * bit is available. - * @param {...*} hasParams Additional parameters for the has method, if any - */ - serialize() { - const serialized = {}; - for (const [flag, bit] of Object.entries(BitField.FLAGS)) - serialized[flag] = this.has(bit); - return serialized; - } - /** - * Gets an {@link Array} of bitfield names based on the bits available. - */ - toArray() { - return Object.keys(BitField.FLAGS).filter((bit) => this.has(bit)); - } - toJSON() { - return this.bitfield; - } - valueOf() { - return this.bitfield; - } - *[Symbol.iterator]() { - yield* this.toArray(); - } - /** - * Data that can be resolved to give a bitfield. This can be: - * * A bit number (this can be a number literal or a value taken from {@link BitField.FLAGS}) - * * An instance of BitField - * * An Array of BitFieldResolvable - * @typedef {number|BitField|BitFieldResolvable[]} BitFieldResolvable - */ - /** - * Resolves bitfields to their numeric form. - * @param {BitFieldResolvable} [bit=0] - bit(s) to resolve - * @returns {number} - */ - static resolve(bit = 0n) { - if ((typeof bit === "number" || typeof bit === "bigint") && bit >= 0n) - return BigInt(bit); - if (bit instanceof BitField) - return bit.bitfield; - if (Array.isArray(bit)) - return bit.map((p) => this.resolve(p)).reduce((prev, p) => BigInt(prev) | BigInt(p), 0n); - if (typeof bit === "string" && typeof this.FLAGS[bit] !== "undefined") - return this.FLAGS[bit]; - throw new RangeError("BITFIELD_INVALID: " + bit); - } -} -exports.BitField = BitField; -//# sourceMappingURL=BitField.js.map \ No newline at end of file