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

cmd-funk

v0.3.0

Published

A minimal functional command line library

Downloads

30

Readme

cmd-funk ("command funk")

A map-based composable call and response framework. cmd-funk is a great option for building lightweight command lines, as well as within more complicated applications that leverage a similar access pattern (like chat bots). Really, anything that predominantly communicates using nested string commands can leverage cmd-funk.

Why use cmd-funk?

  • Composable: Every command line tool has different requirements. Insofar as it is useful, cmd-funk provides the tools to create your tools in whatever way you see fit.
  • Functional: To the extent that it's reasonable, cmd-funk doesn't explicitly track state. There's no classes, minimal initialization, as little overhead as possible.
  • Modern: cmd-funk is written in Typescript and takes advantage of async/await, so no outdated access patterns!

Contents

Installation

Use your favorite package manager and install cmd-funk, for example:

npm i cmd-funk

Concepts

There are 3 building blocks to a cmd-funk application, Mappers, Marshallers, and Outputs.

  • Mappers are objects that map commands to their implementations (or other mappers!).
  • Marshallers take the output of an implementation and convert it to something cmd-funk understands.
  • Outputs are special objects that store information about the result of a command.

Mappers

Mappers are dictionaries that lead to the implementation logic of your commands, as well as the necessary help text associated with them.

Let's say you've got a simple CLI with three commands; add, subtract, and multiply. With this architecture, you'd need just one mapper in the following shape:

import { SimpleMapper } from "cmd-funk";

export const MyCommandMap: SimpleMapper = {
  add: async cmd => // ...do an add command
  subtract: async cmd => // ...do a subtract command
  multiply: async cmd => // ...do a multiply command
  help: () => // ...return a helptext response
};

Let's look at what's going on...

  • async functions are used here, but they are not required. cmd-funk expects each key of a mapper object to return either an output or a promise to one.
  • SimpleMapper is a helper mapper implementation. Use this if you don't need custom contexts.
  • The help key is required on all mappers, and it implements the help text returned to your users.

Marshallers

Since the underlying implementation of a given command likely returns information specific to the applicastion, but each mapper key expects a return of an output or a promise to one, there is a need for an intermediary to translate between these two things.

This is where marshallers are helpful. Let's look at the example mapper from above, but add in an implementation for the add command, which returns a string:

import { Marshallers, SimpleMapper } from "cmd-funk";

const add = async (cmd: SimpleCommand): Promise<string> => {
  // ...some async logic
  return "hello world";
}

export const MyCommandMap: SimpleMapper = {
  add: async cmd => Marshallers.str(await add(cmd)),
  subtract: async cmd => // ...do a subtract command
  multiply: async cmd => // ...do a multiply command
  help: () => // ...return a helptext response
};

So, what's going on?

  • Marshallers is a provided namespace within cmd-funk with implementations for some common marshaller use cases. They take in common return types and translate them to cmd-funk outputs.
  • SimpleCommand is a helper implementation of the command type to use if you don't need custom contexts.

Provided Marshallers

cmd-funk ships with a few marshallers built in to get your project off the ground, they are as follows:

  • error: for marshalling error messages, and optionally the command from which they spawned.
  • help: for marshalling help text. The suggested use case is passing in a key/value map of available commands within a mapper.
  • keyValue: for mapping an object consisting of key/value pairs (with an optional title) to formatted console output.
  • str: for mapping simple strings to console output.

Outputs

cmd-funk provides the CommandOutput<T> type to simplify handling of command results (source). While use is not required, many helper functions leverage it, and all marshallers return objects of this type.

Custom Contexts

UNDER CONSTRUCTION

Examples

Hello World

A Hello world CLI using cmd-funk.