ms() function is the main entry point for Enhanced MS. It formats milliseconds into human-readable duration strings and parses duration strings back into milliseconds.
Import
Overloads
Thems() function has multiple overloads to support different use cases:
Format milliseconds (default)
The duration in milliseconds to format
The formatted duration string, or
null if the duration is invalidFormat with options
The duration in milliseconds to format
The formatting options to customize the output. See FormatOptions for details.
The formatted duration string, or
null if the duration is invalidFormat with preset
The duration in milliseconds to format
The formatting preset to use:
'short': Abbreviated format (e.g.,"1m 30s")'fullPrecision': Includes milliseconds, microseconds, and nanoseconds'colonNotation': Colon-separated format (e.g.,"00:01:30")
The formatted duration string, or
null if the duration is invalidParse duration string
The duration string to parse (e.g.,
"2h 30m", "1 day, 5 hours")The total duration in milliseconds, or
0 if the duration is invalidError handling
When formatting milliseconds, the function validates the input:- Throws
TypeErrorif the value is not a finite number - Throws
TypeErrorif the value is negative - Returns
nullif the duration cannot be formatted
- Returns
0if the string cannot be parsed or is invalid
Type definition
See also
- createMs() - Create a custom ms instance with default options
- formatMilliseconds() - Format milliseconds directly
- parseDuration() - Parse duration strings directly