Quick start
This guide will help you get started with Enhanced MS quickly. You’ll learn the basic concepts and see real working examples.Basic usage
Enhanced MS provides a singlems function that works in two ways:
- Format milliseconds to duration strings - Pass a number
- Parse duration strings to milliseconds - Pass a string
Import the library
First, import thems function from the package:
Format milliseconds to duration
Pass a number of milliseconds to convert it to a human-readable duration:By default, the function returns
null for durations less than 1 second. You can change this behavior with formatting options.Parse duration strings to milliseconds
Pass a duration string to convert it to milliseconds:Formatting options
You can customize how durations are formatted by passing options as the second parameter.Use abbreviations
Shorten unit names to their abbreviations:Limit output units
Show only the largest units:Combine options
You can combine multiple options for more control:Formatting presets
Enhanced MS includes built-in presets for common formatting patterns.Short format
Theshort preset uses abbreviations and limits the output to 2 units:
Colon notation
ThecolonNotation preset formats durations in a time-like format:
Full precision
ThefullPrecision preset includes all units including milliseconds and sub-millisecond units:
Using different languages
You can create a customms function for different languages using createMs:
Each language instance also supports parsing duration strings in that language.
Set default formatting options
You can set default formatting options when creating a custom instance:Common use cases
Here are some practical examples of using Enhanced MS:Display elapsed time
Parse configuration values
Format API response times
Next steps
Now that you understand the basics, explore the full API documentation to learn about all available options and features.API reference
Explore all available functions and options
Formatting options
Learn about all formatting options and presets