explaingit

vercel/ms

Analysis updated 2026-06-26

5,527TypeScriptAudience · developerComplexity · 1/5Setup · easy

TLDR

ms is a tiny JavaScript and TypeScript utility that converts human-readable time strings like '2 days' or '10h' to milliseconds and back, with no dependencies and built-in TypeScript type safety.

Mindmap

mindmap
  root((repo))
    What it does
      String to milliseconds
      Milliseconds to string
      Time conversion
    Input Formats
      Full words 2 minutes
      Short form 2m
      Negative durations
    Features
      No dependencies
      TypeScript types
      Browser and Node
    Use Cases
      Cache expiry
      Timeouts
      Rate limits
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Set cache expiry or JWT token lifetimes using readable strings like '7 days' instead of raw millisecond numbers.

USE CASE 2

Define timeout values in backend config with strings like '30s' or '1h' that any developer can understand at a glance.

USE CASE 3

Convert raw millisecond durations to compact human-readable strings like '2h' for display in a UI.

What is it built with?

TypeScriptJavaScriptNode.js

How does it compare?

vercel/mssnyk/clivalor-software/ngx-bootstrap
Stars5,5275,5295,525
LanguageTypeScriptTypeScriptTypeScript
Setup difficultyeasymoderateeasy
Complexity1/52/52/5
Audiencedeveloperops devopsdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

In plain English

ms is a small JavaScript and TypeScript utility for converting time durations between human-readable strings and raw millisecond numbers. You give it a string like "2 days" or "10h" and it returns the equivalent number of milliseconds. You can also go the other direction: give it a number of milliseconds and it returns a compact string like "1m" or "2h". The library understands a wide range of input formats. You can write durations in full words like "2 minutes", abbreviated forms like "2m", or plain numbers. Capitalization and spacing variations are all accepted. Negative durations are supported too. It is maintained by Vercel and is designed to be tiny, with no dependencies. It works in web browsers, in Node.js, and in newer JavaScript runtimes. The package has TypeScript type definitions built in, and since version 3.0 uses advanced TypeScript features to catch mistakes at compile time if you pass a string the library does not recognize. Installation is a single line with any common JavaScript package manager. The library is widely used in JavaScript projects wherever a readable way to express time durations is needed, such as setting cache expiry times, timeouts, or rate limits.

Copy-paste prompts

Prompt 1
Show me how to use the `ms` library to set cookie and JWT expiry times with readable strings like '7 days' in a Node.js app.
Prompt 2
Write a rate-limiter config using `ms` so I can define the window as '15m' and reference it consistently across my codebase.
Prompt 3
How do I use `ms` to display a countdown timer in a React component that converts remaining milliseconds to a readable string?

Frequently asked questions

What is ms?

ms is a tiny JavaScript and TypeScript utility that converts human-readable time strings like '2 days' or '10h' to milliseconds and back, with no dependencies and built-in TypeScript type safety.

What language is ms written in?

Mainly TypeScript. The stack also includes TypeScript, JavaScript, Node.js.

How hard is ms to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is ms for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.