UNPKG

hyperformula-dc

Version:

HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas

268 lines (249 loc) 13.4 kB
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } 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; } import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.string.iterator.js"; import "core-js/modules/es.weak-map.js"; import "core-js/modules/web.dom-collections.iterator.js"; import "core-js/modules/web.dom-collections.for-each.js"; import "core-js/modules/es.object.assign.js"; import "core-js/modules/es.array.concat.js"; import "core-js/modules/es.symbol.js"; import "core-js/modules/es.symbol.description.js"; import "core-js/modules/es.symbol.iterator.js"; import "core-js/modules/es.array.from.js"; import "core-js/modules/es.array.slice.js"; import "core-js/modules/es.function.name.js"; /** * @license * Copyright (c) 2021 Handsoncode. All rights reserved. */ import { configCheckIfParametersNotInConflict, configValueFromParam, configValueFromParamCheck, validateNumberToBeAtLeast, validateNumberToBeAtMost } from './ArgumentSanitization'; import { defaultParseToDateTime } from './DateTimeDefault'; import { instanceOfSimpleDate } from './DateTimeHelper'; import { AlwaysDense } from './DependencyGraph/AddressMapping/ChooseAddressMappingPolicy'; import { ConfigValueEmpty, ExpectedValueOfTypeError } from './errors'; import { defaultStringifyDateTime, defaultStringifyDuration } from './format/format'; import { checkLicenseKeyValidity } from './helpers/licenseKeyValidator'; import { HyperFormula } from './HyperFormula'; var PossibleGPUModeString = ['gpu', 'cpu', 'dev']; var privatePool = new WeakMap(); export var Config = /*#__PURE__*/function () { function Config() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, accentSensitive = _ref.accentSensitive, binarySearchThreshold = _ref.binarySearchThreshold, caseSensitive = _ref.caseSensitive, caseFirst = _ref.caseFirst, chooseAddressMappingPolicy = _ref.chooseAddressMappingPolicy, currencySymbol = _ref.currencySymbol, dateFormats = _ref.dateFormats, decimalSeparator = _ref.decimalSeparator, evaluateNullToZero = _ref.evaluateNullToZero, functionArgSeparator = _ref.functionArgSeparator, functionPlugins = _ref.functionPlugins, gpujs = _ref.gpujs, gpuMode = _ref.gpuMode, ignorePunctuation = _ref.ignorePunctuation, leapYear1900 = _ref.leapYear1900, localeLang = _ref.localeLang, language = _ref.language, licenseKey = _ref.licenseKey, matchWholeCell = _ref.matchWholeCell, arrayColumnSeparator = _ref.arrayColumnSeparator, arrayRowSeparator = _ref.arrayRowSeparator, maxRows = _ref.maxRows, maxColumns = _ref.maxColumns, nullYear = _ref.nullYear, nullDate = _ref.nullDate, parseDateTime = _ref.parseDateTime, precisionEpsilon = _ref.precisionEpsilon, precisionRounding = _ref.precisionRounding, stringifyDateTime = _ref.stringifyDateTime, stringifyDuration = _ref.stringifyDuration, smartRounding = _ref.smartRounding, timeFormats = _ref.timeFormats, thousandSeparator = _ref.thousandSeparator, useArrayArithmetic = _ref.useArrayArithmetic, useStats = _ref.useStats, undoLimit = _ref.undoLimit, useColumnIndex = _ref.useColumnIndex, useRegularExpressions = _ref.useRegularExpressions, useWildcards = _ref.useWildcards; _classCallCheck(this, Config); this.useArrayArithmetic = configValueFromParam(useArrayArithmetic, 'boolean', 'useArrayArithmetic'); this.accentSensitive = configValueFromParam(accentSensitive, 'boolean', 'accentSensitive'); this.caseSensitive = configValueFromParam(caseSensitive, 'boolean', 'caseSensitive'); this.caseFirst = configValueFromParam(caseFirst, ['upper', 'lower', 'false'], 'caseFirst'); this.ignorePunctuation = configValueFromParam(ignorePunctuation, 'boolean', 'ignorePunctuation'); this.chooseAddressMappingPolicy = chooseAddressMappingPolicy !== null && chooseAddressMappingPolicy !== void 0 ? chooseAddressMappingPolicy : Config.defaultConfig.chooseAddressMappingPolicy; this.dateFormats = _toConsumableArray(configValueFromParamCheck(dateFormats, Array.isArray, 'array', 'dateFormats')); this.timeFormats = _toConsumableArray(configValueFromParamCheck(timeFormats, Array.isArray, 'array', 'timeFormats')); this.functionArgSeparator = configValueFromParam(functionArgSeparator, 'string', 'functionArgSeparator'); this.decimalSeparator = configValueFromParam(decimalSeparator, ['.', ','], 'decimalSeparator'); this.language = configValueFromParam(language, 'string', 'language'); this.licenseKey = configValueFromParam(licenseKey, 'string', 'licenseKey'); this.thousandSeparator = configValueFromParam(thousandSeparator, ['', ',', ' ', '.'], 'thousandSeparator'); this.arrayColumnSeparator = configValueFromParam(arrayColumnSeparator, [',', ';'], 'arrayColumnSeparator'); this.arrayRowSeparator = configValueFromParam(arrayRowSeparator, [';', '|'], 'arrayRowSeparator'); this.localeLang = configValueFromParam(localeLang, 'string', 'localeLang'); this.functionPlugins = _toConsumableArray(functionPlugins !== null && functionPlugins !== void 0 ? functionPlugins : Config.defaultConfig.functionPlugins); this.gpujs = gpujs !== null && gpujs !== void 0 ? gpujs : Config.defaultConfig.gpujs; this.gpuMode = configValueFromParam(gpuMode, PossibleGPUModeString, 'gpuMode'); this.smartRounding = configValueFromParam(smartRounding, 'boolean', 'smartRounding'); this.evaluateNullToZero = configValueFromParam(evaluateNullToZero, 'boolean', 'evaluateNullToZero'); this.nullYear = configValueFromParam(nullYear, 'number', 'nullYear'); validateNumberToBeAtLeast(this.nullYear, 'nullYear', 0); validateNumberToBeAtMost(this.nullYear, 'nullYear', 100); this.precisionRounding = configValueFromParam(precisionRounding, 'number', 'precisionRounding'); validateNumberToBeAtLeast(this.precisionRounding, 'precisionRounding', 0); this.precisionEpsilon = configValueFromParam(precisionEpsilon, 'number', 'precisionEpsilon'); validateNumberToBeAtLeast(this.precisionEpsilon, 'precisionEpsilon', 0); this.useColumnIndex = configValueFromParam(useColumnIndex, 'boolean', 'useColumnIndex'); this.useStats = configValueFromParam(useStats, 'boolean', 'useStats'); this.binarySearchThreshold = configValueFromParam(binarySearchThreshold, 'number', 'binarySearchThreshold'); validateNumberToBeAtLeast(this.binarySearchThreshold, 'binarySearchThreshold', 1); this.parseDateTime = configValueFromParam(parseDateTime, 'function', 'parseDateTime'); this.stringifyDateTime = configValueFromParam(stringifyDateTime, 'function', 'stringifyDateTime'); this.stringifyDuration = configValueFromParam(stringifyDuration, 'function', 'stringifyDuration'); this.translationPackage = HyperFormula.getLanguage(this.language); this.errorMapping = this.translationPackage.buildErrorMapping(); this.nullDate = configValueFromParamCheck(nullDate, instanceOfSimpleDate, 'IDate', 'nullDate'); this.leapYear1900 = configValueFromParam(leapYear1900, 'boolean', 'leapYear1900'); this.undoLimit = configValueFromParam(undoLimit, 'number', 'undoLimit'); this.useRegularExpressions = configValueFromParam(useRegularExpressions, 'boolean', 'useRegularExpressions'); this.useWildcards = configValueFromParam(useWildcards, 'boolean', 'useWildcards'); this.matchWholeCell = configValueFromParam(matchWholeCell, 'boolean', 'matchWholeCell'); validateNumberToBeAtLeast(this.undoLimit, 'undoLimit', 0); this.maxRows = configValueFromParam(maxRows, 'number', 'maxRows'); validateNumberToBeAtLeast(this.maxRows, 'maxRows', 1); this.maxColumns = configValueFromParam(maxColumns, 'number', 'maxColumns'); this.currencySymbol = _toConsumableArray(configValueFromParamCheck(currencySymbol, Array.isArray, 'array', 'currencySymbol')); this.currencySymbol.forEach(function (val) { if (typeof val !== 'string') { throw new ExpectedValueOfTypeError('string[]', 'currencySymbol'); } if (val === '') { throw new ConfigValueEmpty('currencySymbol'); } }); validateNumberToBeAtLeast(this.maxColumns, 'maxColumns', 1); this.warnDeprecatedIfUsed(binarySearchThreshold, 'binarySearchThreshold', '1.1'); privatePool.set(this, { licenseKeyValidityState: checkLicenseKeyValidity(this.licenseKey) }); configCheckIfParametersNotInConflict({ value: this.decimalSeparator, name: 'decimalSeparator' }, { value: this.functionArgSeparator, name: 'functionArgSeparator' }, { value: this.thousandSeparator, name: 'thousandSeparator' }); configCheckIfParametersNotInConflict({ value: this.arrayRowSeparator, name: 'arrayRowSeparator' }, { value: this.arrayColumnSeparator, name: 'arrayColumnSeparator' }); } /** * Proxied property to its private counterpart. This makes the property * as accessible as the other Config options but without ability to change the value. * * @internal */ _createClass(Config, [{ key: "licenseKeyValidityState", get: function get() { return privatePool.get(this).licenseKeyValidityState; } }, { key: "getConfig", value: function getConfig() { var ret = {}; for (var key in Config.defaultConfig) { var val = this[key]; if (Array.isArray(val)) { ret[key] = _toConsumableArray(val); } else { ret[key] = val; } } return ret; } }, { key: "mergeConfig", value: function mergeConfig(init) { var mergedConfig = Object.assign({}, this.getConfig(), init); return new Config(mergedConfig); } }, { key: "warnDeprecatedIfUsed", value: function warnDeprecatedIfUsed(inputValue, paramName, fromVersion, replacementName) { if (inputValue !== undefined) { if (replacementName === undefined) { console.warn("".concat(paramName, " option is deprecated since ").concat(fromVersion)); } else { console.warn("".concat(paramName, " option is deprecated since ").concat(fromVersion, ", please use ").concat(replacementName)); } } } }]); return Config; }(); Config.defaultConfig = { accentSensitive: false, binarySearchThreshold: 20, currencySymbol: ['$'], caseSensitive: false, caseFirst: 'lower', chooseAddressMappingPolicy: new AlwaysDense(), dateFormats: ['DD/MM/YYYY', 'DD/MM/YY'], decimalSeparator: '.', evaluateNullToZero: false, functionArgSeparator: ',', functionPlugins: [], gpujs: undefined, gpuMode: 'gpu', ignorePunctuation: false, language: 'enGB', licenseKey: '', leapYear1900: false, localeLang: 'en', matchWholeCell: true, arrayColumnSeparator: ',', arrayRowSeparator: ';', maxRows: 40000, maxColumns: 18278, nullYear: 30, nullDate: { year: 1899, month: 12, day: 30 }, parseDateTime: defaultParseToDateTime, precisionEpsilon: 1e-13, precisionRounding: 14, smartRounding: true, stringifyDateTime: defaultStringifyDateTime, stringifyDuration: defaultStringifyDuration, timeFormats: ['hh:mm', 'hh:mm:ss.sss'], thousandSeparator: '', undoLimit: 20, useRegularExpressions: false, useWildcards: true, useColumnIndex: false, useStats: false, useArrayArithmetic: false };