Skip to content

Commit

Permalink
docs(core): Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbrg committed Jan 28, 2024
1 parent e3f2c2a commit 76ca8d0
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,16 @@ const criteria = {
hasCoupon: true,
};

/**
* Evaluate the criteria against the rule
*
* The result will be true
*/
/** Evaluate the criteria against the rule */
let result = await RulePilot.evaluate(rule, criteria);
// result == true

// However, if any of the criteria do not pass the check, the result will be false
criteria.totalCheckoutPrice = 25.0;

/**
* The result will be false
*/
/** Evaluate the new criteria against the rule */
result = await RulePilot.evaluate(rule, criteria);
// result == false
```

We can add additional conditions to the rule, for example apart from the above-mentioned conditions, we can also
Expand Down Expand Up @@ -198,16 +194,15 @@ const criteria = {
hasCoupon: true,
};

/**
* The result will be false
*/
/** Evaluate the criteria against the rule */
let result = await RulePilot.evaluate(rule, criteria);
// result == false

/**
* The result will be true
*/
criteria.hasStudentCard = true;

/** Evaluate the new criteria against the rule */
result = await RulePilot.evaluate(rule, criteria);
// result == true
```

If we want to add additional requirements to the rule, we can do so by adding another `any` or `all` condition.
Expand Down Expand Up @@ -441,27 +436,26 @@ const criteria = {
hasCoupon: true,
};

/**
* The result will be 5
*/

/** Evaluate the criteria against the rule */
let result = await RulePilot.evaluate(rule, criteria);
// result = 5

criteria.country = "SE";
criteria.city = "Linköping";

/**
* The result will be 10
*/

/** Evaluate the new criteria against the rule */
result = await RulePilot.evaluate(rule, criteria);
// result = 10

criteria.country = "IT";
criteria.age = 17;
criteria.hasStudentCard = false;

/**
* The result will be false
*/
/** Evaluate the new criteria against the rule */
result = await RulePilot.evaluate(rule, criteria);
// result = false
```

**Important** When using granular rules, the order of conditions in the rule matters!
Expand All @@ -484,10 +478,10 @@ const rule: Rule = {
default: 2.5,
};

/**
* The result will be 2.4
*/

/** Evaluate the criteria against the rule */
let result = await RulePilot.evaluate(rule, {});
// result = 2.5
```

In such a setup as seen above, if no conditions are met, the result will be `2.5`.
Expand Down Expand Up @@ -549,10 +543,9 @@ const criteria = {
},
};

/**
* The result will be true
*/
/** Evaluate the criteria against the rule */
let result = await RulePilot.evaluate(rule, criteria);
// result = true
```

### Evaluating Multiple Criteria At Once
Expand Down Expand Up @@ -585,10 +578,9 @@ const criteria = [
},
];

/**
* The result will be [true, false]
*/
/** Evaluate the criteria against the rule */
let result = await RulePilot.evaluate(rule, criteria);
// result = [true, false]
```

## Validating A Rule
Expand Down

0 comments on commit 76ca8d0

Please sign in to comment.