MCPcopy Index your code
hub / github.com/CacheControl/json-rules-engine / toJSON

Method toJSON

src/condition.js:41–79  ·  view source on GitHub ↗

* Converts the condition into a json-friendly structure * @param {Boolean} stringify - whether to return as a json string * @returns {string,object} json string or json-friendly object

(stringify = true)

Source from the content-addressed store, hash-verified

39 * @returns {string,object} json string or json-friendly object
40 */
41 toJSON (stringify = true) {
42 const props = {}
43 if (this.priority) {
44 props.priority = this.priority
45 }
46 if (this.name) {
47 props.name = this.name
48 }
49 const oper = Condition.booleanOperator(this)
50 if (oper) {
51 if (Array.isArray(this[oper])) {
52 props[oper] = this[oper].map((c) => c.toJSON(false))
53 } else {
54 props[oper] = this[oper].toJSON(false)
55 }
56 } else if (this.isConditionReference()) {
57 props.condition = this.condition
58 } else {
59 props.operator = this.operator
60 props.value = this.value
61 props.fact = this.fact
62 if (this.factResult !== undefined) {
63 props.factResult = this.factResult
64 }
65 if (this.result !== undefined) {
66 props.result = this.result
67 }
68 if (this.params) {
69 props.params = this.params
70 }
71 if (this.path) {
72 props.path = this.path
73 }
74 }
75 if (stringify) {
76 return JSON.stringify(props)
77 }
78 return props
79 }
80
81 /**
82 * Takes the fact result and compares it to the condition 'value', using the operator

Callers

nothing calls this directly

Calls 2

isConditionReferenceMethod · 0.95
booleanOperatorMethod · 0.80

Tested by

no test coverage detected