# tggl-core

> Tggl Typescript core for evaluating flags

Latest version **1.4.0** (published 2024-10-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install tggl-core
pnpm add tggl-core
yarn add tggl-core
bun add tggl-core
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2024-10-19 |
| First published | 2023-02-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nicolas Keller |
| Maintainers | nick-keller |
| Keywords | Tggl, Feature flag, Feature toggle, A/B testing, Remote config, Kill switch |

## Links

- npm: https://www.npmjs.com/package/tggl-core
- Repository: https://github.com/Tggl/tggl-core
- Homepage: https://tggl.io/
- Issues: https://github.com/Tggl/tggl-core/issues
- npm.io page: https://npm.io/package/tggl-core

## Dependencies (1)

- [xxhashjs](https://npm.io/package/xxhashjs.md) ^0.2.2

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 1.4.0 (latest) — 2024-10-19
- 1.3.0 — 2024-10-11
- 1.2.0 — 2023-07-24
- 1.1.0 — 2023-03-26
- 1.0.0 — 2023-02-18

## README

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://tggl.io/tggl-io-logo-white.svg">
    <img align="center" alt="Tggl Logo" src="https://tggl.io/tggl-io-logo-black.svg" width="200rem" />
  </picture>
</p>

<h1 align="center">Tggl Core</h1>

<p align="center">
  This package is used to evaluate flags and serves as a reference implementation.
</p>

<p align="center">
  <a href="https://tggl.io/">🔗 Website</a>
  •
  <a href="https://tggl.io/developers">📚 Documentation</a>
  •
  <a href="https://www.npmjs.com/package/tggl-core">📦 NPM</a>
  •
  <a href="https://www.youtube.com/@Tggl-io">🎥 Videos</a>
</p>

<p align="center">
  <img src="https://img.shields.io/github/actions/workflow/status/Tggl/tggl-core/tests.yml" alt="GitHub Workflow Status (with event)" />
  <img src="https://img.shields.io/coverallsCoverage/github/Tggl/tggl-core" alt="Coveralls branch" />
  <img src="https://img.shields.io/npm/v/tggl-core" alt="npm" />
</p>

## Usage

This library is not intended for direct use, you probably want to use the [client](https://tggl.io/developers/sdks/node) instead. The client nicely wraps this library in a more convenient way.

If you still want to use this library directly, you can add the package to your dependencies:
```
npm i tggl-core
```

And start evaluating flags:
```typescript
import { evalFlag, Flag, Operator } from 'tggl-core'

const flag: Flag = {
  conditions: [
    {
      rules: [
        {
          key: 'email',
          operator: Operator.StrEndsWith,
          values: ['@acme.com'],
          negate: false,
        }
      ],
      variation: {
        active: true,
        value: 'foo'
      }
    },
  ],
  defaultVariation: {
    active: false,
    value: null,
  },
}

const result = evalFlag(
  {
    userId: 'abc',
    email: 'john.doe@acme.com'
  },
  flag
)

console.log(result) // => 'foo'
```

## Porting it to another language

If you are porting it to another language, copy [standard_tests.json](./src/tests/standard_tests.json) and write a single unit tests that iterates over all the examples of this file. This is exactly what [standard.test.ts](./src/tests/standard.test.ts) does.

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