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

quizzo

v1.2.0

Published

Interactive command-line prompts: text, password, confirm, number, select, multiselect, autocomplete and list. Typed answers, Ctrl+C/Esc cancellation, AbortSignal, scrolling and filtering, works when piped (non-TTY). Lightweight alternative to inquirer, p

Readme

quizzo

Ask questions in the terminal: text, password, yes/no, numbers, lists and choices.

npm version bundle size license

quizzo lets your command-line tool ask the user questions and get typed answers back. Use it for setup wizards, create-* scripts and any CLI that needs input from a person. It has no dependencies, it also works when answers are piped in (for example in CI), and it is easy to test.

Features

  • 8 prompt types: text, password, confirm, number, select, multiselect, autocomplete and list.
  • Typed answers: select returns a union of the choice values; quizzo([...]) infers the whole answers object.
  • One way to cancel: Ctrl+C, Esc and an AbortSignal all reject with a CancelError.
  • Safe terminal: the terminal is always restored, even when your own code throws.
  • Validation: sync or async, with the error shown under the input.
  • Long lists: scrolling, disabled choices, hints and type-to-filter.
  • Works when piped: without a terminal, each prompt reads one line, so printf 'my-app\n2\ny\n' | my-cli works.
  • Easy to test: pass your own input and output streams and type keys into them.
  • Themes: change symbols and colors; NO_COLOR and FORCE_COLOR are respected.

Installation

npm install quizzo
pnpm add quizzo
yarn add quizzo
bun add quizzo

Quick start

import { text, select, confirm } from 'quizzo'

const name = await text({ message: 'Project name?', default: 'my-app' })
const lang = await select({
  message: 'Language',
  choices: [
    { value: 'ts', label: 'TypeScript', hint: 'recommended' },
    { value: 'js', label: 'JavaScript' },
  ],
}) // type: 'ts' | 'js'
const git = await confirm({ message: 'Init git?', initial: true })

console.log({ name, lang, git })
// If the user presses Enter three times:
// => { name: 'my-app', lang: 'ts', git: true }

This is what the user sees while the second question is open:

✔ Project name? · my-app
? Language ›
❯ TypeScript recommended
  JavaScript

With CommonJS: const { text, select, confirm } = require('quizzo').

Table of contents

Usage

Ask one question

Each prompt is an async function. Call it with a message and await the answer.

import { text } from 'quizzo'

const name = await text({ message: 'What is your name?' })
console.log(`Hello, ${name}!`)
// => Hello, Ada!   (if the user types "Ada")
? What is your name? › Ada

After Enter, the line changes to show the answer:

✔ What is your name? · Ada

Ask several questions

Pass an array of questions to quizzo(). It asks them in order and returns one object, with each answer under its name. Use when to skip a question based on earlier answers.

import quizzo from 'quizzo'

const answers = await quizzo([
  { name: 'name', message: 'Project name?', default: 'my-app' },
  { type: 'select', name: 'lang', message: 'Language', choices: ['ts', 'js'] },
  {
    type: 'multiselect',
    name: 'tools',
    message: 'Tools',
    choices: ['eslint', 'vitest'],
    when: (answers) => answers.lang === 'ts',
  },
])
// type: { name: string; lang: 'ts' | 'js'; tools?: ('eslint' | 'vitest')[] }
// => { name: 'my-app', lang: 'ts', tools: ['eslint'] }

message can also be a function of the earlier answers. If you already have some answers (for example from CLI flags), pass them in answers. Those questions are skipped and the values are kept.

const answers = await quizzo(
  [
    { name: 'name', message: 'Project name?' },
    { name: 'dir', message: (answers) => `Folder for ${answers.name}?` },
  ],
  { answers: { name: 'my-app' } },
)
// Only "Folder for my-app?" is asked.
// => { name: 'my-app', dir: 'apps/web' }   (if the user types "apps/web")

For anything more dynamic, call the prompt functions one after another. It is just await.

Validate input

