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

easy-toast-js

v2.0.13

Published

A simple Toastr notification package using Tailwind CSS and Vanilla JavaScript with no dependencies.

Downloads

121

Readme

Toast Notification Library Documentation

A robust, object-oriented toast notification library with zero dependencies.

Features

  • 🎨 Four pre-styled types: success, error, warning, info
  • ⚙️ Customizable options
  • 🔄 Queue management for multiple toasts
  • 🖱️ Click to dismiss
  • 📱 Responsive and mobile-friendly
  • 🔥 No dependencies
  • 📝 TypeScript-friendly

Quick Start

Installation

you can ins directly in html and also initial npm package

NPM installation

npm i easy-toast-js

1. Include the Script

<script src="
https://cdn.jsdelivr.net/npm/[email protected]/dist/easyToast.min.js
"></script>
  • If not install Tailwind Css then add easy-toast.min.css or import easy-toast.min.css

2. Basic Usage

// when install throw npm import like below
import { toast } from "easy-toast-js";

// Use the default instance
toast.success("Operation successful!");
toast.error("Something went wrong");
toast.warning("Be careful");
toast.info("Did you know?");

// Or create a custom instance
const myToast = new ToastManager({
  position: "bottom-right",
  maxToasts: 5,
});
myToast.show("Custom toast!");

API Reference

ToastManager Class

Constructor Options

const options = {
  position: "top-right", // 'top-right', 'top-left', 'bottom-right', 'bottom-left'
  maxToasts: 3, // Maximum number of toasts shown at once
  animationDuration: 300, // Animation duration in milliseconds
  defaultDuration: 3000, // Default display duration
  containerClass: "toast-container", // CSS class for the container
};

const toastManager = new ToastManager(options);

Methods

show(message, type, duration)

Shows a toast notification.

  • message (string): The message to display
  • type (string, optional): 'success', 'error', 'warning', or 'info'. Default: 'info'
  • duration (number, optional): Time in milliseconds. Default: 3000
  • Returns: { element, removalPromise }
success(message, duration)

Shows a success toast.

  • message (string): The success message
  • duration (number, optional): Custom duration
error(message, duration)

Shows an error toast.

  • message (string): The error message
  • duration (number, optional): Custom duration
warning(message, duration)

Shows a warning toast.

  • message (string): The warning message
  • duration (number, optional): Custom duration
info(message, duration)

Shows an info toast.

  • message (string): The info message
  • duration (number, optional): Custom duration

Advanced Usage

Custom Instance

const customToast = new ToastManager({
  position: "bottom-left",
  maxToasts: 5,
  defaultDuration: 5000,
});

customToast.success("Custom positioned toast!");

Promise-based Usage

async function showSequentialToasts() {
  await toast.success("First toast").removalPromise;
  await toast.info("Second toast").removalPromise;
  console.log("All toasts have been shown and dismissed");
}

TypeScript Support

interface ToastOptions {
  position?: "top-right" | "top-left" | "bottom-right" | "bottom-left";
  maxToasts?: number;
  animationDuration?: number;
  defaultDuration?: number;
  containerClass?: string;
}

declare class ToastManager {
  constructor(options?: ToastOptions);
  show(message: string, type?: string, duration?: number): ToastResult;
  success(message: string, duration?: number): ToastResult;
  error(message: string, duration?: number): ToastResult;
  warning(message: string, duration?: number): ToastResult;
  info(message: string, duration?: number): ToastResult;
}

interface ToastResult {
  element: HTMLElement;
  removalPromise: Promise<void>;
}

declare const toast: ToastManager;

Browser Support

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

Examples

Basic Usage

toast.success("File uploaded successfully!");
toast.error("Failed to save changes");

Custom Duration

toast.warning("Server maintenance in 5 minutes", 10000);

Sequential Toasts

async function processForm() {
  await toast.info("Validating...").removalPromise;
  await toast.info("Sending data...").removalPromise;
  toast.success("Form submitted!");
}