# inquirer-select-pro

> An inquirer select that supports multiple selections and filtering.

Latest version **1.0.0-alpha.9** (published 2024-12-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install inquirer-select-pro
pnpm add inquirer-select-pro
yarn add inquirer-select-pro
bun add inquirer-select-pro
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.9 |
| Published | 2024-12-14 |
| First published | 2024-05-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 |
| Dependencies | 5 |
| Unpacked size | 267.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | jeffwcx |
| Maintainers | jeffone |
| Keywords | inquirer, prompts, cli, select, multiple, filter, autocomplete |

## Links

- npm: https://www.npmjs.com/package/inquirer-select-pro
- Repository: https://github.com/jeffwcx/inquirer-select-pro
- Homepage: https://github.com/jeffwcx/inquirer-select-pro#readme
- Issues: https://github.com/jeffwcx/inquirer-select-pro/issues
- npm.io page: https://npm.io/package/inquirer-select-pro

## Dependencies (5)

- [chalk](https://npm.io/package/chalk.md) ^5.3.0
- [ansi-escapes](https://npm.io/package/ansi-escapes.md) ^7.0.0
- [@inquirer/core](https://npm.io/package/@inquirer/core.md) ^8.1.0
- [@inquirer/type](https://npm.io/package/@inquirer/type.md) ^1.3.1
- [@inquirer/figures](https://npm.io/package/@inquirer/figures.md) ^1.0.1

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.0-alpha.9 (latest) — 2024-12-14
- 1.0.0-alpha.0 (alpha) — 2024-05-11
- 1.0.0-alpha.8 — 2024-10-29
- 1.0.0-alpha.7 — 2024-08-05
- 1.0.0-alpha.6 — 2024-06-26
- 1.0.0-alpha.5 — 2024-06-26
- 1.0.0-alpha.4 — 2024-05-13
- 1.0.0-alpha.3 — 2024-05-11
- 1.0.0-alpha.2 — 2024-05-11
- 1.0.0-alpha.1 — 2024-05-11

## README

# inquirer-select-pro

<a href="https://www.npmjs.com/package/inquirer-select-pro" target="_blank"><img alt="NPM Version" src="https://img.shields.io/npm/v/inquirer-select-pro"></a> <a href="https://codecov.io/gh/jeffwcx/inquirer-select-pro" target="_blank"><img alt="codecov" src="https://codecov.io/gh/jeffwcx/inquirer-select-pro/graph/badge.svg?token=tjROGqr2yx"></a> <a href="https://github.com/jeffwcx/inquirer-select-pro/actions?query=branch%3Amain" target="_blank"><img src="https://img.shields.io/github/actions/workflow/status/jeffwcx/inquirer-select-pro/.github/workflows/build.yml?branch=main" alt="CI" /></a>

An inquirer select that supports multiple selections and filtering/searching.

## Install

```bash
pnpm i inquirer-select-pro
```

```bash
npm i inquirer-select-pro
```

## Try now?

```bash
npx @jeffwcx/gitignore
```

[![asciicast](https://asciinema.org/a/658848.svg)](https://asciinema.org/a/658848)

> A CLI to generate a `.gitignore` file: [@jeffwcx/gitignore](https://github.com/jeffwcx/jeffwcx-config/blob/main/packages/gitignore).

## Usage

### Multiple selection and async data source

```ts
import { select } from 'inquirer-select-pro';
const answer = await select({
  message: 'select',
  options: async (input) => {
    const res = await fetch('<url>', {
      body: new URLSearchParams({ keyword: input }),
    });
    if (!res.ok) throw new Error('fail to get list!');
    return await res.json();
  },
});
```

### Radio mode

```ts
import { select } from 'inquirer-select-pro';
const answer = await select({
  message: 'select...',
  mutiple: false,
  options: [
    { name: 'Apple', value: 'apple' },
    { name: 'Banana', value: 'banana' },
  ],
});
```

### clearInputWhenSelected

Clear the filter input when the option is selected (also causes the option list to change).

### confirmDelete（multiple only）

The first time you try the delete key, it will focus on the option to be deleted, and the second time it will remove the focused option.

```ts
import { select } from 'inquirer-select-pro';
const answer = await select({
  message: 'select',
  confirmDelete: true,
  options: async (input) => {
    const res = await fetch('<url>', {
      body: new URLSearchParams({ keyword: input }),
    });
    if (!res.ok) throw new Error('fail to get list!');
    return await res.json();
  },
});
```

## API

### select()

An inquirer select that supports multiple selections and filtering

#### Parameters

- `config` [**_SelectProps_**](./src/types.ts#L198) <!-- -->**_\<Value, Multiple>_**

#### Returns

**_CancelablePromise_** <!-- -->**_\<Value>_**

#### Examples

```ts
import { select } from 'inquirer-select-pro';
const answer = await select({
  message: 'select',
  options: async (input) => {
    const res = await fetch('<url>', {
      body: new URLSearchParams({ keyword: input }),
    });
    if (!res.ok) throw new Error('fail to get list!');
    return await res.json();
  },
});
```

### useSelect()

> [!WARNING]
> This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

#### Type

```typescript
declare function useSelect<Value, Multiple extends boolean>(
  props: UseSelectOptions<Value, Multiple>,
): UseSelectReturnValue<Value>;
```

#### Parameters

- `props` [**_UseSelectOptions_**](./src/types.ts#L63)<!-- -->**_\<Value, Multiple>_**

#### Returns

[**_UseSelectReturnValue_**](./src/types.ts#L170)<!-- -->**_\<Value>_**

### Theming

#### Type

```ts
export type SelectTheme = {
  prefix: string;
  spinner: {
    interval: number;
    frames: string[];
  };
  icon: {
    checked: string;
    unchecked: string;
    cursor: string;
    inputCursor: string;
  };
  style: {
    answer: (text: string) => string;
    message: (text: string) => string;
    error: (text: string) => string;
    help: (text: string) => string;
    highlight: (text: string) => string;
    key: (text: string) => string;
    disabledOption: (text: string) => string;
    renderSelectedOptions: <T>(
      selectedOptions: ReadonlyArray<SelectOption<T>>,
      allOptions: ReadonlyArray<SelectOption<T> | Separator>,
    ) => string;
    emptyText: (text: string) => string;
    placeholder: (text: string) => string;
  };
  helpMode: 'always' | 'never' | 'auto';
};
```

#### Examples

```ts
await renderPrompt({
  message,
  placeholder: 'search',
  options: () => top100Films,
  pageSize: 2,
  instructions: false,
  theme: {
    icon: {
      inputCursor: 'filter: ',
      checked: ' √',
      unchecked: ' ',
    },
    style: {
      placeholder: (text: string) => `${text}...`,
    },
  },
});
```

The appearance is as follows:

```
? Choose movie:
filter:  The Shawshank Redemption (1994)
> √ The Shawshank Redemption (1994)
    The Godfather (1972)

```

## How to contribute？

1. Fork the project

2. Start development

```bash
git clone https://github.com/yourname/inquirer-select-pro.git
cd inquirer-select-pro
pnpm i
# Create a branch
git checkout -b my-new-feature
# Develop
pnpm dev
# Build
pnpm build
# Test
pnpm test
```

> [!NOTE]
> Running `pnpm dev` actually allows you to specify the demo directly.

Here is a list of available demos:

- local
- remote
- filter-remote
- filter-local

```bash
pnpm dev filter-remote
```

Parameters can also be fixed. The following parameters can be fixed:

- filter
- clearInputWhenSelected
- required
- loop
- multiple
- canToggleAll
- confirmDelete
- selectFocusedOnSubmit

```bash
pnpm dev filter-demo --multiple=false
```

3. Commit changes to your branch `git commit -am 'Add some feature'`

4. Push your branch `git push origin my-new-feature`

5. Submit a pull request

---
_Source: https://npm.io/package/inquirer-select-pro · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