validate gets the value and returns true (or nothing) when it is valid, or an error message. The message is shown under the input, and the user can fix the answer. validate can be async.

import { text } from 'quizzo'

const email = await text({
  message: 'Email',
  placeholder: '[email protected]',
  validate: (value) => value.includes('@') || 'Please enter an email',
})
? Email › abc
  ✖ Please enter an email

An async check, and transform to change the result type:

import { text } from 'quizzo'

const isTaken = async (name) => name === 'admin'

const username = await text({
  message: 'Username',
  validate: async (value) => ((await isTaken(value)) ? 'This name is taken' : true),
})

const port = await text({ message: 'Port', default: '3000', transform: Number })
// => 3000   (a number, not a string)

Some prompts check things for you: required on text, password and multiselect, and min / max on number, multiselect and list.

Handle Ctrl+C and Esc

When the user presses Ctrl+C or Esc, the prompt rejects with a CancelError. An aborted signal does the same, and the abort reason is on error.cause. Use isCancel() to tell a cancel apart from other errors.

import { text, isCancel } from 'quizzo'

try {
  const name = await text({ message: 'Name', signal: AbortSignal.timeout(30_000) })
} catch (error) {
  if (!isCancel(error)) throw error
  console.log('Bye!')
  process.exit(130)
}
✖ Name
Bye!

In a quizzo([...]) flow, error.answers holds the answers given before the cancel.

Why reject instead of returning a special value? If you forget to check, a cancel cannot turn into a wrong answer that flows into your program: it stops the program.

Whatever happens (cancel, abort, or an error thrown in your validate or transform), quizzo restores raw mode and the cursor before the promise settles. Raw mode is the terminal setting that sends each key right away. quizzo also shows the cursor again if the process exits during a prompt.

Use in CI or with piped input

When input.isTTY is not true (TTY means a real interactive terminal), quizzo does not draw anything interactive. Each prompt prints the question and reads one line. This happens when answers are piped in, or in CI.

printf 'my-app\n2\ny\n' | node create.js
node create.js < /dev/null   # use all defaults

With the Quick start example and the first command above, the output is:

? Project name? (my-app)
✔ Project name? · my-app
? Language (number or name)
  1) TypeScript recommended
  2) JavaScript
✔ Language · JavaScript
? Init git? (Y/n)
✔ Init git? · Yes
{ name: 'my-app', lang: 'js', git: true }

How each line is read:

  • An empty line, or the end of input, is like pressing Enter right away: you get default / initial (the first enabled choice for select, false for confirm).
  • confirm accepts y, yes, true, 1, n, no, false, 0, or the labels.
  • select accepts the choice number (starting at 1), the label or the value (not case-sensitive). multiselect accepts a comma-separated list of those. autocomplete takes the search text and picks the exact match, or else the first match.
  • validate, required and min / max still run. An invalid answer rejects with a PromptError, because there is no way to ask again.

Test your CLI

Pass your own input and output streams, then type keys into the input. Set isTTY: true on the input to test the interactive mode.

import assert from 'node:assert/strict'
import { PassThrough, Writable } from 'node:stream'
import { select } from 'quizzo'

const input = Object.assign(new PassThrough(), { isTTY: true })
let drawn = ''
const output = new Writable({ write(chunk, _, cb) { drawn += chunk; cb() } })

const answer = select({ message: 'Pick', choices: ['a', 'b'], input, output, color: false })
input.write('\x1b[B') // Down arrow
input.write('\r')     // Enter
assert.equal(await answer, 'b')

Keys typed ahead are kept for the next prompt on the same input, so you can write a whole session up front.

| Key | Sequence | |---|---| | Enter | '\r' | | Space | ' ' | | Up / Down | '\x1b[A' / '\x1b[B' | | Right / Left | '\x1b[C' / '\x1b[D' | | Backspace | '\x7f' | | Tab | '\t' | | Esc | '\x1b' | | Ctrl+C | '\x03' |

To test the non-interactive mode, leave isTTY unset and write all lines at once: input.end('line 1\nline 2\n').

