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

@bgunnarsson/toaster

v1.1.1

Published

Toast message javascript library

Readme

@bgunnarsson/toaster

Toaster = Ristavél in Icelandic.


The easiest toast library ever. Nothing you don't need, everything you do need.


I was fed up with notification libraries that were either too complex or simply didn't do the job well. So, I set out to create this package—to make something simple, effective, and easy to use.

@bgunnarsson/Toaster, the lightweight, dependency-free JavaScript library that gives you full control over your notifications—crispy on the outside, customizable on the inside. Whether you're looking to pop up simple text alerts or serve up rich HTML content, This package got your back, no unnecessary fluff, and no burnt toast.

Designed with developers in mind, this package lets you take the wheel. No enforced styles, no bloated features, just a clean, flexible solution that slides perfectly into any project. Want to position your toast in the top right? Bottom left? Sprinkle it with custom classes and your own CSS? Go for it. This package gives you the freedom to create toast notifications that look and behave exactly how you want them to.

With sensible defaults for quick setup, this package is the perfect sidekick—whether you’re in a hurry or have time to fine-tune every last detail. Simple, powerful, and fully customizable—because who doesn't love a perfectly timed toast?


Features

  • Minimal and customizable: No forced styles; bring your own CSS for total control over the appearance.
  • Flexible positioning: Toasts can appear at top left, top right, bottom left, or bottom right of the screen, with additional support for customizable offsets.
  • HTML content support: Display both simple text notifications or rich HTML content inside toasts.
  • Pause on hover: Auto-dismiss timers can pause while the user hovers over a toast.
  • Persistent toasts: Keep toasts visible indefinitely with the persist option.
  • Lightweight and dependency-free: No external libraries required.
  • Custom events: Listen for custom events like toaster:added and toaster:removed.

Installation

Install the @bgunnarsson/toaster library using the package manager of your choice.

pnpm i @bgunnarsson/toaster

yarn @bgunnarsson/toaster

npm i @bgunnarsson/toaster

Sizes

| Original | gzip | |-----------------|-------------| | 3 kb | 348 B |


Documentation

Looking for React, its context or a Zustand slice? Click here

Options

ToasterOptions

| Option | Type | Default | |-----------------|-----------|------------------| | position | string | bottom right | | offset | object | { x: 0, y: 0 } | | customClass | string | | | stack | boolean | true | | dismissLabel | string | Click to dismiss |

With stack on, toasts pile up as a deck: the newest in front, and up to two older ones peeking out behind it, above it for bottom positions and below it for top positions. Set stack: false to list them one after another instead.

dismissLabel is the title of a clickable toast, for a page in another language. The toaster is a polite role="status" region, so screen readers read each toast as it arrives. With transitions turned off, by prefers-reduced-motion or the page's own CSS, a closed toast is removed straight away instead of after it slides out.

Importing

This package is ESM only and ships its own TypeScript declarations.

import Toaster from '@bgunnarsson/toaster'

Basic Usage

const toaster = new Toaster({ duration: 5000 });

toaster.toast({
  content: '<p>Welcome to Toaster!</p>'
})

createToaster

The toaster's functions, without the toaster: it is made the first time a toast is shown, so this can be called at module level, in a store, or during a server render.

import { createToaster } from '@bgunnarsson/toaster'

const { toast, dismiss, clearAllToasts } = createToaster({ position: 'bottom right' })

Initialization

Initialize the Toaster class with custom options for positioning, duration, and more.

const toaster = new Toaster({
  position: 'bottom right',  // Position the toasts at the bottom-right corner.
  offset: { x: 20, y: 20 },  // Offset the toast from the bottom-right by 20px.
  customClass: 'my-toaster', // Add a custom class to the toasts.
})

.toast()

| Option | Type | Default | |-----------------|-----------|------------------| | content | string | | | persist | boolean | false | | duration | number | 3000 | | pause | boolean | true | | clickable | boolean | true |

Creating a Toast

Use the toast() method to create and display a toast notification.

toaster.toast({
  content: '<p>Hello, this is a toast!</p>',  // Display HTML content.
  duration: 3000,  // Auto-dismiss the toast after 3 seconds.
  clickable: true, // Disable the clickability.
})

Manually Dismissing a Toast

You can dismiss the current toast programmatically by calling the dismiss() method.

toaster.dismiss()

Persistent Toast

Toasts can be made persistent by setting the persist option to true. Persistent toasts stay on screen until manually dismissed.

toaster.toast({
  content: 'Persistent toast message!',
  persist: true, // Toast will stay until dismissed manually.
})

Events

The library dispatches custom events when a toast is added or removed:

  • toaster:addedFired when a new toast is added.
  • toaster:removed Fired when a toast is removed from the DOM.
document.addEventListener('toaster:added', (event) => {
  console.log('Toast added:', event.detail);
})

document.addEventListener('toaster:removed', (event) => {
  console.log('Toast removed:', event.detail);
})

Framework/Library Support

At the time of writing (18.10.2024), this package has been tested for use in:

  • Rustikus
  • TypeScript
  • JavaScript
  • React - @bgunnarsson/toaster/react
  • Astro
  • Svelte
  • Vue 3

Upcoming tests:

  • Lit
  • Preact
  • Qwuik
  • Angular
  • Alpine.js