# airflags

> Airtable as a JavaScript feature flags

Latest version **0.3.0** (published 2021-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install airflags
pnpm add airflags
yarn add airflags
bun add airflags
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2021-01-08 |
| First published | 2021-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Th1nkK1D |
| Maintainers | th1nkk1d |

## Links

- npm: https://www.npmjs.com/package/airflags
- Repository: https://github.com/Th1nkK1D/airflags
- npm.io page: https://npm.io/package/airflags

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.21.1

## Recent versions

- 0.3.0 (latest) — 2021-01-08
- 0.2.0 — 2021-01-03
- 0.1.1 — 2021-01-03

## README

# Airflags

_\*This project is in early-development stage. All feedbacks and contributions are welcome!_

![Airtable as a JavaScript feature flags](https://i.imgur.com/QUsQn8p.png)

## Features

- Toggle flags via Airtable
- Config and load once, access flags everywhere
- Support both Node.js and browser
- Written in TypeScript

## Why Airtable?

- Having a web UI
- API ready
- [Free plan](https://airtable.com/pricing) should be more than enough for feature flags

## Installation

With NPM

```bash
npm i airflags
```

or Yarn

```bash
yarn add airflags
```

## Setup Airtable

Create a table with following fields (columns)

1. **Name** as a first field with text type (representing flag name)
2. **Environment** fields as a Checkbox type (representing flag state in each environment)

![Airtable Config](https://i.imgur.com/CuSmNM0.png)

Flags can be toggled on/off by clicking the checkbox.

## Usage

```typescript
import Airflags from 'airflags';

// Config Airflags
Airflags.config({
  environment: 'Development',
  baseId: 'AIRTABLE_BASE_ID',
  tableName: 'AIRTABLE_TABLE_NAME',
  apiKey: 'AIRTABLE_API_KEY',
});

// Load flags from Airtable (asyncronous)
await Airflags.load();

// Get loaded feature flags
const flags = Airflags.getFlags();
```

**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](https://airtable.com/api)

**Example of getFlags return value**

```typescript
{
  featureA: true,
  featureB: false
}
```

**Add type casting (optional)**

```typescript
type Feature = 'featureA' | 'featureB';
type FeatureFlags = Record<Feature, boolean>;

const flags: FeatureFlags = Airflags.getFlags();
```

**Airflags is a singleton**

- `Airflags` is a class with static methods and properties.
- Meaning that `config()` and `load()` methods are required to run atleast once. Then `getFlags()` can be called anywhere.
- However, `config()` and `load()` methods can be called anytime after when you want to change the config or reload the flags.

---
_Source: https://npm.io/package/airflags · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
