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 🙏

© 2024 – Pkg Stats / Ryan Hefner

choicebrew

v1.0.2

Published

simple interactive menus

Downloads

2

Readme

simple interactive menus using inquirer

Version Downloads/week License

Geenee Template

Why

The inquirer package is great for directed interactive sequences, but a CLI menu requires looping and maintaining some context. It's easy to end up with spaghetti code trying to handle nested submenus.

What

A pair of functions and some types to organize your ts code.

  • A Choice is fundamentally a named ChoiceCallback (any function you'd like to execute when the user chooses it.)
  • a ChoiceGenerator takes in a context (any object you'd like) and returns a Choice.
  • menu() takes as a parameter your own ChoiceGenerator.
  • Every menu will automatically add a choice to exit the menu if you don't add it yourself. But you can override it yourself by offering a Choice with flow set to FlowType.back.

Sample

See geenee for a sample CLI using choiceBrew.

API

General Constants and Commands

Functions

functions for working with menus

  • menu: takes a ChoiceGenerator and continuously prompts the user for choices until a choice with the FlowType BACK is selected. When a choice with FlowType BACK is selected, the menu exits. You can also call setFlow in the callback for a choice to set the FlowType to BACK dynamically, thereby exiting the menu after execution of the callback.
  • getValue: returns the value entered or selected by a user. This is useful in the callback for a ChoiceCallback
  • setFlow: sets the flow for a Choice to be a FlowType. Normally, this is only useful for setting flow to BACK in a ChoiceCallback. Doing that will result in the menu exiting after the ChoiceCallback executes. For instance, it will exit a submenu and return to the menu above.

Types

The following types and interfaces are exposed by choicebrew.

Constants

Interfaces and enums used with choicebrew menus

  • FlowType: Options for a flow in a Choice. Currently just BACK (exit the menu or submenu) and COMMAND (execute a command). Almost always you will want to set a Choice to COMMAND, because by default a BACK Choice is created for you automatically unless you override that with your own. But see the setFlow function, which allows you to dynamically change a flow to BACK inside of an executing ChoiceCallback.
  • SelectedInfo: specifying a selection. Consists of a FlowType enum value 'flow' and any 'value' assigned to the choice.
  • MenuAnswers: consists of simply 'selected', which is an instance of SelectedInfo.
  • SelectedInfo: specifying a selection. Consists of a FlowType enum value 'flow' and any 'value' assigned to the choice.
  • Choice: The information for a choice, including the 'flow' (a FlowType, almost always COMMAND), a 'name' string, and a number of options. You can assign the following inquirer fields for a choice: description, value, short version. Also, a callback function.

FunctionTypes

type declarations for the functions used in menus

  • ChoicesGenerator: a function that generates a set of choices for a given menu
  • ChoiceCallback: a function called when a menu option is chosen