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
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const client = createFeatureFlagClient({

### Add properties to client

Secondly we want add some attributes we can use in the condition in each of the feature flags we are creating later. You are allowed to use `string`, `number` or `boolean` types as a property
Secondly we want add some attributes we can use in the condition(s) in each of the feature flags we are creating later. You are allowed to use `string`, `number` or `boolean` types as a property

```ts
import { createFeatureFlagClient } from "toggle-kit";
Expand All @@ -82,7 +82,7 @@ const client = createFeatureFlagClient({

### Create feature flag

Last but not least, we want to create our first flag. Here we specify a name for the feature flag and select the type of condition we want to evaluate upon. Then we select the property we want to evaluate, and an expected value.
Last but not least, we want to create our first flag. Here we specify a name for the feature flag and select the type of condition(s) we want to evaluate upon. Then we select the property we want to evaluate, and an expected value.

```ts
import { createFeatureFlagClient } from "toggle-kit";
Expand All @@ -97,11 +97,13 @@ const client = createFeatureFlagClient({
flags: [
{
name: "secret-page",
condition: {
type: "equal",
attribute: "email",
expectedValue: "test@example.com",
},
conditions: [
{
type: "equal",
attribute: "email",
expectedValue: "test@example.com",
},
],
},
],
});
Expand All @@ -124,11 +126,13 @@ const client = createFeatureFlagClient({
flags: [
{
name: "secret-page",
condition: {
type: "equal",
attribute: "email",
expectedValue: "test@example.com",
},
conditions: [
{
type: "equal",
attribute: "email",
expectedValue: "test@example.com",
},
],
},
],
});
Expand Down
24 changes: 14 additions & 10 deletions docs/conditions/contains.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ const client = createFeatureFlagClient({
flags: [
{
name: "is-admin",
condition: {
type: "contains",
attribute: "roles",
expectedValue: "admin",
},
conditions: [
{
type: "contains",
attribute: "roles",
expectedValue: "admin",
},
],
},
{
name: "is-gmail",
condition: {
type: "contains",
attribute: "email",
expectedValue: "@gmail.com",
},
conditions: [
{
type: "contains",
attribute: "email",
expectedValue: "@gmail.com",
},
],
},
],
});
Expand Down
24 changes: 14 additions & 10 deletions docs/conditions/endsWith.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ const client = createFeatureFlagClient({
flags: [
{
name: "is-example-mail",
condition: {
type: "endsWith",
attribute: "email",
expectedValue: "@example.com",
},
conditions: [
{
type: "endsWith",
attribute: "email",
expectedValue: "@example.com",
},
],
},
{
name: "is-google-mail",
condition: {
type: "endsWith",
attribute: "email",
expectedValue: "@gmail.com",
},
conditions: [
{
type: "endsWith",
attribute: "email",
expectedValue: "@gmail.com",
},
],
},
],
});
Expand Down
24 changes: 14 additions & 10 deletions docs/conditions/equal.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ const client = createFeatureFlagClient({
flags: [
{
name: "is-john",
condition: {
type: "equal",
attribute: "username",
expectedValue: "JohnDoe",
},
conditions: [
{
type: "equal",
attribute: "username",
expectedValue: "JohnDoe",
},
],
},
{
name: "is-jane",
condition: {
type: "equal",
attribute: "username",
expectedValue: "JaneDoe",
},
conditions: [
{
type: "equal",
attribute: "username",
expectedValue: "JaneDoe",
},
],
},
],
});
Expand Down
12 changes: 7 additions & 5 deletions docs/conditions/greaterThan.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ const client = createFeatureFlagClient({
flags: [
{
name: "is-adult",
condition: {
type: "greaterThan",
attribute: "age",
expectedValue: 20,
},
conditions: [
{
type: "greaterThan",
attribute: "age",
expectedValue: 20,
},
],
},
],
});
Expand Down
12 changes: 7 additions & 5 deletions docs/conditions/lessThan.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ const client = createFeatureFlagClient({
flags: [
{
name: "is-child",
condition: {
type: "lessThan",
attribute: "age",
expectedValue: 21,
},
conditions: [
{
type: "lessThan",
attribute: "age",
expectedValue: 21,
},
],
},
],
});
Expand Down
12 changes: 7 additions & 5 deletions docs/conditions/percentage.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ const client = createFeatureFlagClient({
flags: [
{
name: "is-lucky",
condition: {
type: "percentage",
attribute: "userId",
expectedValue: 50,
},
conditions: [
{
type: "percentage",
attribute: "userId",
expectedValue: 50,
},
],
},
],
});
Expand Down
12 changes: 7 additions & 5 deletions docs/conditions/regex.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ const client = createFeatureFlagClient({
flags: [
{
name: "is-gmail",
condition: {
type: "regex",
attribute: "email",
expectedValue: /.+@gmail\.com/,
},
conditions: [
{
type: "regex",
attribute: "email",
expectedValue: /.+@gmail\.com/,
},
],
},
],
});
Expand Down
12 changes: 7 additions & 5 deletions docs/conditions/startsWith.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ const client = createFeatureFlagClient({
flags: [
{
name: "is-john",
condition: {
type: "startsWith",
attribute: "username",
expectedValue: "john",
},
conditions: [
{
type: "startsWith",
attribute: "username",
expectedValue: "john",
},
],
},
],
});
Expand Down
12 changes: 7 additions & 5 deletions docs/usages/simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ const client = createFeatureFlagClient({
flags: [
{
name: "secret-page", // No autocompletion
condition: {
type: "equal",
attribute: "email", // No autocompletion
expectedValue: "test@example.com",
},
conditions: [
{
type: "equal",
attribute: "email", // No autocompletion
expectedValue: "test@example.com",
},
],
},
],
});
Expand Down
12 changes: 7 additions & 5 deletions docs/usages/structured.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ type FlagNames = "secret-page";
const flags: FeatureFlag<PropertyNames, FlagNames>[] = [
{
name: "secret-page", // <--- Autocompletion
condition: {
type: "equal",
attribute: "email", // <--- Autocompletion
expectedValue: "test@example.com",
},
conditions: [
{
type: "equal",
attribute: "email", // <--- Autocompletion
expectedValue: "test@example.com",
},
],
},
];

Expand Down
6 changes: 3 additions & 3 deletions docs/usages/typed.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const client = createFeatureFlagClient<PropertyNames, FlagNames>({
flags: [
{
name: "secret-page", // <--- Autocompletion
condition: {
conditions: {
type: "equal",
attribute: "email", // <--- Autocompletion
expectedValue: "test@example.com",
Expand Down Expand Up @@ -62,7 +62,7 @@ const client = createFeatureFlagClient<string, FlagNames>({
flags: [
{
name: "secret-page", // <--- Autocompletion
condition: {
conditions: {
type: "equal",
attribute: "email", // <--- No Autocompletion
expectedValue: "test@example.com",
Expand Down Expand Up @@ -94,7 +94,7 @@ const client = createFeatureFlagClient<string, string>({
flags: [
{
name: "secret-page", // <--- No Autocompletion
condition: {
conditions: {
type: "equal",
attribute: "email", // <--- No Autocompletion
expectedValue: "test@example.com",
Expand Down
12 changes: 7 additions & 5 deletions src/conditions/contains/contains.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ describe("Condition - Contains", () => {
flags: [
{
name: "admin-dashboard",
condition: {
type: "contains",
attribute: "roles",
expectedValue: "admin",
},
conditions: [
{
type: "contains",
attribute: "roles",
expectedValue: "admin",
},
],
},
],
});
Expand Down
12 changes: 7 additions & 5 deletions src/conditions/endsWith/endsWith.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ describe("Condition - Ends With", () => {
flags: [
{
name: "example-emails",
condition: {
type: "endsWith",
attribute: "email",
expectedValue: "example.com",
},
conditions: [
{
type: "endsWith",
attribute: "email",
expectedValue: "example.com",
},
],
},
],
});
Expand Down
12 changes: 7 additions & 5 deletions src/conditions/equal/equal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ describe("Condition - Equal", () => {
flags: [
{
name: "is-admin",
condition: {
type: "equal",
attribute: "isAdmin",
expectedValue: true,
},
conditions: [
{
type: "equal",
attribute: "isAdmin",
expectedValue: true,
},
],
},
],
});
Expand Down
12 changes: 7 additions & 5 deletions src/conditions/greaterThan/greaterThan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ describe("Condition - Greater Than", () => {
flags: [
{
name: "is-adult",
condition: {
type: "greaterThan",
attribute: "age",
expectedValue: 21,
},
conditions: [
{
type: "greaterThan",
attribute: "age",
expectedValue: 21,
},
],
},
],
});
Expand Down
Loading