node-switchbot
    Preparing search index...

    Class ValidationUtils

    Utility class for comprehensive input validation with improved error messages.

    Index

    Constructors

    Methods

    • Validates buffer and throws descriptive error.

      Parameters

      • buffer: any

        The buffer to validate

      • OptionalexpectedLength: number

        Optional expected length

      • paramName: string = 'buffer'

        The parameter name for error reporting

      Returns asserts buffer is Buffer<ArrayBufferLike>

      When buffer is not a Buffer

      When buffer length doesn't match expected

    • Validates that a value is one of the allowed enum values.

      Type Parameters

      • T

      Parameters

      • value: any

        The value to validate

      • allowedValues: readonly T[]

        Array of allowed values

      • paramName: string = 'value'

        The parameter name for error reporting

      Returns asserts value is T

      When value is not in allowed values

    • Validates MAC address format.

      Parameters

      • address: any

        The MAC address to validate

      • paramName: string = 'address'

        The parameter name for error reporting

      Returns asserts address is string

      When address is not a string

      When address format is invalid

    • Validates percentage value (0-100).

      Parameters

      • value: number

        The value to validate

      • paramName: string = 'value'

        The parameter name for error reporting

      Returns void

      When value is not within valid range

      When value is not a number

    • Validates numeric range with enhanced checks.

      Parameters

      • value: number

        The value to validate

      • min: number

        Minimum allowed value

      • max: number

        Maximum allowed value

      • paramName: string = 'value'

        The parameter name for error reporting

      • mustBeInteger: boolean = false

        Whether the value must be an integer

      Returns void

      When value is not a number

      When value is outside valid range

    • Validates RGB color value (0-255).

      Parameters

      • value: number

        The color value to validate

      • colorName: string = 'color'

        The color name for error reporting

      Returns void

      When value is not within valid range

      When value is not a number

    • Validates string input with comprehensive checks.

      Parameters

      • value: any

        The value to validate

      • paramName: string = 'value'

        The parameter name for error reporting

      • minLength: number = 1

        Minimum required length

      • OptionalmaxLength: number

        Optional maximum length

      Returns asserts value is string

      When value is not a string

      When string length is invalid