Change themes and colors

Use configure() to set a theme for every prompt, or pass theme to one prompt. You only list the parts you want to change.

import { configure } from 'quizzo'

configure({
  theme: {
    symbols: { pointer: '→', done: '✓', checked: '[x]', unchecked: '[ ]' },
    styles: { highlight: 'magenta', answer: ['bold', 'green'], message: (s) => s.toUpperCase() },
  },
})

Colors are on when the output is a terminal. You can change this with environment variables, or with the color option:

NO_COLOR=1 node create.js      # no colors
FORCE_COLOR=1 node create.js   # colors, even when the output is piped
FORCE_COLOR=0 node create.js   # no colors

The order is: the color option, then FORCE_COLOR (0 or false means off), then NO_COLOR, then TERM=dumb (off), then "is the output a terminal". On terminals that cannot draw symbols like ✔ and ❯ (the legacy Windows console and the Linux text console), quizzo uses ASCII symbols instead.

API

Every prompt takes a message plus the shared options and returns a promise.

Shared options

Every prompt and quizzo() accept these options.

| Option | Type | Default | Description | |---|---|---|---| | input | InputStream | process.stdin | Where keys are read from. Interactive only if input.isTTY is true. | | output | OutputStream | process.stdout | Where the prompt is drawn. Uses output.columns and output.rows if present. | | signal | AbortSignal | | Cancels the prompt (rejects with CancelError) when it aborts. | | theme | ThemeOptions | | { symbols?, styles? }. See Theme. | | color | boolean | auto | Force colors on or off. See Change themes and colors. |

text(options)

function text<T = string>(options: TextOptions<T>): Promise<T>

Asks for one line of text. Returns the string, or what transform returns.

? Project name? › my-app

| Option | Type | Default | Description | |---|---|---|---| | message | string | | The question. | | initial | string | | Text already in the input. The user can edit it. | | default | string | | Returned when the input is empty. Shown dimmed; Tab fills it in. | | placeholder | string | | Dimmed hint while the input is empty. | | required | boolean | false | Reject an empty answer ("Please enter a value"). | | validate | (value: string) => ValidateResult \| Promise<ValidateResult> | | Return true or nothing if valid, an error message if not. false shows "Invalid value". | | transform | (value: string) => T \| Promise<T> | | Changes the accepted string into the result. Runs after validate. The result type follows it. |

Keys:

| Key | Action | |---|---| | Enter | Submit. | | Tab | Fill in default when the input is empty. | | Left / Right (Ctrl+B / Ctrl+F) | Move the cursor. | | Home / End (Ctrl+A / Ctrl+E) | Go to the start or end. | | Backspace / Delete (Ctrl+H / Ctrl+D) | Delete a character. | | Ctrl+U / Ctrl+K | Delete to the start / to the end. | | Ctrl+W (Alt+Backspace) | Delete the word before the cursor. | | Alt+Left / Alt+Right (Ctrl+Left / Ctrl+Right) | Jump one word. | | Esc or Ctrl+C | Cancel. |

Without a TTY: an empty line gives default, then initial, then ''.

password(options)

function password(options: PasswordOptions): Promise<string>

Like text, but each typed character is drawn as • (or * without Unicode). The secret is never written to the output.

? Password › ••••••

| Option | Type | Default | Description | |---|---|---|---| | message | string | | The question. | | mask | string | '•' | Character drawn for each typed character. '' shows nothing. | | required | boolean | false | Reject an empty answer. | | validate | (value: string) => ValidateResult \| Promise<ValidateResult> | | Same as in text. |

Keys: the same editing keys as text.

confirm(options)

function confirm(options: ConfirmOptions): Promise<boolean>

Asks a yes/no question.

const ok = await confirm({ message: 'Deploy to production?' })
? Deploy to production? › ○ Yes / ● No

| Option | Type | Default | Description | |---|---|---|---| | message | string | | The question. | | initial | boolean | false | The starting answer. | | active | string | 'Yes' | Label for true. | | inactive | string | 'No' | Label for false. |

