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

notify-util

v1.1.2

Published

Very simple notification system for JS/TS projects.

Downloads

4

Readme

notify-util

Very simple notification system for JS/TS projects.

Live example

Installation via NPM

npm i notify-util

Alternatively, you can include the bundled js file in dist, where notifyUtil is available in the window.

Quick start

Have a div with attribute sn-notification-container. You can use the built in class if you want. It puts it in the top right of the page and adds gap between each notification.

<div nu_notification-container class="nu_notification-container"></div>
import notifyUtil from 'notify-util'

notifyUtil.configure({});

new notifyUtil.Notification({
  type: "success",
  heading: "Wow that was fast!",
  body: "Skrt skrt",
});

Configuration

import notifyUtil from 'notify-util'

notifyUtil.configure({
  // options here
});

Configuration options

You must run configure before using the Notification 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 . | | → headingClass | CSS class as string, no prefixed . | | → bodyClass | CSS class as string, no prefixed . | | → progressBarClass | 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 | | → spinner | string injected as HTML | | Theme | string light / dark / auto / none |

Defaults

configureNotification({
  containerSelector: '[nu_notification-container]',
  classes: {
    notificationClass: 'nu_notification',
    headingWrapperClass: 'nu_notification-heading-wrapper',
    iconClass: 'nu_notification-icon',
    headingClass: 'nu_notification-heading',
    bodyClass: 'nu_notification-body',
    progressBarClass: 'nu_notification-progress-bar'
  },
  icons: {
    success: icons.svg.success,
    warning: icons.svg.warning,
    error: icons.svg.error,
    debug: icons.svg.debug,
    spinner: icons.svg.spinner,
    info: icons.svg.info
  },
  theme: 'light'
});

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

For spinner, clickToClose is forced false and duration is forced null.

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

Examples

Success notification

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

Spinner

const loadingIndicator = new notifyUtil.Notification({
  type: 'spinner',
  heading: 'Loading...',
  body: 'Working on it'
});

// some time passes

loadingIndicator.update({
  heading: 'Loading...',
  body: 'Almost there'
});

// some time passes

loadingIndicator.close();

// some time passes

myLoaderMessage.close();