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

typed-time-log

v1.0.0

Published

A small utility for logging the execution time of functions making console.time type-safe.

Downloads

3

Readme

Typed Console Time

A lightweight, modern, and type-safe utility for timing operations in TypeScript and JavaScript. This package provides a cleaner and more robust alternative to the standard console.time and console.timeEnd, especially when dealing with asynchronous code and modern resource management patterns.

Key Features

  • Type-Safe: Written in TypeScript for a great developer experience.
  • Flexible: Works with both synchronous and asynchronous functions.
  • Modern: Supports the experimental using keyword for automatic, error-proof cleanup.
  • Zero Dependencies: A tiny, focused utility that adds minimal overhead.

Installation

You can use your favorite package manager to install it:

npm install typed-console-time

Usage

There are three primary ways to use this utility, depending on your needs.

1. Manual Start and End

If you need full control over the timer's lifecycle, you can manage it manually. This is the most universally compatible approach.

import { startTimeLog } from "typed-console-time";

// A simple sleep function to simulate async work
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

async function fetchUserData() {
  const timer = startTimeLog("Fetch user data"); // Timer starts

  await sleep(500); // Simulate a network request

  timer.end(); // Manually stop the timer
}

fetchUserData();
// Expected output:
// Fetch user data: 501.456ms

2. Wrapping a Function Call

For timing a single function (synchronous or asynchronous), withTimeLog is a convenient wrapper that handles starting and stopping the timer for you. It returns the result of the wrapped function.

import { withTimeLog } from "typed-console-time";

// A synchronous function that takes some time
const heavySyncCalculation = () => {
  let sum = 0;
  for (let i = 0; i < 1e8; i++) {
    sum += i;
  }
  return sum;
};

// An async function that simulates a delay
const fetchFromApi = async () => {
  await new Promise((resolve) => setTimeout(resolve, 300));
  return { id: 1, name: "John Doe" };
};

async function main() {
  // Time a synchronous function
  const result = await withTimeLog("Sync calculation", () =>
    heavySyncCalculation()
  );
  console.log(`Calculation result: ${result}`);

  // Time an asynchronous function
  const user = await withTimeLog("API fetch", () => fetchFromApi());
  console.log(`Fetched user: ${user.name}`);
}

main();
// Expected output:
// Sync calculation: 150.789ms
// Calculation result: 4999999950000000
// API fetch: 302.111ms
// Fetched user: John Doe

3. Automatic Cleanup with using (Experimental)

This is the cleanest way to time a block of code, leveraging the new Explicit Resource Management feature. The timer is automatically stopped when the block is exited, even if an error occurs.

Warning: The using keyword is an experimental feature. As of late 2025, it is not supported in Safari and Node.js. It requires setting your TypeScript target to ES2022 or newer.

You can learn more about its status and usage on MDN Web Docs.

import { startTimeLog } from "typed-console-time";

function processData() {
  // The timer starts here
  using _timer = startTimeLog("Data processing operation");

  // Simulate some time-consuming work
  for (let i = 0; i < 1e7; i++) {
    // ... crunching numbers ...
  }

  console.log("Finished processing.");
} // The timer automatically ends here and logs the duration

processData();
// Expected output:
// Finished processing.
// Data processing operation: 25.123ms