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 🙏

© 2026 – Pkg Stats / Ryan Hefner

dialog-js2.0

v2.0.1

Published

A lightweight, modern, and dependency-free JavaScript library for creating asynchronous, accessible native modal dialogs and toasts. Powered by the native HTML5 `<dialog>` element and fully compatible with JS Modules (ESM) and, of course, a simple option

Downloads

548

Readme

Dialog JS2.0

A lightweight, modern, and dependency-free JavaScript library for creating asynchronous, accessible native modal dialogs and toasts. Its weight is just (8kb). Powered by the native HTML5 <dialog> element and fully compatible with JS Modules (ESM).

🔔 NOTE ABOUT BUGS 🐞

We have become aware about the behavior of Toast() method called into of .then() 
method control process. We are implementing the solution in our library (Dev and Minified) 
but we will publish the official fixed version in NPM after several validation tests.

Features

  • Asynchronous API: Every modal (Alert, Confirm, Prompt) returns a Promise, allowing clean async/await syntax.
  • Zero Dependencies: Built entirely with native web standards.
  • Fully Animated SVGs: Includes responsive, modern vector icons for different states (SUCCESS, ERROR, WARNING, QUESTION, INFO).
  • Accessible: Uses native browser modal behaviors (showModal()), trap-focus, and supports closing via the Esc key or backdrop clicks.
  • CSS files: You can implement this library with four differents CSS pre-built designs. You can choose between (Default, Dark, iOS, Android) themes or take one CSS file and share it as a model with an A.I. platform to create your own CSS design keeping the same CSS classes pre-built.

Installation & Usage

1. Via NPM (ES Modules)

Install the package in your project:

npm i dialog-js2.0

Import and use it in your JavaScript file:

import { Dialog2 } from 'dialogJS2.0.js';

2. Via CDN

You can also use it directly in the browser via native script modules:

<script type="module">
    import { Dialog2 } from './assets/js/dialogJS2.0.js';
    window.Dialog2 = Dialog2;
</script>

Add this code in the <head> section in your HTML file(s) after download this library. window.dialog2 expose the DialogJS2 object in the window global object. This way able you to call the Dialog2 object into your JS code.


3. CSS styles

⚠️ Note: To make the modals look stunning, make sure to link or include the companion CSS file in your project to expose CSS classes for its Dialog Library.

The default CSS file for this library is dialogJS2-default-theme.css. Reference this CSS file in the <head> section of every HTML file you include to your project.

<link rel="stylesheet" href="./assets/css/dialogJS2-default-theme.css">

Available Styles

Check our offer about different pre-built CSS styles.

  • Apple mobile (iOS - iPadOS)
  • Android (Material 3)
  • Dark theme (same as default but dark)
  • Default theme (of course the main or base option)

API Reference

Alert

Dialog2.Alert(title, message, icon, okButtonText)

Displays an alert box with an 'Ok' button. Resolves to true when closed or null if cancelled via ESC.

|Parameter|Type|Default|Description| |-|-|-|-| |title|string|Required|Title text of the dialog.| |message|string|Required|Body content/message.| |icon|string|'INFO'|Icon type: SUCCESS, ERROR, WARNING, QUESTION, INFO.| |okButtonText|string|'Ok'|Label for the confirmation button.|

Example:

await Dialog2.Alert(
                'System Updated', 
                'All changes have been successfully saved.', 
                'SUCCESS', 
                'Got it!'
);

Confirm

Dialog2.Confirm(title, message, icon, okButtonText, cancelButtonText)

Displays a confirmation dialog box with two buttons. Resolves to true if the user confirms, and false if they cancel or click the backdrop.

|Parameter|Type|Default|Description| |-|-|-|-| |title|string|Required|Title text of the dialog.| |message|string|Required|Question or statement text.| |icon|string|'QUESTION'|"Icon type: SUCCESS, ERROR, WARNING, QUESTION, INFO."| |okButtonText|string|'Confirm'|Label for the positive action button.| |cancelButtonText|string|'Cancel'|Label for the negative action button.|

Example:

const isDeleted = await Dialog2.Confirm(
                            'Delete File', 
                            'Are you sure you want to delete this report?', 
                            'WARNING', 
                            'Yes, delete', 
                            'No, keep it'
                        );

if (isDeleted) {
    // Proceed with deletion logic
}

Prompt

Dialog2.Prompt(title, message, placeholder, inputType, okButtonText, cancelButtonText)

|Parameter|Type|Default|Description| |-|-|-|-| |title|string|Required|Title text of the prompt.| |message|string|Required|Descriptive text guiding the input.| |placeholder|string|''|Placeholder text inside the input box.| |inputType|string|'text'|"The HTML input type (e.g., text, number, password, email)."| |okButtonText|string|'Confirm'|Label for the submission button.| |cancelButtonText|string|'Cancel'|Label for the cancellation button.|

Example:

const userEmail = await Dialog2.Prompt(
                            'Newsletter', 
                            'Please enter your email:', 
                            '[email protected]', 
                            'email'
                        );

if (userEmail) {
    console.log(`Subscribed email: ${userEmail}`);
}

Toast

Dialog2.Toast(message, icon, duration, position) Fires a non-blocking temporary notification stack on the screen with a timed visual progress bar.

|Parameter|Type|Default|Description| |-|-|-|-| |message|string|Required|Message to show in the toast.| |icon|string|'INFO'|Icon type: SUCCESS, ERROR, WARNING, QUESTION, INFO.| |duration|number|3000|Auto-dismiss timer in milliseconds.| |position|string|'top-right'|Toast placement: top-left, top-center, top-right.|

Example:

Dialog2.Toast(
        'Connection lost. Retrying...', 
        'WARNING', 
        5000, 
        'top-center'
);

About

Dialog2.About()

Triggers an informational Alert dialog displaying the library's built-in version, copyright credentials, and license notice.

Dialog2.About();

Promise base code

If you prefer to implement a JS logic by using a .then() Promise control method after pressing Accept or Cancel in a Dialog2 method, check the folowwing sample code:

Dialog2.Confirm(
            'Your dialog title', 
            'Can you confirm to Delete this file?', 
            'QUESTION', 
            'Confirm', 
            'Cancel'
        )
        .then((result) => {
            if (result === true) {
                // your logic here
            } else {
                // another logic after cancel
            }
});

Every Dialog method except Toast() returns a true boolean value when the user press the Ok button, or a false boolean value when the user press the Cancel button. If the user press the ESC key, the dialog will close and the Promise returns null.

Keep this return params in mind and make a full test in different scenarios to apply the best practices in your code.

License & Credits

Developed by Fernando Omar Luna.

This library is free to use in any personal or open-source projects. If you are integrating this library into a commercial application or a popular platform, attributing the author in your app's credits/acknowledgments section is highly appreciated.