@fileverse-dev/formula-parser
Version:
Formula parser
54 lines (51 loc) • 3.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ERROR_VALUE = exports.ERROR_REF = exports.ERROR_NUM = exports.ERROR_NULL = exports.ERROR_NOT_AVAILABLE = exports.ERROR_NAME = exports.ERROR_DIV_ZERO = exports.ERROR = void 0;
exports["default"] = error;
exports.isValidStrict = isValidStrict;
var _errors;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var ERROR = exports.ERROR = "ERROR";
var ERROR_DIV_ZERO = exports.ERROR_DIV_ZERO = "DIV/0";
var ERROR_NAME = exports.ERROR_NAME = "NAME";
var ERROR_NOT_AVAILABLE = exports.ERROR_NOT_AVAILABLE = "N/A";
var ERROR_NULL = exports.ERROR_NULL = "NULL";
var ERROR_NUM = exports.ERROR_NUM = "NUM";
var ERROR_REF = exports.ERROR_REF = "REF";
var ERROR_VALUE = exports.ERROR_VALUE = "VALUE";
var errors = (_errors = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_errors, 'Error: lookup_range and result_range are required', "Lookup range and result range are required"), ERROR, "Syntax error"), ERROR_DIV_ZERO, "#DIV/0!"), ERROR_NAME, "Wrong function name or parameter"), ERROR_NOT_AVAILABLE, "#N/A"), ERROR_NULL, "#NULL!"), ERROR_NUM, "#NUM!"), ERROR_REF, "#REF!"), ERROR_VALUE, "#VALUE!"), 'search_key', "Error: search_key is required"), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_errors, 'lookup_range', "Error: lookup_range is required"), 'result_range', "Error: result_range is required"), 'lookup_range_single', "Error: lookup_range must be a singular row or column"), 'result_range_invalid', "Error: result_range is invalid"), 'lookup_range_and_result_range', "Error: lookup_range and result_range must have the same number of columns"), 'match_mode_must', "Error: match_mode must be 0, 1, -1, or 2"), 'search_mode_must', "Error: search_mode must be 1, -1, 2, or -2"), 'binary_search_and_wildcard', "'Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)"));
/**
* Return error type based on provided error id.
*
* @param {String} type Error type.
* @returns {String|null} Returns error id.
*/
function error(type) {
var result;
type = (type + "").replace(/#|!|\?/g, "");
if (errors[type]) {
result = errors[type];
}
return result ? result : null;
}
/**
* Check if error type is strict valid with knows errors.
*
* @param {String} Error type.
* @return {Boolean}
*/
function isValidStrict(type) {
var valid = false;
for (var i in errors) {
if (Object.prototype.hasOwnProperty.call(errors, i) && errors[i] === type) {
valid = true;
break;
}
}
return valid;
}