Prompt that autocompletes as you type. Can be used standalone or as a plugin for Enquirer. (Note that this prompt does not yet work with the latest prompt base).
Switch branches/tags
Nothing to show
Clone or download
Latest commit ea9daf3 Oct 19, 2017
Permalink
Failed to load latest commit information.
.github first release Oct 13, 2016
examples adds example Oct 19, 2017
.editorconfig run update Oct 19, 2017
.eslintrc.json run update Oct 19, 2017
.gitattributes first release Oct 13, 2016
.gitignore run update Oct 19, 2017
.verb.md rename, since `prompt-autocomplete` is taken Oct 13, 2016
LICENSE run update Oct 19, 2017
README.md fix links Oct 13, 2016
example.gif first release Oct 13, 2016
index.js make comparison more specific Oct 19, 2017
package.json 0.1.2 Oct 19, 2017

README.md

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.