Skip to content

Commit abd304e

Browse files
author
Cache Hamm
committed
Upgrade dependencies to latest; update linting
1 parent 7ff27c4 commit abd304e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1700
-1581
lines changed

examples/01-hello-world.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
*/
1212

1313
require('colors')
14-
let Engine = require('../dist').Engine
15-
let Rule = require('../dist').Rule
14+
const Engine = require('../dist').Engine
15+
const Rule = require('../dist').Rule
1616

1717
/**
1818
* Setup a new engine
1919
*/
20-
let engine = new Engine()
20+
const engine = new Engine()
2121

2222
/**
2323
* Create a rule
2424
*/
25-
let rule = new Rule({
25+
const rule = new Rule({
2626
// define the 'conditions' for when "hello world" should display
2727
conditions: {
2828
all: [{
@@ -48,7 +48,7 @@ engine.addRule(rule)
4848
* Fact values do NOT need to be known at engine runtime; see the
4949
* 03-dynamic-facts.js example for how to pull in data asynchronously during runtime
5050
*/
51-
let facts = { displayMessage: true }
51+
const facts = { displayMessage: true }
5252

5353
// run the engine
5454
engine

examples/02-nested-boolean-logic.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
*/
1212

1313
require('colors')
14-
let Engine = require('../dist').Engine
14+
const Engine = require('../dist').Engine
1515

1616
/**
1717
* Setup a new engine
1818
*/
19-
let engine = new Engine()
19+
const engine = new Engine()
2020

2121
// define a rule for detecting the player has exceeded foul limits. Foul out any player who:
2222
// (has committed 5 fouls AND game is 40 minutes) OR (has committed 6 fouls AND game is 48 minutes)
@@ -56,7 +56,7 @@ engine.addRule({
5656
* define the facts
5757
* note: facts may be loaded asynchronously at runtime; see the advanced example below
5858
*/
59-
let facts = {
59+
const facts = {
6060
personalFoulCount: 6,
6161
gameDuration: 40
6262
}

examples/03-dynamic-facts.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
*/
1313

1414
require('colors')
15-
let Engine = require('../dist').Engine
15+
const Engine = require('../dist').Engine
1616
// example client for making asynchronous requests to an api, database, etc
17-
let apiClient = require('./support/account-api-client')
17+
const apiClient = require('./support/account-api-client')
1818

1919
/**
2020
* Setup a new engine
2121
*/
22-
let engine = new Engine()
22+
const engine = new Engine()
2323

2424
/**
2525
* Rule for identifying microsoft employees taking pto on christmas
2626
*
2727
* the account-information fact returns:
2828
* { company: 'XYZ', status: 'ABC', ptoDaysTaken: ['YYYY-MM-DD', 'YYYY-MM-DD'] }
2929
*/
30-
let microsoftRule = {
30+
const microsoftRule = {
3131
conditions: {
3232
all: [{
3333
fact: 'account-information',
@@ -68,7 +68,7 @@ engine.addFact('account-information', function (params, almanac) {
6868
})
6969

7070
// define fact(s) known at runtime
71-
let facts = { accountId: 'lincoln' }
71+
const facts = { accountId: 'lincoln' }
7272
engine
7373
.run(facts)
7474
.then(results => {

examples/04-fact-dependency.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
*/
1414

1515
require('colors')
16-
let Engine = require('../dist').Engine
17-
let accountClient = require('./support/account-api-client')
16+
const Engine = require('../dist').Engine
17+
const accountClient = require('./support/account-api-client')
1818

1919
/**
2020
* Setup a new engine
2121
*/
22-
let engine = new Engine()
22+
const engine = new Engine()
2323

2424
/**
2525
* Rule for identifying microsoft employees that have been terminated.
2626
* - Demonstrates re-using a same fact with different parameters
2727
* - Demonstrates calling a base fact, which serves to load data once and reuse later
2828
*/
29-
let microsoftRule = {
29+
const microsoftRule = {
3030
conditions: {
3131
all: [{
3232
fact: 'account-information',
@@ -49,14 +49,14 @@ engine.addRule(microsoftRule)
4949
* - Demonstrates calling a base fact, also shared by the account-information-field fact
5050
* - Demonstrates performing computations on data retrieved by base fact
5151
*/
52-
let tenureRule = {
52+
const tenureRule = {
5353
conditions: {
5454
all: [{
5555
fact: 'employee-tenure',
5656
operator: 'greaterThanInclusive',
5757
value: 5,
5858
params: {
59-
'unit': 'years'
59+
unit: 'years'
6060
}
6161
}]
6262
},
@@ -94,8 +94,8 @@ engine.addFact('account-information', (params, almanac) => {
9494
engine.addFact('employee-tenure', (params, almanac) => {
9595
return almanac.factValue('account-information')
9696
.then(accountInformation => {
97-
let created = new Date(accountInformation.createdAt)
98-
let now = new Date()
97+
const created = new Date(accountInformation.createdAt)
98+
const now = new Date()
9999
switch (params.unit) {
100100
case 'years':
101101
return now.getFullYear() - created.getFullYear()

examples/05-optimizing-runtime-with-fact-priorities.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
*/
1212

1313
require('colors')
14-
let Engine = require('../dist').Engine
15-
let accountClient = require('./support/account-api-client')
14+
const Engine = require('../dist').Engine
15+
const accountClient = require('./support/account-api-client')
1616

1717
/**
1818
* Setup a new engine
1919
*/
20-
let engine = new Engine()
20+
const engine = new Engine()
2121

2222
/**
2323
* - Demonstrates setting high performance (cpu) facts higher than low performing (network call) facts.
2424
*/
25-
let microsoftRule = {
25+
const microsoftRule = {
2626
conditions: {
2727
all: [{
2828
fact: 'account-information',
@@ -41,7 +41,7 @@ engine.addRule(microsoftRule)
4141
/**
4242
* Register listeners with the engine for rule success and failure
4343
*/
44-
let facts
44+
const facts = { accountId: 'washington' }
4545
engine
4646
.on('success', event => {
4747
console.log(facts.accountId + ' DID '.green + 'meet conditions for the ' + event.type.underline + ' rule.')
@@ -55,8 +55,8 @@ engine
5555
* Facts that do not have a priority set default to 1
5656
* @type {Integer} - Facts are run in priority from highest to lowest.
5757
*/
58-
let HIGH = 100
59-
let LOW = 1
58+
const HIGH = 100
59+
const LOW = 1
6060

6161
/**
6262
* 'account-information' fact executes an api call - network calls are expensive, so
@@ -82,7 +82,6 @@ engine.addFact('date', (params, almanac) => {
8282
}, { priority: HIGH })
8383

8484
// define fact(s) known at runtime
85-
facts = { accountId: 'washington' }
8685
engine.run(facts).catch(console.log)
8786

8887
/*

examples/06-custom-operators.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
*/
1818

1919
require('colors')
20-
let Engine = require('../dist').Engine
20+
const Engine = require('../dist').Engine
2121

2222
/**
2323
* Setup a new engine
2424
*/
25-
let engine = new Engine()
25+
const engine = new Engine()
2626

2727
/**
2828
* Define a 'startsWith' custom operator, for use in later rules
@@ -35,7 +35,7 @@ engine.addOperator('startsWith', (factValue, jsonValue) => {
3535
/**
3636
* Add rule for detecting words that start with 'a'
3737
*/
38-
let ruleA = {
38+
const ruleA = {
3939
conditions: {
4040
all: [{
4141
fact: 'word',
@@ -52,7 +52,7 @@ engine.addRule(ruleA)
5252
/*
5353
* Add rule for detecting words that start with 'b'
5454
*/
55-
let ruleB = {
55+
const ruleB = {
5656
conditions: {
5757
all: [{
5858
fact: 'word',
@@ -67,7 +67,7 @@ let ruleB = {
6767
engine.addRule(ruleB)
6868

6969
// utility for printing output
70-
let printEventType = {
70+
const printEventType = {
7171
'start-with-a': 'start with "a"',
7272
'start-with-b': 'start with "b"'
7373
}

examples/07-rule-chaining.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
*/
1414

1515
require('colors')
16-
let Engine = require('../dist').Engine
16+
const Engine = require('../dist').Engine
1717

1818
/**
1919
* Setup a new engine
2020
*/
21-
let engine = new Engine()
21+
const engine = new Engine()
2222

2323
/**
2424
* Rule for identifying people who may like screwdrivers
2525
*/
26-
let drinkRule = {
26+
const drinkRule = {
2727
conditions: {
2828
all: [{
2929
fact: 'drinksOrangeJuice',
@@ -51,7 +51,7 @@ engine.addRule(drinkRule)
5151
* - Only invite people who enjoy screw drivers
5252
* - Only invite people who are sociable
5353
*/
54-
let inviteRule = {
54+
const inviteRule = {
5555
conditions: {
5656
all: [{
5757
fact: 'screwdriverAficionado', // this fact value is set when the drinkRule is evaluated

examples/08-fact-comparison.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
*/
1212

1313
require('colors')
14-
let Engine = require('../dist').Engine
14+
const Engine = require('../dist').Engine
1515

1616
/**
1717
* Setup a new engine
1818
*/
19-
let engine = new Engine()
19+
const engine = new Engine()
2020

2121
/**
2222
* Rule for determining if account has enough money to purchase a $50 gift card product
2323
*
2424
* customer-account-balance >= $50 gift card
2525
*/
26-
let rule = {
26+
const rule = {
2727
conditions: {
2828
all: [{
2929
// extract 'balance' from the 'customer' account type
@@ -55,7 +55,7 @@ engine.addFact('account', (params, almanac) => {
5555
return almanac.factValue('accounts')
5656
.then(accounts => {
5757
// use "params" to filter down to the type specified, in this case the "customer" account
58-
let customerAccount = accounts.filter(account => account.type === params.accountType)
58+
const customerAccount = accounts.filter(account => account.type === params.accountType)
5959
// return the customerAccount object, which "path" will use to pull the "balance" property
6060
return customerAccount[0]
6161
})
@@ -66,7 +66,7 @@ engine.addFact('product', (params, almanac) => {
6666
return almanac.factValue('products')
6767
.then(products => {
6868
// use "params" to filter down to the product specified, in this case the "giftCard" product
69-
let product = products.filter(product => product.productId === params.productId)
69+
const product = products.filter(product => product.productId === params.productId)
7070
// return the product object, which "path" will use to pull the "price" property
7171
return product[0]
7272
})
@@ -85,7 +85,7 @@ engine
8585
})
8686

8787
// define fact(s) known at runtime
88-
let productList = {
88+
const productList = {
8989
products: [
9090
{
9191
productId: 'giftCard',

examples/09-rule-results.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
* DEBUG=json-rules-engine node ./examples/09-rule-results.js
1111
*/
1212
require('colors')
13-
let Engine = require('../dist').Engine
13+
const Engine = require('../dist').Engine
1414

1515
/**
1616
* Setup a new engine
1717
*/
18-
let engine = new Engine()
18+
const engine = new Engine()
1919

2020
// rule for determining honor role student athletes (student has GPA >= 3.5 AND is an athlete)
2121
engine.addRule({
@@ -45,7 +45,7 @@ function render (message, ruleResult) {
4545
return console.log(`${message}`.green)
4646
}
4747
// if rule failed, iterate over each failed condition to determine why the student didn't qualify for athletics honor roll
48-
let detail = ruleResult.conditions.all.filter(condition => !condition.result)
48+
const detail = ruleResult.conditions.all.filter(condition => !condition.result)
4949
.map(condition => {
5050
switch (condition.operator) {
5151
case 'equal':

examples/support/account-api-client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require('colors')
44

5-
let accountData = {
5+
const accountData = {
66
washington: {
77
company: 'microsoft',
88
status: 'terminated',

0 commit comments

Comments
 (0)