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

toolkitify

v0.0.26

Published

Toolkit to make your life easier

Readme

Modules

Toolkitify provides different modules depending on the required use.

| Module | Description | Status | | ------------------------------------- | -------------------------------------------------------------------------- | -------------- | | Cache (cache) | Advanced caching system for functions | 🟢 Active | | Client Only (client-only) | Client-side only code directive | 🟢 Active | | Feature Flags (feature-flags) | Advanced feature flags system | 🟢 Active | | Logger (logger) | Advanced logging system | 🟢 Active | | Optimistic UI (optimistic-ui) | Optimistic UI System | 🟢 Active | | Rate Limit (rate-limit) | Advanced Rate Limit System | 🟢 Active | | Server Only (server-only) | Server-side only code directive | 🟢 Active |

Modules Usage Examples

import { Cache, cacheFunction, GlobalCache } from "toolkitify/cache";

// Create a cache instance.
const cache = new Cache({ ttl: "30s", maxUses: 3, storage: "memory", logs: "usage" });

// Set a value.
cache.set("myKey", "Hello World!");

// Get a value
console.log(cache.get("myKey")); // "Hello World!".

// Reset a specific key.
cache.reset("myKey");

// Get all cache items.
console.log(cache.getAll());

// Using the singleton GlobalCache.
GlobalCache.set("singletonKey", 123);
console.log(GlobalCache.get("singletonKey")); // 123.

// Caching a function.

function expensiveCalculation(x: number) {
  console.log("Calculating...");
  return x * 2;
};

// Auto-cache result for 30 seconds.
const cachedCalc = cacheFunction(expensiveCalculation, { ttl: "30s" });

console.log(cachedCalc(5)); // "Calculating..." and returns 10.
console.log(cachedCalc(5)); // Returns 10 without recalculating.
import { useOptimistic } from "toolkitify/optimistic-ui";

// With an asynchronous function.

let value = 0;

await useOptimistic.promise(
    async () => {
        await new Promise((r) => setTimeout(r, 50));
        value += 2;
        return value;
    },
    {
        optimisticUpdate: () => {
            value += 1;
        },
        rollback: () => {
            value = 0;
        },
        onSuccess: (result) => {
            value = result;
        }
    }
);

// With a synchronous function.

let value = 0;

useOptimistic.sync(
    () => {
        value += 2;
        return value;
    },
    {
        optimisticUpdate: () => {
            value += 1;
        },
        rollback: () => {
            value = 0;
        },
        onSuccess: (result) => {
            value = result;
        }
    }
);
import "toolkitify/client-only";

// Run code only on the client/browser.
console.log("This code runs only in the browser, not in Node/SSR");

// Wrap a block.
document.body.style.backgroundColor = "red";
import { flags, FeatureFlags } "toolkitify/feature-flags";

// Load some static and dynamic flags.
flags.load({
  NEW_UI: true,                                  // static flag.
  BETA_FEATURE: false,                           // static disabled.
  USER_SPECIFIC_FEATURE: (ctx: { userId: number; }) => ctx.userId === 42 // dynamic.
});

// Access flags statically.
console.log(flags.isEnabled("NEW_UI"));         // true.
console.log(flags.isEnabled("BETA_FEATURE"));   // false.

// Access dynamic flag with context.
console.log(flags.isEnabled("USER_SPECIFIC_FEATURE", { userId: 42 })); // true.
console.log(flags.isEnabled("USER_SPECIFIC_FEATURE", { userId: 7 }));  // false.

// Update flags dynamically.
flags.set("BETA_FEATURE", true);
console.log(flags.isEnabled("BETA_FEATURE"));   // true.

// Get raw value (boolean or function).
const raw = flags.get("USER_SPECIFIC_FEATURE");
console.log(typeof raw); // function.

// Create a typed instance for full TS autocomplete.
type MyFlags = {
  NEW_UI: boolean;
  BETA_FEATURE: boolean;
  USER_SPECIFIC_FEATURE: (ctx: { userId: number; }) => boolean;
};

const typedFlags = new FeatureFlags<MyFlags, { userId: number; }>();
typedFlags.load({
  NEW_UI: true,
  BETA_FEATURE: false,
  USER_SPECIFIC_FEATURE: ctx => ctx.userId % 2 === 0
});

console.log(typedFlags.isEnabled("USER_SPECIFIC_FEATURE", { userId: 2 })); // true.
console.log(typedFlags.isEnabled("USER_SPECIFIC_FEATURE", { userId: 3 })); // false.
import { Logger } from "toolkitify/logger";

const logger = new Logger({
  level: "DEBUG",    // Minimum log level.
  frequency: 1,      // Default log every 1 message.
  maxUses: Infinity  // Default unlimited uses.
});

// Normal logs.
logger.debug("Debug message");          // Will be shown.
logger.info("Info message");            // Will be shown.

// Logs with frequency: only log every 3 calls.
for (let i = 1; i <= 6; i++) {
  logger.info("Freq message", { frequency: 3 });
  // Will only be shown on iterations 3 and 6.
}

// Logs with color.
logger.warn("Warning in red", { color: "red" });      // Will be shown in red.
logger.info("Info in green", { color: "green" });    // Will be shown in green.

// Logs with global maxUses.
const limitedLogger = new Logger({ maxUses: 2 });

limitedLogger.info("Limited message"); // Will log.
limitedLogger.info("Limited message"); // Will log.
limitedLogger.info("Limited message"); // Will not log, maxUses reached.

// Logs with maxUses for a specific message.
limitedLogger.info("Single-use message", { maxUses: 1 }); // Will log.
limitedLogger.info("Single-use message", { maxUses: 1 }); // Will not log.
import { createRateLimit } from "toolkitify/rate-limit";

// Create a rate limiter for IP addresses: max 5 requests per 10 seconds.
const ratelimitIp = createRateLimit(5, "10s", "ip");

async function handleRequest(ip: string) {
    const { success, limit, remaining, reset } = await ratelimitIp.limit(ip);

    if (!success) {
        console.log(`Rate limit exceeded. Try again after ${new Date(reset).toLocaleTimeString()}`);
        return;
    }

    console.log(`Request allowed. Remaining: ${remaining}/${limit}`);
    // Proceed with your request logic here
}

// Example usage
handleRequest("192.168.0.1");
handleRequest("192.168.0.1");
handleRequest("192.168.0.1");
import "toolkitify/server-only";

// Run code only on the server/Node.
console.log("This code runs only in Node/SSR, not in the browser");

// Access filesystem.
const fs = require("fs");
console.log(fs.readdirSync("."));