• Stars
    star
    343
  • Rank 123,371 (Top 3 %)
  • Language
    JavaScript
  • License
    ISC License
  • Created over 9 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Autocomplete prompt for inquirer

inquirer-autocomplete-prompt

Autocomplete prompt for inquirer

build status

Installation

npm install inquirer-autocomplete-prompt

inquirer v9 and inquirer-autocomplete-prompt v3 and higher are native esm modules, this mean you cannot use the commonjs syntax require('inquirer-autocomplete-prompt') anymore. If you want to learn more about using native esm in Node, I'd recommend reading the following guide. Alternatively, you can rely on an older version until you're ready to upgrade your environment:

npm install inquirer-autocomplete-prompt@^2.0.0

Usage

This prompt is anonymous, meaning you can register this prompt with the type name you please:

import inquirer from 'inquirer';
import inquirerPrompt from 'inquirer-autocomplete-prompt';

inquirer.registerPrompt('autocomplete', inquirerPrompt);
inquirer.prompt({
  type: 'autocomplete',
  ...
})

Change autocomplete to whatever you might prefer.

Options

Note: allowed options written inside square brackets ([]) are optional. Others are required.

type, name, message, source, [default, validate, filter, when, pageSize, prefix, suffix, askAnswered, loop, suggestOnly, searchText, emptyText]

See inquirer readme for meaning of all except source, suggestOnly, searchText and emptyText.

source will be called with previous answers object and the current user input each time the user types, it must return a promise (which resolves to an array of options).

source will be called once at at first before the user types anything with undefined as the value. If a new search is triggered by user input it maintains the correct order, meaning that if the first call completes after the second starts, the results of the first call are never displayed.

suggestOnly is default false. Setting it to true turns the input into a normal text input. Meaning that pressing enter selects whatever value you currently have. And pressing tab autocompletes the currently selected value in the list. This way you can accept manual input instead of forcing a selection from the list.

validate is called with the entered text when suggestOnly is set to true. When suggestOnly is false, validate is called with the choice object. In addition it is called with the answers object so far.

searchText Is the text shown when searching. Defaults: Searching...

emptyText Is the text shown if the search returns no results. Defaults: No results...

Example

import inquirer from 'inquirer';
import inquirerPrompt from 'inquirer-autocomplete-prompt';

inquirer.registerPrompt('autocomplete', inquirerPrompt);
inquirer
  .prompt([
    {
      type: 'autocomplete',
      name: 'from',
      message: 'Select a state to travel from',
      source: (answersSoFar, input) => myApi.searchStates(input),
    },
  ])
  .then((answers) => {
    // etc
  });

See also example.js for a working example.

I recommend using this package with fuzzy if you want fuzzy search. Again, see the example for a demonstration of this.

Autocomplete prompt

Credits

Martin Hansen

License

ISC

More Repositories

1

vue-vuelidate-jsonschema

Create vuelidate validation rules based on json schema
JavaScript
109
star
2

json-schema-merge-allof

Simplify your schema by combining allOf
JavaScript
96
star
3

vue-async-methods

Async method support for vue with relevant state variables for use in the UI.
JavaScript
68
star
4

json-hyper-schema

A javascript implementation of json hyper schema.
JavaScript
42
star
5

json-schema-compare

Compare json schemas correctly
JavaScript
16
star
6

lodash-requirejs-loader-plugin

A require js loader for lodash amd
JavaScript
4
star
7

jQuery.multiscrollfollow

A jquery plugin for creating gmail on android style following headers
JavaScript
4
star
8

jQuery-dependency

A jQuery plugin for creating dependencies between checkboxes/radiobuttons
JavaScript
3
star
9

generator-knockout-binding

Generates a standalone AMD based knockout binding with ready test setup, bower config, travis config, README, Grunt tasks, jshint config, editorconfig etc.
JavaScript
2
star
10

sinon-mock-server

A more elegant mock server based on sinon fake server
JavaScript
2
star
11

json-schema-intersects

A library to determine if a JSON schema has a logical intersection with another schema.
1
star
12

json-schema-subset

Determines if a json schema is a subset of another schema.
1
star
13

lodash-amd-import

Atom package for importing lodash amd packages.
JavaScript
1
star
14

swappable-mock-apis

JavaScript
1
star
15

json-schema-extractor

Extract properties from an object based on json schema
1
star
16

json-schema-conform

Takes an invalid object and modifies/deletes properties so that it conforms to a given JSON schema.
1
star
17

knockout.bindingHandlers.number

JavaScript
1
star
18

knockout-model

JavaScript
1
star