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

tscaf

v1.0.27

Published

`tscaf` helps you set up a TypeScript console application in under **2 minutes**. It provides built-in developer scripts, a command registration system, optional utilities (fetch wrapper, persistent/session storage), and a simple global environment object

Readme

TypeScript Console Application Framework (tscaf)

tscaf helps you set up a TypeScript console application in under 2 minutes. It provides built-in developer scripts, a command registration system, optional utilities (fetch wrapper, persistent/session storage), and a simple global environment object.


Features

  • Quick, minimal boilerplate to start a CLI in TypeScript
  • Built-in scripts: tscaf dev, tscaf build
  • Command registration API and command index generation
  • Optional helpers: FetchWrapper, PersistentStorage, SessionStorage
  • GLOBAL object with environment info

1. Setting up the app

Create the entry file src/index.ts and call runApp():

import { runApp } from "tscaf";

runApp({
  afterLoad: async () => {
    console.log("Application loaded!");
  },
  showStartupMessage: true,
  unregisterDefaultCommands: "all" // or an array of default commands
});

runApp params

export interface AppProps {
  afterLoad?: () => void | Promise<void>;
  showStartupMessage?: boolean;
  unregisterDefaultCommands?: "all" | DefaultCommand[];
  customCompleter?: Completer | AsyncCompleter;
}

Use afterLoad for any async initialization, toggle the startup message with showStartupMessage, or remove default commands with unregisterDefaultCommands. Use the customCompleter prop to pass your own command completer.


2. Creating commands

Register commands by pushing them to the registry:

export const registerCommand = (command: Command) => registry.push(command);

Command interface

interface Command {
  name: string;
  execute: (args: string[]) => void | Promise<void>;
  group: string;
  description?: string;
  aliases?: string[];
  usage?: string;
  specialConfig?: CommandSpecialConfig;
  argValidator?: (args: string[]) => boolean | string;
}

Example command (declarative)

src/commands/hello.ts

import { registerCommand } from "tscaf";

registerCommand({
  name: "hello",
  group: "general",
  description: "Say hello",
  execute: () => {
    console.log("Hello World!");
  }
});

Command index generation

You can either register commands manually as above or let the framework create an index for you:

npx tscaf generate-command-index

This scans directories defined in your tscaf.commandsDirs config and builds the index automatically.


Example package.json

{
  "name": "your-project-name",
  "version": "1.0.0",
  "main": "dist/index.js",
  "license": "MIT",
  "scripts": {
    "dev": "tscaf dev",
    "build:generate": "tscaf generate-command-index",
    "build:perform": "tscaf build",
    "build": "npm run build:generate && npm run build:perform"
  },
  "devDependencies": {
    "@types/node": "^20.0.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.0.0"
  },
  "dependencies": {
    "tscaf": "^1.0.17"
  },
  "tscaf": {
    "commandsDirs": [
      "src/commands"
    ]
  }
}

tsconfig.json required for tscaf build

To use the shipped tscaf build command, include a tsconfig.json like this:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "CommonJS",
    "outDir": "dist",
    "esModuleInterop": true,
    "strict": true
  }
}

If you prefer other packagers (pkg, nexe, etc.) you can build with those instead — tscaf build expects a CommonJS/ES2020 compatible output.


3. Other features

FetchWrapper (optional)

A small convenience wrapper around fetch for common request patterns: This is entirely optional — use native fetch if you prefer.

Persistent & Session Storage

Work with storage objects similar to a browser API:

import { PersistentStorage, SessionStorage } from "tscaf";

PersistentStorage.set("token", "abc123");
const token = PersistentStorage.get("token");

SessionStorage.set("step", "1");

These are lightweight helpers that persist to the filesystem (or memory, depending on configuration).

API (HTTP Server)

tscaf allows you to easily expose all registered commands via a HTTP API. You can use the HTTPServer object.

interface HTTPServer {
  start: (port?: number) => void,
  reload: () => void,
  stop: () => void,
  isRunning: () => boolean,
  getRoutes: () => {
    method: string;
    path: string;
    externalCalls: number;
  }[],
  getPort: () => void | null
}

You can start and stop the HTTP Server and reload the routes. There are also some information methods. The server will not be started automatically.

To use the API, call the command at http://localhost:3000/cmd/<command> with a body of

{
  "args": ["<arg1>", "..."]
}

The API will respond with an object of

  {
    "ok": true,
    "result": "<If your command returns something, it will be returned here aswell>",
    "logs": [
        {
            "type": "log",
            "msg": [
                "<Whatever you log using console.log()>"
            ]
        },
        {
            "type": "log",
            "msg": [
                "<Second usage of console.log()...>"
            ]
        },
        {
            "type": "error",
            "msg": [
                "<Whatever you log using console.error()>"
            ]
        },
    ]
  }

Tips & notes

  • Keep commands small and focused; use argValidator to validate CLI args and return either true or a string message for the user.
  • Use generate-command-index before building to ensure all commands are bundled.
  • tscaf dev runs your project directly (with ts-node or similar) for fast iteration.