Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/f/confirmation
A simple Node tool to replicate Browser's confirm popup on your CLI.
https://github.com/f/confirmation
Last synced: 18 days ago
JSON representation
A simple Node tool to replicate Browser's confirm popup on your CLI.
- Host: GitHub
- URL: https://github.com/f/confirmation
- Owner: f
- License: mit
- Created: 2019-02-24T02:45:50.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-02-24T22:30:22.000Z (over 5 years ago)
- Last Synced: 2024-10-12T13:10:59.765Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 4.01 MB
- Stars: 115
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ⁉️ confirmation
A simple Node tool to have Browser's `confirm` popup on your CLI.
![confirmation](resources/demo.gif?v1)
## Installation
```
yarn add confirmation
```## Usage
In an `async` function just call `await confirmation`.
```js
if (await confirmation('Are you sure?')) {
console.log('Yay!');
} else {
console.log('Oops!');
}
```![confirmation](resources/confirmation.png?v1)
## API
### `await confirmation(message) : bool`
Shows a message and `OK` and `Cancel` buttons.
_Example_:
```js
const result = await confirmation('You will delete your items, are you sure?')
```### `await confirmation(title, message) : bool`
Shows a message with a title and `OK` and `Cancel` buttons.
_Example_:
```js
const result = await confirmation('Warning', 'You will delete your items, are you sure?')
```### `await confirmation(title, message, ok, cancel) : bool`
Shows a message with a title and custom `OK` and custom `Cancel` buttons.
_Example_:
```js
const result = await confirmation(
'Warning',
'You will delete your items, are you sure?',
'I am sure',
'No!'
)
```## The Key bindings
The Y for **OK** and N for **Cancel** are the default key bindings.
When you customize your **OK** and **Cancel** buttons, the **first letter** will be the key binding. If you make **I am Sure** instead of **OK**, you'll need to press I to confirm.
### Example 1
_Example_:
```js
const result = await confirmation(
'Warning',
'You will delete your items, are you sure?',
'[O] OK',
'[X] Close'
)
```
Keymap:
- O to Confirm
- X to Close### Example 2
_Example_:
```js
const result = await confirmation(
'Warnin\'',
'Ye will scuttle yer items, are ye sure?',
'Aye',
'No'
)
```
Keymap:
- A (_A_ye) to Confirm
- N (_N_o) to Close## License
MIT © Fatih Kadir Akin