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 🙏

© 2025 – Pkg Stats / Ryan Hefner

dms-feature-flags-v1

v1.0.21

Published

A lightweight **Firebase Remote Config** powered feature flag library.

Downloads

2,020

Readme

DMS Feature Flags

A lightweight Firebase Remote Config powered feature flag library.

This library provides:

  • Firebase Remote Config integration
  • URL overrides for debugging: ?ff.myFlag=on / off
  • Live updates via a subscriber model
  • useFlag() React hook

Installation

npm install @dartech/dms-feature-flags
# or
yarn add @dartech/dms-feature-flags
# or
pnpm add @dartech/dms-feature-flags

Quick Start

1. Set Defaults (before initializing)

It is crucial to set all expected flags and their default values before calling initFeatureFlags. Only flags defined here are considered by the library.

import { setDefaults } from "@dartech/dms-feature-flags";

setDefaults({
  "billing.newCheckout.v2": false,
  "ui.darkMode.toggle": false,
  "feed.layout.v3": true,
});

2. Initialize Firebase + Remote Config

Call this once, ideally in your app root or MFE entrypoint.

import { initFeatureFlags } from "@dartech/dms-feature-flags";

await initFeatureFlags(
  {
    apiKey: "...",
    authDomain: "...",
    projectId: "...",
    appId: "...",
  },
  { 
    minFetchMs: 60_000 // optional: minimum time between fetches (default is 60s)
    configName: "feature_flags" // optional: Firebase RC name (default is "feature_flags")
  } 
);

⚠️ Calling initFeatureFlags() more than once is safe, but subsequent calls will be ignored.

3. Use Feature Flags

In React:

Use the dedicated hook for auto-updating components.

import {useFlag} from "@dartech/dms-feature-flags";

const isEnabled = useFlag("feed.layout.v3");

Anywhere (services, utils, plain JS):

import { getFlag } from "@dartech/dms-feature-flags";

if (getFlag("feed.layout.v3")) {
  // enable feature logic
}

URL Overrides for Debugging

You can override any flag directly in the browser URL using the ff. prefix. This is the highest priority resolution method.

  • Enable a flag: ?ff.feed.layout.v3=on
  • Disable a flag: ?ff.feed.layout.v3=off
  • Multiple flags: ?ff.feed.layout.v3=on&ff.ui.darkMode.toggle=off

Changes update automatically on browser navigation (popstate).

Priority Order

When resolving a flag's value, the library checks in the following order:

  1. URL override
  2. Remote Config value
  3. Default

useFlag() Hook

const value = useFlag("featureName", fallback?);

Features:

  • Auto-updates when flags change (via Remote Config fetch or URL navigation).
  • Optional fallback if the flag doesn’t exist (though all flags should be defined in setDefaults).

Example:

function Checkout() {
  const showNewCheckout = useFlag("billing.newCheckout.v2");

  return showNewCheckout ? <NewCheckout /> : <DefaultCheckout />;
}

API Reference

setDefaults(defaults)

Set default flag values before calling initFeatureFlags().

initFeatureFlags(firebaseConfig, opts?)

Initializes Firebase and Remote Config.

opts = {
  minFetchMs?: number; // default 60 seconds
  configName?: string; // default "feature-flags"
}

getFlag(key: string): boolean

Returns a boolean flag.

Priority: URL override > Remote Config > Defaults.

subscribe(listener: () => void): () => void

Subscribe to internal flag changes (e.g., after a Remote Config update or URL navigation). Returns an unsubscribe() function.

getUrlOverride(key: string): boolean | null

Returns:

  • true / false if the flag is currently overridden via the URL.
  • null if the flag is not overridden.

Remote Config Format

Remote Config must contain a JSON string under the key: feature_flags (or any custom key you configure)

Example Remote Config data (JSON string value):

{
  "billing.newCheckout.v2": true,
  "ui.darkMode.toggle": false,
  "feed.layout.v3": true
}

Important: Only flags explicitly defined in setDefaults() are considered by the library.


Debugging Tips

  • Check if a flag is overridden by the URL:

    console.log(getUrlOverride("myFlag"));