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

ample-alerts

v1.4.5

Published

A simple alert library for web

Downloads

4

Readme

ample-alerts

npm version npm downloads License
Build Status Code Climate js-myterminal-style Coverage Status
ko-fi
NPM

A simple alert library for web

Features

  • A simple & light-weight alert library
  • Mobile-friendly
  • Supports all types of browser alerts
  • Can be easily themed for any host web application
  • Support for promises
  • Two color-themes: light and dark

How to Use

Directly from a web page

One can use ample-alerts directly from a web-page by a attaching script file and a stylesheet to the DOM.

<!-- Attaching the ample-alerts stylesheet -->
<link type="text/javascript" rel="stylesheet" href="path/to/library/ample-alerts.css" />

<!-- Attaching the ample-alerts script -->
<script type="text/javascript" src="path/to/library/ample-alerts.js"></script>

<!-- Usage -->
<script type="text/javascript">
    ampleAlerts.alert(['Update Available', 'A new update is available'], { autoClose: 3000 });
</script>

With Webpack, Browserify or RequireJS

Install ample-alerts from NPM

npm install ample-alerts --save-dev

Consume as an ES6 module

import * as ampleAlerts from 'ample-alerts';

or

import ampleAlerts from 'ample-alerts';

or

import { alert, confirm, prompt } from 'ample-alerts';

Consume as a CommonJS module

var AmpleAlerts = require('ample-alerts');

Consume as an AMD

require(['ample-alerts'], function (ampleAlerts) {
    // Consume ampleAlerts
}

In order to use the stylesheet,

Import in your React components as

import from '[relative/path/to]/ample-alerts.css';

or in your stylesheet as

@import '[relative/path/to]/ample-alerts.css';

Note: You may have to use Babel for ES6 transpilation.

Supported alert types

Alert

Shows a simple alert with provided text.

ampleAlerts.alert('An update is available!');

Optionally, you can also provide a heading for the alert by sending two strings in an array.

ampleAlerts.alert(['Update Available', 'A new software update is available!']);

You can also make the alert go away after a specified number of milliseconds.

ampleAlerts.alert(['Update Available', 'A new software update is available!'], { autoClose: 5000 });

Confirm

Shows a confirmation message for user to confirm an action.

ampleAlerts.confirm('An update is available! Do you want to load the latest version?', { onAction: onAction });

You can also provide a heading for the confirmation message.

ampleAlerts.confirm(['Update Available', 'Do you want to load the latest version?'], { onAction: onAction });

Prompt

Shows a prompt to ask a value from the user.

ampleAlerts.prompt('What do you want to name the file as?', { onAction: onAction });

As usual, you can also add a heading.

ampleAlerts.prompt(['Saving File', 'What do you want to name the file as?'], { onAction: onAction });

Support for promises

A separate version for promises is available.

In order to take advantage of promises, use ample-alerts.promises.js.

The import path for ES6, CommonJS and AMD changes to ample-alerts/build/scripts/ample-alerts.promises.

For any alert created with this version, all positive actions from the user resolve the promise while others end up rejecting the promise.

For example: dismissing an alert, confirm or prompt using the close button rejects the promise so does negative response for confirm.

Note: You can still use the onAction callback with the promises version.

ampleAlerts.confirm('Are you sure?')
    .then(function () {
        // User responded with a 'YES'
    }).catch(function () {
        // User either responded with a 'NO' or dismissed the alert
    });

Options

While creating an alert, the second argument is an options object. It can have the following properties:

  1. autoClose (number)
    Default: 0 (Does not close automatically)
    Applicable for: alert

  2. onAction (function)
    Default: null
    Applicable for: confirm, prompt
    The method to be called with user response as an argument.
    In case of confirm, this method gets called with either true or false. For prompt, it gets called with the response value from the user.

  3. defaultResponse (string)
    Default: null
    Applicable for: prompt
    The default response from the user.

  4. labels (array)
    Default: ['Yes', 'No'] or ['Ok, 'Cancel']
    Applicable for: confirm, prompt
    Use this option to override button labels shown on alerts.

  5. isModal (boolean)
    Default: false
    Applicable for: confirm, prompt
    Use this option to make the confirm or prompt a modal.
    Please note that the user will still be able to interact with other pop-ups created with ample-alerts.

Color themes

There are two available color themes: light and dark and the default is light. In order for ample-alerts to use the dark theme, attach a CSS class named ample-alerts-dark to the body tag.

<body class="ample-alerts-dark">
    ...
</body>

To switch the theme dynamically, call one of the below two functions.

import { switchToDarkTheme, switchToLightTheme } from 'ample-alerts';

switchToDarkTheme(); // Switches to dark theme
switchToLightTheme(); // Switches to light theme

OR

import ampleAlerts from 'ample-alerts';

amplerAlerts.switchToDarkTheme(); // Switches to dark theme
amplerAlerts.switchToLightTheme(); // Switches to light theme

Demos

Experience ample-alerts in action:

  1. Simple version here
  2. Version with promises here

To-do

  • Implement showing of alerts at different positions on the screen
  • Write unit-tests