Switch Kit

Switch Kit is a “build-your-own” Feature Flagging/Toggling/Experimentation/etc system!

Installation

Install switch-kit via your favorite package manager:

bun install switch-kit
bun install switch-kit

You'll also most likely want to install one of the pre-built Storage Adaptors:

Want to use a different KV (or database) solution? Open a Discussion on the repo to request other adaptors!

Usage:

// Create the SwitchKit client
let switchKit = new SwitchKit({
// This example is using the CloudflareKVAdaptor
// However you can change this out for anything
// that implements the StorageAdaptor interface from `@switch-kit/storage-interface`
adaptor: new CloudflareKVAdaptor({
namespace: "my-switches",
authToken: process.env.CLOUDFLARE_AUTH_TOKEN,
accountID: process.env.CLOUDFLARE_ACCOUNT_ID,
}),
});

// Initialize the SwitchKit client
await switchKit.init();

// Returns either a Switch or undefined
let switchA = await switchKit.get("switch-a");

if (switchA?.value === "on") {
// do something
}
// Create the SwitchKit client
let switchKit = new SwitchKit({
// This example is using the CloudflareKVAdaptor
// However you can change this out for anything
// that implements the StorageAdaptor interface from `@switch-kit/storage-interface`
adaptor: new CloudflareKVAdaptor({
namespace: "my-switches",
authToken: process.env.CLOUDFLARE_AUTH_TOKEN,
accountID: process.env.CLOUDFLARE_ACCOUNT_ID,
}),
});

// Initialize the SwitchKit client
await switchKit.init();

// Returns either a Switch or undefined
let switchA = await switchKit.get("switch-a");

if (switchA?.value === "on") {
// do something
}