BSB Node.js Type Definitions
    Preparing search index...

    Class Tools

    Just a bunch of utility functions - some are used within the framework, others are just general purpose. You can use any of these functions instead of writing your own or importing from an additional library.

    This class only has static methods, so don't going creating instances of it.

    If you want to use it, like for isNullOrUndefined, you can just call it directly on the class: Tools.isNullOrUndefined(value).

    Index

    Properties

    regexes: {
        exhard: RegExp;
        hard: RegExp;
        soft: RegExp;
        url: RegExp;
        ip: RegExp;
        email: RegExp;
    } = ...

    Predefined regular expressions for common string cleaning operations.

    arrays: {
        mapAsync: <Input = any, Output = any>(
            arr: Input[],
            asyncCallback: (item: Input) => Promise<Output>,
        ) => Promise<Output[]>;
        groupListBy: <T = any>(
            groupFunc: (object: T) => string,
            list: T[],
        ) => Record<string, T[]>;
        collectListBy: <T = any>(
            groupFunc: (object: T) => string,
            list: T[],
        ) => T[][];
        head: <T = any>(list: T[]) => T | undefined;
        tail: <T = any>(list: T[]) => T | undefined;
    } = ...

    Collection of utility functions for working with arrays.

    Type Declaration

    • mapAsync: <Input = any, Output = any>(
          arr: Input[],
          asyncCallback: (item: Input) => Promise<Output>,
      ) => Promise<Output[]>

      Asynchronously map over an array with async callback functions.

    • groupListBy: <T = any>(groupFunc: (object: T) => string, list: T[]) => Record<string, T[]>

      Group array items by a key generated from a function.

    • collectListBy: <T = any>(groupFunc: (object: T) => string, list: T[]) => T[][]

      Collect array items into groups using a grouping function, returning only the grouped arrays.

    • head: <T = any>(list: T[]) => T | undefined

      Get the first item in the array.

    • tail: <T = any>(list: T[]) => T | undefined

      Get the last item in the array.

    Methods

    • Parameters

      • objectToClean: any

      Returns string

    • Parameters

      • objectToClean: any
      • maxLimit: number

      Returns string

    • Parameters

      • objectToClean: any
      • maxLimit: number
      • strength: RegExp

      Returns string

    • Parameters

      • objectToClean: any
      • maxLimit: number
      • strength: CleanStringStrength

      Returns string

    • Parameters

      • objectToClean: any
      • maxLimit: number
      • strength: RegExp
      • returnNullAndUndefined: true

      Returns string | null | undefined

    • Parameters

      • objectToClean: any
      • maxLimit: number
      • strength: RegExp
      • returnNullAndUndefined: false

      Returns string

    • Parameters

      • objectToClean: any
      • maxLimit: number
      • strength: CleanStringStrength
      • returnNullAndUndefined: true

      Returns string | null | undefined

    • Parameters

      • objectToClean: any
      • maxLimit: number
      • strength: CleanStringStrength
      • returnNullAndUndefined: false

      Returns string

    • Parameters

      • objectToClean: any
      • maxLimit: number
      • strength: custom
      • returnNullAndUndefined: true
      • customRegex: RegExp

      Returns string | null | undefined

    • Parameters

      • objectToClean: any
      • maxLimit: number
      • strength: custom
      • returnNullAndUndefined: false
      • customRegex: RegExp

      Returns string

    • Automatically capitalize the first letter of each word in a string.

      Parameters

      • data: string

        The string to capitalize

      Returns string

      The string with each word capitalized

    • Get the string keys from an enum object, filtering out numeric keys.

      Type Parameters

      • O extends object
      • K extends string | number | symbol = keyof O

      Parameters

      • obj: O

        The enum object

      Returns K[]

      Array of string keys

    • Flatten a nested object into a single level with dot notation keys.

      Type Parameters

      • T = unknown
      • TR = object

      Parameters

      • obj: T

        The object to flatten

      Returns TR

      The flattened object

      Error if the input is not a valid object

    • Get hierarchical availability of objects based on key-parent relationships.

      Type Parameters

      • T

      Parameters

      • listOfObjects: T[]

        Array of objects to search through

      • key: string

        The key property name

      • parentkey: string

        The parent key property name

      • value: T

        The value to match against

      Returns T[]

      Array of matching objects including hierarchical children

    • Decode a base64 data URL string and extract the image type and data.

      Parameters

      • dataString: string

        Base64 data URL string (e.g., "data:image/png;base64,...")

      Returns any

      Object with type and data properties, or Error if invalid

    • Get a value from a nested object using a string path (e.g., "user.profile.name"). Supports comma-separated paths for concatenation and "*" wildcard for all properties.

      Parameters

      • workingObj: any

        The object to search in

      • stringToGet: string

        Dot-notation path string or comma-separated paths

      Returns any

      The value at the specified path, or null if not found

    • Merge two objects deeply, with the second object taking precedence.

      Parameters

      • src: any

        Source object to merge into

      • against: any

        Object to merge from (takes precedence)

      • initialMigration: boolean = true

        Whether to clone objects before merging (default: true)

      • OptionalreferenceKey: MergeObjectsKey

        Optional reference key for merge operations

      Returns any

      The merged object

    • Replace placeholders in a string with values from an object using {key} syntax.

      Parameters

      • obj: any

        Object containing replacement values

      • str: string

        String with placeholders (e.g., "Hello {name}")

      Returns string

      String with placeholders replaced by object values

    • Convert milliseconds to a human-readable time string.

      Parameters

      • time: number

        Time in milliseconds

      Returns string

      Human-readable time string (e.g., "5 minutes", "2 hours")

    • Create a delay/sleep for the specified number of milliseconds.

      Parameters

      • time: number = 1000

        Time to delay in milliseconds (default: 1000)

      Returns Promise<void>

      Promise that resolves after the specified time

    • Wait with delays while checking a condition, throwing an error on timeout.

      Parameters

      • checkFunc: Function

        Function that returns true while waiting should continue

      • rejectFunc: Function

        Function to call on timeout (before throwing)

      • time: number = 1000

        Delay between checks in milliseconds (default: 1000)

      • timeout: number = 10

        Maximum number of check attempts (default: 10)

      Returns Promise<void>

      "Timeout!" when the timeout is exceeded

    • Check if a value is a simple primitive type (string, number, or boolean).

      Parameters

      • value: unknown

        The value to check

      Returns boolean

      True if the value is a string, number, or boolean

    • Type guard to check if a value is a string.

      Parameters

      • value: unknown

        The value to check

      Returns value is string

      True if the value is a string

    • Type guard to check if a value is a Date object.

      Parameters

      • value: unknown

        The value to check

      • matchString: boolean = true

        Currently unused parameter for potential string date matching

      Returns value is Date

      True if the value is a Date instance

    • Type guard to check if a value is an array.

      Type Parameters

      • T = unknown

      Parameters

      • value: unknown

        The value to check

      Returns value is T[]

      True if the value is an array

    • Type guard to check if a value is a function.

      Parameters

      • value: any

        The value to check

      Returns value is Function

      True if the value is a function

    • Type guard to check if a value is a symbol.

      Parameters

      • value: any

        The value to check

      Returns value is symbol

      True if the value is a symbol

    • Type guard to check if a value is a valid number (not NaN).

      Parameters

      • value: any

        The value to check

      Returns value is number

      True if the value is a number and not NaN

    • Check if a value can be parsed as a valid number and return the parsed result.

      Parameters

      • value: any

        The value to check and parse

      Returns SimpleStatu<number>

      Object with status (true if valid) and value (the parsed number)

    • Type guard to check if a value is a boolean.

      Parameters

      • value: unknown

        The value to check

      Returns value is boolean

      True if the value is a boolean

    • Type guard to check if a value is undefined.

      Parameters

      • value: unknown

        The value to check

      Returns value is undefined

      True if the value is undefined

    • Type guard to check if a value is null.

      Parameters

      • value: unknown

        The value to check

      Returns value is null

      True if the value is null

    • Type guard to check if a value is a plain object (not array, null, etc.).

      Parameters

      • value: unknown

        The value to check

      Returns value is Object

      True if the value is a plain object

    • Type guard to check object constructor type (array or object).

      Type Parameters

      • TR = unknown

      Parameters

      • value: unknown

        The value to check

      • type: "object" | "array"

        The type to check for ("array" or "object")

      Returns value is TR

      True if the value matches the specified constructor type

    • Type guard to check if a value is a plain object with string keys.

      Parameters

      • value: unknown

        The value to check

      Returns value is Record<string, any>

      True if the value is a plain object

    • Type guard to check if a value is null or undefined.

      Parameters

      • value: unknown

        The value to check

      Returns value is null | undefined

      True if the value is null or undefined

    • Generate a random integer between min and max (inclusive).

      Parameters

      • min: number

        Minimum value (inclusive)

      • max: number

        Maximum value (inclusive)

      Returns number

      Random integer between min and max

    • Clamp a number between a minimum and maximum value.

      Parameters

      • min: number

        Minimum allowed value

      • max: number

        Maximum allowed value

      • value: number

        Value to clamp

      Returns number

      The clamped value

      Error if min is greater than max

    • Sleep/delay execution for the specified number of milliseconds.

      Parameters

      • milliseconds: number = 1000

        Time to sleep in milliseconds (default: 1000)

      Returns Promise<void>

      Promise that resolves after the specified time