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

@fabricio-191/ms

v1.5.1

Published

Tiny millisecond conversion utility

Downloads

29

Readme

Discord Tests

@fabricio-191/ms

A powerful tool for parsing times formats and durations into its respective value in milliseconds. And also for converting milliseconds into an human readable format.

Differences with ms

+ Can parse multiple languages
+ Can parse multiple units
+ Formatting has more options
+ Does not round while formatting
- When formatting, it's way slower than ms

Parse

If nothing can be parsed, it returns null

const ms = require('@fabricio-191/ms');

ms('2 hours, 5.5 minutes and .3s'); // 7530300
ms('1 week 2 days'); // 777600000
ms('2 days 1 hour'); // 176400000
ms('1m10secs');      // 70000
ms('5s50ms');        // 5050
ms('1y');            // 31557600000
ms('1d');            // 86400000
ms('10h');           // 36000000
ms('2.5 hrs');       // 9000000
ms('.5m');           // 30000
ms('100');           // 100
ms('0 seconds');     // 0
ms('-.5 mins');      // -30000
ms('- 2m 30s');      // -150000
ms('-3 days');       // -259200000

ms.clock('2:09:00');       // 7740000  (hh:mm:ss)
ms.clock('3:10');          // 11400000 (hh:mm)
ms.clock('3:10', true);    // 190000   (mm:ss)

// english is the default language
ms('1 day', 'es');   // null (wrong language)
ms('1 dia', 'es');   // 86400000
ms('1 日', 'ja');    // 86400000

ms('12 seconds', ['en', 'es']);     // 12000   (english)
ms('-3 minutos', ['en', 'es']);     // -180000 (spanish)
ms('-3 分', ['en', 'es']);          // null
ms('2 minutes 15 seconds', 'all');  // 135000
ms('2 minutos 15 segundos', 'all'); // 135000
ms('2 分 15 秒', 'all');            // 135000

Format

const num = ms('16 days 8 hours 20 mins 40 secs');

ms(num); // default length is 3          // 16d 8h 20m
ms(num, { length: 2 });                  // 16d 8h
ms(num, { length: 8 });                  // 16d 8h 20m 40s

ms(num, { long: true });                 // 16 days 8 hours 20 minutes
ms(num, { long: true, language: 'es' }); // 16 dias 8 horas 20 minutos
ms(num, { language: 'ja' });             // 16日 8時間 20分

Formats

  • Y: year
  • Mo: month
  • W: week
  • D: day
  • H: hour
  • M: minute
  • S: second
  • Ms: milisecond
ms(num);                   // 16d 8h 20m
ms(num, { format: 'HS' }); // 392h 1240s

ms(4100940000, { format: 'WDHM', length: 2 }); // 6w 5d
ms(4100940000, { format: 'WDHM', length: 4 }); // 6w 5d 11h 9m

ms(10, { format: 'HS' }); // 0s (too small)

The default format is YMoDHMSMs (without weeks)

Supported languages

'en' => 'English'
'es' => 'Spanish'
'ja' => 'Japanese'

You can add a language dynamically by using the addLanguage method. here is the documentation.

const ms = require('@fabricio-191/ms'), start = ms('1970 years 1 month');

setInterval(() => {
  process.stdout.clearLine(0);
  process.stdout.cursorTo(0);
  process.stdout.write(ms(Date.now() + start, { length: 8 }));
  process.stdout.cursorTo(31);
}, 1);