Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ A customizable feature flag library, which allows you to define properties and f

## Table of contents

- [Prerequisites](#prerequisites)
- [Table of contents](#table-of-contents)
- [Getting Started](#getting-started)
- [Installation](#installation)
Expand Down Expand Up @@ -107,6 +106,36 @@ const client = createFeatureFlagClient({
});
```

### Evaluate feature flag

When you have finished setting up the feature flag client, and created your flags, you start evaluating flags across your codebase.

```ts
import { createFeatureFlagClient } from "toggle-kit";

const client = createFeatureFlagClient({
property: {
userId: "eb10e5c2-e3f4-46fc-a6fd-f2ddba0973fb",
email: "example@mail.com",
age: 21,
isAdmin: false,
},
flags: [
{
name: "secret-page",
condition: {
type: "equal",
attribute: "email",
expectedValue: "test@example.com",
},
},
],
});

const allowSecretPage = client.isEnabled("secret-page");
console.log(allowSecretPage); // False
```

If the getting started examples isn't enough, you can read more in depth documentation [here](./docs/README.md).

## Contributing
Expand Down
15 changes: 13 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

## Usages

- [Usages](./usages/README.md)
This guide will follow you through the different ways you can utilize the library to manage, control and use your flags.

- [Simple Setup](./usages/simple.md)
- [Typed Setup](./usages/typed.md)
- [Structured Setup](./usages/structured.md)

## Conditions

- [Contains](./conditions/Contains.md)
- [Contains](./conditions/contains.md)
- [Ends With](./conditions/endsWith.md)
- [Equal](./conditions/equal.md)
- [Greater Than](./conditions/greaterThan.md)
- [Less Than](./conditions/lessThan.md)
- [Percentage](./conditions/percentage.md)
- [Regex](./conditions/regex.md)
- [Starts With](./conditions/startsWith.md)
34 changes: 34 additions & 0 deletions docs/conditions/endsWith.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Conditions - Ends With

You can use this conditions to check if the property ends with the value.

## Example

```ts
const client = createFeatureFlagClient({
property: {
email: "test@example.com",
},
flags: [
{
name: "is-example-mail",
condition: {
type: "endsWith",
attribute: "email",
expectedValue: "@example.com",
},
},
{
name: "is-google-mail",
condition: {
type: "endsWith",
attribute: "email",
expectedValue: "@gmail.com",
},
},
],
});

client.isEnabled("is-example-mail"); // True
client.isEnabled("is-google-mail"); // False
```
34 changes: 34 additions & 0 deletions docs/conditions/equal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Conditions - Equal

You can use this conditions to check if the property matches the value.

## Example

```ts
const client = createFeatureFlagClient({
property: {
username: "JohnDoe",
},
flags: [
{
name: "is-john",
condition: {
type: "equal",
attribute: "username",
expectedValue: "JohnDoe",
},
},
{
name: "is-jane",
condition: {
type: "equal",
attribute: "username",
expectedValue: "JaneDoe",
},
},
],
});

client.isEnabled("is-john"); // True
client.isEnabled("is-jane"); // False
```
25 changes: 25 additions & 0 deletions docs/conditions/greaterThan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Conditions - Greater Than

You can use this conditions to check if the property (number) is greater than the value.

## Example

```ts
const client = createFeatureFlagClient({
property: {
age: 21,
},
flags: [
{
name: "is-adult",
condition: {
type: "greaterThan",
attribute: "age",
expectedValue: 20,
},
},
],
});

client.isEnabled("is-adult"); // True
```
25 changes: 25 additions & 0 deletions docs/conditions/lessThan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Conditions - Less Than

You can use this conditions to check if the property (number) is less than the value.

## Example

```ts
const client = createFeatureFlagClient({
property: {
age: 21,
},
flags: [
{
name: "is-child",
condition: {
type: "lessThan",
attribute: "age",
expectedValue: 21,
},
},
],
});

client.isEnabled("is-child"); // True
```
25 changes: 25 additions & 0 deletions docs/conditions/percentage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Conditions - Percentage

You can use this conditions to choose a certain percentage which the flags becomes true.

## Example

```ts
const client = createFeatureFlagClient({
property: {
userId: "399a0d09-066c-42f8-8f4d-ce6afad21859",
},
flags: [
{
name: "is-lucky",
condition: {
type: "percentage",
attribute: "userId",
expectedValue: 50,
},
},
],
});

client.isEnabled("is-lucky"); // 50/50 percentage chance.
```
25 changes: 25 additions & 0 deletions docs/conditions/regex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Conditions - Percentage

You can use this conditions to check if a given property matches the specific regex.

## Example

```ts
const client = createFeatureFlagClient({
property: {
email: "example@gmail.com",
},
flags: [
{
name: "is-gmail",
condition: {
type: "regex",
attribute: "email",
expectedValue: /.+@gmail\.com/,
},
},
],
});

client.isEnabled("is-gmail"); // True
```
25 changes: 25 additions & 0 deletions docs/conditions/startsWith.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Conditions - Starts With

You can use this conditions to check if the property starts with the value.

## Example

```ts
const client = createFeatureFlagClient({
property: {
username: "johndoe",
},
flags: [
{
name: "is-john",
condition: {
type: "startsWith",
attribute: "username",
expectedValue: "john",
},
},
],
});

client.isEnabled("is-john"); // True
```
9 changes: 0 additions & 9 deletions docs/usages/README.md

This file was deleted.