"use strict";
/***************************************************
* Licensed Materials - Property of HCL.
* (c)Copyright HCL America, Inc. 2023-2024
****************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
* @file Logical
* @module logical
* @category Logical
*/
const openf_logic = require('../openformula/logical');
exports._openFormula = openf_logic;
const notesf_logic = require('../notes/logical');
exports._notes = notesf_logic;
const API = tslib_1.__importStar(require("../rosetta/API"));
//-----------------------------
// Rosetta logical - common functions (exist in both OpenFormula and Notes Formula)
/**
* Returns the logical value false (or the number 0).
*
* @returns {boolean | number} False (or 0).
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#FALSE | www.oasis-open.org}
* @example rosettajs.false(); // returns false (openf) or 0 (notesf)
*/
exports.false = () => {
return API.isCurrentAPIOpenFormula() ? openf_logic.FALSE() : notesf_logic.False();
};
/**
* Specifies a logical test to perform and returns the specified value determined by the test.
*
* @param {*} args The parameters that include the condition/action pair(s), and else action.
* @returns {*} The resulting value if true or false.
* and {@link https://www.oasis-open.org/committees/download.php/16826/openformula-spec-20060221.html#IF | www.oasis-open.org}
* @example rosettajs.if(55 >= 12.45, "Over Budget", "OK") // returns "Over Budget"
*/
exports.if = function (...args) {
let value_if_true = arguments.length >= 2 ? args[1] : true;
let value_if_false = arguments.length === 3 ? args[2] : false;
return API.isCurrentAPIOpenFormula() ? openf_logic.IF(args[0], value_if_true, value_if_false) : notesf_logic.If(...args);
};
/**
* Returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula.
*
* @param {*} value The argument that is checked for an error.
* @param {*} value_if_error The value to return if the formula evaluates to an error. The following error types are evaluated: #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!.
* @returns {*} The value you specify if a formula evaluates to an error; otherwise, returns the result of the formula.
* @example rosettajs.ifError(error.value, 2) // returns 2
*/
exports.ifError = (value, value_if_error) => {
return API.isCurrentAPIOpenFormula() ? openf_logic.IFERROR(value, value_if_error) : notesf_logic.IfError(value, value_if_error);
};
/**
* Returns the logical value true (or the number 1).
*
* @returns {boolean | number} True (or 1)
* @example rosettajs.true(); // returns true (openf) or 1 (notesf)
*/
exports.true = () => {
return API.isCurrentAPIOpenFormula() ? openf_logic.TRUE() : notesf_logic.True();
};
//-----------------------------
// Open Formula logical
/**
* Returns TRUE if all of its arguments are TRUE.
*
* @param {Array} values The values to determine whether they are true or not.
* @returns {boolean} True if all of the arguments are true. False if any value is not true.
* @example rosettajs.and(true, false) // returns false
*/
exports.and = (...values) => {
return openf_logic.AND(...values);
};
/**
* Checks whether one or more conditions are met and returns a value that corresponds to the first TRUE condition.
*
* @param {Array} args One or more conditions.
* @returns {*} The value that corresponds to the first TRUE condition.
* @example rosettajs.ifs(false, 1, true, 2) // returns 2
*/
exports.ifs = (...args) => {
return openf_logic.IFS(...args);
};
/**
* Returns the value you specify if the expression resolves to #N/A, otherwise returns the result of the expression.
*
* @param {*} value The expression to compute.
* @param {*} value_if_na The result of the expression to return if the value is not #N/A.
* @returns {*} The value you specify if the expression resolves to #N/A, otherwise returns the result of the expression.
* @example rosettajs.ifNA(error.na, 2) // returns 2
*/
exports.ifNA = (value, value_if_na) => {
return openf_logic.IFNA(value, value_if_na);
};
/**
* Reverses the logic of its argument.
*
* @param {boolean} logical The expression to reverse.
* @returns {boolean} The reversed logic of the logical expression.
* @example rosettajs.not(false) // returns true
*/
exports.not = (logical) => {
return openf_logic.NOT(logical);
};
/**
* Returns TRUE if any argument is TRUE.
*
* @param {Array} values The values to determine whether they are true or not.
* @returns {boolean} True if any one of the arguments are true. False if all values are false.
* @example rosettajs.or(true, false) // returns true
*/
exports.or = (...values) => {
return openf_logic.OR(...values);
};
/**
* Evaluates an expression against a list of values and returns the result corresponding to the first matching value.
* If there is no match, an optional default value may be returned.
*
* @param {Array} args The expression and values to compare.
* @returns {*} The result corresponding to the first matching value.
* @example rosettajs.switch() // returns
*/
exports.switch = (...args) => {
return openf_logic.SWITCH(...args);
};
/**
* Returns a logical exclusive OR of all arguments.
*
* @param {Array} values logical1, logical2,… Logical 1 is required, subsequent logical values are optional.
* 1 to 254 conditions you want to test that can be either TRUE or FALSE, and can be logical values, arrays, or references.
* @returns {boolean} The logical exclusive OR of all arguments.
* @example rosettajs.xor()
*/
exports.xor = (...values) => {
return openf_logic.XOR(...values);
};
//-----------------------------
// Notes @functions logical
/**
* Evaluates expressions from left to right, and returns the value of the last
* expression in the list.
*
* @param {*} expressions One or more expressions to evaluate.
* @returns {*} The resulting value of the last expression in the list.
* @example rosettajs.do(rosettajs.success(), true, false, "message") // returns "message"
*/
exports.do = (...expressions) => {
return notesf_logic.Do(...expressions);
};
/**
* Executes one or more statements iteratively while a condition is true. Checks the condition after executing the statements.
* No plans to implement - Convert to Native JS
*
*/
exports.doWhile = () => {
return notesf_logic.DoWhile();
};
/**
* Returns text that indicates that input to a field does not meet validation.
*
* @param {string} message The error message to be displayed to the user.
* @returns {string} The message indicating the failure.
* @example rosettajs.failure("Failure message test") // returns "Failure message test"
*/
exports.failure = (message) => {
return notesf_logic.Failure(message);
};
/**
* Executes one or more statements iteratively while a condition remains true. Executes an initialization statement.
* Checks the condition before executing the statements and executes an increment statement after executing the statements.
* No plans to implement - Convert to Native JS
*
*/
exports.for = () => {
return notesf_logic.For();
};
/**
* Tests for a null value. Returns true only if a value is a single text value that
* is null, otherwise it returns false. This function also returns false if the
* value is an error.
*
* @param {*} value The value to test for null.
* @returns {boolean} True if value is null, otherwise false.
* @example rosettajs.isNull(null) // true
* @example rosettajs.isNull(4) // false
*/
exports.isNull = (value) => {
return notesf_logic.IsNull(value);
};
/**
* Returns the number 0 (false).
*
* @returns {number} The number 0 (false).
* @example rosettajs.no() // returns 0
*/
exports.no = () => {
return notesf_logic.No();
};
/**
* Immediately stops the execution of a formula and returns the specified value.
* This is useful when you only want the remainder of the formula to be executed
* only if certain conditions are True.
*
* @param {*} value The value to return.
* @returns {*} The value.
* @example rosettajs.return('Message to return') // throws 'Message to return'
*/
exports.return = (value) => {
return notesf_logic.Return(value);
};
/**
* Returns 1 (True). Use this function with @If in field validation formulas to
* indicate that the value entered satisfies the validation criteria.
*
* @returns {number} The number 1 (true).
* @example rosettajs.success() // returns 1
*/
exports.success = () => {
return notesf_logic.Success();
};
/**
* Executes one or more statements iteratively while a condition is true. Checks the condition before executing the statements.
* No plans to implement - Convert to Native JS
*
*/
exports.while = () => {
return notesf_logic.While();
};
/**
* Returns the number 1 (true).
*
* @returns {number} The number 1 (true).
* @example rosettajs.yes() // returns 1
*/
exports.yes = () => {
return notesf_logic.Yes();
};
/**
* This function performs an @If operation; the syntax is the same as for @if.
*
* @throws {Error} No plans to implement
*/
exports.v2If = () => {
return notesf_logic.V2If();
};
//# sourceMappingURL=logical.js.map