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

sting

v0.0.22

Published

Sting! Is a tiny lightweight, themable and highly customizable notification-popup.

Downloads

5

Readme

Sting 1.5kb

is a simple non-dependent, lightweight and customisable notification engine.

Description

Notifications comes in many shapes and forms and yet they all seem to have the same requirements - or at least the most of them. Sting serves the purpos of kickstarting and streamlining your on-site notifications so that you can focus on getting the right messages out there.

Jumping into the source you'd quickly realize that there's no magic going on here. No fancy buzzword-dependencies, promises, observables or other browser-support-concerning-functionality. Just plug it in and get your message out there.

Give me an example already

chill dude - here you go!

// You obviusly need to include Sting
import Sting from 'sting';

// Make your first Sting notification area, with everything on default
const topNotifications = new Sting({
    className: 'sting__notifications', // Wrapper className
    duration: 3000, // 0 or false to disable disapearing notifications
    parentElement: document.body // Where should we inject the notification area?
});

// Boom guys! This is the magic
topNotifications.notify('Hey guys - Check this out!');

Let's say i'd like to wrap it in a promise, for example?

I thought you might ask that Here is an example of how to extend the functinallity to support promises

class StingPromise extends Sting {
	constructor(config) {
		super(config);
	}

	notify(message) {
		return new Promise((resolve) => {
			let notification = super.notify(message);
			notification.on('remove:post', () => resolve(notification));
		});
	}
}

const topNotification = new StingPromise();
topNotification.notify('Sleeeeek').then((notification) => {
	console.log('awesome');
});

API doc

StingBase

The base class used to extend Sting and StingNotification. Adds eventlisteners as well as render and remove methods.

Configuration

|Property||Default| |---|---|---| |className|The DOM items className|''| |tag|The DOM wrapper Node-Tag|div| |parentElement|The Node to append child upon render|document.body |template|Template to render| <${'tag'} class="${'className'}"></${'tag'}>

Methods

|Method||Arguments|Return| |---|---|---|---| |on|Listen to event |(event, callback)|off method |off|Remove event listener |(event, callback)|| |broadcast|Trigger event|(event, values)|| |render|Render and inject to parentElement||| |remove|Remove rendered element|

Events

|Event|Description| |---|---| |render|Pre rendered and injected| |render:post|Post rendered| |remove| Pre rendered element removed| |remove:post|Post removed|

Sting

Extends StingBase Sting is the notification area. This will act as a wrapper to all notifications.

Configuration

|Property||Default| |---|---|---| |className|The DOM items className|'sting__notifications'| |duration|How long the notification is visible. 0 will make it permanent |3000| |notification|Change the notification type|StingNotification

Methods

|Method||Arguments|Return| |---|---|---|---| |notify|Add a notificaiton to the area|(string)|StingNotification

Events

|Event|Description| |---|---| |notify|Pre adding notification| |notify:post|Post added|

StingNotification

Extends StingBase StingNotification is the individual notification. This holds the messages and is the rendered notification shown.

Configuration

|Property||Default| |---|---|---| |className|The DOM items className|'sting__notification'| |duration|How long the notification is visible. 0 will make it permanent |0| |template|Template to render| <${'tag'} class="${'className'}">${message}</${'tag'}>

Methods

|Method||Arguments|Return| |---|---|---|---| |enter|Render the notification||StingNotification |leave|Remove the notification||StingNotification

Events

|Event|Description| |---|---| |enter|Pre rendering| |enter:post|Post rendered and injected| |leave|Pre removing| |leave:post|Pre removing|