*This project is in early-development stage. All feedbacks and contributions are welcome!
- Toggle flags via Airtable
- Config and load once, access flags everywhere
- Support both Node.js and browser
- Written in TypeScript
- Having a web UI
- API ready
- Free plan should be more than enough for feature flags
With NPM
npm i airflags
or Yarn
yarn add airflags
Create a table with following fields (columns)
- Name as a first field with text type (representing flag name)
- Environment fields as a Checkbox type (representing flag status in each environment)
Flags can be toggled on/off by clicking the checkbox.
import Airflags from 'airflags';
// Config Airflags
Airflags.config({
environment: 'Production',
baseId: 'AIRTABLE_BASE_ID',
tableName: 'AIRTABLE_TABLE_NAME',
apiKey: 'AIRTABLE_API_KEY',
});
// Load flags from Airtable (asyncronous)
await Airflags.load();
// Get flag status by feature name (recommended)
Airflags.is('featureA'); // true
Airflags.is('featureB'); // false
// All get all loaded flags
const flags = Airflags.getFlags(); // { featureA: true, featureB: false }
Config object
- environment: The corresponded environment field name in Airtable.
- baseId, tableName and apiKey are for Airtable API. More info can be found on Airtable API doc
Airflags is a singleton
Airflags
is a class with static methods and properties.- Meaning that
config()
andload()
methods are required to run atleast once. Thenis()
andgetFlags()
can be called anywhere. - However,
config()
andload()
methods can be called anytime after when you want to change the config or reload the flags.
Feature name can be stored in an enum
to improve code cleaness and reduce typing mistake.
enum Feature {
FeatureA = 'featureA',
FeatureB = 'featureB',
}
// Use with is method
Airflags.is(Feature.FeatureA);
Airflags.is(Feature.FeatureB);
// Use with getFlags method
const flags: Record<Feature, boolean> = Airflags.getFlags();