2.1.4 • Published 4 years ago

native-prompt v2.1.4

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

native-prompt

Create native prompts with Node.js and Electron

What is this?

While alert and confirm are both supported in Electron, prompt isn't (see this issue). native-prompt aims to fix this by allowing you to create prompt boxes that are native to the user's OS. As an added bonus, it also works in Node.js.

Screenshots

Windows

A prompt showing on Windows

Linux

A prompt showing on Linux

MacOS

A prompt showing on MacOS

Installation

Through NPM:

npm i native-prompt

...or the long way:

npm install native-prompt@latest --save

Usage

Synopsis

prompt (title, body, options)

title:string

The title you want to display at the top of the window

body:string

Any helpful text to go inside the message box

options: { defaultText?: string; mask?: boolean }

Any (optional) extra options (see below)

Options

defaultText?: string

The text you want to already be in the input box beforehand

mask?: boolean

Whether you want the box to have a hidden input

Examples

Importing

Javascript

const prompt = require('native-prompt')

Typescript

import prompt from 'native-prompt'

Async function usage

(async () => {
    const text = await prompt("This is a title.", "What would you really like to see next?", { defaultText: "Nothing" });
    if (text) {
        // Do something with the input
    } else {
        // The user either clicked cancel or left the space blank
    }
})()

Regular promise usage

prompt("This is a title.", "What would you really like to see next?", { defaultText: "Nothing" }).then(text => {
    if (text) {
        // Do something with the input
    } else {
        // The user either clicked cancel or left the space blank
    }
})

Masked textbox example

(async () => {
    const password = await prompt("Login", "Enter your password to log back in.", { mask: true });
    if (isCorrectPassword(password)) {
        // Log the user in
    } else {
        // The user's entered their username or password incorrect
    }
})()

Notes

  • If you plan on using asar to package your electron app, make sure to read this
  • For differences between 1.x and 2.x, see this wiki page.
2.1.4

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago