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 🙏

© 2026 – Pkg Stats / Ryan Hefner

flag-engine

v1.0.0

Published

<div align="center">⛵ A feature flags evaluation engine, runtime agnostic with no remote services. <br/> <br/>

Readme

Demo NextJs | React Native (Snack) | Client Side | Server Side

20 pixelized boats on the sea


What is Flag Engine?

Flag Engine is a runtime agnostic and source agnostic feature flags evaluation engine. You give it a configuration and a context, and it will evaluate the flags for you.

What Flag Engine is not:

  • A feature flag management platform
  • A feature flag dashboard
  • An analytics platform, you have to send your events to your analytics platform
  • A way to store your feature flags
  • A drop-in replacement for OpenFeature. (a provider for Flag Engine will be created to be compliant with the OpenFeature API)

Usage

  1. Install the package:
$ pnpm add @flag-engine/core
  1. Create a configuration (or build it from where it makes sense for you like a DB or a static file, or whatever)
import {
  createFlagEngine,
  FlagsConfiguration,
  UserConfiguration,
} from "@flag-engine/core";

const flagsConfig: FlagsConfiguration = [
  {
    key: "feature-flag-key",
    status: "enabled", // the status of the flag, can be "enabled" or "disabled"
    strategies: [], // a set of condition for customization purpose
  },
];

// This is useful to create conditions based on the user's attributes.
// The __id is mandatory and a special one that will be used to compute % based variants.
const userConfiguration: UserConfiguration = {
  __id: "73a56693-0f83-4ffc-a61d-7c95fdf68693", // a unique identifier for the user or an empty string if the users are not connected.
};

const engine = createFlagEngine(flagsConfig);
const userCtx = engine.createUserContext(userConfiguration);

// Evaluate one specific feature flag
const isFlagEnabled = userCtx.evaluate("feature-flag-key"); // true

// Evaluate all the feature flags at once
const allFlags = userCtx.evaluateAll(); // { "feature-flag-key": true }

Concepts

Flag configuration

It's a descriptive object that contains guidance on how the feature flag should be evaluated. It's composed of a list of feature flags with their status (enabled or disabled) and a list of strategies.

User configuration

This is an object that holds details about the current user. It includes a unique identifier (__id, which is mandatory) and other custom attributes (defined by you) that can be used to evaluate feature flags. These attributes can be utilized within strategies to specify the conditions necessary to determine a computed feature flag variant.

This is useful if you want your QA team to test the feature behind the flag: you can create a strategy that targets users with your domain address (e.g., @gmail.com), ensuring that only they will see the flag enabled.

Another example: the current user has a country attribute with a value of France. I have defined a strategy with a condition on the country attribute with a value of France. This user is eligible to resolve a computed variant. If the user sends a US country, they will resolve a false variant.

Notes:

  • the __id is mandatory and should be your user uniquer id OR an empty string if the users are not connected.

Flag status

  • enabled: The feature flag is enabled. (returns true or the computed variant)
  • disabled: The feature flag is disabled. (returns false every time)

Strategies

Strategies is where all the customization stands. In a strategy, you can define:

  • a set of rules that are needed to be eligible for the feature flag evaluation (using the user configuration/context)
  • a list of variants with the percentage of the population that should see each variant. Those are computed against the __id of the user (this is why it's mandatory).

It's important to understand that:

  • Each strategy is an or. It means that if the user matches at least one strategy, they will be eligible for the feature flag evaluation.

  • Each rule is an and. It means that all the rules in one strategy must be true for the user for the strategy to be eligible.

This is convenient for combining and and or logic and create complex conditional feature flags.

An exhaustive example

I want to show my audience 2 variants of a feature. Only the people living in France and Spain should see the feature.

Here is how I can do that:

const flagsConfig: FlagsConfiguration = [
  {
    key: "feature-flag-key",
    status: "enabled", // the status of the flag, can be "enabled" or "disabled"
    strategies: [
      {
        name: "only-france-and-spain",
        rules: [
          {
            field: "country",
            operator: "in",
            value: ["France", "Spain"],
          },
        ],
        variants: [
          {
            name: "A",
            percent: 50,
          },
          {
            name: "B",
            percent: 50,
          },
        ],
      },
    ],
  },
];

const engine = createFlagEngine(flagsConfig);
const userCtx = engine.createUserContext({
  __id: "b",
  country: "France",
});

const variant = userCtx.evaluate("feature-flag-key"); // gives back B

Now, I suggest you give it a try, build your config object the way you prefer and start building stuff!

❤️❤️❤️


Built by @mfrachet