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 🙏

© 2024 – Pkg Stats / Ryan Hefner

time-convert

v0.0.2

Published

convert miliseconds to any format

Downloads

678

Readme

npm version Open Source Love

time-convert

🕓 Convert durations to other time unit(s).

Usage

npm install time-convert

const { ms, s, m, h, d } = require('time-convert')
/* verbose equivalent */
const { milliseconds, seconds, minutes, hours, days } = require('time-convert') 

/* convert milliseconds to hours, minutes and seconds */
ms.to(h,m,s)(12345678) // [4, 2, 47]

/* convert milliseconds to minutes and seconds */
ms.to(m,s)(12345678) // [242, 47]

/* get milliseconds from 12 hours, 23 minutes, 45 seconds*/
ms.from(h,m,s)(12, 23, 45) // 44625000

/* get hours from 123 minutes and 12 seconds */
h.from(m,s)(123, 12) // 2.0533333333333332

/* ⚠️ precision is lost */
ms.to(s)(1234) // [1] , not [1.234]

The only restriction is that units must be in descending order of magnitude – avoid calling ms.to(m, h, s).

Philosophy

time-convert performs the convertion with the units you specify, but is agnostic as to what you want to do with the converted units.

It is encouraged that you create your own wrapper functions for you specific use-case. For instance, to convert milliseconds to a hh:mm:ss format, you can write the following:

const msToHms = ms => (
    ms.to(h,m,s)(ms)
        .map(n => n < 10? '0'+n : n.toString()) // zero-pad
        .join(':')
)
msToHms(12345678) // '04:02:47'

Contributing

Contributions welcome.

Possible additions:

  • Generalize to units other than time, such as distance, volume, or even currency using a 3rd party exchange-rate API. This addition requires making sure that precision is not lost in operations.

Test

npm run test