# togglee

> Simple library to separate deployment of features from release time. It uses network accessible files without the need of a server to provide feature toggles.

Latest version **1.1.1** (published 2024-08-31) · APACHE-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2024-08-31 |
| First published | 2020-09-15 |
| Weekly downloads | 0 |
| License | APACHE-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 101.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Maintainers | kanekotic |
| Keywords | serverless, flags, toggles |

## Links

- npm: https://www.npmjs.com/package/togglee
- Repository: https://github.com/togglee/togglee-js
- Homepage: https://www.togglee.com/
- Issues: https://github.com/togglee/togglee-js/issues
- npm.io page: https://npm.io/package/togglee

## Dependencies (1)

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

## Recent versions

- 1.1.1 (latest) — 2024-08-31
- 1.1.0 — 2024-08-31
- 1.0.53 — 2023-09-25
- 1.0.52 — 2023-09-18
- 1.0.51 — 2023-09-11
- 1.0.50 — 2023-09-04
- 1.0.49 — 2023-08-28
- 1.0.48 — 2023-08-21
- 1.0.47 — 2023-08-14
- 1.0.46 — 2023-08-07
- 1.0.45 — 2023-07-31
- 1.0.44 — 2023-07-24
- 1.0.43 — 2023-07-17
- 1.0.42 — 2023-07-10
- 1.0.41 — 2023-07-03
- … 55 more at https://npm.io/package/togglee/versions

## README

# ![toggle_logo_text](https://github.com/user-attachments/assets/17e12440-f254-45d9-8e4e-090e52533f1a)

![Build & Publish](https://github.com/togglee/togglee-js/workflows/Build%20&%20Publish/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/togglee/togglee-js/branch/master/graph/badge.svg)](https://codecov.io/gh/togglee/togglee-js)
[![npm](https://img.shields.io/npm/dt/togglee.svg)](https://github.com/togglee/togglee-js)
[![GitHub license](https://img.shields.io/github/license/togglee/togglee-js.svg)](https://github.com/togglee/togglee-js/blob/master/LICENSE)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/togglee/togglee-js/graphs/commit-activity)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/kanekotic/)

## Motivation

Simple library to separate deployment of features from release time. It uses network accesible files without the need of a server to provide feature toggles.

## Installation

add it to your project using `npm install togglee --save` or `yarn add togglee`

## Usage

```js
import { Togglee } from '../lib'
// or: const { Togglee } = require("togglee")

const url = "https://gist.githubusercontent.com/alvarolorentedev/c469f99bef5a5c0634b4a94a4acd6546/raw/toggles"
const refreshRateSeconds = 5
const defaultValues = [
    {
      type: "release",
      name: "prop",
      value: true,
    },
    {
      type: "release",
      name: "prop2",
      value: true
    },
    {
      type: "context",
      name: "prop3",
      conditions: [
        {
          field: "username",
          value: "user1",
          operation: "eq"
        }
      ]
    }
]

const subject = new Togglee(url, refreshRateSeconds, defaultValues)


setInterval(() => {
    if (subject.isEnabled("prop"))
        console.log("do stuff")
    else
        console.log("dont do stuff")
    if (subject.isEnabled("prop3", {"username": "user1"}))
        console.log("do stuff for user 1")
    else
        console.log("dont do stuff for user 1")
    if (subject.isEnabled("prop3", {"username": "user2"}))
        console.log("do stuff for user 2")
    else
        console.log("dont do stuff for user 2")
        
    console.log("-----------")
}, 10000);
```

## Type of toggles

### Release

Simple true/false logical path definition.
```js
{
    type: "release",
    name: "prop",
    value: true,
}
```

### Context

Allows complex logic to decide the outcome of the logical path (example traffic, users, resources available). 
```js
{
    type: "context",
    name: "prop3",
    conditions: [
        {
            field: "username",
            value: "user1",
            operation: "eq"
        }
    ]
}
```
available operations are:
* 'eq': equal (===)
* 'ne': not equal (!==)
* 'gt': greater than (>)
* 'ge': greater equal (>=)
* 'lt': lesser than (<)
* 'le': lesser qqual (<=)

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