π© 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β disabledcharlieβ enabledbobβ disableddeveloper123β enabled
Dynamic Feature Flag DemoCode Sandbox
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
| Parameter | Type | Required | Description |
|---|---|---|---|
ctx | Context | β | Object containing context information for the flag |
| Return value | Bboolean | β | 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.