npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@padmaj/duration

v1.0.2

Published

Parse and format duration strings. '2h30m' ↔ 9000000ms. Zero dependencies. TypeScript-first.

Downloads

475

Readme

@padmaj/duration

Parse and format duration strings. Zero dependencies. TypeScript-first. Works in Node and browser.

Install

npm install @padmaj/duration

Usage

Parse a duration string → milliseconds

import { parseDuration } from '@padmaj/duration'

parseDuration('500ms')   // → 500
parseDuration('30s')     // → 30000
parseDuration('5m')      // → 300000
parseDuration('2h')      // → 7200000
parseDuration('1d')      // → 86400000
parseDuration('1w')      // → 604800000

// Compound durations
parseDuration('2h30m')   // → 9000000
parseDuration('1d12h')   // → 129600000
parseDuration('2h 30m')  // → 9000000 (spaces OK)

Format milliseconds → duration string

import { formatDuration } from '@padmaj/duration'

formatDuration(500)          // → '500ms'
formatDuration(30000)        // → '30s'
formatDuration(9000000)      // → '2h 30m'
formatDuration(129600000)    // → '1d 12h'
formatDuration(0)            // → '0ms'

Supported units

| Unit | Meaning | |---|---| | ms | milliseconds | | s | seconds | | m | minutes | | h | hours | | d | days | | w | weeks |

API

parseDuration(input: string): number

Parses a duration string and returns milliseconds. Throws DurationError if the input is empty or contains no recognizable units.

formatDuration(ms: number): string

Formats milliseconds into a human-readable duration string. Throws RangeError if the value is negative, NaN, or Infinity.

DurationError

Extends Error. Thrown by parseDuration on invalid input.

import { parseDuration, DurationError } from '@padmaj/duration'

try {
  parseDuration('abc')
} catch (e) {
  if (e instanceof DurationError) {
    console.error('Bad duration:', e.message)
  }
}

Notes

  • Input strings longer than 100 characters are rejected with a DurationError to prevent abuse.
  • formatDuration throws RangeError for negative, NaN, or Infinity values.

License

MIT