hyperformula-dc
Version:
HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas
301 lines (221 loc) • 9.56 kB
JavaScript
require("core-js/modules/es.symbol.js");
require("core-js/modules/es.symbol.description.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.symbol.iterator.js");
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/es.string.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
exports.__esModule = true;
exports.isSimpleCellAddress = isSimpleCellAddress;
exports.equalSimpleCellAddress = exports.absoluteSheetReference = exports.addressKey = exports.movedSimpleCellAddress = exports.invalidSimpleCellAddress = exports.simpleCellAddress = exports.invalidSimpleColumnAddress = exports.simpleColumnAddress = exports.invalidSimpleRowAddress = exports.simpleRowAddress = exports.CellError = exports.getCellValueFormat = exports.getCellValueDetailedType = exports.getCellValueType = exports.CellValueTypeOrd = exports.CellValueDetailedType = exports.CellValueType = exports.CellValueJustNumber = exports.CellValueNoNumber = exports.getCellType = exports.CellType = exports.ErrorType = void 0;
require("core-js/modules/es.object.assign.js");
require("core-js/modules/es.array.concat.js");
var _DependencyGraph = require("./DependencyGraph");
var _errorMessage = require("./error-message");
var _InterpreterValue = require("./interpreter/InterpreterValue");
var _SimpleRangeValue = require("./interpreter/SimpleRangeValue");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* Possible errors returned by our interpreter.
*/
var ErrorType;
exports.ErrorType = ErrorType;
(function (ErrorType) {
/** Division by zero. */
ErrorType["DIV_BY_ZERO"] = "DIV_BY_ZERO";
/** Unknown function name. */
ErrorType["NAME"] = "NAME";
ErrorType["VALUE"] = "VALUE";
ErrorType["NUM"] = "NUM";
ErrorType["NA"] = "NA";
/** Cyclic dependency. */
ErrorType["CYCLE"] = "CYCLE";
/** Wrong address reference. */
ErrorType["REF"] = "REF";
/** Array spill error. */
ErrorType["SPILL"] = "SPILL";
/** Invalid/missing licence error. */
ErrorType["LIC"] = "LIC";
/** Generic error */
ErrorType["ERROR"] = "ERROR";
})(ErrorType || (exports.ErrorType = ErrorType = {}));
var CellType;
exports.CellType = CellType;
(function (CellType) {
CellType["FORMULA"] = "FORMULA";
CellType["VALUE"] = "VALUE";
CellType["ARRAY"] = "ARRAY";
CellType["EMPTY"] = "EMPTY";
CellType["ARRAYFORMULA"] = "ARRAYFORMULA";
})(CellType || (exports.CellType = CellType = {}));
var getCellType = function getCellType(vertex, address) {
if (vertex instanceof _DependencyGraph.ArrayVertex) {
if (vertex.isLeftCorner(address)) {
return CellType.ARRAYFORMULA;
} else {
return CellType.ARRAY;
}
}
if (vertex instanceof _DependencyGraph.FormulaCellVertex || vertex instanceof _DependencyGraph.ParsingErrorVertex) {
return CellType.FORMULA;
}
if (vertex instanceof _DependencyGraph.ValueCellVertex) {
return CellType.VALUE;
}
return CellType.EMPTY;
};
exports.getCellType = getCellType;
var CellValueNoNumber;
exports.CellValueNoNumber = CellValueNoNumber;
(function (CellValueNoNumber) {
CellValueNoNumber["EMPTY"] = "EMPTY";
CellValueNoNumber["NUMBER"] = "NUMBER";
CellValueNoNumber["STRING"] = "STRING";
CellValueNoNumber["BOOLEAN"] = "BOOLEAN";
CellValueNoNumber["ERROR"] = "ERROR";
})(CellValueNoNumber || (exports.CellValueNoNumber = CellValueNoNumber = {}));
var CellValueJustNumber;
exports.CellValueJustNumber = CellValueJustNumber;
(function (CellValueJustNumber) {
CellValueJustNumber["NUMBER"] = "NUMBER";
})(CellValueJustNumber || (exports.CellValueJustNumber = CellValueJustNumber = {}));
var CellValueType = Object.assign(Object.assign({}, CellValueNoNumber), CellValueJustNumber);
exports.CellValueType = CellValueType;
var CellValueDetailedType = Object.assign(Object.assign({}, CellValueNoNumber), _InterpreterValue.NumberType);
exports.CellValueDetailedType = CellValueDetailedType;
var CellValueTypeOrd = function CellValueTypeOrd(arg) {
switch (arg) {
case CellValueType.EMPTY:
return 0;
case CellValueType.NUMBER:
return 1;
case CellValueType.STRING:
return 2;
case CellValueType.BOOLEAN:
return 3;
case CellValueType.ERROR:
return 4;
}
throw new Error('Cell value not computed');
};
exports.CellValueTypeOrd = CellValueTypeOrd;
var getCellValueType = function getCellValueType(cellValue) {
if (cellValue === _InterpreterValue.EmptyValue) {
return CellValueType.EMPTY;
}
if (cellValue instanceof CellError || cellValue instanceof _SimpleRangeValue.SimpleRangeValue) {
return CellValueType.ERROR;
}
if (typeof cellValue === 'string') {
return CellValueType.STRING;
} else if ((0, _InterpreterValue.isExtendedNumber)(cellValue)) {
return CellValueType.NUMBER;
} else if (typeof cellValue === 'boolean') {
return CellValueType.BOOLEAN;
}
throw new Error('Cell value not computed');
};
exports.getCellValueType = getCellValueType;
var getCellValueDetailedType = function getCellValueDetailedType(cellValue) {
if ((0, _InterpreterValue.isExtendedNumber)(cellValue)) {
return (0, _InterpreterValue.getTypeOfExtendedNumber)(cellValue);
} else {
return getCellValueType(cellValue);
}
};
exports.getCellValueDetailedType = getCellValueDetailedType;
var getCellValueFormat = function getCellValueFormat(cellValue) {
if ((0, _InterpreterValue.isExtendedNumber)(cellValue)) {
return (0, _InterpreterValue.getFormatOfExtendedNumber)(cellValue);
} else {
return undefined;
}
};
exports.getCellValueFormat = getCellValueFormat;
var CellError = /*#__PURE__*/function () {
function CellError(type, message, root) {
_classCallCheck(this, CellError);
this.type = type;
this.message = message;
this.root = root;
}
_createClass(CellError, [{
key: "attachRootVertex",
value: function attachRootVertex(vertex) {
if (this.root === undefined) {
return new CellError(this.type, this.message, vertex);
} else {
return this;
}
}
}], [{
key: "parsingError",
value: function parsingError() {
return new CellError(ErrorType.ERROR, _errorMessage.ErrorMessage.ParseError);
}
}]);
return CellError;
}();
exports.CellError = CellError;
var simpleRowAddress = function simpleRowAddress(sheet, row) {
return {
sheet: sheet,
row: row
};
};
exports.simpleRowAddress = simpleRowAddress;
var invalidSimpleRowAddress = function invalidSimpleRowAddress(address) {
return address.row < 0;
};
exports.invalidSimpleRowAddress = invalidSimpleRowAddress;
var simpleColumnAddress = function simpleColumnAddress(sheet, col) {
return {
sheet: sheet,
col: col
};
};
exports.simpleColumnAddress = simpleColumnAddress;
var invalidSimpleColumnAddress = function invalidSimpleColumnAddress(address) {
return address.col < 0;
};
exports.invalidSimpleColumnAddress = invalidSimpleColumnAddress;
var simpleCellAddress = function simpleCellAddress(sheet, col, row) {
return {
sheet: sheet,
col: col,
row: row
};
};
exports.simpleCellAddress = simpleCellAddress;
var invalidSimpleCellAddress = function invalidSimpleCellAddress(address) {
return address.col < 0 || address.row < 0;
};
exports.invalidSimpleCellAddress = invalidSimpleCellAddress;
var movedSimpleCellAddress = function movedSimpleCellAddress(address, toSheet, toRight, toBottom) {
return simpleCellAddress(toSheet, address.col + toRight, address.row + toBottom);
};
exports.movedSimpleCellAddress = movedSimpleCellAddress;
var addressKey = function addressKey(address) {
return "".concat(address.sheet, ",").concat(address.row, ",").concat(address.col);
};
exports.addressKey = addressKey;
function isSimpleCellAddress(obj) {
if (obj && (_typeof(obj) === 'object' || typeof obj === 'function')) {
return 'col' in obj && typeof obj.col === 'number' && 'row' in obj && typeof obj.row === 'number' && 'sheet' in obj && typeof obj.sheet === 'number';
} else {
return false;
}
}
var absoluteSheetReference = function absoluteSheetReference(address, baseAddress) {
var _a;
return (_a = address.sheet) !== null && _a !== void 0 ? _a : baseAddress.sheet;
};
exports.absoluteSheetReference = absoluteSheetReference;
var equalSimpleCellAddress = function equalSimpleCellAddress(left, right) {
return left.sheet === right.sheet && left.col === right.col && left.row === right.row;
};
exports.equalSimpleCellAddress = equalSimpleCellAddress;
;