Keys:

| Key | Action | |---|---| | y / n | Answer yes / no right away. | | Left or h / Right or l | Pick yes / no. | | Tab, Space, Up, Down | Switch between yes and no. | | Enter | Submit. | | Esc or Ctrl+C | Cancel. |

Without a TTY: y, yes, true, 1, n, no, false, 0 or the labels. An empty line gives initial.

number(options)

function number(options: NumberOptions): Promise<number>

Asks for a number. Only digits and signs can be typed (plus . and e with float).

const replicas = await number({ message: 'Replicas', initial: 3, min: 1, max: 10 })
? Replicas › 0
  ✖ Must be at least 1

| Option | Type | Default | Description | |---|---|---|---| | message | string | | The question. | | initial | number | | Number already in the input. The user can edit it. | | default | number | | Returned when the input is empty. Shown dimmed; Tab fills it in. | | placeholder | string | | Dimmed hint while the input is empty. | | min | number | | Smallest allowed value ("Must be at least 1"). | | max | number | | Largest allowed value ("Must be at most 10"). | | step | number | 1 | How much Up and Down add or subtract. | | float | boolean | false | Allow decimals. Without it, only whole numbers are accepted. | | validate | (value: number) => ValidateResult \| Promise<ValidateResult> | | Same as in text, but gets the number. |

Keys:

| Key | Action | |---|---| | Up / Down | Add / subtract step, kept between min and max. | | PgUp / PgDn | Add / subtract 10 steps. | | Tab | Fill in default when the input is empty. | | Enter | Submit. | | Esc or Ctrl+C | Cancel. |

The text editing keys from text also work. When the input is empty, the first Up or Down press puts in default (or initial). If neither is set, Up starts at min and Down starts at max (or 0).

Without a TTY: an empty line gives initial, then default. If neither is set, it rejects with PromptError.

select(options)

function select<const V>(options: SelectOptions<V>): Promise<V>

Asks the user to pick one choice. Returns the value of that choice, typed as a union of all choice values.

const size = await select({
  message: 'Size',
  choices: [
    { value: 's', label: 'Small' },
    { value: 'm', label: 'Medium', hint: 'most popular' },
    { value: 'xl', label: 'Extra large', disabled: 'out of stock' },
  ],
  initial: 'm',
}) // type: 's' | 'm' | 'xl'
? Size ›
  Small
❯ Medium most popular
  Extra large (out of stock)

Disabled choices are shown dimmed and skipped. The hint is shown next to the highlighted choice.

| Option | Type | Default | Description | |---|---|---|---| | message | string | | The question. | | choices | Choice<V>[] | | Strings or numbers, or { value, label?, hint?, disabled? }. disabled can be a reason string. Wrap object values in { value }. | | initial | V | first enabled choice | Value of the choice to highlight first. | | pageSize | number | 7 | Rows shown before the list scrolls. Capped to the terminal height. | | loop | boolean | true | Go around from the last choice to the first, and back. | | filter | boolean | false | Let the user type to filter the list. | | match | (query: string, choice: ChoiceInfo<V>) => boolean | defaultMatch | Decides which choices match the filter text. | | placeholder | string | 'Type to filter' | Shown while the filter is empty. |

Long lists scroll and show how many choices are hidden:

? Month ›
  ↑ 1 more
  Feb
  Mar
  Apr
❯ May
  ↓ 7 more

Keys:

| Key | Action | |---|---| | Up / Down (Ctrl+P / Ctrl+N) | Move. | | Tab / Shift+Tab | Move down / up. | | k / j | Move up / down (only without filter). | | PgUp / PgDn | Move one page. | | Home / End | Go to the first / last choice (only without filter). | | Enter | Submit. | | Esc | Clear the filter text. If it is empty, cancel. | | Ctrl+C | Cancel. |

With filter: true, letters go into the filter, and the text editing keys from text work on it.

