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

@darco2903/secondthought

v1.3.1

Published

SecondThought is a TypeScript library that provides typed time units to help prevent errors when working with time-related values. It allows you to use time units such as seconds, minutes, hours, etc., with type safety, ensuring that you don't accidentall

Readme

SecondThought

Description

SecondThought is a TypeScript library that provides typed time units to help prevent errors when working with time-related values. It allows you to use time units such as seconds, minutes, hours, etc., with type safety, ensuring that you don't accidentally mix different time units or make mistakes in calculations.

Features

  • Typed time units to prevent unit-related errors (Nanosecond, Microsecond, Millisecond, Second, Minute, Hour, Day, Week)
  • Safe conversions between time units
  • Methods for common time operations (addition, subtraction, etc.)
  • Comparison methods for time values
  • Support for current time, elapsed time calculations and conversion from/to Date objects

Installation

npm install @darco2903/secondthought

Usage

Common Operations

import { Second, Minute, Hour } from "@darco2903/secondthought";

const time1 = new Second(30); // 30 seconds
const time2 = new Minute(2); // 2 minutes
const time3 = new Hour(1); // 1 hour

const totalTime = time1.add(time2).add(time3).toMillisecond();
console.log(`Total time in milliseconds: ${totalTime.toStringWithUnit()}`); // Total time in milliseconds: 3750000ms

Mutation

Operations that mutate the instance will change the value of the instance and return the same instance. To find out if a method mutates the instance, you can check its documentation.

import { Minute, Second } from "@darco2903/secondthought";

const sec = new Second(90);
const result = sec.sub(new Minute(1)); // sub is a mutating operation
console.log(sec.time, result.time, sec === result); // 30 30 true

To avoid mutating the original instance, you can use the clone method to create a copy of the instance before performing an operation that mutates it.

import { Minute, Second } from "@darco2903/secondthought";

const sec = new Second(90);
const result = sec.clone().sub(new Minute(1));
console.log(sec.time, result.time, sec === result); // 90 30 false

Current Time and Elapsed Time

import { Millisecond } from "@darco2903/secondthought";

const start = Millisecond.now();

// time passed since start
const elapsed = start.diff(Millisecond.now());
const elapsedSeconds = elapsed.toSecond(); // Convert to seconds

Functions with Typed Time Units

import { Millisecond, Second, Time } from "@darco2903/secondthought";

function waitMs(ms: Millisecond) {
    return new Promise((resolve) => setTimeout(resolve, ms.time));
}

await waitMs(new Millisecond(1000)); // correct
await waitMs(new Second(1)); // Error: Second is not assignable to Millisecond
await waitMs(new Second(1).toMillisecond()); // correct

To allow all time units to be used, we can define a more general function that accepts any Time implementation:

import { type Time, Second, Millisecond } from "@darco2903/secondthought";

function wait(time: Time) {
    return new Promise((resolve) => setTimeout(resolve, time.toMillisecond().time));
}

await wait(new Millisecond(1000)); // correct
await wait(new Second(1)); // also correct

Other Methods

This is a non-exhaustive list of other methods available in the library.

import { Millisecond, Minute, Second } from "@darco2903/secondthought";

const ms = new Millisecond(200);
ms.getUnit(); // "ms"
const sec = new Second(90);
sec.getUnit(); // "s"

new Second(3.22).ceil().time; // 4
new Second(3.77).floor().time; // 3
new Second(3.1).round().time; // 3
new Second(3.5).round().time; // 4

new Second(100).clamp(new Second(10), new Minute(1)).time; // 60

new Second(-3).abs().time; // 3
new Second(3).negate().time; // -3

sec.toString(); // "90"
sec.toStringWithUnit(); // "90s"

// comparison methods
const sec = new Second(1);
const min = new Minute(1);
sec.equals(min); // false
sec.notEquals(min); // true
sec.greaterThan(min); // false
sec.lessThan(min); // true
sec.greaterThanOrEqual(min); // false
sec.lessThanOrEqual(min); // true