Skip to content

millisecondsFromString

Type : function

A function that returns a number of milliseconds from a string representation of time.

The millisecondsFromStringErrorScope app error scope array is exported by this utility and can be used to filter thrown AppError by scope for this specific utility.
To learn more about error handling please refer to error handling section of the getting started guide, and the AppError documentation.

Usage

console.log(millisecondsFromString('1s')); // 1000
console.log(millisecondsFromString('2s:500ms')); // 2500
console.log(millisecondsFromString('2s-500ms', { separator: '-' })); // 2500
console.log(millisecondsFromString('1second', {
unitsAlias: {
'seconds': 's',
'second': 's'
}
})); // 1000

Definition

export function millisecondsFromString(
string: TimeUnits,
options?: Options,
): number {}
  • parameters:

    1. string:
      • The string representation of time to convert to milliseconds.
      • See TimeUnits for more details.
    2. options: An object with the following properties:
      • separator:
        • The separator between time units in the string
        • Default is :.
      • unitsAlias: since v2.1.0
        • An object with time unit aliases where keys are aliases and values are time units
        • See Units and their Values for more details.
  • returns: number