prompt-autocompletion

This repository has been archived, use the autocomplete prompt in Enquirer instead.

Showing:

Popularity

Downloads/wk

5.5K

GitHub Stars

12

Maintenance

Last Commit

4yrs ago

Contributors

3

Package

Dependencies

6

Size (min+gzip)

17.5KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

prompt-autocompletion NPM version NPM downloads

Prompt that autocompletes as you type. Can be used standalone or with a prompt system like enquirer

prompt-autocompletion example

Install

Install with npm:

$ npm install --save prompt-autocompletion

Example usage

var states = ['Alabama', 'Alaska', 'American Samoa', ...];
var AutoComplete = require('prompt-autocompletion');
var autocomplete = new AutoComplete({
  type: 'autocomplete',
  name: 'from',
  message: 'Select a state to travel from',
  source: searchStates
});

// promise
autocomplete.run()
  .then(function(answer) {
    console.log(answer);
  });

// or async
autocomplete
  .ask(function(answer) {
    console.log(answer);
  });

function searchStates(answers, input) {
  return new Promise(function(resolve) {
    resolve(states.filter(filter(input)));
  });
}

function filter(input) {
  return function(state) {
    return new RegExp(input, 'i').exec(state) !== null;
  };
}

Enquirer usage

var states = ['Alabama', 'Alaska', 'American Samoa', ...];
var Enquirer = require('enquirer');
var enquirer = new Enquirer();

enquirer.register('autocomplete', require('prompt-autocompletion'));
var questions = [
  {
    type: 'autocomplete',
    name: 'from',
    message: 'Select a state to travel from',
    source: searchStates
  },
  {
    type: 'autocomplete',
    name: 'to',
    message: 'Select a state to travel to',
    source: searchStates
  }
];

enquirer.ask(questions)
  .then(function(answers) {
    console.log(answers);
  })
  .catch(function(err) {
    console.log(err);
  });

function searchStates(answers, input) {
  return new Promise(function(resolve) {
    resolve(states.filter(filter(input)));
  });
}

function filter(input) {
  return function(state) {
    return new RegExp(input, 'i').exec(state) !== null;
  };
}

Prompts

Other prompt modules:

Attribution

This is entirely based on https://www.npmjs.com/package/inquirer-autocomplete-prompt Copyright (c) 2015, Martin Hansen martin@martinhansen.no

Thanks, Martin!

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for avice on opening issues, pull requests, and coding standards.

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb-generate-readme, v0.1.31, on October 13, 2016.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial