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-prune

v1.4.0

Published

Safe, deterministic feature-flag removal codemod for JavaScript and TypeScript

Readme

🧹 flag-prune

Remove feature flags from JavaScript and TypeScript without turning cleanup into a manual refactor.

flag-prune is a safe, deterministic codemod for JS, JSX, TS, and TSX. Give it the final value of a flag and it replaces matching reads, folds expressions to a fixed point, removes dead control flow, and cleans up bindings and imports while preserving required runtime evaluation.

- const enabled = useFlag("new-feature")
- if (enabled) {
-   showFeature()
- } else {
-   legacyFeature()
- }
+ showFeature()
npx flag-prune --set 'useFlag("new-feature")=true' ./

Quick start

Interactive mode

Run without arguments to answer three prompts, preview the result, and optionally write it:

npx flag-prune

Explicit mode

Preview a migration. Dry-run mode is the default, so the first run prints a diff without changing files:

npx flag-prune --set 'useFlag("new-access")=false' ./src

Write the reviewed changes:

npx flag-prune --set 'useFlag("new-access")=false' --write ./src

Then run your project's typecheck, lint, and tests.

But why?

Feature-flag removal should be mechanical.

A general-purpose coding AI agent can coordinate a migration, but the repetitive transformation is better handled by a deterministic tool. The same input and rules should produce the same output. This makes large cleanups faster, more predictable, and much less expensive than burning through LLM tokens or reviewer time.

flag-prune is provider-agnostic. It can match hooks, functions, client methods, imported constants, global members, and variant values without knowing which feature-flag SDK produced them. See the feature flag provider guides for Unleash, LaunchDarkly, PostHog, Statsig, and OpenFeature examples.

Excellent projects of Fallow, Knip, and countless predecessors do a great job of removing unused code, but are focused on dead files and imports rather than evaluation. Use them after a flag-prune pass.

Acknowledgments

This project was inspired by:

Common rules

Repeat --set to remove related flags in one pass.

# Local or global member
npx flag-prune --set 'features.newCheckout=false' ./src

# Imported constant; aliases are resolved
npx flag-prune --set './flags#NEW_CHECKOUT=false' ./src

# Function or method call with an exact argument prefix
npx flag-prune --set 'useFlag("new-checkout")=false' ./src
npx flag-prune --set 'client.isEnabled("new-checkout")=false' ./src

# String, number, and null values
npx flag-prune --set 'getVariant("checkout")=treatment' ./src
npx flag-prune --set 'limits.maxSeats=25' ./src
npx flag-prune --set 'readOverride()=null' ./src

# Environment variables
npx flag-prune --set 'process.env.FEATURE_FLAG=true' ./src

Configured call arguments must be static string, number, boolean, or null literals. Additional arguments at the call site are allowed, and any required evaluation is preserved.

See Flag rules for the complete syntax and matching model.

What can it do?

  • Boolean branches, ternaries, logical expressions, nullish coalescing, and selected loops.
  • String and numeric comparisons such as ===, !==, <, <=, >, and >=.
  • Object and array variant values, folding static member and index reads while preserving object identity.
  • Object spreads that provably contribute nothing after folding, such as ...(false) or ...({}).
  • Stable local bindings assigned from a configured flag read.
  • JSX conditions and boolean attributes.
  • Unreachable statements after return, throw, break, and continue where removal is safe.
  • Imports and bindings made unused by the migration.

Safety and limitations

  • Unknown values and dynamic flag keys stay untouched. Calls with non-static arguments are not matched.
  • Unused files, unused exports, or unused imports that are still referenced by other code are not removed. Use a linter or dead-code tool for that.
  • The transform does not discard required await, yield, or other side effects. Calls, getters, computed keys, spreads, and other observable evaluation are preserved.
  • Lexical scope and protects important comments are protected. Safe scoping blocks left by folding are de-scoped by default (only when provably safe); opt out with --no-flatten-blocks.

See Safety guarantees for the detailed rules and opt-outs.

CI

Use --json for structured output and --strict to turn warnings into exit code 2.

See CI and automation for a GitHub Actions example and exit-code guidance.

Documentation

AI tools and documentation crawlers can use docs/llms.txt for a quick start and documentation link.

| Page | Use it for | | -------------------------------------------------- | ------------------------------------------------------ | | Provider guides | Remove flags from popular feature flag providers: Unleash, LaunchDarkly, PostHog, Statsig, OpenFeature. | | Documentation overview | Choose the right guide or reference page | | Getting started | Run a first migration safely | | Recommended workflow | Chain flag-prune with checks, dead-code tools, and an LLM cleanup pass | | Flag rules | Define exact member, import, and call matches | | Recipes | Copy focused examples for common flag shapes | | CLI reference | Review options, file discovery, output, and exit codes | | CI and automation | Add checks and machine-readable reporting | | Library API | Call the transform from JavaScript or TypeScript | | Safety guarantees | Understand preservation and conservative behavior | | Troubleshooting | Diagnose unmatched rules, warnings, and parse failures |

Requirements

  • Node.js 22 or newer.
  • Supported source files: .js, .jsx, .mjs, .cjs, .ts, .tsx, .mts, and .cts.
  • Type declaration files such as .d.ts are skipped.