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

@mmutils/time

v0.0.1

Published

Common reusable, typed, JavasScript time related utility functions built with TypeScript.

Readme

@mmutils/time

Common reusable, typed, JavasScript time related utility functions built with TypeScript.

Currently supports high resolution time like nanoseconds all the way up to hours. Makes they visual display of high resolution time easier and tidier.

Installation

Install the package

npm install @mmutils/time
# or
yarn add @mmutils/time

Load as module (ESM) or CommonJS

import {
  TimeUnitInNs,
  shiftTimeUnit,
  timeUnitFromNs,
  formatHighResTime,
} from '@mmutils/time';

or

const {
  TimeUnitInNs,
  shiftTimeUnit,
  timeUnitFromNs,
  formatHighResTime,
} = require('@mmutils/time');

Changelog

v0.0.1

Initial release.

Quick reference guide / API

const timeUnits

Descending order time units list.

const timeUnits: readonly[('h', 'm', 's', 'ms', 'µs', 'ns')];

type TimeUnit

type TimeUnit = 'h' | 'm' | 's' | 'ms' | 'µs' | 'ns';

const TimeUnitInNs

Enum containing the minimum value in nanoseconds for each unit of time. Note the range [0,1) is not covered by this Enum.

TimeUnitInNs: {
    readonly h: 3600000000000;
    readonly m: 60000000000;
    readonly s: 1000000000;
    readonly ms: 1000000;
    readonly µs: 1000;
    readonly ns: 1;
    readonly __proto__: null;
}

function shiftTimeUnit

Shift given time unit N positions up or down.

const shiftTimeUnit: (fromUnit: TimeUnit, shiftPositions: number) => TimeUnit;

examples:

shiftTimeUnit('s', -10); // 'h'
shiftTimeUnit('s', -2); // 'h'
shiftTimeUnit('s', -1); // 'm'
shiftTimeUnit('s', 0); // 's'
shiftTimeUnit('s', 1); // 'ms'
shiftTimeUnit('s', 2); // 'µs'
shiftTimeUnit('s', 3); // 'ns'
shiftTimeUnit('s', 10); // 'ns'

function timeUnitFromNs

Get the highest full time unit available for the current nanoseconds input. Works with positive and negative values.

const timeUnitFromNs: (timeNs: number) => TimeUnit;

examples:

timeUnitsFromNs(-999); // 'ns'
timeUnitsFromNs(999); // 'ns'
timeUnitsFromNs(1000); // 'µs'
timeUnitsFromNs(1000000); // 'ms'
timeUnitsFromNs(-1000000); // 'ms'

function formatHighResTime

const formatHighResTime: (
  time: number,
  capTo?: TimeUnit | number,
  timeUnit?: TimeUnit
) => string;

Format time value from nanoseconds, microseconds, milliseconds, seconds, minutes or hours to a more readable string. Provide a duration value and optionally specify in what units the value is expressed. Default is nanoseconds. Fractions will leak down to lower order units. You can cap the output to a specific unit type or to a unit that is N positions lower than the current highest whole unit.

examples:

formatHighResTime(0, 'ms'); // '0ms'
formatHighResTime(0, undefined, 's'); // '0s'
formatHighResTime(0.5, 'ns'); // '0ns'
formatHighResTime(0.5, undefined, 'ms'); // '500µs'
formatHighResTime(0.5, 'ms', 'ms'); // '1ms'
formatHighResTime(1 * 60 * 60 * 1_000_000_000); // '1h' default timeUnit: 'ns'
formatHighResTime(2 * 60 * 1_000_000_000); // '2m'
formatHighResTime(3 * 1_000_000_000); // '3s'
formatHighResTime(4 * 1_000_000); // '4ms'
formatHighResTime(5 * 1_000); // '5µs'
formatHighResTime(6); // '6ns'
formatHighResTime(
  1 * 60 * 60 * 1_000_000_000 +
    2 * 60 * 1_000_000_000 +
    3 * 1_000_000_000 +
    4 * 1_000_000 +
    5 * 1_000 +
    6
); // '1h 2m 3s 4ms 5µs 6ns'
formatHighResTime(1 * 1_000_000_000 + 2 * 1_000_000 + 3 * 1_000 + 4, 'µs'); // '1s 2ms 3µs'
formatHighResTime(1 * 1_000_000_000 + 2 * 1_000_000 + 3 * 1_000 + 4, 2); // '1s 2ms 3µs'
formatHighResTime(1 * 1_000_000 + 2 * 1_000 + 3); // '1ms 2µs 3ns'
formatHighResTime(1 * 1_000_000 + 0 * 1_000 + 3); // '1ms 3ns'
formatHighResTime(1 * 1_000, undefined, 'ms'); // '1s'
formatHighResTime(1 * 1_000 + 1, 'h'); // '0h'
formatHighResTime(1 * 1_000 + 1, 'µs'); // '1µs'
formatHighResTime(1 * 1_000 + 1, 'ns'); // '1µs 1ns'
formatHighResTime(-1_100_100); // '-1ms 100µs 100ns'

License

This project is licensed under the MIT License.