# inquirer-tree-prompt

> Inquirer tree prompt

Latest version **1.1.2** (published 2021-04-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install inquirer-tree-prompt
pnpm add inquirer-tree-prompt
yarn add inquirer-tree-prompt
bun add inquirer-tree-prompt
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2021-04-23 |
| First published | 2021-04-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 15.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Ben Schmidt |
| Maintainers | insightfuls |
| Keywords | inquirer, tree, prompt |

## Links

- npm: https://www.npmjs.com/package/inquirer-tree-prompt
- Repository: https://github.com/insightfuls/inquirer-tree-prompt
- Homepage: https://github.com/insightfuls/inquirer-tree-prompt#readme
- Issues: https://github.com/insightfuls/inquirer-tree-prompt/issues
- npm.io page: https://npm.io/package/inquirer-tree-prompt

## Dependencies (5)

- [rxjs](https://npm.io/package/rxjs.md) ^6.5.2
- [chalk](https://npm.io/package/chalk.md) ^2.4.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [figures](https://npm.io/package/figures.md) ^3.2.0
- [cli-cursor](https://npm.io/package/cli-cursor.md) ^3.1.0

## 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.1.2 (latest) — 2021-04-23
- 1.1.1 — 2021-04-23
- 1.1.0 — 2021-04-23
- 1.0.1 — 2021-04-20
- 1.0.0 — 2021-04-20

## README

## Inquirer Tree Prompt

Heavily based on [inquirer-file-tree-selection](https://github.com/anc95/inquirer-file-tree-selection/blob/master/index.js) by `anc95`.

### QuickDemo

![QuickDemo](./example/screenshot.gif)

### Install

```
npm install inquirer-tree-prompt
```

### Usage

```
const TreePrompt = require('inquirer-tree-prompt');

inquirer.registerPrompt('tree', TreePrompt);

inquirer.prompt({
    type: 'tree',
    ...
})
```

### Options

Takes `type`, `name`, `message`, `tree`, [`filter`, `validate`, `transformer`, `pageSize`, `loop`, `onlyShowValid`, `hideChildrenOfValid`, `multiple`] properties.

The extra options that this plugin provides are:

- `tree`: (Array) list of tree items or (optionally asynchronous) function to obtain them; items are strings or objects with:
  - `name`: (String) to display in list; must provide this or `value`
  - `value`: (String) to put in answers hash; must provide this or `name`
  - `short`: (String) to display after selection
  - `open`: (Boolean) whether the item is expanded or collapsed
  - `children`: (Array or Function) list of child tree items or (optionally asynchronous) function to obtain them; function may return replacement item instead of just list of children

- `onlyShowValid`: (Boolean) if true, will only show valid items (if `validate` is provided). Default: false.

- `hideChildrenOfValid`: (Boolean) if true, will hide children of valid items (if `validate` is provided). Default: false.

- `transformer`: (Function) a hook function to transform the display of item's value (when `name` is not given).

- `multiple`: (Boolean) if true, will enable to select multiple items. Default: false.

### Example

```
const inquirer = require('inquirer');
const TreePrompt = require('inquirer-tree-prompt');

inquirer.registerPrompt('tree', TreePrompt);

inquirer
    .prompt([
        {
            type: 'tree',
            name: 'location',
            message: 'Where is my phone?',
            tree: [
                {
                    value: "in the house",
                    open: true,
                    children: [
                        {
                            value: "in the living room",
                            children: [
                                "on the sofa",
                                "on the TV cabinet"
                            ]
                        },
                        {
                            value: "in the bedroom",
                            children: [
                                "under the bedclothes",
                                "on the bedside table"
                            ]
                        },
                        "in the bathroom"
                    ]
                },
                {
                    value: "in the car",
                    children: [
                        "on the dash",
                        "in the compartment",
                        "on the seat"
                    ]
                }
            ]
        }
    ])
    .then(answers => {
        console.log(JSON.stringify(answers))
    });
```

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