@msg-labs/cli-prompt-list

1.2.0 • Public • Published

cli-prompt-list

Installation

npm install --save @msg-labs/cli-prompt-list

Usage

Default functionality:

const promptForRepo = require( '@msg-labs/cli-prompt-list' );

const repos = [
  'aredridel/node-bin-gen',
  'axios/axios',
  'bitinn/node-fetch',
  'browserify/resolve',
  'chaijs/chai',
  'DefinitelyTyped/DefinitelyTyped',
  'isaacs/rimraf'
];

promptForRepo( repos )
    .then( response => console.dir( response ) );

For all the available options, see the API section.

API

type InteractiveList<T> = (
    candidates: Array<T>,
    prompt?: string,
    renderLine?: (
        candidate?: T,
        index?: number,
        candidates?: Array<T>,
        search?: string
    ) => string,
    searchOptions?: {
        input?: string,
        matchField?: (candidate: T) => any,
        compareFunction?: (
            a?: T,
            b?: T
        ) => boolean,
        limit?: number,
        sortCandidates?: boolean
    }
) => Promise<T>;
Parameter Type Default Description
candidates Array undefined List of elements to search
prompt string '> ' Text to be displayed next to the input
renderLine function candidate => candidate Used to transform the output of each line
searchOptions Object see below Custom search options
searchOptions.input string '' Initial input
searchOptions.matchField function candidate => String( candidate ) Selects which field will be used in the compare function
searchOptions.compareFunction function ( a, b ) => matchField( a).localeCompare( matchField( b ) ) Defines how fields will be sorted after the search
searchOptions.limit number undefined limits the amount of candidates in the output
searchOptions.sortCandidates boolean true alphabetically sorts the candidates

/@msg-labs/cli-prompt-list/

    Package Sidebar

    Install

    npm i @msg-labs/cli-prompt-list

    Weekly Downloads

    0

    Version

    1.2.0

    License

    WTFNMFPL-1.0

    Unpacked Size

    24.8 kB

    Total Files

    14

    Last publish

    Collaborators

    • msg-labs-bot
    • miguelsanchezgonzalez