Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils.d"

Index

Functions

fromByteArray

  • fromByteArray(bytes: number[] | Buffer | Uint8Array, start?: number, end?: number): string
  • Converts array of UTF8 bytes to JavaScript string Can optionally convert only part of array: [start, end)

    Parameters

    • bytes: number[] | Buffer | Uint8Array

      Array of UTF8 bytes to be converted

    • Optional start: number

      Optionally index of first byte to convert, inclusive

    • Optional end: number

      Optionally index of last byte to convert, exclusive

    Returns string

fromHex

  • fromHex(str: string): number[]
  • Converts hexadecimal string to array of bytes.

    Parameters

    • str: string

      Hexadecimal string to convert

    Returns number[]

    Array of bytes

keyByMultiple

  • keyByMultiple(arr: any[], key: string): object
  • Similar to lodash's keyBy function, but creates array for each key

    Parameters

    • arr: any[]

      Input array

    • key: string

      Indexation key

    Returns object

    • [key: string]: any

readVarint

  • readVarint(bytes: number[] | Buffer | Uint8Array, offset?: number): Long
  • Read raw varint (without header etc.) from buffer

    Parameters

    • bytes: number[] | Buffer | Uint8Array

      Array containing a varint

    • Optional offset: number

      Number of bytes to skip before reading (default 0)

    Returns Long

    Parsed varint as a Long

readVarintAndLength

  • readVarintAndLength(bytes: number[] | Buffer | Uint8Array, offset?: number): [Long, number]
  • Read raw varint (without header etc.) from buffer and get its length in bytes

    Parameters

    • bytes: number[] | Buffer | Uint8Array

      Array containing a varint

    • Optional offset: number

      Number of bytes to skip before reading (default 0)

    Returns [Long, number]

    Tuple containing parsed varint and its length in bytes

toByteArray

  • toByteArray(str: string): number[]
  • Converts JavaScript string to array of UTF8 bytes

    Parameters

    • str: string

      String to be converted

    Returns number[]

toHex

  • toHex(bytes: number[] | Buffer | Uint8Array | string): string
  • Converts array of bytes or string to hex. If string is provided, fromByteArray is implicitly used

    Parameters

    • bytes: number[] | Buffer | Uint8Array | string

      Bytes or string to convert

    Returns string

    Hexadecimal string

writeVarint

  • writeVarint(number: number | Long): number[]
  • Write number/Long to a raw varint

    Parameters

    • number: number | Long

      Value to be converted to a varint

    Returns number[]

    Bytes containing value as a varint

Generated using TypeDoc