MCPcopy
hub / github.com/CacheControl/json-rules-engine / setCondition

Method setCondition

src/engine.js:105–113  ·  view source on GitHub ↗

* sets a condition that can be referenced by the given name. * If a condition with the given name has already been set this will replace it. * @param {string} name - the name of the condition to be referenced by rules. * @param {object} conditions - the conditions to use when the condition

(name, conditions)

Source from the content-addressed store, hash-verified

103 * @param {object} conditions - the conditions to use when the condition is referenced.
104 */
105 setCondition (name, conditions) {
106 if (!name) throw new Error('Engine: setCondition() requires name')
107 if (!conditions) throw new Error('Engine: setCondition() requires conditions')
108 if (!Object.prototype.hasOwnProperty.call(conditions, 'all') && !Object.prototype.hasOwnProperty.call(conditions, 'any') && !Object.prototype.hasOwnProperty.call(conditions, 'not') && !Object.prototype.hasOwnProperty.call(conditions, 'condition')) {
109 throw new Error('"conditions" root must contain a single instance of "all", "any", "not", or "condition"')
110 }
111 this.conditions.set(name, new Condition(conditions))
112 return this
113 }
114
115 /**
116 * Removes a condition that has previously been added to this engine

Callers 2

startFunction · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected