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

@abtasty/codebase-analyzer-typescript

v0.1.0

Published

Analyze codebases to detect feature flag usage across multiple platforms

Readme

@abtasty/codebase-analyzer-typescript

A TypeScript library that scans codebases to detect feature flag usage across multiple platforms and programming languages.

Features

  • Multi-platform detection — AB Tasty (Flagship SDK V3), LaunchDarkly, OpenFeature, Optimizely, Split, VWO
  • Multi-language support — JavaScript/TypeScript, Go, Python, Java, Kotlin, PHP, Swift, Objective-C, C#/.NET, VB.NET, Dart, C/C++
  • Flag metadata extraction — flag keys, default values, types (boolean, string, number, json), line numbers
  • Repository linking — generates direct links to flag usages in your source repository
  • Custom regex support — extend detection with your own patterns via JSON configuration
  • Comment-based detection — supports fe:flag: flagKey, type comments for manual flag annotation
  • Dual module format — ships as both CommonJS and ESM with full TypeScript declarations

Installation

npm install @abtasty/codebase-analyzer-typescript

Quick start

import { analyzeCode, createConfig } from "@abtasty/codebase-analyzer-typescript";

const config = createConfig({
  directory: "./src",
  repositoryURL: "https://github.com/your-org/your-repo",
  repositoryBranch: "main",
});

const results = analyzeCode(config);

for (const file of results) {
  if (file.results.length > 0) {
    console.log(`${file.file}: ${file.results.length} flag(s) found`);
    for (const flag of file.results) {
      console.log(`  - ${flag.flagKey} (${flag.flagType}, default: ${flag.flagDefaultValue})`);
    }
  }
}

API

createConfig(options?)

Creates an AnalyzerConfig with sensible defaults.

const config = createConfig({
  directory: "./src",             // Directory to scan (default: ".")
  repositoryURL: "https://...",   // Repository root URL for generating links
  repositoryBranch: "main",      // Branch name (default: "main")
  nbLineCodeEdges: 1,            // Context lines around flag usage (default: 1)
  filesToExclude: [".git", "node_modules"], // Exclusion patterns
  searchCustomRegex: "",          // Custom regex patterns as JSON string
});

analyzeCode(config)

Scans the codebase and logs results to the console. Returns an array of FileAnalyzed objects.

const results: FileAnalyzed[] = analyzeCode(config);

extractFlagsInfo(config)

Same as analyzeCode but without console output. Use this for silent/programmatic analysis.

const results: FileAnalyzed[] = extractFlagsInfo(config);

getFlagType(defaultValue)

Determines the flag type from its default value string.

const { flagType, defaultValue } = getFlagType('"hello"');
// flagType: "string", defaultValue: '"hello"'

const { flagType } = getFlagType("true");
// flagType: "boolean"

getPlatformRegexes(platform)

Returns regex patterns for a specific platform, or null if not found.

import { getPlatformRegexes } from "@abtasty/codebase-analyzer-typescript";

const patterns = getPlatformRegexes("launchdarkly");

Supported platforms: "launchdarkly", "openfeature", "optimizely", "split", "vwo".

getTemplateRegexes()

Returns template regex patterns that can be used as a starting point for custom patterns.

Types

interface AnalyzerConfig {
  directory: string;
  repositoryURL: string;
  repositoryBranch: string;
  nbLineCodeEdges: number;
  filesToExclude: string[];
  searchCustomRegex: string;
}

interface FileAnalyzed {
  file: string;              // Relative file path
  fileURL: string;           // Full URL to the file in the repository
  error: string | null;      // Error message if analysis failed
  results: FlagAnalyzed[];   // Flags found in this file
}

interface FlagAnalyzed {
  lineNumber: number;        // Line where the flag was found
  flagKey: string;           // The flag key/name
  flagDefaultValue: string;  // The default value
  flagType: string;          // "boolean" | "string" | "number" | "json" | "unknown"
  exists: boolean;           // Whether the flag exists in the platform
}

interface RegexPattern {
  file_extension: string;    // File extension regex (e.g. ".[jt]s$")
  regexes: string[];         // Regex patterns to apply
}

type Platform = "launchdarkly" | "openfeature" | "optimizely" | "split" | "vwo";

Custom regex patterns

You can extend detection with custom regex patterns by passing a JSON string to searchCustomRegex:

const customRegex = JSON.stringify([
  {
    file_extension: "\\.tsx?$",
    regexes: [
      "myCustomFlag\\(['\"]([\\w-]+)['\"]\\s*,\\s*([^)]+)\\)"
    ]
  }
]);

const config = createConfig({
  directory: "./src",
  repositoryURL: "https://github.com/org/repo",
  searchCustomRegex: customRegex,
});

Each regex must use capture groups:

  • Group 1 — the flag key
  • Group 2 (optional) — the default value

Comment-based flag annotation

You can annotate flags directly in your code using comments:

// fe:flag: myFlagKey, boolean

This is useful for flags that are not detected by the built-in regex patterns.

Supported SDK methods

AB Tasty (Flagship)

useFsFlag(), getFlag(), getModification(), and key/defaultValue object patterns.

LaunchDarkly

variation(), boolVariation(), stringVariation(), intVariation(), float64Variation(), jsonVariation(), and more.

OpenFeature

getBooleanValue(), getStringValue(), getNumberValue(), getObjectValue(), and their Details variants.

Optimizely

isFeatureEnabled(), getFeatureVariable*(), decide(), and more.

Split

getTreatment(), getTreatmentWithConfig(), and similar.

VWO

isFeatureEnabled(), getFeatureVariableValue(), activate(), and more.

Development

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Type check
npm run typecheck

# Lint
npm run lint

License

MIT

codebase-analyzer-typescript