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

duratiform

v2.0.0

Published

Utility to separate into parts and to format time duration in milliseconds

Downloads

14

Readme

duratiform

Utility to separate into parts and to format time duration in milliseconds.

duratiform.divide(123456789000, 4);   // { day: 1428, hour: 21, minute: 33, second: 9 }
duratiform.format(456789, '(h:h:)(m:mm:)(s:ss)');   // 07:36

See additional examples below.

NPM version Build Status

Installation

Node

npm install duratiform

Bower

bower install duratiform

AMD, <script>

Use dist/duratiform.js or dist/duratiform.min.js (minified version).

Usage

Node

var duratiform = require('duratiform');

AMD

define(['path/to/dist/duratiform.js'], function(duratiform) {
    ...
});

Bower, <script>

<!-- Use bower_components/duratiform/dist/duratiform.js if the library was installed by Bower -->
<script type="text/javascript" src="path/to/dist/duratiform.js"></script>
<script type="text/javascript">
    // duratiform is available via duratiform field of window object
    ...
</script>

Examples

var nDuration = 123456789000;
console.log('5 duration parts: ', duratiform.divide(nDuration, 5));   // { week: 204, day: 0, hour: 21, minute: 33, second: 9 }
console.log(nDuration, ' - ', duratiform.format(nDuration, 'w [weeks] d [days] h [hours] m [minutes] s [seconds]'));   // 204 weeks 0 days 21 hours 33 minutes 9 seconds
console.log('4 duration parts: ', duratiform.divide(nDuration, 4));   // { day: 1428, hour: 21, minute: 33, second: 9 }
console.log(nDuration, ' - ', duratiform.format(nDuration, 'd [days] h [hours] m [minutes] s [seconds]'));   // 1428 days 21 hours 33 minutes 9 seconds

console.log('120184000, 4 parts - ', duratiform.divide(120184000, 4));   // { day: 1, hour: 9, minute: 23, second: 4 }
console.log('120184000, 4 parts and strings - ', duratiform.divide(120184000, 4, true));   // { day: 1, day2: "01", hour: 9, hour2: "09", minute: 23, minute2: "23", second: 4, second2: "04" }
console.log('120184000, 3 parts - ', duratiform.divide(120184000, 3));   // { hour: 33, minute: 23, second: 4 }

console.log('4567890 - ', duratiform.format(4567890, '(h:h:)(m:mm:)(s:ss)'));   // 1:16:07
console.log('456789 - ', duratiform.format(456789, '(h:h:)(m:mm:)(s:ss)'));   // 07:36
console.log('456789 - ', duratiform.format(456789, '(h:h:(m:mm:)(s:ss))'));   // empty string

console.log('4567890 - ', duratiform.format(4567890, 'Duration:(h: h [hr](m: mm [min](s: ss [sec])))(!h: (m:m [min](s: ss [sec]))(!m:s [sec]))'));   // Duration: 1 hr 16 min 07 sec
console.log('456789 - ', duratiform.format(456789, 'Duration:(h: h [hr](m: mm [min](s: ss [sec])))(!h: (m:m [min](s: ss [sec]))(!m:s [sec]))'));   // Duration: 7 min 36 sec
console.log('6789 - ', duratiform.format(6789, 'Duration:(h: h [hr](m: mm [min](s: ss [sec])))(!h: (m:m [min](s: ss [sec]))(!m:s [sec]))'));   // Duration: 6 sec

See test/duratiform.js for additional examples.

API

divide(nDuration: number, [nPartQty: number], [bAddStrings: boolean]): object

Separate time duration into parts.

format(nDuration: number, [sFormat: string]): string

Convert time duration into string.

See docs for details.

License

MIT