Node Popup
Simulates browser-style popups (alert, confirm, and prompt) from the commandline using a promise based API. Additional alerts (choose, choosedropdown, and choosemultiple)
Note: this project uses carlo and you'll need a copy of chrome installed for this it to work.
Demo
This demo shows the six different types of included popups.
Note: The last three questions will be graded
git clone <this repository>cd <cloned folder>npm installnpm run demo
Installation
npm install node-popup
Export
Common JS Module
The default export is a common js module.
const popup = ;
const popup = ;
Bundler
If you're using some sort of package buldler, you can import the default module as an es6 module.
;
Typescript Source
The Typescript source is available... especially useful when bundled as a submodule.
;
ES Module
An ecmascript module is available for use with node's "--experimental-modules" flag. Note: since this is experimental, this may not work.
;
Usage
Alert
Simulate an alert box.
;;
Confirm
Simulate a confirm box.
Note: popup functions will retun a promise that will be rejected if the window is closed or the "cancel" button is clicked.
;const main = { try await ; console;// OK button clicked catcherror console;// cancel button clicked };
Prompt
Simulate a prompt box.
Note: The answer returned is a string.
;const main = { try const name = await ; console;// OK button clicked catcherror console;// cancel button clicked };
Choose and Choosedropdown
Like prompt, but with multiple choices instead of a free text box.
Using choose will present a list of answers as radio buttons.
;const main = { try const name = await ; console;// OK button clicked catcherror console;// cancel button clicked };
Using choosedropdown will present a list of answers as radio buttons.
;const main = { try const choice = await ; console;// OK button clicked catcherror console;// cancel button clicked };
Choosemultiple
Like choose, but with multiple answers selected via checkboxes.
Note: The answer returned is an array of strings.
;const main = { try const choices = await ; console;// OK button clicked catcherror console;// cancel button clicked };
Custom Popups
You can create customized popups.
; const customizedPopup = ;
Debugging
This can be useful for quick debugging; but should be viewed as an anti-pattern.