# enquirer-editor

> An editor prompt for enquirer.js

Latest version **1.0.0** (published 2019-12-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install enquirer-editor
pnpm add enquirer-editor
yarn add enquirer-editor
bun add enquirer-editor
```

## 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.0.0 |
| Published | 2019-12-31 |
| First published | 2019-12-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Ginsm |
| Maintainers | ginsm |
| Keywords | enquirer-editor, editor-prompt, prompt, editor, enquirer, commandline, cli, input |

## Links

- npm: https://www.npmjs.com/package/enquirer-editor
- Repository: https://github.com/ginsm/enquirer-editor
- Homepage: https://github.com/ginsm/enquirer-editor#readme
- Issues: https://github.com/ginsm/enquirer-editor/issues
- npm.io page: https://npm.io/package/enquirer-editor

## Dependencies (2)

- [enquirer](https://npm.io/package/enquirer.md) ^2.3.2
- [external-editor](https://npm.io/package/external-editor.md) ^3.1.0

## Recent versions

- 1.0.0 (latest) — 2019-12-31

## README

# Enquirer Editor

> A prompt built with [enquirer](https://www.npmjs.com/package/enquirer) that spawns a temporary editor using the preferred editor (`$VISUAL` or `$EDITOR`); it will default to Vim or Notepad. The contents of the editor will be returned once the user saves the file. The content can be validated or altered upon being submitted.

&nbsp;

## **Install**

```
npm i enquirer-editor
```

&nbsp;

## **Demonstration**

![Editor Preview](./resources/editor.gif)

&nbsp;

## **Usage**

There are two ways to use `enquirer-editor` — as a standalone prompt or as a plugin for enquirer (which allows the usage of other prompts).

&nbsp;

### **Standalone Prompt**
```javascript
// Import the prompt
const EditorPrompt = require('enquirer-editor');

// Create a new instance of the prompt (name not required)
const prompt = new EditorPrompt({
  type: 'editor',
  message: 'Please write a short bio of at least 3 lines',
  initial: 'Start writing!',
  validate: function (response) {
    if (response.split('\n').length < 4) {
      return 'The bio must be at least 3 lines.';
    }
    return true;
  },
});

// Run the prompt
prompt.run()
    .then(console.log)
    .catch(console.error);
```
&nbsp;

### **Plugin Prompt**
```javascript
// Import enquirer and the editor prompt
const Enquirer = require('enquirer');
const EditorPrompt = require('enquirer-editor');

// Create a new instance of enquirer and register the prompt
const enquirer = new Enquirer();
enquirer.register('editor', EditorPrompt);

// Create your questions (name required)
const questions = [
  {
    type: 'editor',
    name: 'bio',
    message: 'Please write a short bio of at least 3 lines',
    initial: 'Start writing!',
    validate: function (response) {
      if (response.split('\n').length < 4) {
        return 'The bio must be at least 3 lines.';
      }
      return true;
    },
  },
];

// Run prompt with your questions
enquirer.prompt(questions)
    .then(console.log)
    .catch(console.error);
```

&nbsp;

### **Prompt Options**

| option | description | type | default |
| :--- | :--- | :--- | :--- |
| type | The prompt type (`editor`) | string | |
| name | The property name for the prompt's output | string | |
| message | The message that will be displayed during the prompt | string | this.type |
| initial | The initial value for the editor | string | '' |
| validate | A function to validate the submitted output | function | |
| result | A function to alter the submitted output | function | |

&nbsp;

## **Credit**

This prompt was designed based off of [inquirer](https://www.npmjs.com/package/inquirer)'s editor prompt and uses the same editor as the [prompt-editor](https://www.npmjs.com/package/prompt-editor) package. It works with the latest version of [enquirer](https://www.npmjs.com/package/enquirer) (v2.3.2).

&nbsp;

I wrote this for my own personal use but I'm open to feature requests. Feel free to report an [issue](https://github.com/ginsm/enquirer-editor/issues) or request a feature! Thank you for reading. 😄

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