How to use the json-logic-js.add_operation 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
// Configure JsonLogic
lodashOperators.forEach((name) => jsonLogic.add_operation(`_${name}`, _[name]));

// Retrieve Any Date
jsonLogic.add_operation('getDate', (date) => {
  return moment(date).toISOString();
});

// Set Relative Minimum Date
jsonLogic.add_operation('relativeMinDate', (relativeMinDate) => {
  return moment().subtract(relativeMinDate, 'days').toISOString();
});

// Set Relative Maximum Date
jsonLogic.add_operation('relativeMaxDate', (relativeMaxDate) => {
  return moment().add(relativeMaxDate, 'days').toISOString();
});

export { jsonLogic, moment };

/**
 * Evaluate a method.
 *
 * @param func
 * @param args
 * @return {*}
 */
export function evaluate(func, args, ret, tokenize) {
  let returnVal = null;
  const component = args.component ? args.component : { key: 'unknown' };
  if (!args.form && args.instance) {
github formio / formio.js / src / utils / index.js View on Github external
import _ from 'lodash';
import jsonLogic from 'json-logic-js';
import moment from 'moment';

import {lodashOperators} from './jsonlogic/operators';

// Configure JsonLogic
lodashOperators.forEach((name) => jsonLogic.add_operation(`_${name}`, _[name]));

// Retrieve Any Date
jsonLogic.add_operation('getDate', (date) => {
  return moment(date).toISOString();
});

// Set Relative Minimum Date
jsonLogic.add_operation('relativeMinDate', (relativeMinDate) => {
  return moment().subtract(relativeMinDate, 'days').toISOString();
});

// Set Relative Maximum Date
jsonLogic.add_operation('relativeMaxDate', (relativeMaxDate) => {
  return moment().add(relativeMaxDate, 'days').toISOString();
});

const FormioUtils = {
  jsonLogic, // Share
github formio / formio.js / src / utils / index.js View on Github external
// Configure JsonLogic
lodashOperators.forEach((name) => jsonLogic.add_operation(`_${name}`, _[name]));

// Retrieve Any Date
jsonLogic.add_operation('getDate', (date) => {
  return moment(date).toISOString();
});

// Set Relative Minimum Date
jsonLogic.add_operation('relativeMinDate', (relativeMinDate) => {
  return moment().subtract(relativeMinDate, 'days').toISOString();
});

// Set Relative Maximum Date
jsonLogic.add_operation('relativeMaxDate', (relativeMaxDate) => {
  return moment().add(relativeMaxDate, 'days').toISOString();
});

const FormioUtils = {
  jsonLogic, // Share

  /**
   * Determines the boolean value of a setting.
   *
   * @param value
   * @return {boolean}
   */
  boolValue(value) {
    if (_.isBoolean(value)) {
      return value;
    }
github formio / formio.js / src / utils / index.js View on Github external
import _ from 'lodash';
import jsonLogic from 'json-logic-js';
import moment from 'moment';

import {lodashOperators} from './jsonlogic/operators';

// Configure JsonLogic
lodashOperators.forEach((name) => jsonLogic.add_operation(`_${name}`, _[name]));

// Retrieve Any Date
jsonLogic.add_operation('getDate', (date) => {
  return moment(date).toISOString();
});

// Set Relative Minimum Date
jsonLogic.add_operation('relativeMinDate', (relativeMinDate) => {
  return moment().subtract(relativeMinDate, 'days').toISOString();
});

// Set Relative Maximum Date
jsonLogic.add_operation('relativeMaxDate', (relativeMaxDate) => {
  return moment().add(relativeMaxDate, 'days').toISOString();
});

const FormioUtils = {
  jsonLogic, // Share

  /**
   * Determines the boolean value of a setting.
   *
   * @param value
   * @return {boolean}
github Talend / ui / packages / forms / src / UIForm / utils / condition.js View on Github external
import jsonLogic from 'json-logic-js';

function lowercase(a) {
	return a.toLowerCase();
}

function toNumber(a) {
	if (typeof a === 'number') {
		return a;
	} else if (typeof a === 'string') {
		return parseInt(a, 10);
	}
	throw new TypeError(`${a.toString()} is not a number`);
}

jsonLogic.add_operation('lowercase', lowercase);
jsonLogic.add_operation('toNumber', toNumber);

/**
 * If in the path [] appears it will be populated
 * with current key indices value.
 */
function replaceArrayNotationByIndexes(path, key) {
	if (!path || !path.includes('[]')) {
		return path;
	}
	return path
		.split(/\.|\[/)
		.map((part, index) => {
			if (part === ']') {
				return key[index];
			}
github Talend / ui / packages / forms / src / UIForm-v3 / schema / Widget / condition.js View on Github external
function lowercase(a) {
	return a.toLowerCase();
}

function toNumber(a) {
	if (typeof a === 'number') {
		return a;
	} else if (typeof a === 'string') {
		return parseInt(a, 10);
	}
	throw new TypeError(`${a.toString()} is not a number`);
}

jsonLogic.add_operation('lowercase', lowercase);
jsonLogic.add_operation('toNumber', toNumber);

/**
 * If in the path [] appears it will be populated
 * with current key indices value.
 */
function replaceArrayNotationByIndexes(path, key) {
	if (!path || !path.includes('[]')) {
		return path;
	}
	return path
		.split(/\.|\[/)
		.map((part, index) => {
			if (part === ']') {
				return key[index];
			}
			return part;
github Talend / ui / packages / forms / src / UIForm / utils / condition.js View on Github external
function lowercase(a) {
	return a.toLowerCase();
}

function toNumber(a) {
	if (typeof a === 'number') {
		return a;
	} else if (typeof a === 'string') {
		return parseInt(a, 10);
	}
	throw new TypeError(`${a.toString()} is not a number`);
}

jsonLogic.add_operation('lowercase', lowercase);
jsonLogic.add_operation('toNumber', toNumber);

/**
 * If in the path [] appears it will be populated
 * with current key indices value.
 */
function replaceArrayNotationByIndexes(path, key) {
	if (!path || !path.includes('[]')) {
		return path;
	}
	return path
		.split(/\.|\[/)
		.map((part, index) => {
			if (part === ']') {
				return key[index];
			}
			return part;
github Talend / ui / packages / forms / src / UIForm-v3 / schema / Widget / condition.js View on Github external
import jsonLogic from 'json-logic-js';

function lowercase(a) {
	return a.toLowerCase();
}

function toNumber(a) {
	if (typeof a === 'number') {
		return a;
	} else if (typeof a === 'string') {
		return parseInt(a, 10);
	}
	throw new TypeError(`${a.toString()} is not a number`);
}

jsonLogic.add_operation('lowercase', lowercase);
jsonLogic.add_operation('toNumber', toNumber);

/**
 * If in the path [] appears it will be populated
 * with current key indices value.
 */
function replaceArrayNotationByIndexes(path, key) {
	if (!path || !path.includes('[]')) {
		return path;
	}
	return path
		.split(/\.|\[/)
		.map((part, index) => {
			if (part === ']') {
				return key[index];
			}
github formio / formio.js / src / utils / index.js View on Github external
lodashOperators.forEach((name) => jsonLogic.add_operation(`_${name}`, _[name]));
github formio / formio.js / src / utils / utils.js View on Github external
lodashOperators.forEach((name) => jsonLogic.add_operation(`_${name}`, _[name]));

json-logic-js

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

MIT
Latest version published 6 months ago

Package Health Score

70 / 100
Full package analysis

Popular json-logic-js functions