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

js-toast-notifier

v1.0.2

Published

ToastfierJS is a lightweight JavaScript library for customizable toast notifications, supporting dynamic positioning, themes, and notification types with icons—ideal for clean, dependency-free alerts in any web app.

Downloads

174

Readme

JS Toast Notifier

A lightweight toast notification package with anchor support, droplet-style connectors, and pause-on-hover functionality.

Features

  • 📍 Flexible positioning (top, bottom, left, right)
  • 📚 Automatic stacking of multiple notifications
  • 🔗 Anchor element support with droplet-style connectors
  • 🎨 Customizable themes and timeouts
  • ⏸️ Pause on hover functionality
  • ✨ Smooth animations with progress bar
  • 🚫 Optional close button
  • ♿ WCAG 2.1 accessible
  • 0️⃣ Zero dependencies

Installation

npm install js-toast-notifier

Basic Usage

import ToastNotifier from 'js-toast-notifier';

// Initialize with default options
const toast = new ToastNotifier();

// Show a basic toast
toast.show('Hello, World!');

// Show different types of toasts
toast.success('Operation completed!');
toast.error('Something went wrong!');
toast.info('Here is some information.');
toast.warning('Please be careful!');

Configuration Options

Global Configuration

When initializing the toast instance, you can set default options for all notifications:

const toast = new ToastNotifier({
  position: 'top-right',      // Default position
  timeout: 5000,             // Default timeout in milliseconds
  theme: 'light',           // Default theme
  showCloseButton: true,    // Show close button
  pauseOnHover: true,       // Pause timer on hover
  showProgress: true,       // Show progress bar
  progressHeight: '4px',    // Progress bar height
  progressColor: '#fff',    // Progress bar color
  progressBackground: 'rgba(255, 255, 255, 0.2)' // Progress background
});

Individual Toast Configuration

Each toast can override the global configuration:

// Custom themed toast
toast.show('Custom theme!', {
  theme: {
    backgroundColor: '#1a1a1a',
    textColor: '#ffffff'
  },
  customClass: 'my-custom-toast'
});

// Anchored toast with custom position
toast.show('Anchored to button!', {
  anchor: document.getElementById('my-button'),
  position: 'top',
  timeout: 3000
});

// Toast with custom progress bar
toast.show('Custom progress!', {
  progressHeight: '6px',
  progressColor: '#00ff00',
  progressBackground: 'rgba(0, 0, 0, 0.3)',
  pauseOnHover: true
});

// Infinite toast (no timeout)
toast.show('Will not auto-close', {
  timeout: 0,
  showProgress: false
});

API Reference

Constructor Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | position | string | 'top-right' | Toast position: 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right' | | timeout | number | 5000 | Auto-close duration in milliseconds. Set to 0 for no auto-close | | theme | string|object | 'light' | Theme name ('light'/'dark') or custom theme object | | showCloseButton | boolean | true | Show/hide close button | | pauseOnHover | boolean | true | Pause timer when hovering | | showProgress | boolean | true | Show/hide progress bar | | progressHeight | string | '4px' | Progress bar height | | progressColor | string | - | Progress bar color | | progressBackground | string | - | Progress bar background color |

Methods

show(message, options?)

Shows a toast notification with optional configuration.

toast.show('Message', {
  type: 'default',
  timeout: 3000,
  // ... other options
});

success(message, options?)

Shows a success toast.

toast.success('Operation completed!', {
  timeout: 3000
});

error(message, options?)

Shows an error toast.

toast.error('Failed to save!', {
  timeout: 0 // Won't auto-close
});

info(message, options?)

Shows an info toast.

toast.info('New updates available');

warning(message, options?)

Shows a warning toast.

toast.warning('Low disk space');

Custom Themes

Create custom themes by providing a theme object:

const toast = new ToastNotifier({
  theme: {
    backgroundColor: '#1a1a1a',
    textColor: '#ffffff',
    iconColor: '#00ff00' // Optional, defaults to textColor
  }
});

CSS Customization

The package provides CSS classes for custom styling:

/* Custom toast styling */
.toast {
  /* Your custom styles */
}

/* Custom progress bar */
.toast-progress {
  --progress-height: 6px;
  --progress-color: #00ff00;
  --progress-background: rgba(0, 0, 0, 0.2);
}

/* Custom animation on hover */
.toast:hover {
  transform: scale(1.02);
}

Accessibility

  • Follows WCAG 2.1 guidelines
  • Proper ARIA attributes
  • Keyboard navigation support
  • Screen reader friendly messages
  • Respects reduced motion preferences

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)
  • Opera (latest)

License

MIT