bitwise-flag - v2.1.0
    Preparing search index...

    Class FlagBox<TFlags, TBit, TBrand>

    Type Parameters

    • TFlags extends string
    • TBit extends Bit
    • TBrand extends string | symbol

    Implements

    Index

    Constructors

    Properties

    __brand: TBrand

    Do not use. Exists only at the type level — never present at runtime.

    Phantom field that forces TypeScript to structurally distinguish flags from different registries. Without it, two Flag types with different TBrand parameters would be considered identical due to recursive structural checking.

    bits: NoInfer<TBit>

    The raw bitwise value that encodes all active flags.

    flag.bits; // 3n  (for READ=1n | WRITE=2n)
    

    The registry this flag belongs to. Provides access to flag definitions, the bitwise combinator, and the underlying repository.

    Accessors

    • get alias(): string

      Human-readable label for the active flags, formed by joining their names with "+". Returns "EMPTY_FLAG" when no flags are set.

      Returns string

      flag.alias; // "READ+WRITE"
      emptyFlag.alias; // "EMPTY_FLAG"
    • get size(): number

      The number of flags that are currently set (i.e. the popcount of bits).

      Returns number

      flag.size; // 2  (for READ | WRITE)
      

    Methods

    • Parameters

      Returns never

      Use the add operator instead.

      import { add } from "bitwise-flag/operators";

      const next = add(flag, "READ", "WRITE");
    • Returns true if the specified flag is currently set.

      Parameters

      • flag: TFlags

        The flag name to test.

      Returns boolean

      flag.has("READ");  // true
      flag.has("EXEC"); // false
    • Returns true when no flags are set (i.e. bits equals zero).

      Returns boolean

      registry.empty().isEmpty(); // true
      
    • Returns true when every registered flag is set.

      Returns boolean

      registry.of("READ", "WRITE", "EXEC").isFull(); // true
      
    • Parameters

      Returns never

      Use the remove operator instead.

      import { remove } from "bitwise-flag/operators";

      const next = remove(flag, "READ", "WRITE");
    • Serializes the flag set to its string representation.

      Returns string

      The underlying bitmask as a string.

    • Returns a record mapping every registered flag name to a boolean indicating whether it is currently set.

      Returns Record<TFlags, boolean>

      flag.toObject(); // { READ: true, WRITE: true, EXEC: false }
      
    • Returns a string in the format Flag([<alias>]: <bits>). If you need to format bits, use flag.bits.toString().

      Parameters

      • Optionalradix: number

        The radix passed to the underlying numeric toString call (e.g. 2 for binary, 16 for hex). Defaults to 10.

      Returns string

      flag.toString();   // "Flag([READ+WRITE]: 3)"
      flag.toString(2); // "Flag([READ+WRITE]: 11)"
      emptyFlag.toString(); // "Flag([EMPTY_FLAG]: 0)"