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

luggage

v0.0.3

Published

Handy overlapping system-user defaults for NodeJS applications.

Downloads

7

Readme

Luggage

Handy overlapping system-user defaults for NodeJS applications.

Summary

Luggage provides you with a mechnism in your application to provide a base set of preferences that can be overridden by users.

Usage

var luggage = require("luggage")("com.myApp"),
    path = require("path");

luggage.readFromDefaults("./path/to/defaults.json");

luggage.persist({
    broker: "file",
    path: [__dirname, "data"].join(path.sep)
});

// Recover the header color in the explicit system default.
myApp.headerColor = luggage.system.read("[com.myApp.]headerColor", "cornflower-blue");

// Recover the header color user default.
myApp.headerColor = luggage.default.read("[com.myApp.]headerColor", req.session.UserId, "cornflower-blue");

// Writing a default (always writes to user space)
luggage.default.write("[com.myApp.]headerColor", req.session.UserId, "cornflower-blue");

Events

Rather than using fancy hooks Luggage uses EventEmitter to provide extensibility.

New User Key Created

luggage.on("luggageIdentityCreated", cb);
// {who: #}

When a user key is first created in the memory store.

Written to Store

luggage.on("luggageCommitted", cb);
// {}

When data in the memory store is persisted.

Loaded from Store

luggage.on("luggageRestored", cb);
// {}

When data is retrieved from the persistant store.

Modifications

luggage.on("luggageValueChanged", cb);
// {key: #, was: #, now: #, who: #}

When a user had a value for a given key and it was changed.

Value Written

luggage.on("luggageValueWritten", cb);
// {key: #, now: #, who: #}

Whenever a value is written for a user.

Persistence

Implementing persistence for your user defaults is fairly simple. We presently support file storage of user default data. These files are merged at runtime on-demand (using events as your cue.)

var persistenceThreshold = 30,
    persistenceTicks = 0,
    luggage = require("luggage")();

Tell Luggage that you want to keep data around:

luggage.persist({broker: "file", path: __dirname});

Bind to the written event and write every once in a while.

luggage.on(
    "luggageValueWritten",
    function (graph) {
        persistenceTicks++;

        if (persistenceTicks > persistenceThreshold) {
            luggage.persist(); // Will save and then reload.
            luggage.synchronize(false); // Will save only.
            luggage.synchronize(true); // Does the same as persist.
            persistenceTicks = 0;
        }

    }
);

Or you can write periodically.

setTimeout(
    luggage.persist,
    3600
);

Luggage will always try one last time to write its data when the application terminates.