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

@useboolean/boolean-js

v0.1.0

Published

![Boolean logo - real-time feature flags](https://avatars0.githubusercontent.com/u/53407144?s=128&v=4)

Downloads

1

Readme

Boolean logo - real-time feature flags

Boolean

Build Status Coverage Status License Badge

Feature management for modern devops teams by Boolean.

This is a generic JavaScript library to make it easy to create libraries for React, Vue, Node.js etc. Usually you shouldn't use this library directly unless you know what you're doing. :)

npm i @useboolean/boolean-js

Features

  • Percentage-based rollout
  • User targeting & segmentation
  • Turn off features instantly
  • Privacy-first
  • Audit log
  • SSO / SAML

⚠️ Create an account at Boolean. There is a free plan available.


Quick start

Call makeMakeTransport and makeMakeBoolean to configure the setup functions. Use those functions to actually create a Boolean instance.

const makeTransport = makeTransport({
  WebSocket,
  request,
});
const makeBoolean = makeMakeBoolean({
  makeTransport,
});
const boolean = makeBoolean(`api key here`, {
  // You can configure three types of transports: stream, fetch and none.
  transport: {
    type: `stream`,
    timeout: 2000,
  };

  // Used when no data could be fetched for whatever reason.
  initialData: initialData,

  // In case you want to use your own cache system.
  cache: cache,
});

const { isEnabled } = await boolean.evaluate(`my-feature-1`);

makeBoolean

Transports

Stream Transport

This transport is intended to be used when you want a persistent connection. If you want to fetch feature flag data once use the fetch transport instead.

Sets up a WebSocket connection. The WebSocket constructor must be passed in the makeMakeTransport function. This makes it easier to use this library in browser or Node.js.

This transport automatically reconnects when an error occurs using a simple backoff algorithm.

When evaluating a feature and a connection has not been estabished yet it immediately returns a result. Even if the data is not up-to-date yet. You can wait for up-to-date data by calling await makeBoolean(..).promise(), but it only waits until the specified timeout. If no fresh data is in it either falls back to the cache, if specified, or the initial data.

⚠️ It's highly recommended to always specify initialData so you have a fall back when things go down, are slow, or otherwise experience issues.

const boolean = makeBoolean(`api key here`, {
  transport: {
    type: `stream`,
    timeout: 2000,
  };
  initialData,
});

Fetch Transport

The fetch transport simply fetches data over http without any retrying. If the request did not respond within the specified timeout, the promise is rejected. Catch the error if you want to continue evaluating but using the fallback.

If you are evaluating a feature before the request has been finished, Boolean falls back to your cache. If retrieving data from the cache has not been finished yet, it falls back to the initial data.

const boolean = makeBoolean(`api key here`, {
  transport: {
    type: `fetch`,
    timeout: 2000,
  };
  initialData,
});

None Transport

You can disable the transport all together by specifying the none transport. Boolean will fall back to the cache and the initial data.

This may be useful in serverless environments where you use the cache to retrieve fresh feature data. And you use webhooks to keep your cache up to date.

const boolean = makeBoolean(`api key here`, {
  transport: {
    type: `none`,
  };
  initialData,
});

Cache

You can provide your own cache which Boolean will use to fetch initial feature data.

Get

const cache = {
  get(apiKey) {
    // Just retrieve the blob by apiKey you cached using the cache#put operation
  },
};

Put

const cache = {
  put(apiKey, data) {
    // Store data (which is a string) by apiKey.
  },
};

📨 If you have any feedback or just want to say hi you can send us a ping. Over & out!