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

seconds-formater

v2.0.3

Published

Representing seconds in pretty time format

Downloads

585

Readme

Seconds Formatter

Convert seconds into a formatted string from days to months to years.

Now supports TypeScript

Install

$ npm i seconds-formater

// OR
$ pnpm add seconds-formater

// OR
$ yarn add seconds-formater

Usage

Import into the script

var sf = require('seconds-formater');

// OR
import sf from 'seconds-formater';

Default format is: HH:MM:SS, change it if you want different output

sf.convert(7).format(); // 00:00:07
sf.convert(451).format(); // 00:07:31
sf.convert(1518).format(); // 0:25:18
sf.convert(9518).format(); // 02:38:38
sf.convert(119518).format(); // 33:11:58
sf.convert(3159318).format(); // 877:35:18
sf.convert(73159318).format(); // 20322:01:58

Presentation format is changed after this call for every convert that follows

// We change format
sf.change('-MM:SS');
sf.convert(1143).format(); // -19:03
sf.convert(8734).format(); // -145:34
sf.convert(111).format(); // -01:51
sf.convert(65423).format(); // -1090:23

// Back to default format
sf.reset();
sf.convert(783).format(); // 00:13:03

Formatted output set for every call.

// 7 seconds in different formats
sf.convert(7).format('S'); // 7
sf.convert(7).format('SS'); // 07
sf.convert(7).format('M:SS'); // 0:07
sf.convert(7).format('MM:SS'); // 00:07
sf.convert(7).format('-MM:SS'); // -00:07

// Representing 32 seconds in different formats
sf.convert(32).format('S'); // 32
sf.convert(32).format('SS'); // 32
sf.convert(32).format('M:SS'); // 0:32
sf.convert(32).format('-MM:SS'); // -00:32
sf.convert(-32).format('MM:SS'); // -00:32

// Representing 451 seconds in different formats
sf.convert(451).format(); // 00:07:31
sf.convert(451).format('S'); // 451
sf.convert(451).format('SS'); // 451
sf.convert(451).format('-M:SS'); // -7:31
sf.convert(-451).format('MM:SS'); // -07:31

// Representing 1518 seconds in different formats
sf.convert(1518).format('M:SS'); // 25:18
sf.convert(1518).format('MM:SS'); // 25:18
sf.convert(-1518).format('H:MM:SS'); // -0:25:18
sf.convert(1518).format('HH:MM:SS'); // 00:25:18

// Representing 9518 seconds in different formats
sf.convert(9518).format(); // 02:38:38
sf.convert(9518).format('M:S'); // 158:38
sf.convert(9518).format('M:SS'); // 158:38
sf.convert(9518).format('MM:SS'); // 158:38
sf.convert(9518).format('-H:MM:SS'); // -2:38:38
sf.convert(-9518).format('H:MM:SS'); // -2:38:38
sf.convert(9518).format('HH:MM:SS'); // 02:38:38
sf.convert(9518).format('DD:HH:MM:SS'); // 00:02:38:38

// Representing 119518 seconds in different formats
sf.convert(119518).format('S'); // 119518
sf.convert(119518).format('M:S'); // 1991:58
sf.convert(119518).format('-M:SS'); // -1991:58
sf.convert(119518).format('MM:SS'); // 1991:58
sf.convert(-119518).format('H:MM:SS'); // -33:11:58
sf.convert(119518).format(); // 33:11:58
sf.convert(119518).format('DD:HH:MM:SS'); // 01:09:11:58
sf.convert(119518).format('D:HH:MM:SS'); // 1:09:11:58

// It can also be combined with the text
sf.convert(119518).format('D day HH hours M min S s'); // 1 day 09 hours 11 min 58 s
sf.convert(119518).format('DDday Hhours Mmin Ss'); // 01day 9hours 11min 58s
sf.convert(119518).format('Dday Hhours Mmin Ss'); // 1day 9hours 11min 58s
sf.convert(119518).format('H hours M min S sec'); // 33 hours 11 min 58 sec
sf.convert(119518).format('M min S sec'); // 1991 min 58 sec
sf.convert(119518).format('S sec'); // 119518 sec

// Representing 73159318, 3159318 seconds in different formats
sf.convert(3159318).format('-N:DD:HH:MM:SS'); // -1:06:13:35:18
sf.convert(3159318).format('N month D days HH hours M min S s'); // 1 month 6 days 13 hours 35 min 18 s

sf.convert(73159318).format('YY:NN:DD:HH:MM:SS'); // 02:04:06:18:01:58
sf.convert(73159318).format('Y years N month D days HH hours M min S s'); // 2 years 4 month 6 days 18 hours 1 min 58 s

License

MIT