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

    Interface Flag<TFlags, TBit, TBrand>

    interface Flag<
        TFlags extends string,
        TBit extends bigint | number,
        TBrand extends string | symbol = symbol,
    > {
        __brand: TBrand;
        alias: string;
        bits: TBit;
        registry: FlagRegistry<TFlags, TBit, TBrand>;
        size: number;
        value: TBit;
        add(..._flags: TFlags[]): never;
        has(flag: TFlags): boolean;
        isEmpty(): boolean;
        isFull(): boolean;
        remove(..._flags: TFlags[]): never;
        toArray(): TFlags[];
        toJSON(): string;
        toObject(): Record<TFlags, boolean>;
        toString(radix?: number): string;
    }

    Type Parameters

    • TFlags extends string
    • TBit extends bigint | number
    • TBrand extends string | symbol = symbol

    Implemented by

    Index

    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.

    alias: string

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

    flag.alias; // "READ+WRITE"
    emptyFlag.alias; // "EMPTY_FLAG"
    bits: 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.

    size: number

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

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

    The raw bitwise value that encodes all active flags.

    Use Flag.bits instead

    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");
    • 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)"