Cliffy

Number

The Number prompt is a simple number input with support for auto suggestions.

import { Number } from "https://deno.land/x/cliffy@v0.25.7/prompt/number.ts";

const age: number = await Number.prompt("How old are you?");Copy
$ deno run https://deno.land/x/cliffy@v0.25.7/examples/prompt/number.tsCopy

Options

The Number prompt implements all base and auto suggestion options and the following prompt specific options.

Min input value

The min option specifies the minimum input value. Defaults to -Infinity.

Max input value

The max option specifies the maximum input value. Defaults to Infinity.

Decimal value

You can allow floating point inputs with the float option which defaults to false.

The round option specifies the number of decimals to round. Defaults to 2.

List pointer

With the listPointer you specify the list pointer icon. Default is .

Display usage info

The info option enables the info bar which displays some usage information.

Auto suggestions

Tab-completions can be enabled with the suggestions and/or id option. If an id is provided, the value will be saved to the local storage using the id as local storage key. With suggestions you can provide some default suggestions. Both options can be defined at the same time. You can read more about auto suggestions here.

i

❕ The id option requires deno >= 1.10 and the --location flag. Since deno 1.16.0 the --location flag is optional.

import { Number } from "https://deno.land/x/cliffy@v0.25.7/prompt/number.ts";

const color: number = await Number.prompt({
  message: "Choose a number",
  id: "<local-storage-key>",
  suggestions: [
    "111",
    "222",
    "333",
  ],
});

console.log({ color });Copy