Skip to content

Commit cbbad52

Browse files
author
Cache Hamm
committed
replace isPlainObject checking for fact path with isObjectLike
1 parent 7974907 commit cbbad52

6 files changed

Lines changed: 10 additions & 10 deletions

File tree

dist/almanac.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
2323
var debug = require('debug')('json-rules-engine');
2424
var verbose = require('debug')('json-rules-engine-verbose');
2525
var selectn = require('selectn');
26-
var isPlainObject = require('lodash.isplainobject');
26+
var isObjectLike = require('lodash.isobjectlike');
2727
var warn = require('debug')('json-rules-engine:warn');
2828

2929
/**
@@ -167,7 +167,7 @@ var Almanac = function () {
167167

168168
case 15:
169169
if (path) {
170-
if (isPlainObject(factValue) || Array.isArray(factValue)) {
170+
if (isObjectLike(factValue)) {
171171
factValue = selectn(path)(factValue);
172172
debug('condition::evaluate extracting object property ' + path + ', received: ' + factValue);
173173
} else {

dist/condition.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
1111
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1212

1313
var debug = require('debug')('json-rules-engine');
14-
var isPlainObject = require('lodash.isplainobject');
14+
var isObjectLike = require('lodash.isobjectlike');
1515

1616
var Condition = function () {
1717
function Condition(properties) {
@@ -97,7 +97,7 @@ var Condition = function () {
9797
case 0:
9898
value = this.value;
9999

100-
if (!(isPlainObject(value) && value.hasOwnProperty('fact'))) {
100+
if (!(isObjectLike(value) && value.hasOwnProperty('fact'))) {
101101
_context.next = 5;
102102
break;
103103
}

docs/rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Rules contain a set of _conditions_ and a single _event_. When the engine is ru
1111

1212
[Operators](#Operators)
1313

14-
[Results](#Results)
14+
[Rule Results](#rule-results)
1515

1616
## Methods
1717

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"dependencies": {
6868
"debug": "~2.6.3",
6969
"lodash.clonedeep": "~4.5.0",
70-
"lodash.isplainobject": "~4.0.6",
70+
"lodash.isobjectlike": "~4.0.0",
7171
"object-hash": "~1.1.8",
7272
"selectn": "~1.1.2"
7373
}

src/almanac.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { UndefinedFactError } from './errors'
66
let debug = require('debug')('json-rules-engine')
77
let verbose = require('debug')('json-rules-engine-verbose')
88
let selectn = require('selectn')
9-
let isPlainObject = require('lodash.isplainobject')
9+
let isObjectLike = require('lodash.isobjectlike')
1010
let warn = require('debug')('json-rules-engine:warn')
1111

1212
/**
@@ -101,7 +101,7 @@ export default class Almanac {
101101
factValue = await this._setFactValue(fact, params, fact.calculate(params, this))
102102
}
103103
if (path) {
104-
if (isPlainObject(factValue) || Array.isArray(factValue)) {
104+
if (isObjectLike(factValue)) {
105105
factValue = selectn(path)(factValue)
106106
debug(`condition::evaluate extracting object property ${path}, received: ${factValue}`)
107107
} else {

src/condition.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
let debug = require('debug')('json-rules-engine')
4-
let isPlainObject = require('lodash.isplainobject')
4+
let isObjectLike = require('lodash.isobjectlike')
55

66
export default class Condition {
77
constructor (properties) {
@@ -67,7 +67,7 @@ export default class Condition {
6767
*/
6868
async _getValue (almanac) {
6969
let value = this.value
70-
if (isPlainObject(value) && value.hasOwnProperty('fact')) { // value: { fact: 'xyz' }
70+
if (isObjectLike(value) && value.hasOwnProperty('fact')) { // value: { fact: 'xyz' }
7171
value = await almanac.factValue(value.fact, value.params, value.path)
7272
}
7373
return value

0 commit comments

Comments
 (0)