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

railroad-toasts

v1.2.0

Published

Toast notifications and confirm dialogs for web applications. Built on Railroad Runtime philosophy.

Readme

Railroad Toasts

Toast notifications and confirm dialogs for web applications.

Part of the Railroad ecosystem — Pure DOM utilities that work standalone or with Railroad Runtime.

Zero dependencies. ~3KB minified.


Features

✅ Toast notifications (success, error, warn, info)
✅ Animated confirm dialogs
✅ Auto-dismiss or click-to-dismiss
✅ HTMX integration (optional)
✅ Replaces alert() and confirm()
✅ Smooth slide-in animations
✅ Customizable colors and duration


Installation

CDN (fastest):

<script src="https://unpkg.com/[email protected]/dist/toasts.min.js"></script>

npm:

npm install railroad-toasts

Quick Start

Basic Toast

toast('Settings saved!', 'success');
toast('Something went wrong', 'error');
toast('Please review this', 'warn');
toast('Just so you know', 'info');

Confirm Dialog

confirm('Delete this item?').then(confirmed => {
  if (confirmed) {
    // User clicked "Confirm"
  }
});

// With custom button text
confirm('Deploy to production?', {
  confirmText: 'Deploy',
  cancelText: 'Cancel'
}).then(confirmed => {
  if (confirmed) {
    deploy();
  }
});

Custom Duration

// Show for 10 seconds
toast('Important message', 'warn', 10000);

// Never auto-dismiss (must click to dismiss)
toast('Permanent message', 'info', 0);

API

toast(message, type, duration)

Show a toast notification.

Parameters:

  • message (string) - Text to display
  • type (string) - Type: 'success', 'error', 'warn', 'info' (default: 'info')
  • duration (number) - Auto-dismiss duration in ms (default: 4000, use 0 for manual dismiss only)

Example:

toast('File uploaded successfully', 'success');

confirm(message, options)

Show a confirm dialog.

Parameters:

  • message (string) - Question to ask
  • options (object, optional):
    • confirmText (string) - Text for confirm button (default: 'Confirm')
    • cancelText (string) - Text for cancel button (default: 'Cancel')

Returns: Promise<boolean> - Resolves to true if confirmed, false if canceled

Example:

confirm('Delete this user?', {
  confirmText: 'Delete',
  cancelText: 'Keep'
}).then(result => {
  if (result) {
    deleteUser();
  }
});

HTMX Integration

Railroad Toasts automatically integrates with HTMX if present:

1. Override hx-confirm

<button hx-delete="/api/users/123" hx-confirm="Delete this user?">
  Delete
</button>

The confirm dialog will appear automatically (no default confirm() popup).

2. Show Toast via Response Header

Backend (any framework):

# Django
response['HX-Trigger'] = json.dumps({"toast": {"message": "User deleted", "type": "success"}})

# Express.js
res.header('HX-Trigger', JSON.stringify({toast: {message: 'User deleted', type: 'success'}}));

Frontend: Toast appears automatically.

3. Error Handling

Toasts automatically appear for HTMX errors:

  • htmx:responseError → Shows "Request failed (HTTP 500)"
  • htmx:sendError → Shows "Network error — server unreachable"

Styling

Default Colors

  • Success: Green (#16a34a)
  • Error: Red (#dc2626)
  • Warn: Amber (#d97706)
  • Info: Blue (#2563eb)

Customize Colors

// Modify color palette
RailroadToasts.colors.success.bg = 'rgba(34, 197, 94, 0.95)';
RailroadToasts.colors.success.border = '#22c55e';

Position

Toasts appear in the top-right by default. Modify via CSS:

#railroad-toast-container {
  top: 20px !important;
  right: 20px !important;
  /* Or change to bottom-left: */
  /* bottom: 20px !important; */
  /* left: 20px !important; */
}

Examples

Replace alert() Globally

// This happens automatically when railroad-toasts loads
alert('This will be a toast!');  // Shows red error toast

Form Validation

document.querySelector('form').addEventListener('submit', async (e) => {
  e.preventDefault();
  
  const confirmed = await confirm('Submit this form?');
  if (!confirmed) return;
  
  try {
    await fetch('/api/submit', {method: 'POST', body: new FormData(e.target)});
    toast('Form submitted successfully', 'success');
  } catch (err) {
    toast('Submission failed', 'error');
  }
});

Progress Notifications

toast('Starting upload...', 'info');

uploadFile().then(() => {
  toast('Upload complete!', 'success');
}).catch(err => {
  toast('Upload failed: ' + err.message, 'error');
});

Works With

✅ Vanilla JavaScript (no dependencies)
✅ HTMX (optional integration)
✅ Alpine.js
✅ Turbo/Hotwire
✅ Any framework or no framework


Why Railroad Toasts?

Other libraries:

  • Require configuration
  • Large bundle sizes
  • Complex APIs
  • Framework dependencies

Railroad Toasts:

  • Works out of the box
  • ~3KB minified
  • One function: toast(msg, type)
  • Zero dependencies

One line to get started:

<script src="https://unpkg.com/railroad-toasts"></script>

License

MIT

Contributing

Issues and PRs welcome at https://github.com/faroncoder/railroad-toasts


Part of the Railroad ecosystem:

Not a framework. Just utilities.