Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/enquirer/prompt-sort

This repository has been archived, use the built-in sort prompt in Enquirer instead.
https://github.com/enquirer/prompt-sort

items list order prompt sort

Last synced: about 2 months ago
JSON representation

This repository has been archived, use the built-in sort prompt in Enquirer instead.

Awesome Lists containing this project

README

        

# prompt-sort [![NPM version](https://img.shields.io/npm/v/prompt-sort.svg?style=flat)](https://www.npmjs.com/package/prompt-sort) [![NPM monthly downloads](https://img.shields.io/npm/dm/prompt-sort.svg?style=flat)](https://npmjs.org/package/prompt-sort) [![NPM total downloads](https://img.shields.io/npm/dt/prompt-sort.svg?style=flat)](https://npmjs.org/package/prompt-sort)

> Prompt that allows the user to re-order items in a list of choices.

**Re-order choices**

Use shift+up or shift+down to re-order list items.

![prompt-sort example](https://raw.githubusercontent.com/enquirer/prompt-sort/master/docs/example-sort.gif)

**Customize rendering**

_(you can do this kind of customization with any prompt)_

![prompt-sort customized rendering](https://raw.githubusercontent.com/enquirer/prompt-sort/master/docs/example-customized.gif)

## Usage

**Heads up!**

The colors used in the example were added just for that example. See how that works in [examples/prompt.js](examples/prompt.js).

```js
var Prompt = require('prompt-sort');
var prompt = new Prompt({
name: 'colors',
message: 'Sort colors from most to least favorite',
choices: [
'green',
'red',
'yellow'
]
});

// promise
prompt.run()
.then(function(answer) {
console.log(answer);
});

// or async
prompt.ask(function(answer) {
console.log(answer);
});
```

## Enquirer usage

Register as a plugin with [enquirer](http://enquirer.io):

```js
var Enquirer = require('enquirer');
var enquirer = new Enquirer();

enquirer.register('readme', require('prompt-sort'));
```

### Enquirer examples

[Enquirer](http://enquirer.io) supports both the declarative inquirer-style question format and a functional format using the `.question` method:

**Declarative format**

Questions can be defined as an array of objects, or a single question object:

```js
var questions = [
{
type: 'sort', // <= define the prompt "type"
name: 'colors',
message: 'Sort colors from most to least favorite',
choices: [
'green',
'red',
'yellow'
]
}
];

enquirer.ask(questions)
.then(function(answers) {
console.log(answers)
});
```

**Expressive format**

Functional style questions.

```js
enquirer.question('colors', {
type: 'sort',
message: 'Sort colors from most to least favorite',
choices: [
'green',
'red',
'yellow'
]
});

enquirer.ask(['colors'])
.then(function(answers) {
console.log(answers)
});
```

## About

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

### Author

**Brian Woodward**

* [github/doowb](https://github.com/doowb)
* [twitter/doowb](https://twitter.com/doowb)

### License

Copyright © 2017, [Brian Woodward](https://github.com/doowb).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 05, 2017._