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

@alwatr/parse-duration

v5.5.29

Published

A simple utility to parse a duration string into milliseconds number.

Downloads

1,956

Readme

Parse-duration

A simple, efficient utility to parse time duration strings into milliseconds or other time units.

Installation

npm install @alwatr/parse-duration
# or
yarn add @alwatr/parse-duration
# or
pnpm add @alwatr/parse-duration

Features

  • Parse duration strings (like '10s', '5m', '2h') into milliseconds
  • Convert between different time units
  • TypeScript support with full type safety
  • Zero dependencies (except for internal Alwatr utilities)
  • Optimized for performance
  • Comprehensive error handling

Usage

import {parseDuration} from '@alwatr/parse-duration';

// Basic usage - parse to milliseconds
parseDuration('10s');    // 10,000 (10 seconds in milliseconds)
parseDuration('5m');     // 300,000 (5 minutes in milliseconds)
parseDuration('2h');     // 7,200,000 (2 hours in milliseconds)
parseDuration('1.5d');   // 129,600,000 (1.5 days in milliseconds)

// Accept milliseconds as input
parseDuration(5000);     // 5,000 (pass through)

// Convert to different units
parseDuration('10d', 'h');  // 240 (10 days in hours)
parseDuration('1h', 'm');   // 60 (1 hour in minutes)
parseDuration('120s', 'm'); // 2 (120 seconds in minutes)
parseDuration(3600000, 'h'); // 1 (3600000 milliseconds in hours)

API

parseDuration(duration, toUnit?)

Parse a duration string or millisecond number into the specified unit (or milliseconds by default).

Parameters

  • duration: string | number - A duration string (like '10s', '5m') or a number (treated as milliseconds)
  • toUnit: DurationUnit (optional) - The unit to convert to. If omitted, returns milliseconds.

Returns

  • number: The duration in the specified unit (or milliseconds if no unit specified)

Throws

  • Error('not_a_number'): If the duration string doesn't contain a valid number
  • Error('invalid_unit'): If the unit is not recognized
  • Error('invalid_format'): If the duration format is invalid

Supported Units

| Unit | Description | Milliseconds Equivalent | | ---- | ----------- | ----------------------- | | s | Second | 1,000 | | m | Minute | 60,000 | | h | Hour | 3,600,000 | | d | Day | 86,400,000 | | w | Week | 604,800,000 | | M | Month (30d) | 2,592,000,000 | | y | Year (365d) | 31,536,000,000 |

TypeScript Support

import {parseDuration, DurationUnit, Duration} from '@alwatr/parse-duration';

// Type-safe unit parameter
function waitFor(time: Duration): Promise<void> {
  const ms = parseDuration(time);
  return new Promise((resolve) => setTimeout(resolve, ms));
}

// Usage
await waitFor('5s');

Sponsors

The following companies, organizations, and individuals support Nanolib ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.

Contributing

Contributions are welcome! Please read our contribution guidelines before submitting a pull request.