How to use the json-logic-js.apply function in json-logic-js

To help you get started, we’ve selected a few json-logic-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github formio / formio.js / src / utils / utils.js View on Github external
// Execute the script
        const script = new vm.Script(`result = ${func.toString()}(${argStr});`);
        script.runInContext(sandbox, { timeout: 250 });

        returnVal = sandbox.result;
      }
    }
    catch (err) {
      returnVal = null;
      console.warn(`An error occured within custom function for ${componentKey}`, err);
    }
  }
  else if (typeof func === 'object') {
    try {
      returnVal = jsonLogic.apply(func, args);
    }
    catch (err) {
      returnVal = null;
      console.warn(`An error occured within custom function for ${componentKey}`, err);
    }
  }
  else if (func) {
    console.warn(`Unknown function type for ${componentKey}`);
  }
  return returnVal;
}
github formio / formio.js / src / utils / utils.js View on Github external
export function checkJsonConditional(component, json, row, data, form, onError) {
  try {
    return jsonLogic.apply(json, {
      data,
      row,
      form,
      _,
    });
  }
  catch (err) {
    console.warn(`An error occurred in jsonLogic advanced condition for ${component.key}`, err);
    return onError;
  }
}
github transmute-industries / transmute / packages / transmute-framework / src / Store / ReadModel / Logic / Logic.ts View on Github external
export const applyJsonLogic = (rule: any, state: any) => {
    return jsonLogic.apply(rule, state);
  };
github Talend / ui / packages / forms / src / UIForm-v3 / schema / Widget / condition.js View on Github external
function shouldRender(condition, properties, key) {
	if (condition === undefined) {
		return true;
	}
	const runtimeCondition = resolveArrayNotation(condition, key);
	return jsonLogic.apply(runtimeCondition, properties);
}

json-logic-js

Build complex rules, serialize them as JSON, and execute them in JavaScript

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis

Popular json-logic-js functions