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

warmbread

v1.0.4

Published

A toast library with no dependancies*

Downloads

3

Readme

header

Basically, toast.


A small, single-file, vanilla JavaScript toast library under 25kb including all bundled images and styling. No third party libraries required other than for development.

Built mostly to play with ES6, but hopefully useful to somebody.

toast example

Features

  • Multiple logging levels (Info, Success, Warning, Error, Fatal)
  • Fluent toast construction. Chainable methods for constructing toasts and providing overrides to global settings.
  • Toast queue to stop flooding, with queue only executing when toasts are required to keep cut down on required resources.
  • Ability to have toasts active at all available positions concurrently.
  • Embedded templates and CSS for single file deployment. Template can be overridden with CSS on the calling page.
  • ~~Support for central positioning (vertical and horizontal)~~ See Issue #2
  • Support for onOpen and onClose callback methods, including nesting of more toasts.
  • Support for non-expiring toast.
  • Support for custom classes (global and on toast basis)

Roadmap

  • Animations and UX improvements including fading out over time, entry/exit animations (Currently handled by CssClass being able to utilize additional animation libraries like animate.css)

Usage

Script can be acquired from NPM:

npm install warmbread

or from the warmbread.min.js file within the dist folder of this project.

Via import statement

import {Warmbread} from 'warmbread';
let warmbread = new Warmbread();
warmbread.info("foo").show();
Via <script> tag.

Take the warmbread.min.js from dist and either import, or use the <script> tag.

Calling warmbread

Warmbread will automatically initialize when the script is loaded. The first initialization will use the default options. Initialize can be called again with overriding options at any time, overriding default global behavior.

See example/dist/Index.html for the sample. (which is written in horrid JS and awaiting rewrite, as it was for quick tests...) Warmbread uses a fluent API to construct and display new toasts. The chain must end with .show()

warmbread.info("Some message").show()

Example with fluent API/overrides:

warmbread.info("Some message").withTitle("Title").atPosition("top","center").show()

Methods (Library)

  • warmbread.destroyAll()
    • Instantly destroys all active toast items, and purges the queue of any remaining items.
  • warmbread.info(text) , warmbread.succcess(text), warmbread.warn(text), warmbread.error(text), warmbread.fatal(text)
    • Displays the appropriate toast. (See: Usage)

Chainable methods (On toast items)

  • atPosition( [top/bottom] , [left,right])
    • Shows the toast at a position other than the global setting.
  • canBeDismisssed(bool)
    • If provided, sets whether or not the toast disappears when interacted with.
  • canExpire(bool)
    • If provided, sets whether or not the toast gets removed at the timeout. Note that use of this, expectially if the item is not dismissable could block the toast queue.
  • onOpen(fn)
    • If provided, runs the function specified on toast display. i.e. onOpen(function(){ doThings(); })
  • onClose(fn)
    • If provided, runs the function specified on toast destroy. i.e. onClose(function(){ doThings(); })
  • withTitle(text)
    • Adds a title message into the toast.
  • withClass
    • Sets the class name to apply to the toast, overrides global classname. Can be used with something like animate.css to apply entry animations.

Methods (Library)

  • warmbread.destroyAll()
    • Instantly destroys all active toast items, and purges the queue of any remaining items.

Config (Defaults shown)

Config is set by (re)calling

warmbread.init(options);

Options:

All optional.

{
positionVertical: "bottom", // (top, center, bottom
positionHorizontal: "right", // (left, center, right)
timeout: 5000,
dismissable: true,
canExpire: true,
alertType: "core", // core/material
maxQueueSize : 4,
loggingEnabled: false,
cssClass : "",
catchAllUnhandledExceptions: true,
}
  • positionVertical: top/bottom. Vertical positioning on the screen.
  • positionHorizontal: right/left. Horizontal positioning on the screen.
  • timeout: Time in ms before the toast will auto-dismiss.
  • dismissable: If the toast can be dismissed on-click.
  • canExpire: If the toast can expire automatically.
  • alertType: core/material. The base template to use. Template can be overridden in CSS, but we aim to have user defined templates in the future.
  • maxQueueSize: Max number of toast items to display at any given time. This is globally and not per-position.
  • loggingEnabled : If enabled, will provide some additional logging.
  • cssClass : Class to use for toast.
  • catchAllUnhandledExceptions : If set to true, will attempt to log all uncaught JS exceptions as Fatal toasts. (Note: window.onerror does not fire with console active unless event is deferred)

How it works

Before the show() is called, all items are Bread. When show is called, Bread is added to the loaf.

If the queue has allocation remaining and it is running, it will "Toast" the Bread. If the queue is not running, it will start a queue and continue processing as per above until the queue is empty, then stop.

Development/Compiling

Development requires and environment with Node JS installed.

  • Package.json Commands
    • pack-prod - Produces warmbread.min.js under dist folder for production
    • pack-dev - Produces warmbread.dev.js under dist folder for the samples and debug
    • test - Runs unit tests
    • pack - Runs the 2 pack commands, and also the mocha unit tests. Pack will also update the example project under the "example" folder.

To use source maps for debugging, change package.json to have the "main" file use dist\warmbread.dev.js instead of dist\warmbread.min.js

i.e. "main": "dist/warmbread.dev.js",

If you start a live server against example/dist/index.html post running pack you will be able to debug using the source maps. Note that hot reloading is not currently enabled for the JS - something to sort later, for now sadly it's a case of re-running pack and using live-server.

If using VSCode, you can make use of the "launch sample page" config within launch.json.