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

battery-callback

v1.0.1

Published

A battery power level based callback manager. Execute functionality if a device has enough power.

Downloads

1

Readme

Battery Callback

Battery Callback allows you to trigger JS functionality with the users battery charge in mind.

When conditionally loading content you may want to check if the users battery charge is high enough to handle the content you're embedding. If their battery is low you may want user confirmation before they dive into content that could eat away at their battery making their device unusable.

Configuration

  • batteryThreshold (Int) Battery level to trigger alert (Default: 0.1)
  • msgTitle (String) Warning message title (Default: "Warning: Your battery is low")
  • message (String) Warning message text (Default: "It seems that your battery is quite low. Are you sure you wish view this map? If not you could always come back later.")
  • confirmButtonText (String) Confirm button text (Default: "")
  • cancelButtonText (String) Cancel button text (Default: "")
  • useNativeAlert (Bool) Usage of the default browser confirm message (Default: false)
  • storeInput (Bool) Store the users 'confirmed' choice (Default: true)
  • executeOnFailure (Bool) If the battery check fails (API may not be supported) then execute the functionality anyways (Default: true)
  • activeDelay (Int) The time before a 'active' class is added to the message, which helps with animation the message if required (Default: 200)

Methods

  • checkBattery (parameters: {function} callback to call, {node} The node in which is used to construct the message)
  • clearChoiceStored clears user choice stored
  • destroyMessage destroys/removes all messages

There are other methods but really they shouldn't be touched. I recommend that you only stick to the three above.

Installation

npm install —save battery-callback

Usage

// Require & Construct
var batteryCallback = require('battery-callback');

var AppBatteryCallback = new BatteryCallback({
    'batteryThreshold': 0.2,
    'msgTitle': 'Your battery is low!',
    'message': 'It seems that your battery is quite low. Are you sure you wish view this content?',
});

// An example of a function that utilises the battery callback
function yourFunction(){
    // Runs the 'checkBattery' method
    AppBatteryCallback.checkBattery(function(){
        // RUN YOUR CODE HERE
    }, this);
}

document.getElementById('id').addEventListener('click', yourFunction , false);