@fileverse-dev/formula-parser
Version:
Formula parser
53 lines (50 loc) • 2.63 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;
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 = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ERROR, "#ERROR!"), ERROR_DIV_ZERO, "#DIV/0!"), ERROR_NAME, "#NAME?"), ERROR_NOT_AVAILABLE, "#N/A"), ERROR_NULL, "#NULL!"), ERROR_NUM, "#NUM!"), ERROR_REF, "#REF!"), ERROR_VALUE, "#VALUE!");
/**
* 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;
}