FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
json-rules-engine/src/operator.js at master · CacheControl/json-rules-engine · GitHub
CacheControl
/
json-rules-engine
Public
Notifications
You must be signed in to change notification settings
Fork
507
Star
3.1k
Code
Issues
61
Pull requests
7
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
json-rules-engine
/
src
/
operator.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (27 loc) · 1.08 KB
Breadcrumbs
json-rules-engine
/
src
/
operator.js
Copy path
File metadata and controls
29 lines (27 loc) · 1.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict'
export
default
class
Operator
{
/**
* Constructor
*
@param
{
string
} name - operator identifier
*
@param
{
function(factValue, jsonValue)
} callback - operator evaluation method
*
@param
{
function
} [factValueValidator] - optional validator for asserting the data type of the fact
*
@returns
{
Operator
} - instance
*/
constructor
(
name
,
cb
,
factValueValidator
)
{
this
.
name
=
String
(
name
)
if
(
!
name
)
throw
new
Error
(
'Missing operator name'
)
if
(
typeof
cb
!==
'function'
)
throw
new
Error
(
'Missing operator callback'
)
this
.
cb
=
cb
this
.
factValueValidator
=
factValueValidator
if
(
!
this
.
factValueValidator
)
this
.
factValueValidator
=
(
)
=>
true
}
/**
* Takes the fact result and compares it to the condition 'value', using the callback
*
@param
{
mixed
} factValue - fact result
*
@param
{
mixed
} jsonValue - "value" property of the condition
*
@returns
{
Boolean
} - whether the values pass the operator test
*/
evaluate
(
factValue
,
jsonValue
)
{
return
this
.
factValueValidator
(
factValue
)
&&
this
.
cb
(
factValue
,
jsonValue
)
}
}
Back
|
FazBrowse Home
|
New Git URL