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

@benzn/to-ms

v3.0.9

Published

Converts a time string with units to milliseconds

Readme

to-ms - Convert Time Strings to Milliseconds as fast as posible

Overview

to-ms is a lightweight TypeScript utility that converts human-readable time strings (e.g., "5s", "2.6 h") into milliseconds.
It supports multiple time units, making it easy to work with time-based calculations.

Why use it ? : because its faster that ms by 40%. Tests?

Installation

You can install to-ms via npm or yarn:

npm install @benzn/to-ms

or

yarn add @benzn/to-ms

Usage

Import

import tms from "@benzn/to-ms";

Require

const tms = require("@benzn/to-ms")

Converting Time Strings to Milliseconds

console.log(tms("5s"));   // 5000 (5 seconds in ms)
console.log(tms("2m"));   // 120000 (2 minutes in ms)
console.log(tms("1h"));   // 3600000 (1 hour in ms)
console.log(tms("1d"));   // 86400000 (1 day in ms)
console.log(tms("1M"));   // 2629800000 (1 month in ms, avg 30.436875 days)
console.log(tms("1y"));   // 31557600000 (1 year in ms, avg 365.25 days)

Passing Numbers

If a number is passed, the function returns it as-is, but logs a warning:

console.log(tms(5000));   // 5000 (Warning: The input was a number, no need for converting)

[!NOTE] For now to-ms Does Not convert numbers back to human-readable time strings. for that use ms.
It will be included in future updates

Tests

To test it run npm test,or npx mocha

tms: 122ms, 246ms
ms : 227ms, 505ms
test1

tms: 122ms, 246ms
ms : 227ms, 505ms
test2

tms: 122ms, 246ms
ms : 227ms, 505ms
test3

Supported Time Units

| Unit | Description | Example | | :---: | :----------------------: | :-----: | | ms | Milliseconds | 500ms | | s | Seconds | 5s | | m | Minutes | 2m | | h | Hours | 1h | | d | Days | 1d | | w | Weeks | 1w | | M | Months (≈30.436875 days) | 1M | | y | Years (≈365.25 days) | 1y |

TypeScript Support

The function is fully typed for TypeScript. The input type ensures only valid time formats are allowed.

  • errors
tms("5x"); // ❌ TypeScript error - Invalid unit
  • exports
import tms, { msInput, msUnits } from "@benzn/to-ms"

tms(value as msInput)

Error Handling

The function throws errors in the following cases:

  • Invalid Format: If the input is not a recognized time format.
  • Incorrect Type: If the input is neither a string nor a number.
// manual
try {
    tms("invalid"); //=> throws Error
} catch (error) {
    console.error(error.message); // "Invalid time format, support:[ms,s,m,h,d,w,M,y]"
}

// automatic
tms("invalid", true); //=> logs Error

License

MIT