# compatx

> 🌴 Gradual feature flags.

Latest version **0.2.0** (published 2025-04-07) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2025-04-07 |
| First published | 2024-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 10.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 63 |
| Maintainers | pi0 |

## Links

- npm: https://www.npmjs.com/package/compatx
- Repository: https://github.com/unjs/compatx
- Homepage: https://github.com/unjs/compatx#readme
- Issues: https://github.com/unjs/compatx/issues
- npm.io page: https://npm.io/package/compatx

## Recent versions

- 0.2.0 (latest) — 2025-04-07
- 0.1.8 — 2024-06-12
- 0.1.7 — 2024-06-12
- 0.1.6 — 2024-06-12
- 0.1.5 — 2024-06-12
- 0.1.4 — 2024-06-12
- 0.1.3 — 2024-06-10
- 0.1.2 — 2024-06-10
- 0.1.1 — 2024-06-10
- 0.1.0 — 2024-06-10
- 0.0.0 — 2024-06-10

## README

# `compatx`

<!-- automd:badges -->

[![npm version](https://img.shields.io/npm/v/compatx)](https://npmjs.com/package/compatx)
[![npm downloads](https://img.shields.io/npm/dm/compatx)](https://npm.chart.dev/compatx)

<!-- /automd -->

🌴 Compatibility toolkit.

> [!NOTE]
> This is a WIP toolkit. See [RFC](./RFC.md) for initial motivations.

## Install

<!-- automd:pm-install dev -->

```sh
# ✨ Auto-detect
npx nypm install -D compatx

# npm
npm install -D compatx

# yarn
yarn add -D compatx

# pnpm
pnpm install -D compatx

# bun
bun install -D compatx

# deno
deno install --dev compatx
```

<!-- /automd -->

## Utils

<!-- automd:jsdocs src="./src/index.ts" -->

### `formatCompatibilityDate(input)`

Format compatibility date spec to a string

### `formatDate(date)`

Format a date to a `YYYY-MM-DD` string

**Example:**

```ts
formatDateString(new Date("2021/01/01")) // "2021-01-01"
```

### `getCompatibilityChanges(allUpdates, compatibilityDate1, compatibilityDate2)`

Get compatibility changes between two dates.

### `getCompatibilityUpdates(allUpdates, compatibilityDate)`

Get compatibility updates applicable for the user given platform and date range.

### `platforms`

- **Type**: `array`
- **Default**: `["aws","azure","cloudflare","deno","firebase","netlify","vercel"]`

### `resolveCompatibilityDates(input?, defaults?)`

Normalize the compatibility dates from input config and defaults.

### `resolveCompatibilityDatesFromEnv(overridesInput?)`

Resolve compatibility dates with environment variables as defaults.

Environment variable name format is `COMPATIBILITY_DATE` for default and `COMPATIBILITY_DATE_<PLATFORM>` for specific platforms.

<!-- /automd -->

## Types

```js
import type {
  // Typed date string in `YYYY-MM-DD` format
  DateString,
  // Platform names
  PlatformName,
  // Compatibility dates
  CompatibilityDateSpec,
  CompatibilityDates,
  // Compatibility updates
  CompatibilityUpdate,
  CompatibilityUpdates
} from "./types";
```

## Development

- Clone this repository
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`

## License

Made with 💛

Published under [MIT License](./LICENSE).

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