Without a TTY: the choices are printed with numbers. The line can be the number (starting at 1), the label or the value (not case-sensitive). An empty line gives initial or the first enabled choice.

multiselect(options)

function multiselect<const V>(options: MultiselectOptions<V>): Promise<V[]>

Asks the user to pick any number of choices. Values come back in the order of choices.

const features = await multiselect({
  message: 'Features',
  choices: ['auth', 'payments', 'emails'],
  initial: ['auth'],
  required: true,
}) // type: ('auth' | 'payments' | 'emails')[]
? Features › (space: select, a: all, enter: submit)
❯ ◉ auth
  ◯ payments
  ◯ emails

All select options work here (choices, pageSize, loop, filter, match, placeholder), plus:

| Option | Type | Default | Description | |---|---|---|---| | initial | V[] | | Values checked at the start. | | required | boolean | false | At least one choice (same as min: 1). | | min | number | | Fewest choices allowed. | | max | number | | Most choices allowed. Checking more shows an error. | | validate | (values: V[]) => ValidateResult \| Promise<ValidateResult> | | Your own check on the array. | | instructions | boolean \| string | true | Key help after the question. false hides it; a string replaces it. |

Keys (plus the moving keys from select):

| Key | Action | |---|---| | Space | Check or uncheck the highlighted choice. | | a | Check all, or uncheck all if all are checked. With filter, use Ctrl+A. | | i | Invert all checks (only without filter). | | Right / Left | Check / uncheck the highlighted choice (only without filter). | | Enter | Submit. | | Esc | Clear the filter text. If it is empty, cancel. | | Ctrl+C | Cancel. |

With filter: true, Ctrl+A checks all of the visible choices. Checks are kept when the filter changes.

Without a TTY: a comma-separated list of numbers, labels or values, such as 1, prettier. An empty line gives initial.

autocomplete(options)

function autocomplete<const V>(options: AutocompleteOptions<V>): Promise<V>

Like select, but the user always types to search. Give it static choices, or a source function that loads them (for example from an API).

const pkg = await autocomplete({
  message: 'Package',
  source: async (query, signal) => {
    const url = `https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(query)}&size=10`
    const res = await fetch(url, { signal })
    const { objects } = await res.json()
    return objects.map((o) => ({ value: o.package.name, hint: o.package.description }))
  },
})

With static choices: ['react', 'redux', 'vue'] and the text re, the user sees:

? Package › re
❯ react
  redux

source(query, signal) runs at the start and each time the text changes. The signal of the previous call aborts when the text changes and when the prompt ends, and old results are ignored. Enter waits for a search that is still running. If source throws, its error message is shown under the input.

| Option | Type | Default | Description | |---|---|---|---| | message | string | | The question. | | choices | Choice<V>[] | | Static choices, filtered as the user types. Use this or source. | | source | (query: string, signal: AbortSignal) => Choice<V>[] \| Promise<Choice<V>[]> | | Loads the choices for the typed text. | | initial | V | | Value of the choice to highlight first. | | match | (query: string, choice: ChoiceInfo<V>) => boolean | defaultMatch | Filter for static choices. | | pageSize | number | 7 | Rows shown before the list scrolls. | | loop | boolean | true | Go around at the ends of the list. | | placeholder | string | 'Type to filter' | Shown while the search text is empty. |

Keys: type to search (with the text editing keys from text), Up / Down (Ctrl+P / Ctrl+N), Tab / Shift+Tab, PgUp / PgDn, Enter to submit, Esc to clear the text (or cancel if it is empty), Ctrl+C to cancel.

Without a TTY: the line is the search text. quizzo picks the choice whose label or value matches exactly, or else the first match.

list(options)

function list(options: ListOptions): Promise<string[]>

Asks for several values on one line. Items are trimmed and empty items are dropped.

const tags = await list({ message: 'Tags', placeholder: 'a, b, c' })
// The user types "a, b,,c "
// => ['a', 'b', 'c']
✔ Tags · a, b, c

