New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sting

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sting

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

latest
npmnpm
Version
0.0.22
Version published
Weekly downloads
4
-20%
Maintainers
1
Weekly downloads
 
Created
Source

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

PropertyDefault
classNameThe DOM items className''
tagThe DOM wrapper Node-Tagdiv
parentElementThe Node to append child upon renderdocument.body
templateTemplate to render<${'tag'} class="${'className'}"></${'tag'}>

Methods

MethodArgumentsReturn
onListen to event(event, callback)off method
offRemove event listener(event, callback)
broadcastTrigger event(event, values)
renderRender and inject to parentElement
removeRemove rendered element

Events

EventDescription
renderPre rendered and injected
render:postPost rendered
removePre rendered element removed
remove:postPost removed

Sting

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

Configuration

PropertyDefault
classNameThe DOM items className'sting__notifications'
durationHow long the notification is visible. 0 will make it permanent3000
notificationChange the notification typeStingNotification

Methods

MethodArgumentsReturn
notifyAdd a notificaiton to the area(string)StingNotification

Events

EventDescription
notifyPre adding notification
notify:postPost added

StingNotification

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

Configuration

PropertyDefault
classNameThe DOM items className'sting__notification'
durationHow long the notification is visible. 0 will make it permanent0
templateTemplate to render<${'tag'} class="${'className'}">${message}</${'tag'}>

Methods

MethodArgumentsReturn
enterRender the notificationStingNotification
leaveRemove the notificationStingNotification

Events

EventDescription
enterPre rendering
enter:postPost rendered and injected
leavePre removing
leave:postPre removing

Keywords

Notification

FAQs

Package last updated on 16 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts