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

@j-o-r/cli

v2.1.5

Published

This project provides a command line interface (CLI) for creating interactive dialogs

Readme

Interactive CLI Framework

A CLI framework with mode-based input handling, command processing, and terminal control for building interactive command-line applications.

Features

  • Mode-based terminal output (user, log, system, error, assistant, etc.)
  • Command parsing and execution with built-in system commands
  • Interactive questions and selections (yes/no, multiple choice)
  • Custom key mappings for keyboard shortcuts
  • Spinner controls and terminal manipulation
  • Event-driven architecture with graceful error handling

Installation

import cli from '@j-o-r/cli';

Quick Start

// Set up input handler (required)
cli.inputHandler = async (input) => {
  cli.focus('assistant');
  cli.write(`echo ${input}`);
  cli.focus(); // Back to user input
};

// Optional: Custom exit handler
cli.exitHandler = async (code) => {
  console.log('Cleaning up...');
  process.exit(code);
};

// Start the CLI
cli.focus('log');
cli.write('Welcome! Type something...');
cli.focus(); // Switch to user input mode

Core API

Input/Output

// Write output (only when not in user mode)
cli.write('Hello world');
cli.write('No newline', false);

// Different output modes
cli.focus('log');       // Log output
cli.focus('error');     // Error output  
cli.focus('assistant'); // Assistant output
cli.focus('user');      // User input mode

Interactive Questions

// Simple question
const name = await cli.question('What is your name? ');

// Yes/no question
const confirmed = await cli.yesNo('Are you sure? ');

// Multiple choice selection
const choice = await cli.select('Choose option:', [
  'Option 1',
  'Option 2', 
  'Option 3'
]);

Key Mappings

cli.registerKeyMappings([
  { 
    name: 'd', ctrl: true, meta: false, shift: false, 
    handler: async () => process.exit(0) // Ctrl+D to exit
  },
  { 
    name: 'r', ctrl: true, meta: false, shift: false, 
    handler: async () => cli.clear() // Ctrl+R to clear
  }
]);

Utility Functions

// Terminal control
cli.clear();           // Clear screen
cli.startSpinner();    // Show loading spinner
cli.stopSpinner();     // Hide spinner

// Logging
cli.log('Debug info'); // Log
cli.error('Error!');   // Error output

Custom Roles

// Create custom output modes
cli.setRole('debug', '[DEBUG] ', 'brightGreen');
cli.focus('debug');
cli.write('Debug message');

Built-in Commands

The framework includes built-in system commands that can be used in user input:

  • >edit< - Open the default editor (vim, nano, helix). Fine tune the user input.
  • My text >paste< here - Clipboard operations, paste clipboard and opens an editor
  • >#!bash cat ./README.md< - Execute a bash command and opens an editor

Mode System

The CLI operates in different modes that control input/output behavior:

  • user - Accepts user input, processes commands
  • log - For logging output
  • system - System messages
  • error - Error output
  • assistant - Assistant responses
  • util - Utility prompts (questions, selections)

Error Handling

The framework provides robust error handling:

  • Graceful shutdown on signals (SIGINT, SIGTERM, etc.)
  • Uncaught exception handling
  • 5-second timeout for cleanup operations
  • Custom exit handlers

Example Application

#!/usr/bin/env node
import cli from '@j-o-r/cli';

// Register shortcuts
cli.registerKeyMappings([
  { name: 'd', ctrl: true, meta: false, shift: false, 
    handler: async () => process.exit(0) }
]);

// Handle user input
cli.inputHandler = async (input) => {
  if (!input) return;
  
  cli.focus('log');
  cli.write(`You typed: ${input}`);
  
  const name = await cli.question('What is your name? ');
  const happy = await cli.yesNo(`${name}, are you happy? `);
  
  cli.focus('assistant');
  cli.write(happy ? 'Great to hear!' : 'Hope things get better!');
  
  cli.focus(); // Back to user input
};

// Start the application
cli.focus('log');
cli.write('Welcome to the example app!');
cli.focus();

API Reference

| Method | Description | |--------|-------------| | inputHandler(input) | Handle user input (must override) | | exitHandler(code) | Handle application exit | | focus(role) | Switch to specific mode | | write(content, newline) | Write to console | | question(prompt) | Ask question, return answer | | yesNo(prompt) | Ask yes/no, return boolean | | select(prompt, choices) | Multiple choice selection | | registerKeyMappings(keys) | Register keyboard shortcuts | | setRole(name, prompt, color) | Create custom role | | clear() | Clear terminal screen | | log(message) | Log with formatting | | error(err) | Display error | | stop() | Graceful shutdown |

License

MIT