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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ms2text

v1.0.1

Published

Convert time in milliseconds to a human-readable string.

Downloads

28

Readme

ms2text

Convert time in milliseconds to a human-readable string. An UMD-module with fully typed API.

Installation

npm:

npm i ms2text

browsers / static website:

<!-- In HTML <head> -->
<script src="https://unpkg.com/ms2text" crossorigin="anonymous"></script>

Usage

node.js:

const { ms2text } = require('ms2text');
ms2text(1234567); // 20 minutes and 35 seconds

browsers / static website:

ms2text(1234567); // 20 minutes and 35 seconds

Languages You can select output language of defined languages (see Custom languages):

node.js:

const { ms2text } = require('ms2text');
ms2text(1234567, 'ru'); // 20 минут и 35 секунд

browsers / static website:

ms2text(1234567, 'ru'); // 20 минут и 35 секунд

UNIX Timestamp range node.js:

const { ms2text } = require('ms2text');
ms2text(1767123193174, 1767124427741); // 20 minutes and 35 seconds

/* You can also specify output language:
 * ms2text(1767123193174, 1767124427741, 'ru'); // 20 минут и 35 секунд
 */

browsers / static website:

ms2text(1767123193174, 1767124427741); // 20 minutes and 35 seconds

/* You can also specify output language:
 * ms2text(1767123193174, 1767124427741, 'ru'); // 20 минут и 35 секунд
 */

Adjust calculations You can specify the number of days in a month (30 by default) and the number of days in a year (365 by default):

node.js:

const { ms2text } = require('ms2text');
ms2text(
    1234567, 
    30, // Days in a month
    365 // Days in a year
); // '20 minutes and 35 seconds'

/* You can also specify output language:
 * ms2text(1234567, 30, 365, 'ru'); // 20 минут и 35 секунд
 */

browsers / static website:

ms2text(
    1234567, 
    30, // Days in a month
    365 // Days in a year
); // '20 minutes and 35 seconds'

/* You can also specify output language:
 * ms2text(1234567, 30, 365, 'ru'); // 20 минут и 35 секунд
 */

q: Why can't I specify these numbers in UNIX Timestamp range? a: It looks at the actual number of days in each month and the number of days in each year, so you don't need to adjust the calculations.

Custom languages

Currently (In v1.0.1), by default, there are already 'en' (English, default) and 'ru' (Russian). But you can also define other languages or redefine the built-ins:

const exampleLang = {
    words: {
        years: {
            11: 'years',
            1: 'year',
            /*
             * It looks at the number as a string and checks if it ends with a number/string that matches the key. If it does, then the word is the value of that key.
             * If there is no such key, it uses the word in "any".
             * 
             * Top = more priority
             * Bottom = less priority
             */

            any: 'years', // Should be plural
            oneWordPrefix: 'a ' /* Optional. "1 year" -> "a year" (or you can leave it empty to make it "1 year" -> "year").
                                 * Note: The first character of output will be uppercased.
                                 * This will be used if `rules.useOneWordIfOne` and/or `rules.useOneWordAtStartIfOne`.
                                 */
        },
        months: {
            11: 'months',
            1: 'month',
            any: 'months',
            oneWordPrefix: 'a '
        },
        weeks: {
            11: 'weeks',
            1: 'week',
            any: 'weeks',
            oneWordPrefix: 'a '
        },
        days: {
            11: 'days',
            1: 'day',
            any: 'days',
            oneWordPrefix: 'a '
        },
        hours: {
            11: 'hours',
            1: 'hour',
            any: 'hours',
            oneWordPrefix: 'an '
        },
        minutes: {
            11: 'minutes',
            1: 'minute',
            any: 'minutes',
            oneWordPrefix: 'a '
        },
        seconds: {
            11: 'seconds',
            1: 'second',
            any: 'seconds',
            oneWordPrefix: 'a '
        }
    },
    rules: {
        comma: ', ', // Separator ("A year, 4 days (...)"). It will use `rules.and` if this is not specified.
        and: ' and ', // Last separator ("(...) 20 minutes and 35 seconds"). It will use `rules.comma` if this is not specified.
        // It will not add any separator if both `rules.comma` and `rules.and` are not specified.

        spaces: true, // Add space between number and word ("5 days").

        useOneWordIfOne: false, // Use one word if the number is 1.
        useOneWordAtStartIfOne: true, // Use one word if the number is 1 and this is the first word in output string.
        // It will add a prefix if specified in `words{}`.

        wordThenNumber: false, // Reverse "5 days" to "days 5".

        reverse: false, /* Reverse from Years>Months>...>Minutes>Seconds to Seconds>Minutes>...>Months>Years.
                         * ("A year, 4 days, 20 minutes and 35 seconds" -> "35 seconds, 20 minutes, 4 days and a year")
                         */
    }
}

node.js:

const { getLanguage, setLanguage } = require('ms2text');
setLanguage(
    'example', // Language name/code
    exampleLang
); // Returns language object (`exampleLang`).

getLanguage('example'); // Returns language object or undefined if the language has not been defined.

browsers / static website:

ms2text.setLanguage(
    'example', // Language name/code
    exampleLang
); // Returns language object (`exampleLang`).

ms2text.getLanguage('example'); // Returns language object or undefined if the language has not been defined.

.min.js

For .min.js, I use UglifyJS by Mihai Bazon.

npm i uglify-js
uglifyjs index.js -c -m "reserved=['ms2text','getLanguage','setLanguage']" -o index.min.js