mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* add types for turndown * use auto-genned tsconfig and tslint * add dom types * re-generate module * fix tests and typescript version * feature/json-rules-engine: add initial types for json-rules-engine * feature/json-rules-engine: update test * also satisfy linter * feature/json-rules-engine: update types * chore: pre-commit hook fixes * chore: fix missing optional param * feature/json-rules-engine: remove generic type
51 lines
1.0 KiB
TypeScript
51 lines
1.0 KiB
TypeScript
// NOTE: used from: https://github.com/CacheControl/json-rules-engine#basic-example
|
|
import { Engine } from "json-rules-engine";
|
|
|
|
interface PlayerStats {
|
|
personalFoulCount: number;
|
|
gameDuration: number;
|
|
}
|
|
|
|
const engine = new Engine();
|
|
|
|
engine.addRule({
|
|
conditions: {
|
|
any: [{
|
|
all: [{
|
|
fact: 'gameDuration',
|
|
operator: 'equal',
|
|
value: 40
|
|
}, {
|
|
fact: 'personalFoulCount',
|
|
operator: 'greaterThanInclusive',
|
|
value: 5
|
|
}]
|
|
}, {
|
|
all: [{
|
|
fact: 'gameDuration',
|
|
operator: 'equal',
|
|
value: 48
|
|
}, {
|
|
fact: 'personalFoulCount',
|
|
operator: 'greaterThanInclusive',
|
|
value: 6
|
|
}]
|
|
}]
|
|
},
|
|
event: {
|
|
type: 'fouledOut',
|
|
params: {
|
|
message: 'Player has fouled out!'
|
|
}
|
|
}
|
|
});
|
|
|
|
const facts: PlayerStats = {
|
|
gameDuration: 6,
|
|
personalFoulCount: 40,
|
|
};
|
|
|
|
engine.run(facts).then(results => {
|
|
results.events.map(event => event.params.message);
|
|
});
|