add example of custom operator
Signed-off-by: goenning <me@goenning.net>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-tech-insights-backend-module-jsonfc': minor
|
||||
'@backstage/plugin-tech-insights-backend-module-jsonfc': patch
|
||||
---
|
||||
|
||||
ability to add custom operators
|
||||
|
||||
@@ -85,3 +85,32 @@ export const exampleCheck: TechInsightJsonRuleCheck = {
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
# Custom operators
|
||||
|
||||
json-rules-engine supports a limited [number of built-in operators](https://github.com/CacheControl/json-rules-engine/blob/master/docs/rules.md#operators) that can be used in conditions. You can add your own operators by adding them to the `operators` array in the `JsonRulesEngineFactCheckerFactory` constructor. For example:
|
||||
|
||||
```diff
|
||||
const myFactCheckerFactory = new JsonRulesEngineFactCheckerFactory({
|
||||
checks: [],
|
||||
logger,
|
||||
+ operators: [ new Operator("startsWith", (a, b) => a.startsWith(b) ]
|
||||
})
|
||||
```
|
||||
|
||||
And you can then use it in your checks like this:
|
||||
|
||||
```js
|
||||
...
|
||||
rule: {
|
||||
conditions: {
|
||||
any: [
|
||||
{
|
||||
fact: 'version',
|
||||
operator: 'startsWith',
|
||||
value: '12',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user