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

millisec

v0.2.0

Published

Prettify milliseconds with customizable format

Downloads

1,468

Readme

millisec

Build Status

Turn milliseconds into a human readable and customizable format.

Installation

npm install --save millisec

Usage

var millisec = require('millisec');
var ms = 93791334; // 1 day 2 hours 3 minutes 11.334 seconds

millisec(ms).format('DD - HH - MM - SS');
// => '1 day - 2 hours - 3 minutes - 11 seconds'

millisec(ms).format('hh : mm : ss');
// => '2 : 3 : 11'

Documentation

Require the module and call it with the millisecond you wish to format. It will return an object that contains the following methods.

format(output)

Output a human readable string representation of the milliseconds with the given format.

output is a required argument.

  • dd - raw days (e.g. 0, 1, 2, ...)

  • hh - raw hours with a maximum value 23. (e.g. 0, 1, 2, ..., 23)

  • mm - raw minutes with a maximum value 59. (e.g. 0, 1, 2, ..., 59)

  • ss - raw seconds with maximum value 59. (e.g. 0, 1, 2, ..., 59)

  • DD - days followed by a count noun (e.g. 0 days, 1 day, 2 days, ...)

  • HH - hours followed by a count noun. The maximum value is 23. (e.g. 0 hours, 1 hour, 2 hours, ..., 23 hours)

  • MM - minutes followed by a count noun. The maximum value is 59. (e.g. 0 minutes, 1 minute, 2 minutes, ..., 59 minutes)

  • SS - seconds followed by a count noun. The maximum value is 59. (e.g. 0 seconds, 1 second, 2 seconds, ..., 59 seconds)

  • hhh - the hours equivalent of the millisecond (e.g. 0, 1, 2, 24, ..., 48, ...)

  • mmm - the minutes equivalent of the millisecond (e.g. 0, 1, 2, ..., 100, ...)

  • sss - the seconds equivalent of the millisecond (e.g. 0, 1, 2, ..., 3500, ...)

  • HHH - the hours equivalent of the millisecond, followed by a count noun (e.g. 0 hours, 1 hour, 2 hours, ..., 24 hours, ..., 48 hours)

  • MMM - the minutes equivalent of the millisecond, followed by a count noun (e.g. 0 minutes, 1 minute, 2 minutes, ..., 100 minutes)

  • SSS - the seconds equivalent of the millisecond, followed by a count noun (e.g. 0 seconds, 1 second, 2 seconds, ..., 3500 seconds)

var millisec = require('millisec');
var ms = 93791334; // 1 day 2 hours 3 minutes 11.334 seconds

millisec(ms).format('HH MM SS');
// => '2 hours 3 minutes 11 seconds'
millisec(ms).format('DAY (dd) HOURS (hh) MINUTES (mm)');
// => 'DAY (1) HOURS (2) MINUTES (3)'
millisec(ms).format('MMM');
// => '1563 minutes'
millisec(ms).format('Seconds left: sss');
// => 'Seconds left: 93791'

getDays

Get the day component of the millisecond. The returned value is Number, not a String. Returns 0 if the millisecond is less than one day.

var millisec = require('millisec');
var ms = 93791334; // 1 day 2 hours 3 minutes 11.334 seconds

millisec(ms).getDays();
// => 1

getHours

Get the hour component of the millisecond. The returned value is Number, not a String. If the millisecond is less than one hour, returns 0.

var millisec = require('millisec');
var ms = 93791334; // 1 day 2 hours 3 minutes 11.334 seconds

millisec(ms).getHours();
// => 2

getMinutes

Get the minute component of the millisecond. The returned value is Number, not a String. If the millisecond is less than one minute, returns 0.

var millisec = require('millisec');
var ms = 93791334; // 1 day 2 hours 3 minutes 11.334 seconds

millisec(ms).getMinutes();
// => 3

getSeconds

Get the second component of the millisecond. The returned value is Number, not a String. The decimals are ignored.

var millisec = require('millisec');
var ms = 93791334; // 1 day 2 hours 3 minutes 11.334 seconds

millisec(ms).getSeconds();
// => 11

Contributing

Run npm test to run tests locally.

License

MIT