npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

plain-dialogs

v0.1.1

Published

HTML5 dialog element based alert, confirm, prompt; modal/non-modal variants, promisified API, no fancy CSS by default

Downloads

7

Readme

plain-dialogs

HTML5 dialog element based alert/confirm/prompt; modal/non-modal variants, promisified API, no fancy CSS by default.

Demo

npm i plain-dialogs

| file | lang | type | minified | | ----------------------- | ----- | ---------- | -------- | | dist/plain-dialogs.js | es6 | UMD | x | | index.mjs | es6 | es6 module | |

Use dialog-polyfil for non-Chromium browsers (just include .css & .js before plain-dialogs lib; you don't need to initialize anything).

An unstyled modal alert:

The same dialog after applying some CSS:

Why?

The Chromium team actively discourages us from using window.alert et al., sometimes even implicitly preventing us from doing so.

One of the alternatives is to use a "native" dialog element that is supported by Chrome since forever but is still under a flag in Firefox.

Unfortunately, this means that the old sync pattern of

let r = confirm('are you sure?')
if (r) erase_all_the_monies()

doesn't work w/ "new" dialog elements. To ask a user we need to create a <dialog> dom node, fill it w/ the text of the question, add 2 buttons w/ the proper event listeners, wait for an answer, remove the node from the document.

This is what this lib does automatically, allowing us to write:

plainDialogs.confirm('are you sure?').then(erase_all_the_monies)

or

let r = await plainDialogs.confirm2('are you sure?')
if (r) erase_all_the_monies()

API

Every fn return a promise. The last arg of every fn is an option hash. The default opts are:

{
    modal: true,
    escape: true,
    title: undefined
}

alert

> await plainDialogs.alert('Hi, mom!')
true

> await plainDialogs.alert('<h1>Hi, mom!</h1>', {escape: false})
true

confirm

Reject a promise on clicking Cancel:

> try { await plainDialogs.confirm('really?') } catch (e) { console.log(`result: ${e}`) }
result: false

confirm2

Return a promise that always resolves. Here, a user clicks Cancel:

> await plainDialogs.confirm2('really?')
false

prompt

Reject a promise on clicking Cancel:

> await plainDialogs.prompt('Діти, хто це?', 'Це їжачок.')
Uncaught (in promise) null

prompt2

Return a promise that always resolves. If a user clicks Cancel, resolves to null.

Styling

By default there's no styling whatsoever. Every fn creates a tmp <dialog> node w/ b59LdZ-dlg class. Create a dialog & use the Elements tab in Developer Tools to discover more. See test/smoke.js for examples.

.b59LdZ-dlg {
  width: 275px;
  background: red;
}

License

MIT.