40

confirmation.js: A simple Node tool to replicate Browser's confirm popup...

 5 years ago
source link: https://www.tuicool.com/articles/hit/yqUzuej
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

:interrobang: confirmation

A simple Node tool to have Browser's confirm popup on your CLI.

63yaQzi.png!web

Installation

yarn add confirmation

Usage

if (await confirmation('Are you sure?')) {
  console.log('Yay!');
} else {
  console.log('Oops!');
}

API

confirmation(message) : bool

Shows a message and OK and Cancel buttons.

Example :

const result = await confirmation('You will delete your items, are you sure?')

confirmation(title, message) : bool

Shows a message with a title and OK and Cancel buttons.

Example :

const result = await confirmation('Warning', 'You will delete your items, are you sure?')

confirmation(title, message, ok, cancel) : bool

Shows a message with a title and custom OK and custom Cancel buttons.

Example :

const result = await confirmation(
  'Warning',
  'You will delete your items, are you sure?',
  'I am sure',
  'No!'
)

The Key bindings

The O for _O_K and C for _C_ancel 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.

License

MIT © Fatih Kadir Akin


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK