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

@guigaib/lib

v0.3.0

Published

General purpose library

Downloads

155

Readme

@guigaib/lib

Table of Contents

Introduction

@guigaib/lib is a collection of utility TypeScript code designed to handle common tasks, including environment variables, debouncing, and error handling.

Installation

Install the library using your favorite package manager: npm install @guigaib/lib or yarn add @guigaib/lib

Usage

Import the relevant modules and use them directly within your TypeScript project. See the exports section in the package.json to better understand how modules are exported.

Components

MyEnv

MyEnv is a small Node.js utility for reading environment variables. It supports caching, default values, transformations, masking, and error handling, and can be used either with static methods or instance methods (each has its own cache).

Note This library treats empty strings as if they were unset environment variables. Keep that in mind if you rely on empty strings as valid values.

Features

  • Get or require environment variables.
  • Default values and warnings if a variable isn’t set.
  • Transformers (e.g., convert "true" to true, parse numbers, etc.).
  • Masking sensitive values in logs.
  • Per-instance or global (static) caches.
  • Treat empty strings as undefined.

Usage

1. Quick Start: require Example
import { MyEnv } from "@guigaib/lib/env";

// Forcing a variable to exist:
const myToken = MyEnv.require("TOKEN");
// If TOKEN is missing or empty, it throws an EnvError.
2. Providing a Default Value
const myPort = MyEnv.require("PORT", { defaultValue: 8080 });
// If PORT is unset or empty, returns 8080 instead of throwing.
3. Using a Transformer
const debugMode = MyEnv.require("DEBUG", {
  transformer: (v) => v === "true",
});
// If process.env.DEBUG === "true", returns true; if empty, throws because no fallback value was provided.
4. Masking Values in Logs
const secretVal = MyEnv.require("SECRET_KEY", {
  maskValue: true,
  defaultValue: "masked",
});
// If SECRET_KEY isn't set, logs: Using default value "****" for environment variable "SECRET_KEY"
5. Distinguishing Static vs. Instance Methods
const instance = new MyEnv();
instance.require("TOKEN"); // uses instance cache
MyEnv.require("TOKEN"); // uses static (global) cache
6. get vs. require
  • get(varName, options?): Returns a raw string or undefined if the variable is unset/empty. You can optionally skip the cache by passing { force: true }.

Debouncer

A convenient utility for rate-limiting or postponing function calls:

  • Configurable timeout in milliseconds
  • Callback for handling debounced executions and errors
  • Ideal for expensive or frequency-limited operations

Error Handling

Custom error framework with typed classes:

  • ConfigError, ValidationError, and EnvError for specific contexts
  • Maintain consistent error messages
  • Optionally enforce error codes and extended validation

Usage Examples

Debouncer

import { Debouncer } from "@guigaib/lib";

const debouncer = Debouncer.getInstance({
  timeoutMs: 3000,
  onTimeout: () => {
    console.log("Operation completed");
  },
});
debouncer.delay();

Error Handling

import { ConfigError } from "@guigaib/lib";

try {
  throw new ConfigError("Something went wrong");
} catch (error) {
  console.error(error);
}

License

This project is available under the MIT License.