Skip to main content

@sallai/ask@2.0.2
Built and signed on GitHub Actions

Interactive command-line prompts for Deno.

This package works with Deno
This package works with Deno
JSR Score
100%
Published
a month ago (2.0.2)

ask

Interactive command-line prompts for Deno.

Demo

Description

ask is a slick Deno module that allows you to create interactive command-line applications, similar to what you'd achieve with inquirer in Node.js.

Overview

  • Supported prompts:
    • input (plain text)
    • number (integer or float)
    • password (hidden/masked input)
    • confirm (yes/no)
    • editor (open an editor to write longer text)
    • select (pick one item from a list)
    • checkbox (pick multiple items from a list)
  • Elegant output.
  • Familiar, inquirer-like syntax.
  • Easily configurable.
  • Strong type-safety.

Basic Usage

First, install the package from JSR:

deno add jsr:@sallai/ask

Then just create an Ask instance and use the prompt() method to enumerate your questions.

import { Ask } from "@sallai/ask";

const ask = new Ask(); // global options are also supported!

const answers = await ask.prompt([
  {
    name: "name",
    type: "input",
    message: "Name:",
  },
  {
    name: "age",
    type: "number",
    message: "Age:",
  },
] as const);

console.log(answers); // { name: "Joe", age: 19 }

You can also just ask a single question:

const { name } = await ask.input({
  name: "name",
  message: "Name:",
} as const);

console.log(name); // Joe

Note: The as const assertion is necessary to ensure that the name property is not widened to string. This is necessary for the type-checking to work properly.

Documentation and API

Please visit the JSR documentation page for more information on how to use the library.

License

MIT.

Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@sallai/ask

Import symbol

import * as ask from "@sallai/ask";

---- OR ----

Import directly with a jsr specifier

import * as ask from "jsr:@sallai/ask";