Options
All
  • Public
  • Public/Protected
  • All
Menu

Module core/utils

Index

Type aliases

JSONArray: JSONValue[]
JSONObject: {}

Type declaration

JSONPrimitive: string | number | boolean

Functions

  • generateUUIDv4(): string
  • Generates a UUIDv4.

    Will provide a fallback in case crypto is not available, which makes the "uuid" package generator not work.

    Important

    This workaround is here for usage in Qt/QML environments, where crypto is not available. Bug 1688015 was opened to figure out a less hacky way to do this.

    Returns string

    A randomly generated UUIDv4.

  • getMonotonicNow(): number
  • A helper function to get the current amount of milliseconds passed since a given time origin.

    Returns number

    The number of milliseconds since the time origin.

  • isBoolean(v: unknown): v is boolean
  • Checks whether or not v is a boolean.

    Parameters

    • v: unknown

      The value to verify.

    Returns v is boolean

    A special Typescript value (which compiles down to a boolean) stating whether v is a boolean.

  • isInteger(v: unknown): v is number
  • Checks whether or not v is an integer.

    Parameters

    • v: unknown

      The value to verify.

    Returns v is number

    A special Typescript value (which compiles down to a boolean) stating whether v is a number.

  • Verifies if a given value is a valid JSONValue.

    Parameters

    • v: unknown

      The value to verify

    Returns v is JSONValue

    A special Typescript value (which compiles down to a boolean) stating whether v is a valid JSONValue.

  • isNumber(v: unknown): v is number
  • Checks whether or not v is a number.

    Parameters

    • v: unknown

      The value to verify.

    Returns v is number

    A special Typescript value (which compiles down to a boolean) stating whether v is a number.

  • isObject(v: unknown): v is Record<string | number | symbol, unknown>
  • Checks whether or not v is a simple data object.

    Parameters

    • v: unknown

      The value to verify.

    Returns v is Record<string | number | symbol, unknown>

    A special Typescript value (which compiles down to a boolean) stating whether v is a valid data object.

  • isString(v: unknown): v is string
  • Checks whether or not v is a string.

    Parameters

    • v: unknown

      The value to verify.

    Returns v is string

    A special Typescript value (which compiles down to a boolean) stating whether v is a string.

  • isUndefined(v: unknown): v is undefined
  • Checks whether or not v is undefined.

    Parameters

    • v: unknown

      The value to verify.

    Returns v is undefined

    A special Typescript value (which compiles down to a boolean) stating whether v is undefined.

  • sanitizeApplicationId(applicationId: string): string
  • Generates a pipeline-friendly string that replaces non alphanumeric characters with dashes.

    Parameters

    • applicationId: string

      The application if to sanitize.

    Returns string

    The sanitized applicaiton id.

  • saturatingAdd(...args: number[]): number
  • Computes a sum, saturating at Number.MAX_SAFE_INTEGER.

    Parameters

    • Rest ...args: number[]

      Arguments to sum

    Returns number

    Sum result, of Number.MAX_SAFE_INTEGER is sum was larger than that.

  • testOnlyCheck(name: string, logTag?: string): boolean
  • Decorator factory that will only allow a function to be called when Glean is in testing mode.

    Parameters

    • name: string

      The name of the function that is being called. Used for logging purposes only.

    • logTag: string = LOG_TAG

      The log tag of the current module.

    Returns boolean

    Whether or not Glean is in testing mode.

  • truncateStringAtBoundaryWithError(metric: MetricType, value: unknown, length: number): Promise<string>
  • Truncates a string to a given max length.

    If the string required truncation, records an error through the error reporting mechanism.

    throws

    In case value is not a string.

    Parameters

    • metric: MetricType

      The metric to record an error to, if necessary,

    • value: unknown

      The string to truncate.

    • length: number

      The lenght to truncate to.

    Returns Promise<string>

    A string with at most length bytes.

  • validateHeader(v: string): boolean
  • Validates whether or not a given value is an acceptable HTTP header for outgoing pings.

    Parameters

    • v: string

      The value to validate.

    Returns boolean

    Whether or not the given value is a valid HTTP header value.

  • validateURL(v: string): boolean
  • Check that a given string is a valid URL.

    Parameters

    • v: string

      The string to validate.

    Returns boolean

    Whether or not the given string is a valid url.

Generated using TypeDoc