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

unitime

v1.2.1

Published

Convert between time units using human-readable syntax. Similar to TimeUnit in Java.

Downloads

6

Readme

Unitime - Simplified time units

NPM Version Build Status Code Coverage License

Unitime is a lightweight JavaScript utility module which provides powerful, human-readable functions for converting various time units. The project was inspired by Java's TimeUnit by Doug Lea.

Human-readable, yet concise

const { h, ms } = require("unitime");

h`720`.days();  // evaluates to 7
ms`3`.nanos();  // evaluates to 3000000

Installation

npm install unitime

Description

Unitime provides lightweight methods for converting between different units of time with a human-readable syntax. The idea is reducing the mental load caused by interpreting complex time declarations like 24*60*60*1000 or 86400000 which both describe the number of milliseconds in a single day. Using this library you can simply write d(1), or d`1` if you prefer template literals.

Time formats that are currently supported are:

  • Nanoseconds (ns)
  • Microseconds (us)
  • Milliseconds (ms)
  • Seconds (s)
  • Minutes (min)
  • Hours (h)
  • Days (d)

You can specify the target format on initialization to make the code even more concise. This is especially useful when writing configuration files in JavaScript:

const { d, h } = require("unitime").to("ms")

const config = {
    duration: d`7`, // evaluates to 604800000
    interval: h`12` // evaluates to 43200000
}

The library is written entirely in Typescript.

Usage examples

Convert to a predefined time unit

You can predefine the target unit by using .to(unit) when initializing:

const { ns, s } = require("unitime").to("ms")

ns`100`; // 0.0001
s(1000); // 1000000

Convert to any time unit

You can also individually decide the target unit for each variable:

const { ns, s } = require("unitime")

ns`100`.millis(); // 0.0001
s(100).minutes(); // 1.6666666666666667

License

This work by Jonatan Hamberg is licensed under the MIT License.