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

notification-util

v1.0.8

Published

Very simple notification system for JS/TS projects.

Downloads

511

Readme

Notification util

Very simple notification system for JS/TS projects.

Installation

npm i notification-util

Configuration

Only has to be called once, before using the Notification or Loader class.

import {
  Notification,
  Loader,
  configureNotifications
} from 'notification-util';

configureNotification({}); // Required, but can be empty

Configuration options

You must run configureNotification before using the Notification or Loader class.

To run without customization, pass an empty object as argument.

You can override any of default settings by following the structure below.

Notifiation dissection

| Option | Description | | --------------------- | ----------------------------------------------------------------------------------------------- | | containerSelector | Selector for notification container. Attribute, ID, class as string with # or . as needed | | classes | Override the default CSS classes by providing your own | | → notificationClass | CSS class as string, no prefixed . | | → headingWrapperClass | CSS class as string, no prefixed . | | → iconClass | CSS class as string, no prefixed . | | → messageClass | CSS class as string, no prefixed . | | → headingClass | CSS class as string, no prefixed . | | icons | Override the default icons by providing your own. | | → success | string injected as HTML | | → warning | string injected as HTML | | → error | string injected as HTML | | → debug | string injected as HTML | | → loading | string injected as HTML | | injectCss | boolean Inject default CSS. If disabling, be sure to provide your own animation CSS. |

Defaults

configureNotification({
  containerSelector: '[sn-notification-container]',
  classes: {
    notificationClass: 'sn_notification',
    headingWrapperClass: 'sn_notification-heading-wrapper',
    iconClass: 'sn_notification-icon',
    messageClass: 'sn_notification-message',
    headingClass: 'sn_notification-heading'
  },
  icons: {
    success: icons.success,
    warning: icons.warning,
    error: icons.error,
    debug: icons.debug,
    loading: icons.loading
  },
  injectCss: false
});

Animation CSS provided

growWidth is used for showing duration of notification, rotation is used in loading icon.

@keyframes growWidth {
  from {
    width: 0%;
  }
  to {
    width: 100%;
  }
}
@keyframes rotation {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

Notification

Displays a notification with a heading and message. Can be closed by clicking on it when enabled.

Returns an object if you need to remove it programmatically. e.g.: myNotification.remove().

Options

new Notification({
  type: 'success' | 'warning' | 'error' | 'debug', // Required
  heading: string, // Required
  message: string,
  duration: number | null, // Default: 3500 (ms), null for infinite
  clickToClose: boolean // Default: true
});

Example usage

import { Notification, configureNotifications } from 'notification-util';

configureNotification({}); // Required, but can be empty

new Notification({
  type: 'success',
  heading: 'Success heading',
  message: 'Success message'
});

Loader

Displays a spinning loader with a heading and message. Returns an object with methods to update the loader and close it.

Options

new Loader({
  heading: string, // Required
  message: string
});

Example usage

import { Loader, configureNotifications } from 'notification-util';

configureNotification({}); // Required, but can be empty

const myLoaderMessage = new Loader({
  heading: 'Loader heading',
  message: 'Loader message'
});

// some time passes

myLoaderMessage.update({
  heading: 'Updated heading',
  message: 'Updated message'
});

// some time passes

myLoaderMessage.close();