Gathering detailed insights and metrics for inquirer-autocomplete-standalone
Gathering detailed insights and metrics for inquirer-autocomplete-standalone
Gathering detailed insights and metrics for inquirer-autocomplete-standalone
Gathering detailed insights and metrics for inquirer-autocomplete-standalone
npm install inquirer-autocomplete-standalone
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
354 Stars
311 Commits
82 Forks
3 Watching
8 Branches
23 Contributors
Updated on 08 Nov 2024
JavaScript (57.16%)
TypeScript (42.84%)
Cumulative downloads
Total Downloads
Last day
-5.9%
25,772
Compared to previous day
Last week
2.7%
145,855
Compared to previous week
Last month
14.3%
610,348
Compared to previous month
Last year
1,779.3%
4,684,977
Compared to previous year
4
2
Standalone autocomplete prompt for the CLI based on inquirer core.
Allows you to show dynamic choices in a list based on user input, both synchronous or asynchronous, allowing you to connect to an external service.
npm install inquirer-autocomplete-standalone
This is a native ES module package. If you are using it with commonjs you need to import it like this:
1async function main() { 2 const { default: autocomplete, Separator } = await import( 3 'inquirer-autocomplete-standalone' 4 ); 5 const answer = await autocomplete({}); 6} 7 8main();
If you are using it with typescript see here for examples of how to use it if emitting commonjs or esm from your typescript.
If you want the legacy version used with inquirer version 9 and below then that is located here and can be installed with:
1npm install inquirer-autocomplete-prompt
That version will still be maintained for bugs and other issues, but is not the recommended way to use this prompt. This is following the change that Inquirer itself chose. Now the preferred way is to have standalone prompts that you can pick and choose from.
Run a quick demo locally with
1npx inquirer-autocomplete-demo
1import autocomplete from 'inquirer-autocomplete-standalone'; 2import { searchCountries } = './some-external-api'; 3 4const answer = await autocomplete({ 5 message: 'Travel from what country?', 6 source: async (input) => { 7 const filteredCountries = await searchCountries(input) 8 return filteredCountries.map(country => { 9 return { 10 value: country, 11 description: `${country} is a great place to visit` 12 } 13 }) 14 } 15}) 16 17// user searches and selects a country from the returned list 18console.log(answer) // Norway
The generic type Value
is whatever type the value of your choices are.
Property | Type | Required | Description |
---|---|---|---|
message | string | yes | The question to ask |
source | (input?: string) => Promise<Choice<Value> | Separator> | Choice<Value> | Separator | yes | A function that will be called first once with undefined at the start. Then later with whatever value the user has typed. See table below for full description of the Choice<Value> type. Can also return choices synchronous. |
transformer | (string, { isFinal: boolean }) => string | no | Transform/Format the raw value entered by the user. Once the prompt is completed, isFinal will be true. This function is purely visual, modify the answer in your code if needed. |
validate | (value: Value) => boolean | string | Promise<string | boolean> | no | On submit, validate the filtered answered content. When returning a string, it'll be used as the error message displayed to the user. Note: returning a rejected promise, we'll assume a code error happened and crash. |
default | string | no | If suggestOnly is true : will select that value if pressing enter and no input. If false : will select the choice with this value in the list when source resolves. |
emptyText | string | no | The text shown if the source function returns no results. Default: No results... |
pageSize | number | no | By default, lists of choice longer than 7 will be paginated. Use this option to control how many choices will appear on the screen at once. |
searchText | string | no | The text shown when the promise is pending. Default: Searching... |
suggestOnly | boolean | no | Default false . If false you must select one of the supplied choices in the list. You select by pressing enter. If true , pressing enter will select any text currently entered, regardless if of what is selected in the list. To choose one of the choices in the list, press tab to make your input the value of that choice. |
1type Choice<Value> = { 2 value: Value; 3 name?: string; 4 description?: string; 5 disabled?: boolean | string; 6};
Property | Type | Required | Description |
---|---|---|---|
value | any | yes | The value that will be returned from the prompt when the question has been answered. Should be string if name is absent. If not it is stringified for display. |
name | string | no | The text to display for the choice. |
description | string | no | Any extra description to show below the list when that choice is selected. |
disabled | boolean | string | no | Set to false to disable the choice for selection and to a string to disable it but with a custom text. |
You can also render any Separator to group choices.
1import autocomplete, { Separator } from 'inquirer-autocomplete-standalone'; 2 3const answer = await autocomplete({ 4 message: 'Travel from what country?', 5 source: async (input) => { 6 return [ 7 new Separator('Africa'), 8 new Separator(), 9 { 10 value: 'Egypt', 11 }, 12 new Separator('Europe'), 13 new Separator(), 14 { 15 value: 'Norway', 16 }, 17 ]; 18 }, 19});
? Travel from what country? (Use arrow keys or type to search)
Africa
──────────────
❯ Egypt
Europe
──────────────
Norway
ISC
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
16 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More