| Option | Type | Default | Description | |---|---|---|---| | message | string | | The question. | | separator | string \| RegExp | ',' | What splits the items. | | min | number | | Fewest items ("Enter at least 2 items"). | | max | number | | Most items ("Enter at most 3 items"). | | validate | (items: string[]) => ValidateResult \| Promise<ValidateResult> | | Your own check on the items. | | initial | string | | Text already in the input. | | default | string | | Used when the input is empty. | | placeholder | string | | Dimmed hint while the input is empty. |

Keys: the same as text.

quizzo(questions, options?)

function quizzo<const Qs extends readonly Question[]>(questions: Qs, options?: FlowOptions): Promise<Answers<Qs>>

Asks the questions in order and returns an answers object. Also exported as prompt. It is the default export too, and the default export has every named export attached (quizzo.text, quizzo.isCancel, ...).

In CommonJS, require('quizzo') returns this function:

const quizzo = require('quizzo')

async function main() {
  const answers = await quizzo([{ name: 'name', message: 'Name?' }])
  const ok = await quizzo.confirm({ message: 'Sure?' })
}
main()

Each question takes the options of its prompt type, plus these keys:

| Key | Type | Default | Description | |---|---|---|---| | type | 'text' \| 'password' \| 'confirm' \| 'number' \| 'select' \| 'multiselect' \| 'autocomplete' \| 'list' | 'text' | Which prompt to show. | | name | string | | Key of the answer in the result. Required. | | message | string \| (answers) => string | | The question, or a function of the answers so far. | | when | boolean \| (answers) => boolean \| Promise<boolean> | | Skip the question when this is (or returns) false. Answers of questions with when are optional in the result type. |

options takes the shared options, which apply to every question, plus:

| Option | Type | Default | Description | |---|---|---|---| | answers | Record<string, any> | | Answers you already have, for example from CLI flags. Questions with these names are skipped and the values are kept. |

On cancel, it rejects with a CancelError whose answers holds the answers given so far.

configure(options)

function configure(options: Omit<SharedOptions, 'signal'>): Omit<SharedOptions, 'signal'>

Sets default input, output, theme and color for every later prompt. Each call merges with the earlier defaults (theme symbols and styles are merged too). Returns the new defaults. Options passed to a prompt win over these defaults.

isCancel(error)

function isCancel(error: unknown): error is CancelError

Returns true if error is a CancelError. It also works when your app has two copies of quizzo installed.

CancelError

class CancelError extends Error {
  name: string // 'CancelError'
  answers?: Record<string, unknown>
}

The rejection when the user presses Ctrl+C or Esc, or when the signal aborts.

  • cause: the abort reason, when a signal caused it.
  • answers: the answers given before the cancel (only set by quizzo([...])).

PromptError

class PromptError extends Error {
  name: string // 'PromptError'
  input: string | undefined
}

The rejection when an answer read without a TTY is invalid. input is the line that was read ('' at the end of input). The message names the question and the problem, for example Deploy? Please answer y or n (got 'nope').

defaultMatch(query, choice)

function defaultMatch(query: string, choice: ChoiceInfo<unknown>): boolean

The default filter. It checks if the label or the value contains query, not case-sensitive. Use it inside your own match:

import { select, defaultMatch } from 'quizzo'

const city = await select({
  message: 'City',
  filter: true,
  choices: [{ value: 'nyc', label: 'New York', hint: 'NY' }, { value: 'la', label: 'Los Angeles', hint: 'CA' }],
  match: (query, choice) => defaultMatch(query, choice) || (choice.hint ?? '').toLowerCase() === query.toLowerCase(),
})

ChoiceInfo<V> has value, label, hint, disabled, reason (the disabled reason, '' if none) and index (the position in choices).

Theme

theme is { symbols?, styles? }. Each part is optional.

Symbols:

