utility-pickle - v0.1.0
    Preparing search index...

    Class Guard

    A static utility class providing type-safe runtime type guards. These methods help with type narrowing and validation in TypeScript code.

    Index

    Properties

    factory: typeof GuardFactory = GuardFactory

    Provides access to a set of factory methods for generating reusable, parameterized type guards (e.g., for specific values or types).

    Use Guard.factory to construct custom guards dynamically, such as:

    • Checking for specific literal values
    • Creating guards for user-defined constraints

    Methods

    • Checks if an object has a given property key.

      Type Parameters

      Parameters

      • obj: unknown

        The object to check.

      • key: T

        The property key to look for.

      Returns obj is Record<T, unknown>

      True if the object contains the property key.

    • Checks if a value is an array.

      Type Parameters

      • T extends unknown

      Parameters

      • value: unknown

        The value to check.

      Returns value is T[]

      True if value is an array.

    • Checks if a value is a boolean.

      Parameters

      • value: unknown

        The value to check.

      Returns value is boolean

      True if value is of type boolean.

    • Checks if an array is empty.

      Parameters

      • value: unknown[]

        The array to check.

      Returns value is []

      True if the array has no elements.

    • Checks if a string is exactly the empty string ("").

      Parameters

      • value: string

        The string to check.

      Returns value is ""

      True if the string is empty.

    • Checks if a value equals one of the provided literal values.

      Type Parameters

      Parameters

      • value: unknown

        The value to check.

      • ...literals: readonly T[]

        A list of literal values to compare against.

      Returns value is T

      True if value is included in the provided literals.

    • Checks if an array is not empty.

      Type Parameters

      • T

      Parameters

      • value: T[]

        The array to check.

      Returns value is T[]

      True if the array has at least one element.

    • Checks if a string is not empty.

      Type Parameters

      • T extends string

      Parameters

      • value: T

        The string to check.

      Returns value is T

      True if the string is non-empty.

    • Checks if a value is not nullish.

      Type Parameters

      • T

      Parameters

      Returns value is T

      True if value is not Nullish (null or undefined).

    • Checks if a value is nullish.

      Parameters

      • value: unknown

        The value to check.

      Returns value is Nullish

      True if value is Nullish (null or undefined).

    • Checks if a value is a number.

      Parameters

      • value: unknown

        The value to check.

      Returns value is number

      True if value is a number.

    • Checks if a value is a plain object (excluding arrays and null).

      Parameters

      • value: unknown

        The value to check.

      Returns value is Record<PropertyName, unknown>

      True if value is a non-null object.

    • Checks if a value is strictly equal to a specific expected value.

      Type Parameters

      • T

      Parameters

      • value: unknown

        The value to check.

      • expected: T

        The specific value to compare against.

      Returns value is T

      True if value equals expected.

    • Checks if a value is a string.

      Parameters

      • value: unknown

        The value to check.

      Returns value is string

      True if value is a string.

    • Checks if a value is a tuple with the exact length and types, verified using the provided guard functions for each position.

      Type Parameters

      • T extends unknown[]

      Parameters

      • value: unknown

        The value to check.

      • ...guards: GuardFuncCollection<T>

        A guard function for each element in the tuple.

      Returns value is T

      True if value is a tuple matching the guard pattern.