declare const FlagEntriesSymbol: unique symbol; declare class BitField | Record> { readonly type: Flags[keyof Flags] extends number ? 'number' : 'bigint'; readonly zero: Flags[keyof Flags] extends number ? 0 : 0n; readonly mask: ValueType; readonly flags: Flags; private readonly [FlagEntriesSymbol]; constructor(flags: Readonly); /** * Resolves a: * - `string`: If it's a property of {@link Flags}. * - `number`: If the BitField processes `number` primitives. * - `bigint`: If the BitField processes `bigint` primitives. * - `Array`: Resolves recursively. * @param resolvable The value to resolve. * @returns The resolved value. */ resolve(resolvable: ValueResolvable): ValueType; /** * Checks whether or not `field` contains any of the bits from `bits`. * @param field The bits to compare the bits from. * @param bits The bits to compare with. * @returns Whether or not `field` has any of `bits`'s bits, also denoted as `A ∩ B ≠ ∅`. */ any(field: ValueResolvable, bits: ValueResolvable): boolean; /** * Checks whether or not `field` is a superset of or equal to `bits`. * @param field The bits to compare the bits from. * @param bits The bits to compare with. * @returns Whether or not `field` is a superset of or equal to `bits`, also denoted as `A ⊇ B`. */ has(field: ValueResolvable, bits: ValueResolvable): boolean; /** * Makes the complement of `field`, which is a field of all bits (of `U` or the union of all {@link Flags} bits) * that do not belong to `A`. It is the result of `U ∖ A`, or `difference(U, field)`. * @param field The bits to get the complement of. * @returns The complement of `field`, also denoted `Aᶜ` or `A'`. * @example * ```typescript * const bitfield = new BitField({ * Read: 0b0001, * Write: 0b0010, * Edit: 0b0100, * Delete: 0b1000 * }); * * bitfield.complement(0b0100); * // 0b1011 * ``` */ complement(field: ValueResolvable): ValueType; /** * Makes a union of all the bits. * @param fields The bits to create a union of. * @returns The result of combining all bits together, also denoted as `∅ ⋃ fields`. * @example * ```typescript * bitfield.union(0b0001, 0b0100); * // 0b0101 * * bitfield.union(0b1100, 0b0001, 0b0010); * // 0b1111 * ``` * @seealso {@linkplain https://en.wikipedia.org/wiki/Union_(set_theory)} */ union(...fields: ReadonlyArray>): ValueType; /** * Makes an intersection of all the bits. * @param bitfield The first field. * @param fields The bits to intersect with `bitfield`. * @returns The result of intersecting `bitfield` with all of the `fields`, also denoted as `A ⋂ fields`. * @example * ```typescript * bitfield.intersection(0b0001, 0b0100); * // 0b0000 * * bitfield.intersection(0b1100, 0b0100); * // 0b0100 * * bitfield.intersection(0b1101, 0b0101, 0b1100); * // 0b0100 * ``` * @seealso {@linkplain https://en.wikipedia.org/wiki/Intersection_(set_theory)} */ intersection(bitfield: ValueResolvable, ...fields: ReadonlyArray>): ValueType; /** * Removes from `a` the bits that exist in `b`. * @param a The first field. * @param b The bits to remove from `a`. * @returns The result of `a ∖ b`. * @example * ```typescript * bitfield.difference(0b1100, 0b0100); * // 0b1000 * * bitfield.difference(0b1111, 0b0110); * // 0b1001 * ``` * @seealso {@linkplain https://en.wikipedia.org/wiki/Difference_(set_theory)} */ difference(a: ValueResolvable, b: ValueResolvable): ValueType; /** * Computes the symmetric difference, denoted as `A ⊖ B` or `A Δ B`, which is the disjunctive union, or the set of * elements which are in either of the sets, but not in their intersection. As such, this is the result of * `(A ∖ B) ∪ (B ∖ A)`, `union(difference(a, b), difference(b, a))`, or `a ⊕ b`. * @remarks The empty set (`∅`) is neutral, as such, `A Δ ∅ = A` and `A Δ A = ∅` * @param a The first field. * @param b The second field. * @returns The result of computing `a Δ b`. * @example * ```typescript * bitfield.symmetricDifference(0b1100, 0b0011); * // 0b1111 * * bitfield.symmetricDifference(0b1101, 0b1011); * // 0b0110 * ``` * @seealso {@linkplain https://en.wikipedia.org/wiki/Symmetric_difference} */ symmetricDifference(a: ValueResolvable, b: ValueResolvable): ValueType; /** * Retrieves an array of the properties from {@link Flags} whose values are contained in `field`. * @param field The field to convert to an array. * @returns The names of the {@link BitField}'s flag properties whose value are contained in `field`. * @example * ```typescript * const bitfield = new BitField({ * Read: 0b0001, * Write: 0b0010, * Edit: 0b0100, * Delete: 0b1000 * }); * * bitfield.toArray(0b0101); * // ['Read', 'Edit'] * ``` */ toArray(field: ValueResolvable): Array; /** * Retrieves an iterator of the properties from {@link Flags} whose values are contained in `field`. * @param field The field to convert to an iterator. * @returns An iterator with the keys of the {@link BitField}'s flag properties whose value are contained in `field`. * @example * ```typescript * const bitfield = new BitField({ * Read: 0b0001, * Write: 0b0010, * Edit: 0b0100, * Delete: 0b1000 * }); * * [...bitfield.toKeys(0b0101)]; * // ['Read', 'Edit'] * ``` */ toKeys(field: ValueResolvable): IterableIterator; /** * Retrieves an iterator of the values from {@link Flags} whose values are contained in `field`. * @param field The field to convert to an iterator. * @returns An iterator with the values of the {@link BitField}'s flag properties whose value are contained in `field`. * @example * ```typescript * const bitfield = new BitField({ * Read: 0b0001, * Write: 0b0010, * Edit: 0b0100, * Delete: 0b1000 * }); * * [...bitfield.toValues(0b0101)]; * // [0b0001, 0b0100] * ``` */ toValues(field: ValueResolvable): IterableIterator>; /** * Retrieves an iterator of the entries from {@link Flags} whose values are contained in `field`. * @param field The field to convert to an iterator. * @returns An iterator with the entries of the {@link BitField}'s flag properties whose value are contained in `field`. * @example * ```typescript * const bitfield = new BitField({ * Read: 0b0001, * Write: 0b0010, * Edit: 0b0100, * Delete: 0b1000 * }); * * [...bitfield.toEntries(0b0101)]; * // [['Read', 0b0001], ['Edit', 0b0100]] * ``` */ toEntries(field: ValueResolvable): IterableIterator<[key: keyof Flags, value: ValueType]>; /** * Retrieves an object with the properties from {@link Flags} whose values are boolean denoting whether or not the * flag's bit is contained in `field`. * @param field The field to convert to an object. * @returns An object with the properties of {@link Flags} which values are boolean. * @example * ```typescript * const bitfield = new BitField({ * Read: 0b0001, * Write: 0b0010, * Edit: 0b0100, * Delete: 0b1000 * }); * * bitfield.toObject(0b0101); * // { * // Read: true, * // Write: false, * // Edit: true, * // Delete: false * // } * ``` */ toObject(field: ValueResolvable): Record; } type PrimitiveType = Type extends number ? number : bigint; type MaybeArray = Type | readonly Type[]; /** * Resolves the type of the values the specified {@link BitField} takes. * @typeparam A {@link BitField} instance type. */ type ValueType = Type extends BitField ? PrimitiveType : never; /** * Resolves the possible types accepted by the specified {@link BitField}. * @typeparam A {@link BitField} instance type. */ type ValueResolvable = Type extends BitField ? MaybeArray> : never; export { BitField, type MaybeArray, type PrimitiveType, type ValueResolvable, type ValueType };