You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

enhanced-ms

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enhanced-ms

Convert milliseconds to human-readable duration strings and vice versa

4.1.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Enhanced MS

Convert milliseconds to human-readable duration strings and vice versa
npm install enhanced-ms
package version total downloads
enhanced-ms repo stars apteryxxyz followers discord shield

🤔 About

enhanced-ms is a flexible library for formatting milliseconds into human-readable durations and vice versa. It is an enhanced version of the popular ms with support for multiple inputs, localization, and more options.

🏓 Table of Contents

📦 Installation

Install using your preferred package manager:

npm install enhanced-ms
pnpm add enhanced-ms
yarn add enhanced-ms

🧭 Comparison

As mentioned above, enhanced-ms is an enhanced version of the popular ms, so how does it compare?

Featureenhanced-msmspretty-msitty-time
Convert Milliseconds to Duration
Convert Milliseconds to Multiple Duration Units
Convert Duration to Milliseconds
Convert Multiple Duration Units to Milliseconds
Localization Support

🌐 Languages

The currently supported languages include:

LanguageKey
English (default)en
Germande
Russianru
Māorimi
Spanishes
Dutchnl
Italianit
Frenchfr

You can help by adding support for more languages.

Make a pull request here.

🚀 Usage

Language and Default Options

The createMs function allows you to create a new instance of ms with a custom language and custom default options. This is useful if you want to use a different language or prefer different default options for parsing and formatting.

function createMs(options?: CreateMsOptions): typeof ms;
OptionTypeDescriptionDefault
languageLocale | LanguageDefinitionThe language to use for parsing and formatting, if your preferred isn't supported, you can directly pass a language definition.en
formatOptionsFormatOptions | FormatOptionsPresetThe options to use for formatting.see below

Formatting Milliseconds to Duration

The ms function allows you to format a number of milliseconds to a duration string. Passing a number of milliseconds will return a duration string, if the number is invalid, it will return null. The milliseconds overloads also allows you to pass a FormatOptions object or a FormatOptionsPreset to customise the formatting.

function ms(milliseconds: number): string | null;
function ms(milliseconds: number, options: FormatOptions): string | null;
function ms(milliseconds: number, preset: FormatOptionsPreset): string | null;
OptionTypeDescriptionDefault
extendsFormatOptionsPresetExtends the preset with the given options.none
hideUnitNamesbooleanHide unit names from the output.false
useAbbreviationsbooleanUse abbreviations for unit names.false
includeZerobooleanInclude units with the value 0 in the output.false
includeMsbooleanInclude milliseconds in the output.false
includeSubMsbooleanInclude sub-millisecond units in the output.false
includedUnitsParseUnit[]Which units should be included in the output.['year', 'day', 'hour', 'minute', 'second']
unitLimitnumberThe maximum number of units to include in the output.-1
unitSeparatorstringThe separator to use between units.
minimumDigitsnumberThe minimum number of digits for a unit, aka will pad with zeroes.0
PresetExample
short1m 30s
fullPrecision10 seconds 100 milliseconds 100 microseconds 100 nanoseconds
colonNotation00:01:30

Parsing Duration to Milliseconds

The ms function also allows you to parse a duration string (1 day, 3 weeks 4 days, etc). Passing a duration string will return a number of milliseconds, if no valid duration units are found, it will return 0.

function ms(duration: string): number;

Keywords

humanize

FAQs

Package last updated on 20 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.