| Symbol | Default | ASCII fallback | Used for | |---|---|---|---| | prompt | ? | ? | Before an open question. | | done | ✔ | √ | Before an answered question. | | cancel | ✖ | × | Before a cancelled question. | | separator | › | > | Between the question and the input. | | answerSeparator | · | - | Between an answered question and its answer. | | pointer | ❯ | > | The highlighted choice. | | checked | ◉ | (*) | A checked multiselect choice. | | unchecked | ◯ | ( ) | An unchecked multiselect choice. | | radioOn | ● | (*) | The selected confirm option. | | radioOff | ○ | ( ) | The other confirm option. | | error | ✖ | × | Before a validation error. | | more | ↑ | ^ | "More choices above". | | moreBelow | ↓ | v | "More choices below". | | busy | … | ... | While an async check or search runs. | | mask | • | * | Password characters. |

Styles:

| Style | Default | Used for | |---|---|---| | prompt | 'cyan' | The ? before an open question. | | done | 'green' | The ✔ before an answered question. | | cancel | 'red' | The ✖ before a cancelled question. | | message | 'bold' | The question text. | | answer | 'cyan' | The submitted answer. | | highlight | 'cyan' | The highlighted choice and the pointer. | | hint | 'gray' | Hints, key help, scroll markers and separators. | | placeholder | 'gray' | Placeholder and default values in an empty input. | | error | 'red' | Validation errors. | | disabled | 'gray' | Disabled choices. | | checked | 'green' | The checked marker in multiselect. |

A style is a name (black, red, green, yellow, blue, magenta, cyan, white, gray, bold, dim, italic, underline, inverse, strikethrough), an array of names, or a function (text) => string. Named styles turn off when colors are off. Functions are always used as given.

Types

All types are exported:

  • Options: SharedOptions, BaseOptions, TextOptions, PasswordOptions, ConfirmOptions, NumberOptions, SelectOptions, MultiselectOptions, AutocompleteOptions, ListOptions, FlowOptions.
  • Choices: Choice<V>, ChoiceObject<V>, ChoiceInfo<V>.
  • Flows: Question, TextQuestion, PasswordQuestion, ConfirmQuestion, NumberQuestion, SelectQuestion, MultiselectQuestion, AutocompleteQuestion, ListQuestion, Answers<Qs>, AnswerOf<Q>, AnswersSoFar.
  • Themes: ThemeOptions, Symbols, Styles, Style, ColorName.
  • Other: ValidateResult, InputStream, OutputStream, Key.

Comparison

inquirer, prompts, enquirer and @clack/prompts are all good libraries. quizzo is for when you want one small package with no dependencies, strong types, and a cancel model that is hard to get wrong.

| | inquirer | prompts | enquirer | @clack/prompts | quizzo | |---|---|---|---|---|---| | Runtime dependencies | Yes | Yes | Yes | Yes | No | | TypeScript types | Built in | Separate (@types/prompts) | Built in | Built in | Built in, answers type inferred | | On Ctrl+C | Rejects (ExitPromptError) | Resolves with the answers so far (or calls onCancel) | Rejects | Returns a symbol you check with isCancel() | Rejects with CancelError (flows attach the answers so far) |

What quizzo adds: a typed quizzo([...]) flow with when, AbortSignal support on every prompt, a documented non-TTY mode, and a way to test with fake streams that needs no mocking library.

Notes and limitations

  • Without a TTY, each prompt reads exactly one line. An invalid answer rejects with PromptError; it is not asked again.
  • In a flow, set input, output, signal, theme and color in the second argument of quizzo(), not on each question.
  • Choice values that are objects must be wrapped: { value: myObject, label: 'My object' }.
  • With filter: true, letter keys type into the filter, so j / k, Home / End, and (in multiselect) a, i and Left / Right do not move or check.
  • pageSize is capped to the terminal height.
  • On the legacy Windows console and the Linux text console (TERM=linux), ASCII symbols are used instead of Unicode ones.

Requirements

  • Node.js 20 or newer.
  • ESM and CommonJS builds.
  • TypeScript types included.
  • Zero dependencies, about 9 KB gzipped.

License

MIT