Options
All
  • Public
  • Public/Protected
  • All
Menu

@behaveware/nucleus

Index

Type aliases

AppEventPrefix

AppEventPrefix: string

Application prefix for an event name

EventName

EventName: `${AppEventPrefix}:${EventPrefix}:${string}`

Name of an event matching the format of: AppEventPrefix:EventPrefix:string

EventPrefix

EventPrefix: string

Prefix for an event name usually the screen, page, service, etc.

Variables

GIGABYTE_SIZE

GIGABYTE_SIZE: number = ...

The size of a GB in base 2. More Info

KILOBYTE_SIZE

KILOBYTE_SIZE: 1024 = 1024

The size of a KB in base 2. More Info

MEGABYTE_SIZE

MEGABYTE_SIZE: number = ...

The size of a MB in base 2. More Info

TERABYTE_SIZE

TERABYTE_SIZE: number = ...

The size of a TB in base 2. More Info

Functions

Const arraysAreEqual

  • arraysAreEqual<T>(a: T[], b: T[], equals: (a: T, b: T) => boolean): boolean
  • Determines if two arrays of type T[] are equal

    Type parameters

    • T

    Parameters

    • a: T[]

      Array of objects

    • b: T[]

      Array of objects

    • equals: (a: T, b: T) => boolean

      Function for comparing objects of type T

        • (a: T, b: T): boolean
        • Parameters

          • a: T
          • b: T

          Returns boolean

    Returns boolean

    boolean

Const batchArray

  • batchArray<T>(array: T[], batchSize?: number): T[][]
  • Breaks an array T[] into an array of batches T[][]

    Type parameters

    • T

    Parameters

    • array: T[]
    • batchSize: number = 0

    Returns T[][]

    An array of batches: T[][]

Const capitalize

  • capitalize(word: string): string
  • Capitalizes the first letter of a given word.

    Parameters

    • word: string

      Word to capitalize

    Returns string

    A capitalized copy of the word

    Example:

    const result: string = capitalize("nucleus");
    console.log(result); // Nucleus

Const compareArrays

  • compareArrays<T>(a: T[], b: T[]): boolean
  • Compares two arrays of type T where T extends IComparable

    Type parameters

    Parameters

    • a: T[]

      Array of IComparable objects

    • b: T[]

      Array of IComparable objects

    Returns boolean

    boolean

Const equalAsStrings

  • equalAsStrings<T>(a: T, b: T): boolean
  • Determines if two objects of type T are equivalent when stringified

    Type parameters

    • T

    Parameters

    • a: T

      First object to compare

    • b: T

      Second object to compare

    Returns boolean

    A boolean representing whether the two are equal as strings

Const filenameFrom

  • filenameFrom(path: string): string
  • Retrieves the filename from a path.

    Parameters

    • path: string

      Filepath or Url to retrieve the filename from

    Returns string

    A filename

    Examples:

    const nameFromUrl: string = filenameFrom("https://www.behaveware.org/test.jpeg");
    console.log(nameFromUrl); // test.jpeg

    const nameFromFilepath: string = filenameFrom("C:\\behaveware\\nucleus\\test.jpeg");
    console.log(nameFromFilepath); // test.jpeg

Const foreachParallelAsync

  • foreachParallelAsync<T>(array: T[], actionAsync: (element: T) => Promise<void>, batchSize?: number): Promise<void>
  • Loops through an array executing an action on each element in parallel

    Type parameters

    • T

    Parameters

    • array: T[]

      Array to loop through

    • actionAsync: (element: T) => Promise<void>

      Function to be called on each element

        • (element: T): Promise<void>
        • Parameters

          • element: T

          Returns Promise<void>

    • Optional batchSize: number

      (Optional) Size of batches, for working with larger arrays

    Returns Promise<void>

Const isEmail

  • isEmail(text: string): boolean
  • Determines if text is an email. Based on the RFC 5322 Specification.

    Parameters

    • text: string

      Text to check

    Returns boolean

    Whether or not the text is an email

    Example:

    const result: boolean = isEmail("support@behaveware.org");
    console.log(result); // true

Const isInteger

  • isInteger(text: string): boolean
  • Determines if text is an integer.

    Parameters

    • text: string

      Text to check

    Returns boolean

    Whether or not the text is an integer

    Example:

    const result: boolean = isInteger("42");
    console.log(result); //true

Const isPhoneNumber

  • isPhoneNumber(text: string): boolean

Const mapParallelAsync

  • mapParallelAsync<T, TT>(array: T[], mapAsync: (element: T) => Promise<TT>, batchSize?: number): Promise<TT[]>
  • Maps an array of type T[] to an array of type T[][] in parallel. The order of the output array can not be guaranteed. When the order needs to be maintained a Synchronous approach should be used.

    Type parameters

    • T

    • TT

    Parameters

    • array: T[]

      Array to map

    • mapAsync: (element: T) => Promise<TT>

      Mapping function

        • (element: T): Promise<TT>
        • Parameters

          • element: T

          Returns Promise<TT>

    • Optional batchSize: number

      Size of batches for dealing with large arrays

    Returns Promise<TT[]>

    A promise with the mapped array of type TT[]

Const toGigabytes

  • toGigabytes(bytes: number): number
  • Converts bytes to gigabytes.

    Example:

    const gigabytes = toGigabytes(1024 * 1024 * 1024);
    console.log(gigabytes); // 1

    Parameters

    • bytes: number

      Number of bytes

    Returns number

    Number of gigabytes

Const toKilobytes

  • toKilobytes(bytes: number): number
  • Converts bytes to kilobytes.

    Example:

    const kilobytes = toKilobytes(1024);
    console.log(kilobytes); // 1

    Parameters

    • bytes: number

      Number of bytes

    Returns number

    Number of kilobytes

Const toMegabytes

  • toMegabytes(bytes: number): number
  • Converts bytes to megabytes.

    Example:

    const megabytes = toMegabytes(1024 * 1024);
    console.log(megabytes); // 1

    Parameters

    • bytes: number

      Number of bytes

    Returns number

    Number of megabytes

Const toTerabytes

  • toTerabytes(bytes: number): number
  • Converts bytes to terabytes.

    Example:

    const terabytes = toTerabytes(1024 * 1024 * 1024 * 1024);
    console.log(terabytes); // 1

    Parameters

    • bytes: number

      Number of bytes

    Returns number

    Number of terabytes

Const trimBuffer

  • trimBuffer(buffer: Buffer, maxSize: number): Buffer
  • Trim the Buffer to a max size in bytes.

    Example:

    const buffer = Buffer.from("nucleus");
    console.log(buffer.byteLength); // 7

    const trimmedBuffer = trimBuffer(buffer, 4);
    console.log(trimmedBuffer.byteLength); // 4

    Parameters

    • buffer: Buffer

      Buffer to be trimmed

    • maxSize: number

      Max size in bytes to trim to

    Returns Buffer

    The trimmed Buffer

Generated using TypeDoc