exiftool-vendored
    Preparing search index...

    Type Alias StrEnumHelpers<T>

    Helper methods and properties for string enum types created with strEnum.

    Provides type-safe utilities for working with predefined string literal types, including validation, comparison, and transformation operations.

    type StrEnumHelpers<T extends string> = {
        "[toStringTag]": "StrEnum";
        length: number;
        values: T[];
        "[iterator]"(): IterableIterator<T>;
        cmp(a: Nullable<string>, b: Nullable<string>): Maybe<number>;
        firstValid(...arr: Nullable<string>[]): Maybe<T>;
        getCI(s: Nullable<string>): Maybe<T>;
        has(s: Nullable<string>): s is T;
        includes(s: Nullable<string>): s is T;
        indexOf(s: Nullable<string>): Maybe<number>;
        lt(a: T, b: T): boolean;
        mapValid<R>(s: Nullable<string>, f: (t: T) => R): Maybe<R>;
        next(s: Nullable<string>): Maybe<T>;
        omit<O extends string>(...t: O[]): Exclude<T, O>[];
        ordinal(s: Nullable<string>): number;
        pick<O extends string>(...t: O[]): Extract<T, O>[];
        toReversed(): StrEnum<T>;
        toValid(s: Nullable<string>): Maybe<T>;
    }

    Type Parameters

    • T extends string

      The union of string literals that make up this enum

    Index

    Properties

    "[toStringTag]": "StrEnum"

    String tag used by Object.prototype.toString() for better debugging.

    const Colors = strEnum("red", "green", "blue");
    Object.prototype.toString.call(Colors) // "[object StrEnum]"
    length: number

    Number of enum values

    values: T[]

    Array of all valid enum values in declaration order

    Methods

    • Makes the StrEnum iterable, allowing use in for...of loops and array destructuring.

      Returns IterableIterator<T>

      Iterator that yields enum values in declaration order

      const Colors = strEnum("red", "green", "blue");
      for (const color of Colors) {
      console.log(color); // "red", "green", "blue"
      }
      const [first, second] = Colors; // first="red", second="green"
    • Compare two strings based on their enum order.

      Parameters

      • a: Nullable<string>

        First string to compare

      • b: Nullable<string>

        Second string to compare

      Returns Maybe<number>

      -1 if a < b, 0 if a === b, 1 if a > b, undefined if either is invalid

      const Colors = strEnum("red", "green", "blue");
      Colors.cmp("red", "green") // -1 (red comes before green)
      Colors.cmp("blue", "red") // 1 (blue comes after red)
    • Find the first valid enum value from a list of candidates.

      Parameters

      • ...arr: Nullable<string>[]

        Array of potential enum values to check

      Returns Maybe<T>

      First valid enum value found, or undefined if none match

      const Colors = strEnum("red", "green", "blue");
      Colors.firstValid("purple", "GREEN", "red") // "green" (case-insensitive match)
    • Get enum value with case-insensitive matching.

      Parameters

      • s: Nullable<string>

        String to match (can be null/undefined)

      Returns Maybe<T>

      Matching enum value or undefined if no match

      const Colors = strEnum("red", "green", "blue");
      Colors.getCI("RED") // "red"
      Colors.getCI("purple") // undefined
    • Synonym for includes. Checks if a string is a valid enum value.

      Parameters

      • s: Nullable<string>

        String to check (can be null/undefined)

      Returns s is T

      Type predicate indicating if s is a valid enum value

    • Type-safe check if a string is a valid enum value (case-sensitive).

      Parameters

      • s: Nullable<string>

        String to check (can be null/undefined)

      Returns s is T

      Type predicate indicating if s is a valid enum value

      const Colors = strEnum("red", "green", "blue");
      Colors.includes("red") // true
      Colors.includes("RED") // false
    • Get the zero-based index of an enum value.

      Parameters

      • s: Nullable<string>

        Enum value to find (can be null/undefined)

      Returns Maybe<number>

      Index of the value or undefined if not found

      const Colors = strEnum("red", "green", "blue");
      Colors.indexOf("green") // 1
      Colors.indexOf("purple") // undefined
    • Check if first enum value comes before second in declaration order.

      Parameters

      • a: T

        First enum value

      • b: T

        Second enum value

      Returns boolean

      True if a comes before b in the enum declaration

      const Colors = strEnum("red", "green", "blue");
      Colors.lt("red", "green") // true
      Colors.lt("green", "red") // false
    • Apply a function to a string if it's a valid enum value.

      Type Parameters

      • R

      Parameters

      • s: Nullable<string>

        String to check and potentially transform

      • f: (t: T) => R

        Function to apply if s is a valid enum value

      Returns Maybe<R>

      Result of function application, or undefined if s is invalid

      const Colors = strEnum("red", "green", "blue");
      Colors.mapValid("red", color => color.toUpperCase()) // "RED"
      Colors.mapValid("purple", color => color.toUpperCase()) // undefined
    • Get the next enum value in declaration order.

      Parameters

      Returns Maybe<T>

      Next enum value, or undefined if s is the last value or invalid

      const Colors = strEnum("red", "green", "blue");
      Colors.next("red") // "green"
      Colors.next("blue") // undefined (no next value)
    • Create a new array containing all enum values except the specified ones.

      Type Parameters

      • O extends string

      Parameters

      • ...t: O[]

        Enum values to exclude

      Returns Exclude<T, O>[]

      Array of remaining enum values

      const Colors = strEnum("red", "green", "blue");
      Colors.omit("green") // ["red", "blue"]
    • Get the ordinal position of an enum value, or length if not found. Useful for sorting where invalid values should sort last.

      Parameters

      • s: Nullable<string>

        Enum value to find (can be null/undefined)

      Returns number

      Index of the value, or enum length if not found

      const Colors = strEnum("red", "green", "blue");
      Colors.ordinal("green") // 1
      Colors.ordinal("purple") // 3 (length)
    • Create a new array containing only the specified enum values.

      Type Parameters

      • O extends string

      Parameters

      • ...t: O[]

        Enum values to include

      Returns Extract<T, O>[]

      Array of specified enum values

      const Colors = strEnum("red", "green", "blue");
      Colors.pick("red", "blue") // ["red", "blue"]
    • Create a new StrEnum with the values in reverse order.

      (This follows the new "toReversed" ES2023 naming convention for methods that return a new object)

      Returns StrEnum<T>

      New StrEnum with values in reverse declaration order

      const Colors = strEnum("red", "green", "blue");
      const Reversed = Colors.toReversed();
      Reversed.values // ["blue", "green", "red"]
    • Synonym for getCI. Get enum value with case-insensitive matching.

      Parameters

      • s: Nullable<string>

        String to validate (can be null/undefined)

      Returns Maybe<T>

      Valid enum value or undefined if no match