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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zyrohub/utilities

v1.0.10

Published

A collection of utility functions and classes.

Readme

ZyroHub - Utilities

Table of Contents

Getting Started

To install the utilities package, use one of the following package managers:

NPM Repository

# npm
npm install @zyrohub/utilities
# yarn
yarn add @zyrohub/utilities
# pnpm
pnpm add @zyrohub/utilities
# bun
bun add @zyrohub/utilities

Utilities

Terminal

A terminal service for beautifully formatted console outputs with timestamps, package names, and process IDs.

import { Terminal } from '@zyrohub/utilities';

// Standard logging methods with predefined colors
Terminal.success('BOOT', 'System started successfully');
// Output example: 27/11 10:00:00 | MY-APP | 8520 | [BOOT] System started successfully

Terminal.error('DB', ['Connection failed:', errorObject]);
Terminal.info('USER', 'User logged in');
Terminal.warn('MEM', 'High memory usage detected');

Custom Logging

You can use the log method to define a custom flag and its color using the Ansi utility.

import { Terminal, Ansi } from '@zyrohub/utilities';

// Terminal.log(flag, colorFunction, content)
Terminal.log('CRON', Ansi.magenta, 'Scheduled task executed.');
Terminal.log('DEBUG', Ansi.gray, ['Variable state:', { a: 1, b: 2 }]);

Ansi / Colors

A zero-dependency, type-safe ANSI formatter. It supports standard colors, bright variants, backgrounds, and text styles. It handles style nesting correctly and respects environment variables.

Basic Usage

import { Ansi } from '@zyrohub/utilities';

console.log(Ansi.red('This is red text'));
console.log(Ansi.bgBlue(Ansi.white('White text on blue background')));

Style Composition & Nesting

The Ansi utility intelligently handles nested styles, ensuring inner styles don't break the outer formatting.

// Complex composition
const message = Ansi.bold(`Error: ${Ansi.red('File not found')} in ${Ansi.underline('src/index.ts')}`);

console.log(message);

Available Methods

All methods are static and available directly from the Ansi class.

| Category | Methods | | :---------------- | :------------------------------------------------------------------------------------------------------------------- | | Colors | black, red, green, yellow, blue, magenta, cyan, white, gray | | Bright Colors | brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite | | Backgrounds | bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray | | Bright BGs | bgBrightRed, bgBrightGreen, bgBrightYellow, bgBrightBlue, bgBrightMagenta, bgBrightCyan, bgBrightWhite | | Styles | bold, dim, italic, underline, blink, reverse, strikethrough |

Environment Variables

The utility automatically detects if colors should be disabled based on the environment:

  • NO_COLOR: If present, all coloring is disabled.
  • FORCE_COLOR: Forces color output even in non-TTY environments.
  • TERM: Checks for dumb terminals.

Exposed Constants

For advanced use cases, you can access the raw ANSI maps and environment status directly.

  • ANSI_CODES: Map containing all raw opening ANSI codes.
  • ANSI_CLOSE_CODES: Map containing all raw closing ANSI codes.
  • isEnvColorsAllowed: Boolean indicating if color output is currently enabled.
import { ANSI_CODES, ANSI_CLOSE_CODES, isEnvColorsAllowed } from '@zyrohub/utilities';

if (isEnvColorsAllowed) {
	console.log(`${ANSI_CODES.red}Manual Red Text${ANSI_CODES.reset}`);
}

Time

A utility for time manipulation and formatting.

Duration Formatting

Formats milliseconds into readable strings, automatically scaling to seconds (s) or minutes (m).

import { Time } from '@zyrohub/utilities';

console.log(Time.duration(500)); // "500ms"
console.log(Time.duration(1500)); // "1.5s"
console.log(Time.duration(90000)); // "1.5m"

Sleep

Promise-based delay function to pause execution.

import { Time } from '@zyrohub/utilities';

await Time.sleep(1000); // Pauses execution for 1 second