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 🙏

© 2026 – Pkg Stats / Ryan Hefner

tshell

v0.1.4

Published

TypeScript library for running shell commands

Readme

tshell

The tshell module provides a simple interface to a subset of the functionality of the Nodejs child process primitives. It is intended as an alternative to writing some shell scripts.

A command is a function to run a program, specified by a string or another command, with an optional list of string arguments. A global object, returned by the shell function, defines the execution context, including environment variables, current directory, and standard I/O redirection. A command function returns a promise for the exit status of the process, which is either an exit code (number) or error.

Commands

import { cmd, shell, exec, output, subshell } from 'tshell'

// Run a command.
await cmd('echo')('hi mom!')

// Create a command and then run it.
const echo = cmd('echo')
await echo('hi mom!')

// Create a command with (some) arguments and run it.
const ls = cmd('ls', '-l')
await ls('.')

// Handle an exception for non-zero exit status.
try {
    await cmd('cat')('no-such-file')
} catch (e) {
    // e is a RangeError subclass with e.code === 1
}

// Return exit status of 1 without an exception.
shell().context.throwFlag = false
const status = await cmd('cat')('no-such-file')

// Capture stdout for a command as a string with newlines removed,
// returning 'hi mom!'.
await output(cmd(echo, 'hi mom!'))

// Capture stderr for a command as a string with newlines removed,
// returning 'hi mom!'.
await capture('stderr', bash, '>&2 echo "hi mom!"')

// Capture stdout and stderr both as one string with newlines removed,
// returning ['hi mom!', 'foo'].
await capture('stdout+stderr', bash, 'echo hi mom!; printf "%s\\n" foo >&2')

Contexts

When a command function is called, the configuration of the child process depends on the current context, which is defined as a global instead of being passed as an argument in every call. The exec function allows one to override the context when executing a specific command. One can use this function to redirect the input or output of the command.

// Redirect input or output.
await exec(cmd(echo, 'hi mom!'), {'>': 'out.txt'})
await exec(cmd(sort, '-n'), {'<': 'data.txt', '>': 'sorted.txt'})

// Also can redirect to stderr with '2>', combine stdout and stderr
// with '&>', and append with '>>', '2>>', and '&>>'.

// Run with a different working directory.
await exec(cmd('ls'), {dir: '..'})

// Run with a different environment.
await exec(bash, {env: {PATH: ...})

Subshells

The subshell function handles sequential nesting by returning a special command that calls a user-defined async function. This feature is useful to encapsulate calls to commands in a different context.

// Function body as a command.
async function body() {
    await echo('hi mom!')
    if (cond) {
        shell().exit(1)
        return
    }

    await echo('goodbye')
}
await exec(subshell(body), { '>': output })

Using a global works well for a single path of execution, but the use of await means one should be careful using multiple code blocks that execute commands. If there might be parallel command execution, such as executing commands in a callback, one must use the result method to ensure the current context is properly restored before continuing after a use of await.

// Multiple parallel shell context
await exec(
    subshell(
        async function() {
            const sh = shell()
            sh.context.throwFlag = true
            if (sh.result(await echo('hi mom!')) !== 0) {
                sh.exit(0)
                return
            }
            sh.result(await echo('goodbye'))
        }
    )
)

ShellListener

The shell