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

sheldon

v3.0.1

Published

Fun with (feature) flags!

Downloads

7

Readme

#Sheldon

Bringing the fun and power of flags to your application

##Overview

Sheldon is a feature flag client wrapped around a Redis database. It is designed to handle multiple services and environments for a microservice architecture, while being fairly agnostic about what type of flag you want to keep.

##Installation

npm install sheldon --save

##Use

const Sheldon = require('sheldon');
const sheldonOptions = {
  redisConnectionString: 'redis://:[email protected]:10101',
  appName: 'my-amazing-app-live',
  defaults: {
     'partyTime': 'on'
  }
};

const feature = new Sheldon(sheldonOptions);
feature.readAndStartWatching();

if (feature.flag('partyTime') === 'on') {
  console.log('start the party!');
} else {
  console.log('no party yet');
}

##Options

new Sheldon() takes an options object with the following fields:

  • redisConnectionString[required]: the connection string to the Redis database. This can also be a path to a json file for local dev, see below.
  • appName[required]: the unique identifier for the application. I.e. my-app-ci, or great-service-qa
  • pollInterval[optional]: the poll interval for Sheldon to poll the Redis database. Defaults to 15 seconds.
  • defaults[required]: Used when application starts (or restarted) and redis can't be reached. Note that if you dont define all your flags the flag function will return an error for unrecognised flags.
  • logger[required]: Used for logging instead of the console.log (./specs/helpers.js)[see the methods required for logger]
  • statsd[required]: Used to capture metrics around the redis connection for now

##API readAndStartWatching() Reads the current flag states stored in the Redis database for the given appName and starts polling at the pollInterval interval.

flag(String) => String Takes a flag name (a String) and returns its value (also a String - JavaScript, eh?)

##Recommended uses We'd recommend flagging on a match to a string, as in flag === 'on' and having the "safe" setting being the inverse (to guard against typos).

##Adding, Updating and Deleting flags Writing to underlying the Redis database is not handled by Sheldon. Sheldon reads a hash stored at the key of appName, and reads in the fields and values as the flags and settings respectively. To update, add and delete flags we'd recommend using the Redis command line tool (redis-cli), using HSET and HGET to set and get the value of individual flags, and HDEL to delete them.

##Local JSON file for dev If the redisConnectionString is specified as a file url, e.g. file://./sheldon-override.json then it will read flags from that json file instead. If json document should be formatted as an object with a key for the name of the application. That key should point to an object that contains the flags.

E.g. if the application name is 'my-test-app' and you want to set the flag 'cool-stuff' to 'on' and 'old-stuff' to 'off':

{
  "my-test-app": {
    "cool-stuff": "on",
    "old-stuff": "off"
  }
}

##Contributing Feel free to open a pull request.