🚩 Feature Flags

Learn about Toolkitify Feature Flags.

Dynamic Feature Flag Demo with User Input

In this demo, users can type any ID or word, and a feature will be enabled or disabled depending on a rule:

  • If the input has more than 5 characters, the feature is enabled.
  • Otherwise, it is disabled.

Try the following example inputs to see the behavior:

  • alice β†’ disabled
  • charlie β†’ enabled
  • bob β†’ disabled
  • developer123 β†’ enabled
Dynamic Feature Flag Demo

Feature Flags TypeScript Example

Here is how you define a dynamic feature flag and what the function receives:

// Define the type of context the dynamic function receives
interface UserContext {
  input: string; // The user-provided ID or word
}

// Load flags
flags.load({
  INPUT_FEATURE: (ctx: UserContext) => {
    // Rule: feature enabled if input length > 5
    return ctx.input.length > 5;
  }
});

// Usage
const userInput = "charlie";

if (flags.isEnabled("INPUT_FEATURE", { input: userInput })) {
  console.log("Feature enabled βœ…");
} else {
  console.log("Feature locked ❌");
}

Interfaces

ParameterTypeRequiredDescription
ctxContextβœ…Object containing context information for the flag
Return valueBbooleanβœ…true if the feature should be enabled, else false

This demonstrates how to write a dynamic feature flag function and how the typed context ensures proper usage and auto-completion in TypeScript.