hyperformula-dc
Version:
HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas
527 lines (526 loc) • 16 kB
TypeScript
/**
* @license
* Copyright (c) 2021 Handsoncode. All rights reserved.
*/
import { TranslatableErrorType } from './Cell';
import { DateTime, SimpleDate, SimpleDateTime, SimpleTime } from './DateTimeHelper';
import { ChooseAddressMapping } from './DependencyGraph/AddressMapping/ChooseAddressMappingPolicy';
import { LicenseKeyValidityState } from './helpers/licenseKeyValidator';
import { TranslationPackage } from './i18n';
import { FunctionPluginDefinition } from './interpreter';
import { Maybe } from './Maybe';
import { ParserConfig } from './parser/ParserConfig';
declare type GPUMode = 'gpu' | 'cpu' | 'dev';
export interface ConfigParams {
/**
* When set to `true`, makes string comparison accent-sensitive.
*
* Applies only to comparison operators.
*
* @default false
*
* @category String
*/
accentSensitive: boolean;
/**
* Sets a minimum number of elements that a range must have to use binary search.
*
* @deprecated Every search of sorted data always uses binary search.
*
* @default 20
*
* @category Engine
*/
binarySearchThreshold: number;
/**
* When set to `true`, makes string comparison case-sensitive.
*
* Applies to comparison operators only.
*
* @default false
*
* @category String
*/
caseSensitive: boolean;
/**
* When set to `upper`, upper case sorts first.
*
* When set to `lower`, lower case sorts first.
*
* When set to `false`, uses the locale's default.
*
* @default 'lower'
*
* @category String
*/
caseFirst: 'upper' | 'lower' | 'false';
/**
* Sets the address mapping policy to be used.
*
* Built-in implementations:
* - `DenseSparseChooseBasedOnThreshold`: sets the address mapping policy separately for each sheet, based on fill ratio.
* - `AlwaysDense`: uses `DenseStrategy` for all sheets.
* - `AlwaysSparse`: uses `SparseStrategy` for all sheets.
*
* @default AlwaysDense
*
* @category Engine
*/
chooseAddressMappingPolicy: ChooseAddressMapping;
/**
* Sets symbols that denote currency numbers.
*
* @default ['$']
*
* @category Number
*/
currencySymbol: string[];
/**
* Sets date formats that are supported by date-parsing functions.
*
* The separator is ignored and can be any of the following:
* - `-` (dash)
* - ` ` (empty space)
* - `/` (slash)
*
* `YY` can be replaced with `YYYY`.
*
* Any order of `YY`, `MM`, and `DD` is accepted as a date.
*
* @default ['MM/DD/YYYY', 'MM/DD/YY']
*
* @category Date and Time
*/
dateFormats: string[];
/**
* Sets a separator character that separates procedure arguments in formulas.
*
* Must be different from [[decimalSeparator]] and [[thousandSeparator]].
*
* @default ','
*
* @category Formula Syntax
*/
functionArgSeparator: string;
/**
* Sets a decimal separator used for parsing numerical literals.
*
* Can be one of the following:
* - `.` (period)
* - `,` (comma)
*
* Must be different from [[thousandSeparator]] and [[functionArgSeparator]].
*
* @default '.'
*
* @category Number
*/
decimalSeparator: '.' | ',';
/**
* When set to `true`, formulas evaluating to `null` evaluate to `0` instead.
*
* @default false
*
* @category Engine
*/
evaluateNullToZero: boolean;
/**
* Lists additional function plugins to be used by the formula interpreter.
*
* @default []
*
* @category Formula Syntax
*/
functionPlugins: any[];
/**
* A GPU.js constructor used by array functions.
*
* When not provided, the plain CPU implementation is used.
*
* @default undefined
*
* @category Engine
*/
gpujs?: any;
/**
* Sets array calculations to use either GPU or CPU.
*
* When set to `gpu`, tries to use GPU for array calculations.
*
* When set to `cpu`, enforces CPU usage.
*
* Use other values only for debugging purposes.
*
* For more information, see the [GPU.js documentation](https://github.com/gpujs/gpu.js/#readme).
*
* @default 'gpu'
*
* @category Engine
*/
gpuMode: GPUMode;
/**
* When set to `true`, string comparison ignores punctuation.
*
* @default false
*
* @category String
*/
ignorePunctuation: boolean;
/**
* Sets a translation package for function and error names.
*
* @default 'enGB'
*
* @category Formula Syntax
*/
language: string;
/**
* Sets year 1900 as a leap year.
*
* For compatibility with Lotus 1-2-3 and Microsoft Excel, set this option to `true`.
*
* For more information, see [[nullDate]].
*
* @default false
*
* @category Date and Time
*/
leapYear1900: boolean;
/**
* Sets your HyperFormula license key.
*
* To use HyperFormula on the GPLv3 license terms, set this option to `gpl-v3`.
*
* To use HyperFormula with your commercial license, set this option to your valid license key string.
*
* For more information, go [here](/guide/license-key.html).
*
* @default undefined
*
* @category License
*/
licenseKey: string;
/**
* Sets the locale for language-sensitive string comparison.
*
* Accepts **IETF BCP 47** language tags.
*
* @default 'en'
*
* @category String
*/
localeLang: string;
/**
* When set to `true`, function criteria require whole cells to match the pattern.
*
* When set to `false`, function criteria require just a subword to match the pattern.
*
* @default true
* @category String
*/
matchWholeCell: boolean;
/**
* Sets a column separator symbol for array notation.
*
* @default ','
* @category Formula syntax
*/
arrayColumnSeparator: ',' | ';';
/**
* Sets a row separator symbol for array notation.
*
* @default ';'
* @category Formula syntax
*/
arrayRowSeparator: ';' | '|';
/**
* Sets the maximum number of rows.
*
* @default 40,000
*
* @category Engine
* */
maxRows: number;
/**
* Sets the maximum number of columns.
*
* @default 18,278
*
* @category Engine
* */
maxColumns: number;
/**
* Internally, each date is represented as a number of days that passed since `nullDate`.
*
* This option sets a specific date from which that number of days is counted.
*
* @default {year: 1899, month: 12, day: 30}
*
* @category Date and Time
*/
nullDate: SimpleDate;
/**
* Sets the interpretation of two-digit year values.
*
* Two-digit year values (`xx`) can either become `19xx` or `20xx`.
*
* If `xx` is less or equal to `nullYear`, two-digit year values become `20xx`.
*
* If `xx` is more than `nullYear`, two-digit year values become `19xx`.
*
* @default 30
*
* @category Date and Time
*/
nullYear: number;
/**
* Sets a function that parses strings representing date-time into actual date-time.
*
* @default defaultParseToDateTime
*
* @category Date and Time
*/
parseDateTime: (dateTimeString: string, dateFormat?: string, timeFormat?: string) => Maybe<DateTime>;
/**
* Sets how far two numerical values need to be from each other to be treated as non-equal.
*
* `a` and `b` are equal if all three of the following conditions are met:
* - Both `a` and `b` are of the same sign
* - `abs(a)` <= `(1+precisionEpsilon) * abs(b)`
* - `abs(b)` <= `(1+precisionEpsilon) * abs(a)`
*
* Additionally, this option controls the snap-to-zero behavior for additions and subtractions:
* - For `c=a+b`, if `abs(c)` <= `precisionEpsilon * abs(a)`, then `c` is set to `0`
* - For `c=a-b`, if `abs(c)` <= `precisionEpsilon * abs(a)`, then `c` is set to `0`
*
* @default 1e-13
*
* @category Number
*/
precisionEpsilon: number;
/**
* Sets calculations' precision level.
*
* Numerical outputs are rounded to the `precisionRounding` number of digits after the decimal.
*
* @default 14
*
* @category Number
*/
precisionRounding: number;
/**
* Sets a function that converts date-time into strings.
*
* @default defaultStringifyDateTime
*
* @category Date and Time
*/
stringifyDateTime: (dateTime: SimpleDateTime, dateTimeFormat: string) => Maybe<string>;
/**
* Sets a function that converts time duration into strings.
*
* @default defaultStringifyDuration
*
* @category Date and Time
*/
stringifyDuration: (time: SimpleTime, timeFormat: string) => Maybe<string>;
/**
* When set to `false`, no rounding happens, and numbers are equal if and only if they are of truly identical value.
*
* For more information, see [[precisionEpsilon]].
*
* @default true
*
* @category Number
*/
smartRounding: boolean;
/**
* Sets a thousands separator symbol for parsing numerical literals.
*
* Can be one of the following:
* - empty
* - `,` (comma)
* - ` ` (empty space)
*
* Must be different from [[decimalSeparator]] and [[functionArgSeparator]].
*
* @default ''
*
* @category Number
*/
thousandSeparator: '' | ',' | ' ' | '.';
/**
* Sets time formats that will be supported by time-parsing functions.
*
* The separator is `:` (colon).
*
* Accepts any configuration of at least two of the following, in any order:
* - `hh`: hours
* - `mm`: minutes
* - `ss`: seconds
*
* @default ['hh:mm', 'hh:mm:ss.sss']
*
* @category Date and Time
*/
timeFormats: string[];
/**
* When set to `true`, array arithmetic is enabled globally.
*
* When set to `false`, array arithmetic is enabled only inside array functions (`ARRAYFORMULA`, `FILTER`, and `ARRAY_CONSTRAIN`).
*
* For more information, see the [Arrays guide](/guide/arrays.html).
*
* @default false
*
* @category Engine
*/
useArrayArithmetic: boolean;
/**
* When set to `true`, switches column search strategy from binary search to column index.
*
* Using column index improves efficiency of the `VLOOKUP` and `MATCH` functions, but increases memory usage.
*
* When searching with wildcards or regular expressions, column search strategy falls back to binary search (even with `useColumnIndex` set to `true`).
*
* @default false
*
* @category Engine
*/
useColumnIndex: boolean;
/**
* When set to `true`, enables gathering engine statistics and timings.
*
* Useful for testing and benchmarking.
*
* @default false
*
* @category Engine
*/
useStats: boolean;
/**
* Sets the number of elements kept in the undo history.
*
* @default 20
*
* @category Undo and Redo
*/
undoLimit: number;
/**
* When set to `true`, criteria in functions (SUMIF, COUNTIF, ...) are allowed to use regular expressions.
*
* @default false
* @category String
*/
useRegularExpressions: boolean;
/**
* When set to `true`, criteria in functions (SUMIF, COUNTIF, ...) can use the `*` and `?` wildcards.
*
* @default true
* @category String
*/
useWildcards: boolean;
}
export declare type ConfigParamsList = keyof ConfigParams;
export declare class Config implements ConfigParams, ParserConfig {
static defaultConfig: ConfigParams;
/** @inheritDoc */
readonly useArrayArithmetic: boolean;
/** @inheritDoc */
readonly caseSensitive: boolean;
/** @inheritDoc */
readonly chooseAddressMappingPolicy: ChooseAddressMapping;
/** @inheritDoc */
readonly accentSensitive: boolean;
/** @inheritDoc */
readonly caseFirst: 'upper' | 'lower' | 'false';
/** @inheritDoc */
readonly dateFormats: string[];
/** @inheritDoc */
readonly timeFormats: string[];
/** @inheritDoc */
readonly functionArgSeparator: string;
/** @inheritDoc */
readonly arrayColumnSeparator: ',' | ';';
/** @inheritDoc */
readonly arrayRowSeparator: ';' | '|';
/** @inheritDoc */
readonly decimalSeparator: '.' | ',';
/** @inheritDoc */
readonly thousandSeparator: '' | ',' | ' ' | '.';
/** @inheritDoc */
readonly language: string;
/** @inheritDoc */
readonly licenseKey: string;
/** @inheritDoc */
readonly functionPlugins: FunctionPluginDefinition[];
/** @inheritDoc */
readonly gpujs?: any;
/** @inheritDoc */
readonly gpuMode: GPUMode;
/** @inheritDoc */
readonly leapYear1900: boolean;
/** @inheritDoc */
readonly ignorePunctuation: boolean;
/** @inheritDoc */
readonly localeLang: string;
/** @inheritDoc */
readonly evaluateNullToZero: boolean;
/** @inheritDoc */
readonly nullYear: number;
/** @inheritDoc */
readonly parseDateTime: (dateString: string, dateFormat?: string, timeFormat?: string) => Maybe<SimpleDateTime>;
/** @inheritDoc */
readonly stringifyDateTime: (date: SimpleDateTime, formatArg: string) => Maybe<string>;
/** @inheritDoc */
readonly stringifyDuration: (time: SimpleTime, formatArg: string) => Maybe<string>;
/** @inheritDoc */
readonly precisionEpsilon: number;
/** @inheritDoc */
readonly precisionRounding: number;
/** @inheritDoc */
readonly smartRounding: boolean;
/** @inheritDoc */
readonly useColumnIndex: boolean;
/** @inheritDoc */
readonly useStats: boolean;
/** @inheritDoc */
readonly binarySearchThreshold: number;
/** @inheritDoc */
readonly nullDate: SimpleDate;
/** @inheritDoc */
readonly currencySymbol: string[];
/** @inheritDoc */
readonly undoLimit: number;
/**
* Built automatically based on translation package.
*
* @internal
*/
readonly errorMapping: Record<string, TranslatableErrorType>;
/** @inheritDoc */
readonly maxRows: number;
/** @inheritDoc */
readonly maxColumns: number;
/**
* Built automatically based on language.
*
* @internal
*/
readonly translationPackage: TranslationPackage;
readonly useRegularExpressions: boolean;
readonly useWildcards: boolean;
readonly matchWholeCell: boolean;
/**
* 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
*/
get licenseKeyValidityState(): LicenseKeyValidityState;
constructor({ accentSensitive, binarySearchThreshold, caseSensitive, caseFirst, chooseAddressMappingPolicy, currencySymbol, dateFormats, decimalSeparator, evaluateNullToZero, functionArgSeparator, functionPlugins, gpujs, gpuMode, ignorePunctuation, leapYear1900, localeLang, language, licenseKey, matchWholeCell, arrayColumnSeparator, arrayRowSeparator, maxRows, maxColumns, nullYear, nullDate, parseDateTime, precisionEpsilon, precisionRounding, stringifyDateTime, stringifyDuration, smartRounding, timeFormats, thousandSeparator, useArrayArithmetic, useStats, undoLimit, useColumnIndex, useRegularExpressions, useWildcards, }?: Partial<ConfigParams>);
getConfig(): ConfigParams;
mergeConfig(init: Partial<ConfigParams>): Config;
private warnDeprecatedIfUsed;
}
export {};