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

off-the-grid

v1.4.3

Published

Save data when there is no connection and replay back data as soon as connection established or within specified interval

Downloads

14

Readme

Off the Grid

CircleCI Codecov semantic-release Commitizen friendly

When using 3rd party data analytics service in an offline capable app such as when using Electron, constant internet connection is required to keep sending data to the analytics service. When the internet connection drops out, we can't send data to the service, resulting in data loss.

Off the Grid is designed to handle this scenario. The basic idea is, Off the Grid will cache the data if our app is offline and will send the data if our app is online.

  1. Getting Started
  2. API
  3. Contributing
  4. License

Getting Started

Installation

$ npm install --save off-the-grid 

Usage

Example usage with analytics in Electron app:

// makeAnalyticsOfflineCapable.js

const electron = require("electron");
const analytics = require("your-favorite-analytics-library");
const OffTheGrid = require("off-the-grid");

let offTheGrid;

const { ipcMain } = electron;

ipcMain.on("prepareAnalytics", (event) => {
  initializeOffTheGridAnalytics();
});

ipcMain.on('actions', (event, data) => {
  offTheGrid.record(data.type, data.content);
})

function initializeOffLineAnalytics() {
  offTheGrid = new OffTheGrid({
    logFilePath: "pathToLogFile.log",
    flushInterval: (1000 * 60 * 30),
    cacheSize: 10000000,                            // log file size of 10 MB
    checkConditionBeforeFlush: checkInternetConn(), // returns a promise
    replayImmediately: true,           
    callback: (data) => {
      // Do something with the data here
      analytics.track(data);
    }
  });
}

API

Constructor

new OffTheGrid(opts)

Instantiates a new OffTheGrid object, with opts:

  • logFilePath

    Path to log file. Make sure the parent folders are created prior.

  • flushInterval

    Time interval specified in miliseconds to replay the cached data and give it to the callback.

  • cacheSize

    Maximum log file size. If it exceeds this size, the log file will be deleted on the next interval when at that time the condition is not satisfied.

  • checkConditionBeforeFlush

    Function to check current status of internet connection.

  • replayImmediately

    Whether to replay the cached data immediately after instantiation.

  • callback(data) {}

    Callback to be called when replaying each cached data.

Methods

  • record(message, body)

    Record data. message is String and body is JSON.

Contributing

CONTRIBUTING.md

License

MIT