diff --git a/CHANGELOG.md b/CHANGELOG.md index 66ae6fbb1c..4f3e5b850b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Expanded the HyperFormula public API by adding the code entities that are necessary to implement a complex custom function: `ArraySize`, `ImplementedFunctions`, `FunctionMetadata`, `FunctionArgumentType`. [#779](https://github.com/handsontable/hyperformula/issues/779) + ## [2.2.0] - 2022-11-17 ### Added diff --git a/docs/guide/arrays.md b/docs/guide/arrays.md index 000748eeb8..fa06dfce3b 100644 --- a/docs/guide/arrays.md +++ b/docs/guide/arrays.md @@ -72,7 +72,7 @@ ISEVEN(A2:A5*10) Thanks to HyperFormula's built-in array features, you can: * [Operate on arrays](#operating-on-arrays) just like on [scalars](#about-arrays) -* [Pass arrays to functions](#passing-arrays-to-scalar-functions) that accept [scalars](#about-arrays) +* [Pass arrays to functions](#passing-arrays-to-scalar-functions-vectorization) that accept [scalars](#about-arrays) * [Broadcast](#broadcasting) smaller input arrays across larger output areas You can also: @@ -83,7 +83,7 @@ You can also: You can operate on arrays just like on single values. -When the [array arithmetic mode](#enabling-the-array-arithmetic-mode) is enabled, each output array value is the result of your operation on the corresponding input array value. +When the [array arithmetic mode](#array-arithmetic-mode) is enabled, each output array value is the result of your operation on the corresponding input array value. ``` =ARRAYFORMULA(A2:A5*B2:B5) @@ -95,22 +95,23 @@ When the [array arithmetic mode](#enabling-the-array-arithmetic-mode) is enabled // =A5*B5 ``` -### Passing arrays to scalar functions -You can pass arrays to functions that would normally accept [scalars](#about-arrays) (thanks to HyperFormula's **vectorization** feature). +### Passing arrays to scalar functions (vectorization) -When the [array arithmetic mode](#enabling-the-array-arithmetic-mode) is enabled, and you pass an array to a [scalar](#about-arrays) function, that function produces an array on the output as well. +When the [array arithmetic mode](#array-arithmetic-mode) is enabled, HyperFormula automatically _vectorizes_ most functions. + +As a consequence of that, you can pass arrays to functions that would normally accept [scalars](#about-arrays). The result would also be an array. ``` -=ARRAYFORMULA(ISEVEN(A2:A5*10)) +=ARRAYFORMULA(ISEVEN(A2:A5)) // calculates: -// =ISEVEN(A2*10) -// =ISEVEN(A3*10) -// =ISEVEN(A4*10) -// =ISEVEN(A5*10) +// =ISEVEN(A2) +// =ISEVEN(A3) +// =ISEVEN(A4) +// =ISEVEN(A5) ``` -#### Broadcasting +### Broadcasting If an input array has a dimension of `1`, it's automatically repeated ("broadcast") on that dimension to match the size of the output. @@ -126,7 +127,7 @@ If an input array has a dimension of `1`, it's automatically repeated ("broadcas ### Filtering an array -When the [array arithmetic mode](#enabling-the-array-arithmetic-mode) is enabled, you can filter an array, based on boolean arrays, using the `FILTER` function: +When the [array arithmetic mode](#array-arithmetic-mode) is enabled, you can filter an array, based on boolean arrays, using the `FILTER` function: | Syntax | Example | |:-----------------------------------------------------|:------------------------------------------------| @@ -134,7 +135,7 @@ When the [array arithmetic mode](#enabling-the-array-arithmetic-mode) is enabled ### Constraining an array's size -When the [array arithmetic mode](#enabling-the-array-arithmetic-mode) is enabled, you can constrain the size of the output array, using the `ARRAY_CONSTRAIN` function: +When the [array arithmetic mode](#array-arithmetic-mode) is enabled, you can constrain the size of the output array, using the `ARRAY_CONSTRAIN` function: | Syntax | Example | |:-------------------------------------------|:----------------------------------------------| @@ -148,7 +149,7 @@ If your specified output array size is larger or equal to the input array size, ### With the array arithmetic mode enabled -When the [array arithmetic mode](#enabling-the-array-arithmetic-mode) is enabled, and you pass an array to a [scalar](#about-arrays) function, the following rules apply: +When the [array arithmetic mode](#array-arithmetic-mode) is enabled, and you pass an array to a [scalar](#about-arrays) function, the following rules apply: * Array dimensions need to be consistent (e.g. every row needs to be of the same length). * If an input array value is missing (due to a difference in dimensions), the corresponding output array value is `#N/A`. * If a cell evaluates to an array, the array values are spilled into neighboring cells (unless the neighboring cells are already filled).
This behavior doesn't apply to ranges, which return the `#VALUE!` error in this case. @@ -156,9 +157,9 @@ When the [array arithmetic mode](#enabling-the-array-arithmetic-mode) is enabled ### With the array arithmetic mode disabled -When the [array arithmetic mode](#enabling-the-array-arithmetic-mode) is disabled, and you pass an array to a [scalar](#about-arrays) function, the array is reduced to 1 element (usually the array's top-left value). +When the [array arithmetic mode](#array-arithmetic-mode) is disabled, and you pass an array to a [scalar](#about-arrays) function, the array is reduced to 1 element (usually the array's top-left value). -When the [array arithmetic mode](#enabling-the-array-arithmetic-mode) is disabled, and you operate on a range of width/height equal to `1`, the behavior depends on your array formula's location: +When the [array arithmetic mode](#array-arithmetic-mode) is disabled, and you operate on a range of width/height equal to `1`, the behavior depends on your array formula's location: | Your array formula's location | Behavior | |:--------------------------------------------------|:---------------------------------------| diff --git a/docs/guide/custom-functions.md b/docs/guide/custom-functions.md index 2c29bad571..689e0b0da4 100644 --- a/docs/guide/custom-functions.md +++ b/docs/guide/custom-functions.md @@ -1,66 +1,61 @@ # Custom functions -Expand the function library of your application, by adding custom functions. +Expand the function library of your application by adding custom functions. **Contents:** [[toc]] -## Add a custom function +## Add a simple custom function -As an example, let's create a function that returns the number of letters in the word "HyperFormula". - - +As an example, let's create a custom function `GREET` that accepts a person's first name as a string argument and returns a personalized greeting. ### 1. Create a function plugin Import `FunctionPlugin`, and extend it with a new class. For example: -```javascript +```js import { FunctionPlugin } from 'hyperformula'; -// let's call the function plugin `CountHF` -export class CountHF extends FunctionPlugin { +// let's call the function plugin `MyCustomPlugin` +export class MyCustomPlugin extends FunctionPlugin { } ``` -### 2. Define your function's ID and method +### 2. Define your function's ID, method, and metadata -In your function plugin, in the static `implementedFunctions` property, define an object that contains your custom function. +In your function plugin, in the static `implementedFunctions` property, define an object that declares the functions provided by this plugin. -The name of that object becomes the ID by which [translations](#function-translations), [aliases](#function-aliases), and other elements refer to your function. +The name of that object becomes the ID by which [translations](#function-name-translations), [aliases](#function-aliases), and other elements refer to your function. Make the ID unique among all HyperFormula functions ([built-in](built-in-functions.md#list-of-available-functions) and custom). -Then, in your function's object, define a `method` property, which maps your function to an implementation method (we'll define it later on). +In your function's object, you can specify: +- a `method` property (required), which maps your function to the implementation method (we'll define it later on), +- a `parameters` array that describes the arguments accepted by your function and [validation options](#argument-validation-options) for each argument, +- other [custom function options](#custom-function-options). -```javascript -CountHF.implementedFunctions = { - // let's define the function's ID as `HYPER` - HYPER: { - // we'll define the `hyper` method later on - method: 'hyper', - }, +```js +import { FunctionPlugin, FunctionArgumentType } from 'hyperformula'; + +MyCustomPlugin.implementedFunctions = { + // let's define the function's ID as `GREET` + GREET: { + method: "greet", + parameters: [ + { argumentType: FunctionArgumentType.STRING } + ], + } }; ``` -::: tip -In `implementedFunctions`, you can also define your [custom function options](#custom-function-options) and [argument validation options](#argument-validation-options). -::: - ::: tip To define multiple functions in a single function plugin, add them all to the `implementedFunctions` object. ```js -CountHF.implementedFunctions = { - HYPER: { +MyCustomPlugin.implementedFunctions = { + FUNCTION_A: { //... }, - SUPER: { + FUNCTION_B: { //... }, }; @@ -69,20 +64,17 @@ CountHF.implementedFunctions = { ### 3. Add your function's names -In your function plugin, in the static `translations` property, define your function's names in every language you want to support. Your end users use these names to call your function inside formulas. - -If you support just one language, you still need to define the name of your function in that language. - -::: tip -Function names are case-insensitive, as they are all normalized to uppercase. -::: +In a separate object, [define your function's names in every language you want to support](#function-name-translations). -```javascript -CountHF.translations = { +```js +export const MyCustomPluginTranslations = { enGB: { - // in English, let's set the function's name to `HYPER` - HYPER: 'HYPER', + GREET: "GREET", }, + enUS: { + GREET: "GREET", + } + // repeat for all languages used in your system... }; ``` @@ -92,23 +84,22 @@ In your function plugin, add a method that implements your function's calculatio * Take two optional arguments: `ast` and `state`. * Return the results of your calculations. -```javascript -export class CountHF extends FunctionPlugin { - hyper(ast, state) { - return 'Hyperformula'.length; - } -} -``` - To benefit from HyperFormula's automatic validations, wrap your method in the built-in `runFunction()` method, which: * Verifies the format of the values returned by your function. * Validates your function's parameters against your [custom function options](#custom-function-options). * Validates arguments passed to your function against your [argument validation options](#argument-validation-options). -```javascript -export class CountHF extends FunctionPlugin { - hyper(ast, state) { - return this.runFunction(ast.args, state, this.metadata('HYPER'), () => 'Hyperformula'.length); +```js +export class MyCustomPlugin extends FunctionPlugin { + greet(ast, state) { + return this.runFunction( + ast.args, + state, + this.metadata('GREET'), + (firstName) => { + return `👋 Hello, ${firstName}!`; + }, + ); } } ``` @@ -119,23 +110,23 @@ Register your function plugin (and its translations) so that HyperFormula can re Use the [`registerFunctionPlugin()`](../api/classes/hyperformula.md#registerfunctionplugin) method: -```javascript -HyperFormula.registerFunctionPlugin(CountHF, CountHF.translations); +```js +HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations); ``` ### 6. Use your custom function inside a formula -Now, you can use your HYPER function inside a formula: +Now, you can use your GREET function inside a formula: -```javascript +```js // prepare spreadsheet data -const data = [['=HYPER()']]; +const data = [['Anthony', '=GREET(A1)']]; // build a HyperFormula instance where you can use your function directly const hfInstance = HyperFormula.buildFromArray(data); // read the value of cell A1 -const result = hfInstance.getCellValue({ sheet: 0, col: 0, row: 0 }); +const result = hfInstance.getCellValue({ sheet: 0, col: 1, row: 0 }); // open the browser's console to see the results console.log(result); @@ -143,48 +134,216 @@ console.log(result); ### Full example -```javascript -import { FunctionPlugin } from 'hyperformula'; +The complete implementation of this custom function is also included in the [demo](#working-demo). -export class CountHF extends FunctionPlugin { - hyper(ast, state) { - return this.runFunction(ast.args, state, this.metadata('HYPER'), () => 'Hyperformula'.length); +```js +import { FunctionPlugin, FunctionArgumentType } from 'hyperformula'; + +export class MyCustomPlugin extends FunctionPlugin { + greet(ast, state) { + return this.runFunction( + ast.args, + state, + this.metadata('GREET'), + (firstName) => { + return `👋 Hello, ${firstName}!`; + }, + ); } } -CountHF.implementedFunctions = { - HYPER: { - method: 'hyper', - }, +MyCustomPlugin.implementedFunctions = { + GREET: { + method: 'greet', + parameters: [ + { argumentType: FunctionArgumentType.STRING } + ], + } }; -CountHF.translations = { +export const MyCustomPluginTranslations = { enGB: { - HYPER: 'HYPER', + GREET: 'GREET', }, + enUS: { + GREET: 'GREET', + } }; -HyperFormula.registerFunctionPlugin(CountHF, CountHF.translations); +HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations); ``` +## Advanced custom function example + +In a more advanced example, we'll create a custom function `DOUBLE_RANGE` that takes a range of numbers and returns the range of the same size with all the numbers doubled. + +### Accept a range argument + +To accept a range argument, declare it in the `parameters` array: + +```js +MyCustomPlugin.implementedFunctions = { + DOUBLE_RANGE: { + method: 'doubleRange', + parameters: [ + { argumentType: FunctionArgumentType.RANGE }, + ], + } +}; +``` + +The range arguments are passed to the implementation method as instances of the [`SimpleRangeValue` class](../api/classes/simplerangevalue.md): + +```js +export class MyCustomPlugin extends FunctionPlugin { + doubleRange(ast, state) { + return this.runFunction( + ast.args, + state, + this.metadata('DOUBLE_RANGE'), + (range) => { + const rangeData = range.data; + // ... + }, + ); + } +} +``` + +### Return an array of data + +A function may return multiple values in the form of an [array](arrays.md). To do that, use [`SimpleRangeValue` class](../api/classes/simplerangevalue.md): + +```js +export class MyCustomPlugin extends FunctionPlugin { + doubleRange(ast, state) { + return this.runFunction( + ast.args, + state, + this.metadata('DOUBLE_RANGE'), + (range) => { + const resultArray = //... + return SimpleRangeValue.onlyValues(resultArray); + }, + ); + } +} +``` + +A function that returns an array will cause the `VALUE!` error unless you also declare a companion method for the array size. +To do that, provide the `arraySizeMethod` that calculates the size of the result array based on the function arguments and returns an instance of the [`ArraySize` class](../api/classes/arraysize.md). + +```js +export class MyCustomPlugin extends FunctionPlugin { + doubleRangeResultArraySize(ast, state) { + const arg = ast?.args?.[0]; + + if (arg?.start == null || arg?.end == null) { + return ArraySize.scalar(); + } + + const width = arg.end.col - arg.start.col + 1; + const height = arg.end.row - arg.start.row + 1; + + return new ArraySize(width, height); + } +} + +MyCustomPlugin.implementedFunctions = { + DOUBLE_RANGE: { + method: 'doubleRange', + arraySizeMethod: 'doubleRangeResultArraySize', + parameters: [ + { argumentType: FunctionArgumentType.RANGE }, + ], + } +}; +``` + +### Validate the arguments and return an error + +To handle invalid inputs, the custom function should return an instance of the [`CellError` class](../api/classes/cellerror.md) with the relevant [error type](types-of-errors.md). +Errors are localized according to your [language settings](localizing-functions.md). + +```js +if (rangeData.some(row => row.some(val => typeof rawValue !== 'number'))) { + return new CellError('VALUE', 'Function DOUBLE_RANGE operates only on numbers.'); +} +``` + +::: tip +All HyperFormula [error types](types-of-errors.md) support optional custom error messages. Put them to good use: let your users know what caused the error and how to avoid it in the future. +::: + +### Test your function + +You may add unit tests to ensure your custom function works correctly using one of the JavaScript testing libraries. + +```js +it('works for a range of numbers', () => { + HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations); + + const engine = HyperFormula.buildFromArray([ + [1, '=DOUBLE_RANGE(A1:A3)'], + [2], + [3], + ], { licenseKey: 'gpl-v3' }); + + expect(engine.getCellValue({ sheet: 0, row: 0, col: 1 })).toEqual(2); + expect(engine.getCellValue({ sheet: 0, row: 1, col: 1 })).toEqual(4); + expect(engine.getCellValue({ sheet: 0, row: 2, col: 1 })).toEqual(6); +}); + +it('returns a VALUE error if the range argument contains a string', () => { + HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations); + + const engine = HyperFormula.buildFromArray([ + [1, '=DOUBLE_RANGE(A1:A3)'], + ['I should not be here'], + [3], + ], { licenseKey: 'gpl-v3' }); + + expect(engine.getCellValueType({ sheet: 0, row: 0, col: 1 })).toEqual('ERROR'); + expect(engine.getCellValue({ sheet: 0, row: 0, col: 1 }).value).toEqual('#VALUE!'); +}); +``` + +## Working demo + +This demo contains the implementation of both `GREET` and `DOUBLE_RANGE` custom functions. + + + ## Custom function options -You can configure your custom function to: -* Use the [array arithmetic mode](arrays.md). -* Treat reference or range arguments as arguments that don't create dependency. -* Inline range arguments to scalar arguments. -* Get recalculated with each sheet shape change. -* Be a [volatile](volatile-functions.md) function. -* Repeat a specified number of last arguments indefinitely. -* Never get vectorized. +You can set the following options for your function: -In your function plugin, in the static `implementedFunctions` property, add your function's options: +| Option | Type | Description | +|-------------------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `method` (required) | String | Name of the method that implements the custom function logic. | +| `parameters` | Array | Specification of the arguments accepted by the function and their [validation options](#argument-validation-options). | +| `arraySizeMethod` | String | Name of the method that calculates the size of the result array. Not required for functions that never return an array. | +| `returnNumberType` | String | If the function returns a numeric value, this option indicates how to interpret the returned number.
Possible values: `NUMBER_RAW, NUMBER_DATE, NUMBER_TIME, NUMBER_DATETIME, NUMBER_CURRENCY, NUMBER_PERCENT`.
Default: `NUMBER_RAW` | +| `repeatLastArgs` | Number | For functions with a variable number of arguments: sets how many last arguments can be repeated indefinitely.
Default: `0` | +| `expandRanges` | Boolean | `true`: ranges in the function's arguments are inlined to (possibly multiple) scalar arguments.
Default: `false` | +| `isVolatile` | Boolean | `true`: the function is [volatile](volatile-functions.md).
Default: `false` | +| `isDependentOnSheetStructureChange` | Boolean | `true`: the function gets recalculated with each sheet shape change (e.g., when adding/removing rows or columns).
Default: `false` | +| `doesNotNeedArgumentsToBeComputed` | Boolean | `true`: the function treats reference or range arguments as arguments that don't create dependency (other arguments are properly evaluated).
Default: `false` | +| `arrayFunction` | Boolean | `true`: the function enables the [array arithmetic mode](arrays.md) in its arguments and nested expressions.
Default: `false` | +| `vectorizationForbidden` | Boolean | `true`: the function will never get [vectorized](arrays.md#passing-arrays-to-scalar-functions-vectorization).
Default: `false` | + +The options listed above are set in the static `implementedFunctions` property of your function plugin: ```javascript -MyFunctionPlugin.implementedFunctions = { +MyCustomPlugin.implementedFunctions = { MY_FUNCTION: { method: 'myFunctionMethod', - // set options for `MY_FUNCTION` arrayFunction: false, doesNotNeedArgumentsToBeComputed: false, expandRanges: false, @@ -195,28 +354,27 @@ MyFunctionPlugin.implementedFunctions = { }; ``` -You can set the following options for your function: - -| Option | Type | Description | -|-------------------------------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------| -| `arrayFunction` | Boolean | `true`: the function enables the [array arithmetic mode](arrays.md) in its arguments and nested expressions. | -| `doesNotNeedArgumentsToBeComputed` | Boolean | `true`: the function treats reference or range arguments as arguments that don't create dependency (other arguments are properly evaluated). | -| `expandRanges` | Boolean | `true`: ranges in the function's arguments are inlined to (possibly multiple) scalar arguments. | -| `isDependentOnSheetStructureChange` | Boolean | `true`: the function gets recalculated with each sheet shape change (e.g., when adding/removing rows or columns). | -| `isVolatile` | Boolean | `true`: the function is [volatile](volatile-functions.md). | -| `repeatLastArgs` | Number | For functions with a variable number of arguments: sets how many last arguments can be repeated indefinitely. | - ### Argument validation options -You can set rules for your function's argument validation. +You can set the following argument validation options: -In your function plugin, in the static `implementedFunctions` property, next to other options add an array called `parameters`: +| Option | Type | Description | +|---------------------------|-------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `argumentType` (required) | `FunctionArgumentType` | Expected type of the argument. Possible values: `STRING, NUMBER, BOOLEAN, SCALAR, NOERROR, RANGE, INTEGER, COMPLEX, ANY`. | +| `defaultValue` | `InternalScalarValue` or `RawScalarValue` | If set: if an argument is missing, its value defaults to `defaultValue`. | +| `passSubtype` | Boolean | `true`: arguments are passed with full type information (e.g., for numbers: `Date` or `DateTime` or `Time` or `Currency` or `Percentage`).
Default: `false` | +| `optionalArg` | Boolean | `true`: if an argument is missing, and no `defaultValue` is set, the argument defaults to `undefined` (instead of throwing an error).
Default: `false`
Setting this option to `true` is the same as setting `defaultValue` to `undefined`. | +| `minValue` | Number | If set: numerical arguments need to be greater than or equal to `minValue`. | +| `maxValue` | Number | If set: numerical arguments need to be less than or equal to `maxValue`. | +| `lessThan` | Number | If set: numerical argument needs to be less than `lessThan`. | +| `greaterThan` | Number | If set: numerical argument needs to be greater than `greaterThan`. | -```javascript -MyFunctionPlugin.implementedFunctions = { +In your function plugin, in the static `implementedFunctions` property, add an array called `parameters`: + +```js +MyCustomPlugin.implementedFunctions = { MY_FUNCTION: { method: 'myFunctionMethod', - // set argument validation options for `MY_FUNCTION` parameters: [{ passSubtype: false, defaultValue: 10, @@ -230,18 +388,6 @@ MyFunctionPlugin.implementedFunctions = { }; ``` -You can set the following argument validation options: - -| Option | Type | Description | -|----------------|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `passSubtype` | Boolean | `true`: arguments are passed with full type information (e.g., for numbers: `Date` or `DateTime` or `Time` or `Currency` or `Percentage`). | -| `defaultValue` | `InternalScalarValue` \ | `RawScalarValue` | If set: if an argument is missing, its value defaults to `defaultValue`. | -| `optionalArg` | Boolean | `true`: if an argument is missing, and no `defaultValue` is set, the argument defaults to `undefined` (instead of throwing an error).

Setting this option to `true` is the same as setting `defaultValue` to `undefined`. | -| `minValue` | Number | If set: numerical arguments need to be greater than or equal to `minValue`. | -| `maxValue` | Number | If set: numerical arguments need to be less than or equal to `maxValue`. | -| `lessThan` | Number | If set: numerical argument need to be less than `lessThan`. | -| `greaterThan` | Number | If set: numerical argument need to be greater than `greaterThan`. | - #### Handling missing arguments Both the `defaultValue` and `optionalArg` options let you decide what happens when a user doesn't pass enough valid arguments to your custom function. @@ -250,45 +396,20 @@ Setting a `defaultValue` for an argument always makes that argument optional. Bu If you don't want to set any `defaultValue` (because, for example, your function's behavior depends on the number of valid arguments passed), use the `optionalArg` setting instead. -## Function aliases - -You can assign multiple aliases to a single custom function. +## Function name translations -In your function plugin, in the static `aliases` property, add aliases for your function: - -```javascript -MyFunctionPlugin.aliases = { - // `=MY_ALIAS()` will work the same as `=MY_FUNCTION()` - 'MY_ALIAS': 'MY_FUNCTION' -}; -``` +You can provide the translations for your function name in multiple languages. +Your end users use the translated names to call your function inside formulas. ::: tip -For each alias of your function, define a translation, even if you want to support only one language. -```js -MyFunctionPlugin.translations = { - enGB: { - 'MY_FUNCTION': 'MY_FUNCTION', - 'MY_ALIAS': 'MY_ALIAS', - }, -}; -``` +If you support just one language, you still need to define the name of your function in that language. ::: -## Function name translations - -You can configure the name of your function with multiple translations. -Your end users call your function by referring to those translations. - -In your function plugin, in the static `translations` property, define your function's names, -in every language that you want to support. - -::: tip +In a separate object, define the translations of your custom functions' names in every language you want to support. Function names are case-insensitive, as they are all normalized to uppercase. -::: -```javascript -MyFunctionPlugin.translations = { +```js +export const MyCustomPluginTranslations = { enGB: { // formula in English: `=MY_FUNCTION()` 'MY_FUNCTION': 'MY_FUNCTION' @@ -296,64 +417,40 @@ MyFunctionPlugin.translations = { deDE: { // formula in German: `=MEINE_FUNKTION()` 'MY_FUNCTION': 'MEINE_FUNKTION' - } -}; - -// register your function plugin and translations -HyperFormula.registerFunctionPlugin(MyFunctionPlugin, MyFunctionPlugin.translations); -``` - -You can also define `translations` as a standalone object: - -```js -export const MyFunctionNameTranslations = { - enGB: { - 'MY_FUNCTION': 'MY_FUNCTION' }, - deDE: { - 'MY_FUNCTION': 'MEINE_FUNKTION' - } + // repeat for all languages used in your system... }; // register your function plugin and translations -HyperFormula.registerFunctionPlugin(MyFunctionPlugin, MyFunctionNameTranslations); +HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations); ``` ::: tip Before using a translated function name, remember to [register and set the language](localizing-functions.md). ::: -## Returning errors - -If you want your custom function to return an error, check the [API reference](../api) for the HyperFormula [error types](types-of-errors.md). +## Function aliases -::: tip -All HyperFormula [error types](types-of-errors.md) support optional custom error messages. Put them to good use: let your users know what caused the error and how to avoid it in the future. -::: +You can also assign multiple aliases to a single custom function. -For example, if you want to return a `#DIV/0!` error with your custom error message, use the [`CellError` class](../api/classes/cellerror.md), and the [DIV_BY_ZERO](../api/enums/errortype.md#div-by-zero) error type: +In your function plugin, in the static `aliases` property, add aliases for your function: -```javascript -// import `CellError` and `ErrorType` -import { FunctionPlugin, CellError, ErrorType } from 'hyperformula'; - -export class MyFunctionPlugin extends FunctionPlugin { - myFunctionMethod(ast, state) { - if (!ast.args.length) { - // create a `CellError` instance with an `ErrorType` of `DIV_BY_ZERO` - // with your custom error message (optional) - return new CellError(ErrorType.DIV_BY_ZERO, 'Sorry, cannot divide by zero!'); - } - - return this.runFunction(ast.args, state, this.metadata('HYPER'), () => 'Hyperformula'.length) - } -} +```js +MyCustomPlugin.aliases = { + // `=MY_ALIAS()` will work the same as `=MY_FUNCTION()` + 'MY_ALIAS': 'MY_FUNCTION' +}; ``` -The error displays as `#DIV/0` and gets translated appropriately. - -### Error localization - -Errors returned by methods such as `getCellValue` are wrapped in the [`DetailedCellError` type](../api/classes/detailedcellerror.md). +::: tip +For each alias of your function, define a translation, even if you want to support only one language. +```js -`DetailedCellError` localizes the error based on your [internationalization settings](localizing-functions.md). +MyCustomPlugin.translations = { + enGB: { + 'MY_FUNCTION': 'MY_FUNCTION', + 'MY_ALIAS': 'MY_ALIAS', + }, +}; +``` +::: diff --git a/docs/guide/localizing-functions.md b/docs/guide/localizing-functions.md index a20da5dfaf..7d9937e496 100644 --- a/docs/guide/localizing-functions.md +++ b/docs/guide/localizing-functions.md @@ -71,22 +71,8 @@ errors: { ## Localizing custom functions -You can translate your own [custom functions](custom-functions) into -different languages too. You need to define the translations and register the corresponding language pack after registering a plugin: - -```javascript -const translations = { - 'enGB': { - 'HYPER': 'HYPER' - }, - 'enUS': { - 'HYPER': 'HYPER' - }, - 'plPL': { - 'HYPER': 'HAJPER' - } -} -``` +Localization of custom functions is also supported. +[Custom functions guide](custom-functions.md#function-name-translations) describes, how to define the translations for your custom functions in multiple languages. ### List of supported languages | Language name | Language code | diff --git a/src/ArraySize.ts b/src/ArraySize.ts index 56d5472735..845ef75f43 100644 --- a/src/ArraySize.ts +++ b/src/ArraySize.ts @@ -8,7 +8,7 @@ import {SimpleCellAddress} from './Cell' import {Config} from './Config' import {FunctionRegistry} from './interpreter/FunctionRegistry' import {InterpreterState} from './interpreter/InterpreterState' -import {ArgumentTypes} from './interpreter/plugin/FunctionPlugin' +import {FunctionArgumentType} from './interpreter/plugin/FunctionPlugin' import {Ast, AstNodeType, ProcedureAst} from './parser' export class ArraySize { @@ -156,7 +156,7 @@ export class ArraySizePredictor { let maxWidth = 1 let maxHeight = 1 for (let i = 0; i < subChecks.length; i++) { - if (argumentDefinitions[i].argumentType !== ArgumentTypes.RANGE && argumentDefinitions[i].argumentType !== ArgumentTypes.ANY) { + if (argumentDefinitions[i].argumentType !== FunctionArgumentType.RANGE && argumentDefinitions[i].argumentType !== FunctionArgumentType.ANY) { maxHeight = Math.max(maxHeight, subChecks[i].height) maxWidth = Math.max(maxWidth, subChecks[i].width) } diff --git a/src/ArrayValue.ts b/src/ArrayValue.ts index b87007c340..d42ff0c999 100644 --- a/src/ArrayValue.ts +++ b/src/ArrayValue.ts @@ -6,7 +6,7 @@ import {ArraySize} from './ArraySize' import {CellError} from './Cell' import {EmptyValue, InternalScalarValue, InterpreterValue} from './interpreter/InterpreterValue' -import {SimpleRangeValue} from './interpreter/SimpleRangeValue' +import {SimpleRangeValue} from './SimpleRangeValue' export interface IArray { size: ArraySize, diff --git a/src/Cell.ts b/src/Cell.ts index 1b572aa92e..e5dfdf214b 100644 --- a/src/Cell.ts +++ b/src/Cell.ts @@ -14,7 +14,7 @@ import { isExtendedNumber, NumberType, } from './interpreter/InterpreterValue' -import {SimpleRangeValue} from './interpreter/SimpleRangeValue' +import {SimpleRangeValue} from './SimpleRangeValue' import {Maybe} from './Maybe' import {CellAddress} from './parser' import {AddressWithSheet} from './parser/Address' diff --git a/src/ContentChanges.ts b/src/ContentChanges.ts index 3e3a46dfd1..d22cc9e092 100644 --- a/src/ContentChanges.ts +++ b/src/ContentChanges.ts @@ -5,7 +5,7 @@ import {addressKey, SimpleCellAddress} from './Cell' import {InterpreterValue} from './interpreter/InterpreterValue' -import {SimpleRangeValue} from './interpreter/SimpleRangeValue' +import {SimpleRangeValue} from './SimpleRangeValue' export interface CellValueChange { address: SimpleCellAddress, diff --git a/src/DependencyGraph/DependencyGraph.ts b/src/DependencyGraph/DependencyGraph.ts index 2f6c2e9aeb..fe19794996 100644 --- a/src/DependencyGraph/DependencyGraph.ts +++ b/src/DependencyGraph/DependencyGraph.ts @@ -20,7 +20,7 @@ import { InterpreterValue, RawScalarValue } from '../interpreter/InterpreterValue' -import {SimpleRangeValue} from '../interpreter/SimpleRangeValue' +import {SimpleRangeValue} from '../SimpleRangeValue' import {LazilyTransformingAstService} from '../LazilyTransformingAstService' import {Maybe} from '../Maybe' import {NamedExpressions} from '../NamedExpressions' diff --git a/src/Evaluator.ts b/src/Evaluator.ts index e6877ca572..650b6c3e45 100644 --- a/src/Evaluator.ts +++ b/src/Evaluator.ts @@ -13,7 +13,7 @@ import {FormulaVertex} from './DependencyGraph/FormulaCellVertex' import {Interpreter} from './interpreter/Interpreter' import {InterpreterState} from './interpreter/InterpreterState' import {EmptyValue, getRawValue, InterpreterValue} from './interpreter/InterpreterValue' -import {SimpleRangeValue} from './interpreter/SimpleRangeValue' +import {SimpleRangeValue} from './SimpleRangeValue' import {LazilyTransformingAstService} from './LazilyTransformingAstService' import {ColumnSearchStrategy} from './Lookup/SearchStrategy' import {Ast, RelativeDependency} from './parser' diff --git a/src/Exporter.ts b/src/Exporter.ts index 08ea03ebba..c4ab725f51 100644 --- a/src/Exporter.ts +++ b/src/Exporter.ts @@ -9,7 +9,7 @@ import {Config} from './Config' import {CellValueChange, ChangeExporter} from './ContentChanges' import {ErrorMessage} from './error-message' import {EmptyValue, getRawValue, InterpreterValue, isExtendedNumber} from './interpreter/InterpreterValue' -import {SimpleRangeValue} from './interpreter/SimpleRangeValue' +import {SimpleRangeValue} from './SimpleRangeValue' import {LazilyTransformingAstService} from './LazilyTransformingAstService' import {NamedExpressions} from './NamedExpressions' import {SheetIndexMappingFn, simpleCellAddressToString} from './parser/addressRepresentationConverters' diff --git a/src/Lookup/AdvancedFind.ts b/src/Lookup/AdvancedFind.ts index e42404da9f..fb85689503 100644 --- a/src/Lookup/AdvancedFind.ts +++ b/src/Lookup/AdvancedFind.ts @@ -10,7 +10,7 @@ import { RawInterpreterValue, RawNoErrorScalarValue } from '../interpreter/InterpreterValue' -import {SimpleRangeValue} from '../interpreter/SimpleRangeValue' +import {SimpleRangeValue} from '../SimpleRangeValue' import {SearchOptions} from './SearchStrategy' import {forceNormalizeString} from '../interpreter/ArithmeticHelper' import {findLastOccurrenceInOrderedRange} from '../interpreter/binarySearch' diff --git a/src/Lookup/ColumnBinarySearch.ts b/src/Lookup/ColumnBinarySearch.ts index 7e6b640856..3426445e52 100644 --- a/src/Lookup/ColumnBinarySearch.ts +++ b/src/Lookup/ColumnBinarySearch.ts @@ -7,7 +7,7 @@ import {SimpleCellAddress} from '../Cell' import {CellValueChange} from '../ContentChanges' import {DependencyGraph} from '../DependencyGraph' import {RawNoErrorScalarValue, RawScalarValue} from '../interpreter/InterpreterValue' -import {SimpleRangeValue} from '../interpreter/SimpleRangeValue' +import {SimpleRangeValue} from '../SimpleRangeValue' import {ColumnsSpan} from '../Span' import {AdvancedFind} from './AdvancedFind' import {ColumnSearchStrategy, SearchOptions} from './SearchStrategy' diff --git a/src/Lookup/ColumnIndex.ts b/src/Lookup/ColumnIndex.ts index da71080e93..e7cc65c298 100644 --- a/src/Lookup/ColumnIndex.ts +++ b/src/Lookup/ColumnIndex.ts @@ -18,7 +18,7 @@ import { RawNoErrorScalarValue, RawScalarValue } from '../interpreter/InterpreterValue' -import {SimpleRangeValue} from '../interpreter/SimpleRangeValue' +import {SimpleRangeValue} from '../SimpleRangeValue' import {LazilyTransformingAstService} from '../LazilyTransformingAstService' import {ColumnsSpan, RowsSpan} from '../Span' import {Statistics, StatType} from '../statistics' diff --git a/src/Lookup/RowSearchStrategy.ts b/src/Lookup/RowSearchStrategy.ts index 0a73c6d7b0..6b70c432ca 100644 --- a/src/Lookup/RowSearchStrategy.ts +++ b/src/Lookup/RowSearchStrategy.ts @@ -5,7 +5,7 @@ import {DependencyGraph} from '../DependencyGraph' import {RawNoErrorScalarValue} from '../interpreter/InterpreterValue' -import {SimpleRangeValue} from '../interpreter/SimpleRangeValue' +import {SimpleRangeValue} from '../SimpleRangeValue' import {AdvancedFind} from './AdvancedFind' import {SearchOptions, SearchStrategy} from './SearchStrategy' diff --git a/src/Lookup/SearchStrategy.ts b/src/Lookup/SearchStrategy.ts index 0672d6247d..d658d75584 100644 --- a/src/Lookup/SearchStrategy.ts +++ b/src/Lookup/SearchStrategy.ts @@ -8,7 +8,7 @@ import {Config} from '../Config' import {CellValueChange} from '../ContentChanges' import {DependencyGraph} from '../DependencyGraph' import {RawInterpreterValue, RawNoErrorScalarValue, RawScalarValue} from '../interpreter/InterpreterValue' -import {SimpleRangeValue} from '../interpreter/SimpleRangeValue' +import {SimpleRangeValue} from '../SimpleRangeValue' import {ColumnsSpan} from '../Span' import {Statistics} from '../statistics' import {ColumnBinarySearch} from './ColumnBinarySearch' diff --git a/src/interpreter/SimpleRangeValue.ts b/src/SimpleRangeValue.ts similarity index 94% rename from src/interpreter/SimpleRangeValue.ts rename to src/SimpleRangeValue.ts index c87651ee9a..62b2f6f6b1 100644 --- a/src/interpreter/SimpleRangeValue.ts +++ b/src/SimpleRangeValue.ts @@ -3,12 +3,13 @@ * Copyright (c) 2022 Handsoncode. All rights reserved. */ -import {AbsoluteCellRange} from '../AbsoluteCellRange' -import {ArraySize} from '../ArraySize' -import {CellError, ErrorType, simpleCellAddress, SimpleCellAddress} from '../Cell' -import {DependencyGraph} from '../DependencyGraph' -import {ErrorMessage} from '../error-message' -import {InternalScalarValue, isExtendedNumber} from './InterpreterValue' +import {AbsoluteCellRange} from './AbsoluteCellRange' +import {ArraySize} from './ArraySize' +import {CellError, ErrorType, simpleCellAddress, SimpleCellAddress} from './Cell' +import {DependencyGraph} from './DependencyGraph' +import {ErrorMessage} from './error-message' +import {InternalScalarValue, isExtendedNumber} from './interpreter/InterpreterValue' + export class SimpleRangeValue { public readonly size: ArraySize @@ -135,6 +136,7 @@ export class SimpleRangeValue { if (this._data !== undefined) { return } + this._hasOnlyNumbers = true this._data = this.range!.addressesArrayMap(this.dependencyGraph!, cellFromRange => { const value = this.dependencyGraph!.getCellValue(cellFromRange) @@ -148,6 +150,5 @@ export class SimpleRangeValue { return value as InternalScalarValue } }) - } } diff --git a/src/index.ts b/src/index.ts index 26e864ea65..ec48bc779c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ */ import {SimpleCellRange} from './AbsoluteCellRange' +import {ArraySize} from './ArraySize' import {CellError, CellType, CellValueDetailedType, CellValueType, ErrorType, SimpleCellAddress} from './Cell' import {RawCellContent} from './CellContentParser' import {CellValue, DetailedCellError, NoErrorCellValue} from './CellValue' @@ -47,15 +48,17 @@ import {ExportedCellChange, ExportedChange, ExportedNamedExpressionChange} from import {HyperFormula} from './HyperFormula' import {RawTranslationPackage} from './i18n' import enGB from './i18n/languages/enGB' -import {FunctionArgument, FunctionPlugin, FunctionPluginDefinition} from './interpreter' +import {FunctionArgument, FunctionPlugin, FunctionPluginDefinition, FunctionArgumentType, ImplementedFunctions, FunctionMetadata} from './interpreter' import {FormatInfo} from './interpreter/InterpreterValue' import * as plugins from './interpreter/plugin' -import {SimpleRangeValue} from './interpreter/SimpleRangeValue' +import {SimpleRangeValue} from './SimpleRangeValue' import {NamedExpression, NamedExpressionOptions} from './NamedExpressions' import {SerializedNamedExpression} from './Serialization' import {Sheet, SheetDimensions, Sheets} from './Sheet' -/** @internal */ +/** + * Aggregate class for default export + */ class HyperFormulaNS extends HyperFormula { public static HyperFormula = HyperFormula public static ErrorType = ErrorType @@ -70,7 +73,9 @@ class HyperFormulaNS extends HyperFormula { public static EvaluationSuspendedError = EvaluationSuspendedError public static ExpectedOneOfValuesError = ExpectedOneOfValuesError public static ExpectedValueOfTypeError = ExpectedValueOfTypeError + public static ArraySize = ArraySize public static FunctionPlugin = FunctionPlugin + public static FunctionArgumentType = FunctionArgumentType public static FunctionPluginValidationError = FunctionPluginValidationError public static InvalidAddressError = InvalidAddressError public static InvalidArgumentsError = InvalidArgumentsError @@ -145,7 +150,11 @@ export { EvaluationSuspendedError, ExpectedOneOfValuesError, ExpectedValueOfTypeError, + ArraySize, FunctionPlugin, + ImplementedFunctions, + FunctionMetadata, + FunctionArgumentType, FunctionPluginValidationError, InvalidAddressError, InvalidArgumentsError, diff --git a/src/interpreter/ArithmeticHelper.ts b/src/interpreter/ArithmeticHelper.ts index 6a447051bc..73afc4f7b6 100644 --- a/src/interpreter/ArithmeticHelper.ts +++ b/src/interpreter/ArithmeticHelper.ts @@ -33,7 +33,7 @@ import { RawScalarValue, TimeNumber } from './InterpreterValue' -import {SimpleRangeValue} from './SimpleRangeValue' +import {SimpleRangeValue} from '../SimpleRangeValue' import Collator = Intl.Collator export type complex = [number, number] diff --git a/src/interpreter/CriterionFunctionCompute.ts b/src/interpreter/CriterionFunctionCompute.ts index 02c147b9da..0a1fc449a7 100644 --- a/src/interpreter/CriterionFunctionCompute.ts +++ b/src/interpreter/CriterionFunctionCompute.ts @@ -12,7 +12,7 @@ import {Maybe} from '../Maybe' import {CriterionLambda, CriterionPackage} from './Criterion' import {Interpreter} from './Interpreter' import {getRawValue, InternalScalarValue, RawScalarValue} from './InterpreterValue' -import {SimpleRangeValue} from './SimpleRangeValue' +import {SimpleRangeValue} from '../SimpleRangeValue' const findSmallerRangeForMany = (dependencyGraph: DependencyGraph, conditionRanges: AbsoluteCellRange[], valuesRange: AbsoluteCellRange): { smallerRangeVertex?: RangeVertex, restConditionRanges: AbsoluteCellRange[], restValuesRange: AbsoluteCellRange } => { if (valuesRange.end.row > valuesRange.start.row) { diff --git a/src/interpreter/Interpreter.ts b/src/interpreter/Interpreter.ts index 5e8c323baa..dece0f3b47 100644 --- a/src/interpreter/Interpreter.ts +++ b/src/interpreter/Interpreter.ts @@ -39,7 +39,7 @@ import { InterpreterValue, isExtendedNumber, } from './InterpreterValue' -import {SimpleRangeValue} from './SimpleRangeValue' +import {SimpleRangeValue} from '../SimpleRangeValue' export class Interpreter { public readonly criterionBuilder: CriterionBuilder diff --git a/src/interpreter/InterpreterValue.ts b/src/interpreter/InterpreterValue.ts index adc53c2c29..d419e09b10 100644 --- a/src/interpreter/InterpreterValue.ts +++ b/src/interpreter/InterpreterValue.ts @@ -4,7 +4,7 @@ */ import {CellError} from '../Cell' -import {SimpleRangeValue} from './SimpleRangeValue' +import {SimpleRangeValue} from '../SimpleRangeValue' export const EmptyValue = Symbol('Empty value') export type EmptyValueType = typeof EmptyValue diff --git a/src/interpreter/index.ts b/src/interpreter/index.ts index ec9d0c108e..f6751d2a46 100644 --- a/src/interpreter/index.ts +++ b/src/interpreter/index.ts @@ -9,7 +9,8 @@ import { FunctionMetadata, FunctionPlugin, FunctionPluginDefinition, - ImplementedFunctions + ImplementedFunctions, + FunctionArgumentType, } from './plugin/FunctionPlugin' export { @@ -18,5 +19,6 @@ export { FunctionPlugin, ImplementedFunctions, FunctionMetadata, - FunctionTranslationsPackage + FunctionTranslationsPackage, + FunctionArgumentType, } diff --git a/src/interpreter/plugin/AbsPlugin.ts b/src/interpreter/plugin/AbsPlugin.ts index 18a2526a1d..4a711adad7 100644 --- a/src/interpreter/plugin/AbsPlugin.ts +++ b/src/interpreter/plugin/AbsPlugin.ts @@ -6,14 +6,14 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class AbsPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'ABS': { method: 'abs', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, } diff --git a/src/interpreter/plugin/ArrayPlugin.ts b/src/interpreter/plugin/ArrayPlugin.ts index 708093655d..48261c710a 100644 --- a/src/interpreter/plugin/ArrayPlugin.ts +++ b/src/interpreter/plugin/ArrayPlugin.ts @@ -10,8 +10,8 @@ import {AstNodeType, ProcedureAst} from '../../parser' import {coerceScalarToBoolean} from '../ArithmeticHelper' import {InterpreterState} from '../InterpreterState' import {InternalScalarValue, InterpreterValue} from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {SimpleRangeValue} from '../../SimpleRangeValue' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class ArrayPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { @@ -20,16 +20,16 @@ export class ArrayPlugin extends FunctionPlugin implements FunctionPluginTypeche arraySizeMethod: 'arrayformulaArraySize', arrayFunction: true, parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], }, 'ARRAY_CONSTRAIN': { method: 'arrayconstrain', arraySizeMethod: 'arrayconstrainArraySize', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.INTEGER, minValue: 1}, - {argumentType: ArgumentTypes.INTEGER, minValue: 1}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 1}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 1}, ], vectorizationForbidden: true, }, @@ -38,8 +38,8 @@ export class ArrayPlugin extends FunctionPlugin implements FunctionPluginTypeche arraySizeMethod: 'filterArraySize', arrayFunction: true, parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], repeatLastArgs: 1, } @@ -101,9 +101,11 @@ export class ArrayPlugin extends FunctionPlugin implements FunctionPluginTypeche return new CellError(ErrorType.NA, ErrorMessage.EqualLength) } } + if (rangeVals.width() > 1 && rangeVals.height() > 1) { return new CellError(ErrorType.NA, ErrorMessage.WrongDimension) } + const vals = rangeVals.data const ret = [] for (let i = 0; i < rangeVals.height(); i++) { diff --git a/src/interpreter/plugin/BitShiftPlugin.ts b/src/interpreter/plugin/BitShiftPlugin.ts index bdfd140e14..b4a9a32c68 100644 --- a/src/interpreter/plugin/BitShiftPlugin.ts +++ b/src/interpreter/plugin/BitShiftPlugin.ts @@ -8,7 +8,7 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' const MAX_48BIT_INTEGER = 281474976710655 const SHIFT_MIN_POSITIONS = -53 @@ -19,15 +19,15 @@ export class BitShiftPlugin extends FunctionPlugin implements FunctionPluginType 'BITLSHIFT': { method: 'bitlshift', parameters: [ - {argumentType: ArgumentTypes.INTEGER, minValue: 0}, - {argumentType: ArgumentTypes.INTEGER, minValue: SHIFT_MIN_POSITIONS, maxValue: SHIFT_MAX_POSITIONS}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: SHIFT_MIN_POSITIONS, maxValue: SHIFT_MAX_POSITIONS}, ] }, 'BITRSHIFT': { method: 'bitrshift', parameters: [ - {argumentType: ArgumentTypes.INTEGER, minValue: 0}, - {argumentType: ArgumentTypes.INTEGER, minValue: SHIFT_MIN_POSITIONS, maxValue: SHIFT_MAX_POSITIONS}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: SHIFT_MIN_POSITIONS, maxValue: SHIFT_MAX_POSITIONS}, ] }, } diff --git a/src/interpreter/plugin/BitwiseLogicOperationsPlugin.ts b/src/interpreter/plugin/BitwiseLogicOperationsPlugin.ts index 218d9743f7..dd2396b4f3 100644 --- a/src/interpreter/plugin/BitwiseLogicOperationsPlugin.ts +++ b/src/interpreter/plugin/BitwiseLogicOperationsPlugin.ts @@ -6,29 +6,29 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class BitwiseLogicOperationsPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'BITAND': { method: 'bitand', parameters: [ - {argumentType: ArgumentTypes.INTEGER, minValue: 0}, - {argumentType: ArgumentTypes.INTEGER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0}, ] }, 'BITOR': { method: 'bitor', parameters: [ - {argumentType: ArgumentTypes.INTEGER, minValue: 0}, - {argumentType: ArgumentTypes.INTEGER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0}, ] }, 'BITXOR': { method: 'bitxor', parameters: [ - {argumentType: ArgumentTypes.INTEGER, minValue: 0}, - {argumentType: ArgumentTypes.INTEGER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0}, ] }, } diff --git a/src/interpreter/plugin/BooleanPlugin.ts b/src/interpreter/plugin/BooleanPlugin.ts index 837b9a84c1..e20a4374fe 100644 --- a/src/interpreter/plugin/BooleanPlugin.ts +++ b/src/interpreter/plugin/BooleanPlugin.ts @@ -8,7 +8,7 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InternalNoErrorScalarValue, InternalScalarValue, InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' /** * Interpreter plugin containing boolean functions @@ -26,15 +26,15 @@ export class BooleanPlugin extends FunctionPlugin implements FunctionPluginTypec 'IF': { method: 'conditionalIf', parameters: [ - {argumentType: ArgumentTypes.BOOLEAN}, - {argumentType: ArgumentTypes.SCALAR, passSubtype: true}, - {argumentType: ArgumentTypes.SCALAR, defaultValue: false, passSubtype: true}, + {argumentType: FunctionArgumentType.BOOLEAN}, + {argumentType: FunctionArgumentType.SCALAR, passSubtype: true}, + {argumentType: FunctionArgumentType.SCALAR, defaultValue: false, passSubtype: true}, ], }, 'AND': { method: 'and', parameters: [ - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.BOOLEAN}, ], repeatLastArgs: 1, expandRanges: true, @@ -42,7 +42,7 @@ export class BooleanPlugin extends FunctionPlugin implements FunctionPluginTypec 'OR': { method: 'or', parameters: [ - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.BOOLEAN}, ], repeatLastArgs: 1, expandRanges: true, @@ -50,7 +50,7 @@ export class BooleanPlugin extends FunctionPlugin implements FunctionPluginTypec 'XOR': { method: 'xor', parameters: [ - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.BOOLEAN}, ], repeatLastArgs: 1, expandRanges: true, @@ -58,37 +58,37 @@ export class BooleanPlugin extends FunctionPlugin implements FunctionPluginTypec 'NOT': { method: 'not', parameters: [ - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'SWITCH': { method: 'switch', parameters: [ - {argumentType: ArgumentTypes.NOERROR}, - {argumentType: ArgumentTypes.SCALAR, passSubtype: true}, - {argumentType: ArgumentTypes.SCALAR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR}, + {argumentType: FunctionArgumentType.SCALAR, passSubtype: true}, + {argumentType: FunctionArgumentType.SCALAR, passSubtype: true}, ], repeatLastArgs: 1, }, 'IFERROR': { method: 'iferror', parameters: [ - {argumentType: ArgumentTypes.SCALAR, passSubtype: true}, - {argumentType: ArgumentTypes.SCALAR, passSubtype: true}, + {argumentType: FunctionArgumentType.SCALAR, passSubtype: true}, + {argumentType: FunctionArgumentType.SCALAR, passSubtype: true}, ] }, 'IFNA': { method: 'ifna', parameters: [ - {argumentType: ArgumentTypes.SCALAR, passSubtype: true}, - {argumentType: ArgumentTypes.SCALAR, passSubtype: true}, + {argumentType: FunctionArgumentType.SCALAR, passSubtype: true}, + {argumentType: FunctionArgumentType.SCALAR, passSubtype: true}, ] }, 'CHOOSE': { method: 'choose', parameters: [ - {argumentType: ArgumentTypes.INTEGER, minValue: 1}, - {argumentType: ArgumentTypes.SCALAR, passSubtype: true}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 1}, + {argumentType: FunctionArgumentType.SCALAR, passSubtype: true}, ], repeatLastArgs: 1, }, diff --git a/src/interpreter/plugin/CharPlugin.ts b/src/interpreter/plugin/CharPlugin.ts index da29d15635..777c914a13 100644 --- a/src/interpreter/plugin/CharPlugin.ts +++ b/src/interpreter/plugin/CharPlugin.ts @@ -8,20 +8,20 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class CharPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'CHAR': { method: 'char', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ], }, 'UNICHAR': { method: 'unichar', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ], }, } diff --git a/src/interpreter/plugin/CodePlugin.ts b/src/interpreter/plugin/CodePlugin.ts index f99060ec1c..b1164490a7 100644 --- a/src/interpreter/plugin/CodePlugin.ts +++ b/src/interpreter/plugin/CodePlugin.ts @@ -8,20 +8,20 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class CodePlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'CODE': { method: 'code', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ] }, 'UNICODE': { method: 'unicode', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ] }, } diff --git a/src/interpreter/plugin/ComplexPlugin.ts b/src/interpreter/plugin/ComplexPlugin.ts index 57de25a381..f21077b3ca 100644 --- a/src/interpreter/plugin/ComplexPlugin.ts +++ b/src/interpreter/plugin/ComplexPlugin.ts @@ -9,171 +9,171 @@ import {ProcedureAst} from '../../parser' import {coerceComplexToString, complex} from '../ArithmeticHelper' import {InterpreterState} from '../InterpreterState' import {InterpreterValue, RawInterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class ComplexPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'COMPLEX': { method: 'complex', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.STRING, defaultValue: 'i'}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.STRING, defaultValue: 'i'}, ], }, 'IMABS': { method: 'imabs', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMAGINARY': { method: 'imaginary', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMREAL': { method: 'imreal', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMARGUMENT': { method: 'imargument', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMCONJUGATE': { method: 'imconjugate', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMCOS': { method: 'imcos', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMCOSH': { method: 'imcosh', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMCOT': { method: 'imcot', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMCSC': { method: 'imcsc', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMCSCH': { method: 'imcsch', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMSEC': { method: 'imsec', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMSECH': { method: 'imsech', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMSIN': { method: 'imsin', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMSINH': { method: 'imsinh', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMTAN': { method: 'imtan', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMDIV': { method: 'imdiv', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMPRODUCT': { method: 'improduct', parameters: [ - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1, }, 'IMSUM': { method: 'imsum', parameters: [ - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1, }, 'IMSUB': { method: 'imsub', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMEXP': { method: 'imexp', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMLN': { method: 'imln', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMLOG10': { method: 'imlog10', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMLOG2': { method: 'imlog2', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, 'IMPOWER': { method: 'impower', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.COMPLEX}, + {argumentType: FunctionArgumentType.NUMBER}, ], }, 'IMSQRT': { method: 'imsqrt', parameters: [ - {argumentType: ArgumentTypes.COMPLEX}, + {argumentType: FunctionArgumentType.COMPLEX}, ], }, } diff --git a/src/interpreter/plugin/ConditionalAggregationPlugin.ts b/src/interpreter/plugin/ConditionalAggregationPlugin.ts index abe5fbf494..3133c04fcd 100644 --- a/src/interpreter/plugin/ConditionalAggregationPlugin.ts +++ b/src/interpreter/plugin/ConditionalAggregationPlugin.ts @@ -17,8 +17,8 @@ import { RawInterpreterValue, RawScalarValue } from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {SimpleRangeValue} from '../../SimpleRangeValue' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' class AverageResult { public static empty = new AverageResult(0, 0) @@ -79,58 +79,58 @@ export class ConditionalAggregationPlugin extends FunctionPlugin implements Func SUMIF: { method: 'sumif', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NOERROR}, - {argumentType: ArgumentTypes.RANGE, optionalArg: true}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NOERROR}, + {argumentType: FunctionArgumentType.RANGE, optionalArg: true}, ], }, COUNTIF: { method: 'countif', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NOERROR}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NOERROR}, ], }, AVERAGEIF: { method: 'averageif', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NOERROR}, - {argumentType: ArgumentTypes.RANGE, optionalArg: true}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NOERROR}, + {argumentType: FunctionArgumentType.RANGE, optionalArg: true}, ], }, SUMIFS: { method: 'sumifs', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NOERROR}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NOERROR}, ], repeatLastArgs: 2, }, COUNTIFS: { method: 'countifs', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NOERROR}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NOERROR}, ], repeatLastArgs: 2, }, MINIFS: { method: 'minifs', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NOERROR}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NOERROR}, ], repeatLastArgs: 2, }, MAXIFS: { method: 'maxifs', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NOERROR}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NOERROR}, ], repeatLastArgs: 2, }, diff --git a/src/interpreter/plugin/CountBlankPlugin.ts b/src/interpreter/plugin/CountBlankPlugin.ts index f58ab7009f..228b9fe574 100644 --- a/src/interpreter/plugin/CountBlankPlugin.ts +++ b/src/interpreter/plugin/CountBlankPlugin.ts @@ -6,7 +6,7 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {EmptyValue, InterpreterValue, RawScalarValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' /** * Interpreter plugin containing MEDIAN function @@ -17,7 +17,7 @@ export class CountBlankPlugin extends FunctionPlugin implements FunctionPluginTy 'COUNTBLANK': { method: 'countblank', parameters: [ - {argumentType: ArgumentTypes.SCALAR} + {argumentType: FunctionArgumentType.SCALAR} ], repeatLastArgs: 1, expandRanges: true, diff --git a/src/interpreter/plugin/CountUniquePlugin.ts b/src/interpreter/plugin/CountUniquePlugin.ts index cde296bbd8..4542f56055 100644 --- a/src/interpreter/plugin/CountUniquePlugin.ts +++ b/src/interpreter/plugin/CountUniquePlugin.ts @@ -7,7 +7,7 @@ import {CellError, ErrorType} from '../../Cell' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {EmptyValueType, InterpreterValue, RawScalarValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' /** * Interpreter plugin containing COUNTUNIQUE function @@ -17,7 +17,7 @@ export class CountUniquePlugin extends FunctionPlugin implements FunctionPluginT 'COUNTUNIQUE': { method: 'countunique', parameters: [ - {argumentType: ArgumentTypes.SCALAR}, + {argumentType: FunctionArgumentType.SCALAR}, ], repeatLastArgs: 1, expandRanges: true, diff --git a/src/interpreter/plugin/DateTimePlugin.ts b/src/interpreter/plugin/DateTimePlugin.ts index f199d55647..9ba18003e3 100644 --- a/src/interpreter/plugin/DateTimePlugin.ts +++ b/src/interpreter/plugin/DateTimePlugin.ts @@ -30,8 +30,8 @@ import { RawNoErrorScalarValue, RawScalarValue, } from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {SimpleRangeValue} from '../../SimpleRangeValue' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' /** * Interpreter plugin containing date-specific functions @@ -41,110 +41,110 @@ export class DateTimePlugin extends FunctionPlugin implements FunctionPluginType 'DATE': { method: 'date', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], returnNumberType: NumberType.NUMBER_DATE }, 'TIME': { method: 'time', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], returnNumberType: NumberType.NUMBER_TIME }, 'MONTH': { method: 'month', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'YEAR': { method: 'year', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'HOUR': { method: 'hour', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'MINUTE': { method: 'minute', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'SECOND': { method: 'second', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'TEXT': { method: 'text', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.STRING}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.STRING}, ] }, 'EOMONTH': { method: 'eomonth', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, ], returnNumberType: NumberType.NUMBER_DATE }, 'DAY': { method: 'day', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'DAYS': { method: 'days', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'WEEKDAY': { method: 'weekday', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, ] }, 'WEEKNUM': { method: 'weeknum', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, ] }, 'ISOWEEKNUM': { method: 'isoweeknum', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'DATEVALUE': { method: 'datevalue', parameters: [ - {argumentType: ArgumentTypes.STRING}, + {argumentType: FunctionArgumentType.STRING}, ], returnNumberType: NumberType.NUMBER_DATE }, 'TIMEVALUE': { method: 'timevalue', parameters: [ - {argumentType: ArgumentTypes.STRING}, + {argumentType: FunctionArgumentType.STRING}, ], returnNumberType: NumberType.NUMBER_TIME }, @@ -163,73 +163,73 @@ export class DateTimePlugin extends FunctionPlugin implements FunctionPluginType 'EDATE': { method: 'edate', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, ], returnNumberType: NumberType.NUMBER_DATE }, 'DAYS360': { method: 'days360', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.BOOLEAN, defaultValue: false}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.BOOLEAN, defaultValue: false}, ], }, 'DATEDIF': { method: 'datedif', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.STRING}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.STRING}, ], }, 'YEARFRAC': { method: 'yearfrac', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.INTEGER, defaultValue: 0, minValue: 0, maxValue: 4}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, defaultValue: 0, minValue: 0, maxValue: 4}, ], }, 'INTERVAL': { method: 'interval', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ], }, 'NETWORKDAYS': { method: 'networkdays', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.RANGE, optionalArg: true} + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.RANGE, optionalArg: true} ], }, 'NETWORKDAYS.INTL': { method: 'networkdaysintl', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NOERROR, defaultValue: 1}, - {argumentType: ArgumentTypes.RANGE, optionalArg: true} + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NOERROR, defaultValue: 1}, + {argumentType: FunctionArgumentType.RANGE, optionalArg: true} ], }, 'WORKDAY': { method: 'workday', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.RANGE, optionalArg: true} + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.RANGE, optionalArg: true} ], }, 'WORKDAY.INTL': { method: 'workdayintl', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NOERROR, defaultValue: 1}, - {argumentType: ArgumentTypes.RANGE, optionalArg: true} + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NOERROR, defaultValue: 1}, + {argumentType: FunctionArgumentType.RANGE, optionalArg: true} ], }, } diff --git a/src/interpreter/plugin/DegreesPlugin.ts b/src/interpreter/plugin/DegreesPlugin.ts index a359c4c47c..d9b01c1359 100644 --- a/src/interpreter/plugin/DegreesPlugin.ts +++ b/src/interpreter/plugin/DegreesPlugin.ts @@ -6,14 +6,14 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class DegreesPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'DEGREES': { method: 'degrees', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, } diff --git a/src/interpreter/plugin/DeltaPlugin.ts b/src/interpreter/plugin/DeltaPlugin.ts index 9ab1c30a85..55647913b4 100644 --- a/src/interpreter/plugin/DeltaPlugin.ts +++ b/src/interpreter/plugin/DeltaPlugin.ts @@ -6,15 +6,15 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class DeltaPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'DELTA': { method: 'delta', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ] }, } diff --git a/src/interpreter/plugin/ExpPlugin.ts b/src/interpreter/plugin/ExpPlugin.ts index c4b7821f64..53603848a2 100644 --- a/src/interpreter/plugin/ExpPlugin.ts +++ b/src/interpreter/plugin/ExpPlugin.ts @@ -6,14 +6,14 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class ExpPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'EXP': { method: 'exp', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ], }, } diff --git a/src/interpreter/plugin/FinancialPlugin.ts b/src/interpreter/plugin/FinancialPlugin.ts index 7923e16818..68bf11a722 100644 --- a/src/interpreter/plugin/FinancialPlugin.ts +++ b/src/interpreter/plugin/FinancialPlugin.ts @@ -15,243 +15,243 @@ import { NumberType, RawInterpreterValue } from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {SimpleRangeValue} from '../../SimpleRangeValue' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class FinancialPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'PMT': { method: 'pmt', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'IPMT': { method: 'ipmt', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'PPMT': { method: 'ppmt', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'FV': { method: 'fv', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'CUMIPMT': { method: 'cumipmt', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.INTEGER, minValue: 1}, - {argumentType: ArgumentTypes.INTEGER, minValue: 1}, - {argumentType: ArgumentTypes.INTEGER, minValue: 0, maxValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 1}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 1}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0, maxValue: 1}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'CUMPRINC': { method: 'cumprinc', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.INTEGER, minValue: 1}, - {argumentType: ArgumentTypes.INTEGER, minValue: 1}, - {argumentType: ArgumentTypes.INTEGER, minValue: 0, maxValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 1}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 1}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0, maxValue: 1}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'DB': { method: 'db', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.INTEGER, minValue: 0}, - {argumentType: ArgumentTypes.INTEGER, minValue: 0}, - {argumentType: ArgumentTypes.INTEGER, minValue: 1, maxValue: 12, defaultValue: 12}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 1, maxValue: 12, defaultValue: 12}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'DDB': { method: 'ddb', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.INTEGER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0, defaultValue: 2}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0, defaultValue: 2}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'DOLLARDE': { method: 'dollarde', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ], }, 'DOLLARFR': { method: 'dollarfr', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ], }, 'EFFECT': { method: 'effect', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ], returnNumberType: NumberType.NUMBER_PERCENT }, 'ISPMT': { method: 'ispmt', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], }, 'NOMINAL': { method: 'nominal', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ], returnNumberType: NumberType.NUMBER_PERCENT }, 'NPER': { method: 'nper', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ], }, 'PV': { method: 'pv', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'RATE': { method: 'rate', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0.1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0.1}, ], returnNumberType: NumberType.NUMBER_PERCENT }, 'RRI': { method: 'rri', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], returnNumberType: NumberType.NUMBER_PERCENT }, 'SLN': { method: 'sln', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'SYD': { method: 'syd', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'TBILLEQ': { method: 'tbilleq', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, ], returnNumberType: NumberType.NUMBER_PERCENT }, 'TBILLPRICE': { method: 'tbillprice', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'TBILLYIELD': { method: 'tbillyield', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, ], returnNumberType: NumberType.NUMBER_PERCENT }, 'FVSCHEDULE': { method: 'fvschedule', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.RANGE}, ], returnNumberType: NumberType.NUMBER_CURRENCY }, 'NPV': { method: 'npv', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1, returnNumberType: NumberType.NUMBER_CURRENCY @@ -259,26 +259,26 @@ export class FinancialPlugin extends FunctionPlugin implements FunctionPluginTyp 'MIRR': { method: 'mirr', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], returnNumberType: NumberType.NUMBER_PERCENT }, 'PDURATION': { method: 'pduration', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, ], }, 'XNPV': { method: 'xnpv', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: -1}, - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: -1}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, } diff --git a/src/interpreter/plugin/FormulaTextPlugin.ts b/src/interpreter/plugin/FormulaTextPlugin.ts index 4dc49f1deb..e5e6fef42e 100644 --- a/src/interpreter/plugin/FormulaTextPlugin.ts +++ b/src/interpreter/plugin/FormulaTextPlugin.ts @@ -9,14 +9,14 @@ import {ProcedureAst} from '../../parser' import {FunctionPlugin} from '../index' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPluginTypecheck} from './FunctionPlugin' export class FormulaTextPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'FORMULATEXT': { method: 'formulatext', parameters: [ - {argumentType: ArgumentTypes.NOERROR} + {argumentType: FunctionArgumentType.NOERROR} ], doesNotNeedArgumentsToBeComputed: true, isDependentOnSheetStructureChange: true, diff --git a/src/interpreter/plugin/FunctionPlugin.ts b/src/interpreter/plugin/FunctionPlugin.ts index fa00d74109..5e76abe586 100644 --- a/src/interpreter/plugin/FunctionPlugin.ts +++ b/src/interpreter/plugin/FunctionPlugin.ts @@ -35,7 +35,7 @@ import { RawNoErrorScalarValue, RawScalarValue } from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' +import {SimpleRangeValue} from '../../SimpleRangeValue' export interface ImplementedFunctions { [formulaId: string]: FunctionMetadata, @@ -67,20 +67,24 @@ export interface FunctionMetadata { * Return number value is packed into this subtype. */ returnNumberType?: NumberType, + /** * Engine. */ method: string, + /** * Engine. */ arraySizeMethod?: string, + /** * Engine. * * If set to `true`, the function is volatile. */ isVolatile?: boolean, + /** * Engine. * @@ -88,6 +92,7 @@ export interface FunctionMetadata { * (e.g. when adding/removing rows or columns). */ isDependentOnSheetStructureChange?: boolean, + /** * Engine. * @@ -96,6 +101,7 @@ export interface FunctionMetadata { * Other arguments are properly evaluated. */ doesNotNeedArgumentsToBeComputed?: boolean, + /** * Engine. * @@ -120,7 +126,7 @@ export interface FunctionPluginDefinition { new(interpreter: Interpreter): FunctionPlugin, } -export enum ArgumentTypes { +export enum FunctionArgumentType { /** * String type. @@ -169,7 +175,7 @@ export enum ArgumentTypes { } export interface FunctionArgument { - argumentType: ArgumentTypes, + argumentType: FunctionArgumentType, /** * If set to `true`, arguments need to be passed with full type information. @@ -279,8 +285,8 @@ export abstract class FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'ISEVEN': { method: 'iseven', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, } diff --git a/src/interpreter/plugin/IsOddPlugin.ts b/src/interpreter/plugin/IsOddPlugin.ts index f68be6546d..acb5ed786c 100644 --- a/src/interpreter/plugin/IsOddPlugin.ts +++ b/src/interpreter/plugin/IsOddPlugin.ts @@ -6,14 +6,14 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class IsOddPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'ISODD': { method: 'isodd', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, } diff --git a/src/interpreter/plugin/LogarithmPlugin.ts b/src/interpreter/plugin/LogarithmPlugin.ts index f608b03585..9e03e948f5 100644 --- a/src/interpreter/plugin/LogarithmPlugin.ts +++ b/src/interpreter/plugin/LogarithmPlugin.ts @@ -6,7 +6,7 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class LogarithmPlugin extends FunctionPlugin implements FunctionPluginTypecheck { @@ -14,20 +14,20 @@ export class LogarithmPlugin extends FunctionPlugin implements FunctionPluginTyp 'LOG10': { method: 'log10', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'LOG': { method: 'log', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 10, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 10, greaterThan: 0}, ] }, 'LN': { method: 'ln', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, } diff --git a/src/interpreter/plugin/LookupPlugin.ts b/src/interpreter/plugin/LookupPlugin.ts index 6366ecac8a..2c61e2d7d1 100644 --- a/src/interpreter/plugin/LookupPlugin.ts +++ b/src/interpreter/plugin/LookupPlugin.ts @@ -13,35 +13,35 @@ import {StatType} from '../../statistics' import {zeroIfEmpty} from '../ArithmeticHelper' import {InterpreterState} from '../InterpreterState' import {InternalScalarValue, InterpreterValue, RawNoErrorScalarValue} from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {SimpleRangeValue} from '../../SimpleRangeValue' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class LookupPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'VLOOKUP': { method: 'vlookup', parameters: [ - {argumentType: ArgumentTypes.NOERROR}, - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.BOOLEAN, defaultValue: true}, + {argumentType: FunctionArgumentType.NOERROR}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.BOOLEAN, defaultValue: true}, ] }, 'HLOOKUP': { method: 'hlookup', parameters: [ - {argumentType: ArgumentTypes.NOERROR}, - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.BOOLEAN, defaultValue: true}, + {argumentType: FunctionArgumentType.NOERROR}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.BOOLEAN, defaultValue: true}, ] }, 'MATCH': { method: 'match', parameters: [ - {argumentType: ArgumentTypes.NOERROR}, - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.NOERROR}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, ] }, } diff --git a/src/interpreter/plugin/MathConstantsPlugin.ts b/src/interpreter/plugin/MathConstantsPlugin.ts index f80d20169d..beb3788633 100644 --- a/src/interpreter/plugin/MathConstantsPlugin.ts +++ b/src/interpreter/plugin/MathConstantsPlugin.ts @@ -6,7 +6,7 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export const PI = parseFloat(Math.PI.toFixed(14)) @@ -19,7 +19,7 @@ export class MathConstantsPlugin extends FunctionPlugin implements FunctionPlugi 'SQRTPI': { method: 'sqrtpi', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0} + {argumentType: FunctionArgumentType.NUMBER, minValue: 0} ], }, } diff --git a/src/interpreter/plugin/MathPlugin.ts b/src/interpreter/plugin/MathPlugin.ts index f6e079c084..c285fdc6c9 100644 --- a/src/interpreter/plugin/MathPlugin.ts +++ b/src/interpreter/plugin/MathPlugin.ts @@ -8,62 +8,62 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue, RawInterpreterValue} from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {SimpleRangeValue} from '../../SimpleRangeValue' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class MathPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'FACT': { method: 'fact', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0, maxValue: 170} + {argumentType: FunctionArgumentType.NUMBER, minValue: 0, maxValue: 170} ] }, 'FACTDOUBLE': { method: 'factdouble', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0, maxValue: 288} + {argumentType: FunctionArgumentType.NUMBER, minValue: 0, maxValue: 288} ] }, 'COMBIN': { method: 'combin', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0, lessThan: 1030}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0} + {argumentType: FunctionArgumentType.NUMBER, minValue: 0, lessThan: 1030}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0} ] }, 'COMBINA': { method: 'combina', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0} + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0} ] }, 'GCD': { method: 'gcd', parameters: [ - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1 }, 'LCM': { method: 'lcm', parameters: [ - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1 }, 'MROUND': { method: 'mround', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], }, 'MULTINOMIAL': { method: 'multinomial', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], repeatLastArgs: 1, expandRanges: true, @@ -71,44 +71,44 @@ export class MathPlugin extends FunctionPlugin implements FunctionPluginTypechec 'QUOTIENT': { method: 'quotient', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], }, 'SERIESSUM': { method: 'seriessum', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.RANGE}, ], }, 'SIGN': { method: 'sign', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], }, 'SUMX2MY2': { method: 'sumx2my2', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, 'SUMX2PY2': { method: 'sumx2py2', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, 'SUMXMY2': { method: 'sumxmy2', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, } diff --git a/src/interpreter/plugin/MatrixPlugin.ts b/src/interpreter/plugin/MatrixPlugin.ts index d6ee352a99..6fbaafa244 100644 --- a/src/interpreter/plugin/MatrixPlugin.ts +++ b/src/interpreter/plugin/MatrixPlugin.ts @@ -9,8 +9,8 @@ import {ErrorMessage} from '../../error-message' import {AstNodeType, ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InternalScalarValue, InterpreterValue} from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {SimpleRangeValue} from '../../SimpleRangeValue' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export type KernelRunShortcut = (...args: any[]) => number[][] @@ -43,8 +43,8 @@ export class MatrixPlugin extends FunctionPlugin implements FunctionPluginTypech method: 'mmult', arraySizeMethod: 'mmultArraySize', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], vectorizationForbidden: true, }, @@ -52,7 +52,7 @@ export class MatrixPlugin extends FunctionPlugin implements FunctionPluginTypech method: 'transpose', arraySizeMethod: 'transposeArraySize', parameters: [ - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], vectorizationForbidden: true, }, @@ -60,9 +60,9 @@ export class MatrixPlugin extends FunctionPlugin implements FunctionPluginTypech method: 'maxpool', arraySizeMethod: 'maxpoolArraySize', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true}, ], vectorizationForbidden: true, }, @@ -70,9 +70,9 @@ export class MatrixPlugin extends FunctionPlugin implements FunctionPluginTypech method: 'medianpool', arraySizeMethod: 'medianpoolArraySize', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true}, ], vectorizationForbidden: true, }, diff --git a/src/interpreter/plugin/MedianPlugin.ts b/src/interpreter/plugin/MedianPlugin.ts index 5a857677e8..3f09b53703 100644 --- a/src/interpreter/plugin/MedianPlugin.ts +++ b/src/interpreter/plugin/MedianPlugin.ts @@ -8,8 +8,8 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue, RawScalarValue} from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {SimpleRangeValue} from '../../SimpleRangeValue' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' /** * Interpreter plugin containing MEDIAN function @@ -20,22 +20,22 @@ export class MedianPlugin extends FunctionPlugin implements FunctionPluginTypech 'MEDIAN': { method: 'median', parameters: [ - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1, }, 'LARGE': { method: 'large', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ], }, 'SMALL': { method: 'small', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ], }, } diff --git a/src/interpreter/plugin/ModuloPlugin.ts b/src/interpreter/plugin/ModuloPlugin.ts index bf0dc2de26..0574237503 100644 --- a/src/interpreter/plugin/ModuloPlugin.ts +++ b/src/interpreter/plugin/ModuloPlugin.ts @@ -7,15 +7,15 @@ import {CellError, ErrorType} from '../../Cell' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class ModuloPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'MOD': { method: 'mod', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], }, } diff --git a/src/interpreter/plugin/NumericAggregationPlugin.ts b/src/interpreter/plugin/NumericAggregationPlugin.ts index 87937162e0..ae2dd1683c 100644 --- a/src/interpreter/plugin/NumericAggregationPlugin.ts +++ b/src/interpreter/plugin/NumericAggregationPlugin.ts @@ -13,8 +13,8 @@ import {ColumnRangeAst, RowRangeAst} from '../../parser/Ast' import {coerceBooleanToNumber} from '../ArithmeticHelper' import {InterpreterState} from '../InterpreterState' import {EmptyValue, ExtendedNumber, getRawValue, InternalScalarValue, isExtendedNumber} from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {SimpleRangeValue} from '../../SimpleRangeValue' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' import {RangeVertex} from '../../DependencyGraph' export type BinaryOperation = (left: T, right: T) => T @@ -80,141 +80,141 @@ export class NumericAggregationPlugin extends FunctionPlugin implements Function 'SUM': { method: 'sum', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'SUMSQ': { method: 'sumsq', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'MAX': { method: 'max', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'MIN': { method: 'min', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'MAXA': { method: 'maxa', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'MINA': { method: 'mina', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'COUNT': { method: 'count', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'COUNTA': { method: 'counta', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'AVERAGE': { method: 'average', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'AVERAGEA': { method: 'averagea', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'PRODUCT': { method: 'product', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'VAR.S': { method: 'vars', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'VAR.P': { method: 'varp', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'VARA': { method: 'vara', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'VARPA': { method: 'varpa', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'STDEV.S': { method: 'stdevs', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'STDEV.P': { method: 'stdevp', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'STDEVA': { method: 'stdeva', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'STDEVPA': { method: 'stdevpa', parameters: [ - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, }, 'SUBTOTAL': { method: 'subtotal', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.ANY} + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.ANY} ], repeatLastArgs: 1, } @@ -377,7 +377,7 @@ export class NumericAggregationPlugin extends FunctionPlugin implements Function if (ast.args.length < 2) { return new CellError(ErrorType.NA, ErrorMessage.WrongArgNumber) } - const functionType = this.coerceToType(this.evaluateAst(ast.args[0], state), {argumentType: ArgumentTypes.NUMBER}, state) + const functionType = this.coerceToType(this.evaluateAst(ast.args[0], state), {argumentType: FunctionArgumentType.NUMBER}, state) const args = ast.args.slice(1) switch (functionType) { case 1: @@ -552,6 +552,7 @@ export class NumericAggregationPlugin extends FunctionPlugin implements Function if (acc instanceof CellError) { return acc } + if (arg.type === AstNodeType.CELL_RANGE || arg.type === AstNodeType.COLUMN_RANGE || arg.type === AstNodeType.ROW_RANGE) { const val = this.evaluateRange(arg, state, initialAccValue, functionName, reducingFunction, mapFunction, coercionFunction) if (val instanceof CellError) { @@ -559,6 +560,7 @@ export class NumericAggregationPlugin extends FunctionPlugin implements Function } return reducingFunction(val, acc) } + let value value = this.evaluateAst(arg, state) if (value instanceof SimpleRangeValue) { diff --git a/src/interpreter/plugin/PowerPlugin.ts b/src/interpreter/plugin/PowerPlugin.ts index 9a743d25f4..3149d428bc 100644 --- a/src/interpreter/plugin/PowerPlugin.ts +++ b/src/interpreter/plugin/PowerPlugin.ts @@ -6,15 +6,15 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class PowerPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'POWER': { method: 'power', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], }, } diff --git a/src/interpreter/plugin/RadiansPlugin.ts b/src/interpreter/plugin/RadiansPlugin.ts index 7a8365219b..66c3b64a43 100644 --- a/src/interpreter/plugin/RadiansPlugin.ts +++ b/src/interpreter/plugin/RadiansPlugin.ts @@ -6,14 +6,14 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class RadiansPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'RADIANS': { method: 'radians', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ], }, } diff --git a/src/interpreter/plugin/RadixConversionPlugin.ts b/src/interpreter/plugin/RadixConversionPlugin.ts index 9e92f54da3..b6950bcdcf 100644 --- a/src/interpreter/plugin/RadixConversionPlugin.ts +++ b/src/interpreter/plugin/RadixConversionPlugin.ts @@ -10,7 +10,7 @@ import {Maybe} from '../../Maybe' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' const MAX_LENGTH = 10 const DECIMAL_NUMBER_OF_BITS = 255 @@ -23,97 +23,97 @@ export class RadixConversionPlugin extends FunctionPlugin implements FunctionPlu 'DEC2BIN': { method: 'dec2bin', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true, minValue: 1, maxValue: 10}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true, minValue: 1, maxValue: 10}, ], }, 'DEC2OCT': { method: 'dec2oct', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true, minValue: 1, maxValue: 10}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true, minValue: 1, maxValue: 10}, ], }, 'DEC2HEX': { method: 'dec2hex', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true, minValue: 1, maxValue: 10}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true, minValue: 1, maxValue: 10}, ], }, 'BIN2DEC': { method: 'bin2dec', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ], }, 'BIN2OCT': { method: 'bin2oct', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, ], }, 'BIN2HEX': { method: 'bin2hex', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, ], }, 'OCT2DEC': { method: 'oct2dec', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ], }, 'OCT2BIN': { method: 'oct2bin', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, ], }, 'OCT2HEX': { method: 'oct2hex', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, ], }, 'HEX2DEC': { method: 'hex2dec', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ], }, 'HEX2BIN': { method: 'hex2bin', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, ], }, 'HEX2OCT': { method: 'hex2oct', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true, minValue: 0, maxValue: MAX_LENGTH}, ], }, 'DECIMAL': { method: 'decimal', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, minValue: MIN_BASE, maxValue: MAX_BASE}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, minValue: MIN_BASE, maxValue: MAX_BASE}, ], }, 'BASE': { method: 'base', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: MIN_BASE, maxValue: MAX_BASE}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true, minValue: 0, maxValue: DECIMAL_NUMBER_OF_BITS}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: MIN_BASE, maxValue: MAX_BASE}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true, minValue: 0, maxValue: DECIMAL_NUMBER_OF_BITS}, ], }, } diff --git a/src/interpreter/plugin/RandomPlugin.ts b/src/interpreter/plugin/RandomPlugin.ts index 12a89921f2..418c5ac518 100644 --- a/src/interpreter/plugin/RandomPlugin.ts +++ b/src/interpreter/plugin/RandomPlugin.ts @@ -8,7 +8,7 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class RandomPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { @@ -20,8 +20,8 @@ export class RandomPlugin extends FunctionPlugin implements FunctionPluginTypech 'RANDBETWEEN': { method: 'randbetween', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], isVolatile: true, }, diff --git a/src/interpreter/plugin/RomanPlugin.ts b/src/interpreter/plugin/RomanPlugin.ts index a1cf113679..87b0db2b40 100644 --- a/src/interpreter/plugin/RomanPlugin.ts +++ b/src/interpreter/plugin/RomanPlugin.ts @@ -8,21 +8,21 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {getRawValue, InterpreterValue, RawScalarValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class RomanPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'ROMAN': { method: 'roman', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 1, lessThan: 4000}, - {argumentType: ArgumentTypes.NOERROR, optionalArg: true, defaultValue: 0} + {argumentType: FunctionArgumentType.NUMBER, minValue: 1, lessThan: 4000}, + {argumentType: FunctionArgumentType.NOERROR, optionalArg: true, defaultValue: 0} ], }, 'ARABIC': { method: 'arabic', parameters: [ - {argumentType: ArgumentTypes.STRING}, + {argumentType: FunctionArgumentType.STRING}, ], }, } diff --git a/src/interpreter/plugin/RoundingPlugin.ts b/src/interpreter/plugin/RoundingPlugin.ts index 8ad9e0e5be..d2bafa093e 100644 --- a/src/interpreter/plugin/RoundingPlugin.ts +++ b/src/interpreter/plugin/RoundingPlugin.ts @@ -8,7 +8,7 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export function findNextOddNumber(arg: number): number { const ceiled = Math.ceil(arg) @@ -25,84 +25,84 @@ export class RoundingPlugin extends FunctionPlugin implements FunctionPluginType 'ROUNDUP': { method: 'roundup', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ], }, 'ROUNDDOWN': { method: 'rounddown', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ], }, 'ROUND': { method: 'round', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ], }, 'INT': { method: 'intFunc', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ], }, 'EVEN': { method: 'even', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ], }, 'ODD': { method: 'odd', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ], }, 'CEILING.MATH': { method: 'ceilingmath', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ], }, 'CEILING': { method: 'ceiling', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], }, 'CEILING.PRECISE': { method: 'ceilingprecise', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, ], }, 'FLOOR.MATH': { method: 'floormath', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, ], }, 'FLOOR': { method: 'floor', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ], }, 'FLOOR.PRECISE': { method: 'floorprecise', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, ], }, } diff --git a/src/interpreter/plugin/SimpleArithmertic.ts b/src/interpreter/plugin/SimpleArithmertic.ts index b10e3d182b..17c1ce16e5 100644 --- a/src/interpreter/plugin/SimpleArithmertic.ts +++ b/src/interpreter/plugin/SimpleArithmertic.ts @@ -6,110 +6,110 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class SimpleArithmerticPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'HF.ADD': { method: 'add', parameters: [ - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, ], }, 'HF.CONCAT': { method: 'concat', parameters: [ - {argumentType: ArgumentTypes.STRING, passSubtype: true}, - {argumentType: ArgumentTypes.STRING, passSubtype: true}, + {argumentType: FunctionArgumentType.STRING, passSubtype: true}, + {argumentType: FunctionArgumentType.STRING, passSubtype: true}, ], }, 'HF.DIVIDE': { method: 'divide', parameters: [ - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, ], }, 'HF.EQ': { method: 'eq', parameters: [ - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, ] }, 'HF.GT': { method: 'gt', parameters: [ - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, ] }, 'HF.GTE': { method: 'gte', parameters: [ - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, ] }, 'HF.LT': { method: 'lt', parameters: [ - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, ] }, 'HF.LTE': { method: 'lte', parameters: [ - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, ] }, 'HF.MINUS': { method: 'minus', parameters: [ - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, ], }, 'HF.MULTIPLY': { method: 'multiply', parameters: [ - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, ], }, 'HF.NE': { method: 'ne', parameters: [ - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, - {argumentType: ArgumentTypes.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, + {argumentType: FunctionArgumentType.NOERROR, passSubtype: true}, ] }, 'HF.POW': { method: 'pow', parameters: [ - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, ], }, 'HF.UMINUS': { method: 'uminus', parameters: [ - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, ], }, 'HF.UNARY_PERCENT': { method: 'upercent', parameters: [ - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, ], }, 'HF.UPLUS': { method: 'uplus', parameters: [ - {argumentType: ArgumentTypes.NUMBER, passSubtype: true}, + {argumentType: FunctionArgumentType.NUMBER, passSubtype: true}, ], }, } diff --git a/src/interpreter/plugin/SqrtPlugin.ts b/src/interpreter/plugin/SqrtPlugin.ts index d9e4c04299..1aeeedf728 100644 --- a/src/interpreter/plugin/SqrtPlugin.ts +++ b/src/interpreter/plugin/SqrtPlugin.ts @@ -6,14 +6,14 @@ import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class SqrtPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'SQRT': { method: 'sqrt', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ], }, } diff --git a/src/interpreter/plugin/StatisticalAggregationPlugin.ts b/src/interpreter/plugin/StatisticalAggregationPlugin.ts index 3bc04682a2..b6a45ad565 100644 --- a/src/interpreter/plugin/StatisticalAggregationPlugin.ts +++ b/src/interpreter/plugin/StatisticalAggregationPlugin.ts @@ -14,7 +14,7 @@ import { isExtendedNumber, RawInterpreterValue } from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' +import {SimpleRangeValue} from '../../SimpleRangeValue' import { centralF, chisquare, @@ -28,122 +28,122 @@ import { sumsqerr, variance } from './3rdparty/jstat/jstat' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class StatisticalAggregationPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'AVEDEV': { method: 'avedev', parameters: [ - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1, }, 'DEVSQ': { method: 'devsq', parameters: [ - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1, }, 'GEOMEAN': { method: 'geomean', parameters: [ - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1, }, 'HARMEAN': { method: 'harmean', parameters: [ - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1, }, 'CORREL': { method: 'correl', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, 'RSQ': { method: 'rsq', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, 'COVARIANCE.P': { method: 'covariancep', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, 'COVARIANCE.S': { method: 'covariances', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, 'Z.TEST': { method: 'ztest', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true}, ], }, 'F.TEST': { method: 'ftest', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, 'STEYX': { method: 'steyx', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, 'SLOPE': { method: 'slope', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, 'CHISQ.TEST': { method: 'chisqtest', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], }, 'T.TEST': { method: 'ttest', parameters: [ - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.RANGE}, - {argumentType: ArgumentTypes.INTEGER, minValue: 1, maxValue: 2}, - {argumentType: ArgumentTypes.INTEGER, minValue: 1, maxValue: 3}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 1, maxValue: 2}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 1, maxValue: 3}, ], }, 'SKEW': { method: 'skew', parameters: [ - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1, }, 'SKEW.P': { method: 'skewp', parameters: [ - {argumentType: ArgumentTypes.ANY}, + {argumentType: FunctionArgumentType.ANY}, ], repeatLastArgs: 1, }, diff --git a/src/interpreter/plugin/StatisticalPlugin.ts b/src/interpreter/plugin/StatisticalPlugin.ts index bbd5b93fda..b6a1a2000c 100644 --- a/src/interpreter/plugin/StatisticalPlugin.ts +++ b/src/interpreter/plugin/StatisticalPlugin.ts @@ -30,361 +30,361 @@ import { tci, weibull } from './3rdparty/jstat/jstat' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class StatisticalPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'ERF': { method: 'erf', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true}, ] }, 'ERFC': { method: 'erfc', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'EXPON.DIST': { method: 'expondist', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'FISHER': { method: 'fisher', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: -1, lessThan: 1} + {argumentType: FunctionArgumentType.NUMBER, greaterThan: -1, lessThan: 1} ] }, 'FISHERINV': { method: 'fisherinv', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'GAMMA': { method: 'gamma', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'GAMMA.DIST': { method: 'gammadist', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'GAMMALN': { method: 'gammaln', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0} + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0} ] }, 'GAMMA.INV': { method: 'gammainv', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0, lessThan: 1}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0, lessThan: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, ] }, 'GAUSS': { method: 'gauss', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'BETA.DIST': { method: 'betadist', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.BOOLEAN}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, ] }, 'BETA.INV': { method: 'betainv', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0, maxValue: 1}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 0}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0, maxValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, ] }, 'BINOM.DIST': { method: 'binomialdist', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0, maxValue: 1}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0, maxValue: 1}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'BINOM.INV': { method: 'binomialinv', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0, maxValue: 1}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0, lessThan: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0, maxValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0, lessThan: 1}, ] }, 'BESSELI': { method: 'besselifn', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'BESSELJ': { method: 'besseljfn', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'BESSELK': { method: 'besselkfn', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'BESSELY': { method: 'besselyfn', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, ] }, 'CHISQ.DIST': { method: 'chisqdist', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1, maxValue: 1e10}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1, maxValue: 1e10}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'CHISQ.DIST.RT': { method: 'chisqdistrt', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1, maxValue: 1e10}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1, maxValue: 1e10}, ] }, 'CHISQ.INV': { method: 'chisqinv', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0, maxValue: 1}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1, maxValue: 1e10}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0, maxValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1, maxValue: 1e10}, ] }, 'CHISQ.INV.RT': { method: 'chisqinvrt', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0, maxValue: 1}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0, maxValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ] }, 'F.DIST': { method: 'fdist', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'F.DIST.RT': { method: 'fdistrt', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ] }, 'F.INV': { method: 'finv', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0, maxValue: 1}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0, maxValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ] }, 'F.INV.RT': { method: 'finvrt', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0, maxValue: 1}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0, maxValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ] }, 'WEIBULL.DIST': { method: 'weibulldist', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'POISSON.DIST': { method: 'poissondist', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'HYPGEOM.DIST': { method: 'hypgeomdist', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'T.DIST': { method: 'tdist', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'T.DIST.2T': { method: 'tdist2t', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ] }, 'T.DIST.RT': { method: 'tdistrt', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ] }, 'TDIST': { method: 'tdistold', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, - {argumentType: ArgumentTypes.INTEGER, minValue: 1, maxValue: 2}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.INTEGER, minValue: 1, maxValue: 2}, ] }, 'T.INV': { method: 'tinv', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0, lessThan: 1}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0, lessThan: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ] }, 'T.INV.2T': { method: 'tinv2t', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0, maxValue: 1}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0, maxValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ] }, 'LOGNORM.DIST': { method: 'lognormdist', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'LOGNORM.INV': { method: 'lognorminv', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0, lessThan: 1}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0, lessThan: 1}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, ] }, 'NORM.DIST': { method: 'normdist', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'NORM.INV': { method: 'norminv', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0, lessThan: 1}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0, lessThan: 1}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, ] }, 'NORM.S.DIST': { method: 'normsdist', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'NORM.S.INV': { method: 'normsinv', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0, lessThan: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0, lessThan: 1}, ] }, 'PHI': { method: 'phi', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'NEGBINOM.DIST': { method: 'negbinomdist', parameters: [ - {argumentType: ArgumentTypes.NUMBER, minValue: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, - {argumentType: ArgumentTypes.NUMBER, minValue: 0, maxValue: 1}, - {argumentType: ArgumentTypes.BOOLEAN}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 0, maxValue: 1}, + {argumentType: FunctionArgumentType.BOOLEAN}, ] }, 'CONFIDENCE.NORM': { method: 'confidencenorm', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0, lessThan: 1}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0, lessThan: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ], }, 'CONFIDENCE.T': { method: 'confidencet', parameters: [ - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0, lessThan: 1}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, - {argumentType: ArgumentTypes.NUMBER, minValue: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0, lessThan: 1}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER, minValue: 1}, ], }, 'STANDARDIZE': { method: 'standardize', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER, greaterThan: 0}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER, greaterThan: 0}, ], }, } diff --git a/src/interpreter/plugin/SumprodPlugin.ts b/src/interpreter/plugin/SumprodPlugin.ts index f93e186235..5f416ab0d6 100644 --- a/src/interpreter/plugin/SumprodPlugin.ts +++ b/src/interpreter/plugin/SumprodPlugin.ts @@ -8,15 +8,15 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {getRawValue, InterpreterValue, isExtendedNumber} from '../InterpreterValue' -import {SimpleRangeValue} from '../SimpleRangeValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {SimpleRangeValue} from '../../SimpleRangeValue' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' export class SumprodPlugin extends FunctionPlugin implements FunctionPluginTypecheck { public static implementedFunctions = { 'SUMPRODUCT': { method: 'sumproduct', parameters: [ - {argumentType: ArgumentTypes.RANGE}, + {argumentType: FunctionArgumentType.RANGE}, ], repeatLastArgs: 1, }, diff --git a/src/interpreter/plugin/TextPlugin.ts b/src/interpreter/plugin/TextPlugin.ts index 772e570720..9f3946caaf 100644 --- a/src/interpreter/plugin/TextPlugin.ts +++ b/src/interpreter/plugin/TextPlugin.ts @@ -8,7 +8,7 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue, RawScalarValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' /** * Interpreter plugin containing text-specific functions @@ -18,7 +18,7 @@ export class TextPlugin extends FunctionPlugin implements FunctionPluginTypechec 'CONCATENATE': { method: 'concatenate', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ], repeatLastArgs: 1, expandRanges: true, @@ -26,120 +26,120 @@ export class TextPlugin extends FunctionPlugin implements FunctionPluginTypechec 'EXACT': { method: 'exact', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.STRING} ] }, 'SPLIT': { method: 'split', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER}, ] }, 'LEN': { method: 'len', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ] }, 'LOWER': { method: 'lower', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ] }, 'MID': { method: 'mid', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ] }, 'TRIM': { method: 'trim', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ] }, 'T': { method: 't', parameters: [ - {argumentType: ArgumentTypes.SCALAR} + {argumentType: FunctionArgumentType.SCALAR} ] }, 'PROPER': { method: 'proper', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ] }, 'CLEAN': { method: 'clean', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ] }, 'REPT': { method: 'rept', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER}, ] }, 'RIGHT': { method: 'right', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, ] }, 'LEFT': { method: 'left', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, ] }, 'REPLACE': { method: 'replace', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.STRING} ] }, 'SEARCH': { method: 'search', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, ] }, 'SUBSTITUTE': { method: 'substitute', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, optionalArg: true} + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, optionalArg: true} ] }, 'FIND': { method: 'find', parameters: [ - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.STRING}, - {argumentType: ArgumentTypes.NUMBER, defaultValue: 1}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.STRING}, + {argumentType: FunctionArgumentType.NUMBER, defaultValue: 1}, ] }, 'UPPER': { method: 'upper', parameters: [ - {argumentType: ArgumentTypes.STRING} + {argumentType: FunctionArgumentType.STRING} ] }, } diff --git a/src/interpreter/plugin/TrigonometryPlugin.ts b/src/interpreter/plugin/TrigonometryPlugin.ts index a0f8b217c4..669c6b264a 100644 --- a/src/interpreter/plugin/TrigonometryPlugin.ts +++ b/src/interpreter/plugin/TrigonometryPlugin.ts @@ -8,7 +8,7 @@ import {ErrorMessage} from '../../error-message' import {ProcedureAst} from '../../parser' import {InterpreterState} from '../InterpreterState' import {InterpreterValue} from '../InterpreterValue' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from './FunctionPlugin' import {PI} from './MathConstantsPlugin' /** @@ -20,128 +20,128 @@ export class TrigonometryPlugin extends FunctionPlugin implements FunctionPlugin 'ACOS': { method: 'acos', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'ASIN': { method: 'asin', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'COS': { method: 'cos', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'SIN': { method: 'sin', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'TAN': { method: 'tan', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'ATAN': { method: 'atan', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'ATAN2': { method: 'atan2', parameters: [ - {argumentType: ArgumentTypes.NUMBER}, - {argumentType: ArgumentTypes.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, + {argumentType: FunctionArgumentType.NUMBER}, ] }, 'COT': { method: 'cot', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'SEC': { method: 'sec', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'CSC': { method: 'csc', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'SINH': { method: 'sinh', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'COSH': { method: 'cosh', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'TANH': { method: 'tanh', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'COTH': { method: 'coth', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'SECH': { method: 'sech', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'CSCH': { method: 'csch', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'ACOT': { method: 'acot', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'ASINH': { method: 'asinh', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'ACOSH': { method: 'acosh', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'ATANH': { method: 'atanh', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, 'ACOTH': { method: 'acoth', parameters: [ - {argumentType: ArgumentTypes.NUMBER} + {argumentType: FunctionArgumentType.NUMBER} ] }, } diff --git a/test/content-changes.spec.ts b/test/content-changes.spec.ts index e1c0c39b7f..79849cc0ec 100644 --- a/test/content-changes.spec.ts +++ b/test/content-changes.spec.ts @@ -1,5 +1,5 @@ import {CellValueChange, ChangeExporter, ContentChanges} from '../src/ContentChanges' -import {SimpleRangeValue} from '../src/interpreter/SimpleRangeValue' +import {SimpleRangeValue} from '../src/SimpleRangeValue' import {adr} from './testUtils' class SimpleChangeExporter implements ChangeExporter { diff --git a/test/custom-functions.spec.ts b/test/custom-functions.spec.ts index 36efcdfa82..890f70c0e3 100644 --- a/test/custom-functions.spec.ts +++ b/test/custom-functions.spec.ts @@ -1,14 +1,19 @@ -import {FunctionPluginValidationError, HyperFormula, SimpleRangeValue} from '../src' +import { + CellError, + ErrorType, + FunctionArgumentType, + FunctionPluginValidationError, + HyperFormula, + SimpleRangeValue +} from '../src' import {ArraySize} from '../src/ArraySize' -import {ErrorType} from '../src/Cell' import {ErrorMessage} from '../src/error-message' import {AliasAlreadyExisting, ProtectedFunctionError, ProtectedFunctionTranslationError} from '../src/errors' import {plPL} from '../src/i18n/languages' import {InterpreterState} from '../src/interpreter/InterpreterState' import {InternalScalarValue} from '../src/interpreter/InterpreterValue' import {FunctionPlugin, FunctionPluginTypecheck} from '../src/interpreter/plugin/FunctionPlugin' -import {NumericAggregationPlugin} from '../src/interpreter/plugin/NumericAggregationPlugin' -import {ConditionalAggregationPlugin} from '../src/interpreter/plugin/ConditionalAggregationPlugin' +import {ConditionalAggregationPlugin, NumericAggregationPlugin} from '../src/interpreter/plugin' import {VersionPlugin} from '../src/interpreter/plugin/VersionPlugin' import {ProcedureAst} from '../src/parser' import {adr, detailedError, expectArrayWithSameContent} from './testUtils' @@ -126,6 +131,74 @@ class ReservedNamePlugin extends FunctionPlugin implements FunctionPluginTypeche } } +class SquarePlugin extends FunctionPlugin implements FunctionPluginTypecheck { + public static implementedFunctions = { + // Key of the mapping describes which function will be used to compute it + 'SQUARE': { + method: 'square', + }, + } + + public square(ast: ProcedureAst, state: InterpreterState): InternalScalarValue { + // Take ast of first argument from list of arguments + const arg = ast.args[0] + + // If there was no argument, return NA error + if (!arg) { + return new CellError(ErrorType.NA) + } + + // Compute value of argument + const argValue = this.evaluateAst(arg, state) + + if (argValue instanceof CellError) { + // If the value is some error, return that error + return argValue + } else if (typeof argValue === 'number') { + // If it's a number, compute the result + return (argValue * argValue) + } else { + // If it's some other type which doesn't make sense in terms of square (string, boolean), return VALUE error + return new CellError(ErrorType.VALUE) + } + } +} + +class GreetingsPlugin extends FunctionPlugin { + public static implementedFunctions = { + GREET: { + method: 'greet', + parameters: [ + { argumentType: FunctionArgumentType.STRING } + ], + } + } + + public static translations = { + enGB: { + GREET: 'GREET', + }, + enUS: { + GREET: 'GREET', + } + } + + greet(ast: ProcedureAst, state: InterpreterState) { + return this.runFunction( + ast.args, + state, + this.metadata('GREET'), + (username) => { + if (!username) { + return new CellError(ErrorType.VALUE) + } + + return `👋 Hello, ${username}!` + }, + ) + } +} + describe('Register static custom plugin', () => { it('should register plugin with translations', () => { HyperFormula.registerLanguage('plPL', plPL) @@ -393,3 +466,57 @@ describe('aliases', () => { }).toThrow(new AliasAlreadyExisting('FOO', 'OverloadedAliasPlugin')) }) }) + +describe('Argument validation implemented by hand (without call to runFunction)', () => { + it('works', () => { + HyperFormula.registerFunctionPlugin(SquarePlugin) + HyperFormula.getLanguage('enGB').extendFunctions({SQUARE: 'SQUARE'}) + + const engine = HyperFormula.buildFromArray([ + ['=SQUARE(2)'], + ['=SQUARE()'], + ['=SQUARE(TRUE())'], + ['=SQUARE(1/0)'], + ]) + + expect(engine.getCellValue(adr('A1'))).toEqual(4) + expect(engine.getCellValue(adr('A2'))).toEqualError(detailedError(ErrorType.NA)) + expect(engine.getCellValue(adr('A3'))).toEqualError(detailedError(ErrorType.VALUE)) + expect(engine.getCellValue(adr('A4'))).toEqualError(detailedError(ErrorType.DIV_BY_ZERO)) + }) +}) + +describe('Custom function implemented with runFunction)', () => { + it('works for a non-empty string', () => { + HyperFormula.registerFunctionPlugin(GreetingsPlugin, GreetingsPlugin.translations) + + const engine = HyperFormula.buildFromArray([['Anthony', '=GREET(A1)']]) + + expect(engine.getCellValue(adr('B1'))).toEqual('👋 Hello, Anthony!') + }) + + it('returns #VALUE! error for empty string', () => { + HyperFormula.registerFunctionPlugin(GreetingsPlugin, GreetingsPlugin.translations) + + const engine = HyperFormula.buildFromArray([['', '=GREET(A1)']]) + + expect(engine.getCellValue(adr('B1'))).toEqualError(detailedError(ErrorType.VALUE)) + }) + + it('propagates #DIV_BY_ZERO! error', () => { + HyperFormula.registerFunctionPlugin(GreetingsPlugin, GreetingsPlugin.translations) + + const engine = HyperFormula.buildFromArray([['=1/0', '=GREET(A1)']]) + + expect(engine.getCellValue(adr('B1'))).toEqualError(detailedError(ErrorType.DIV_BY_ZERO)) + }) + + it('propagates #CYCLE! error', () => { + HyperFormula.registerFunctionPlugin(GreetingsPlugin, GreetingsPlugin.translations) + + const engine = HyperFormula.buildFromArray([['=B1', '=GREET(A1)']]) + + + expect(engine.getCellValue(adr('B1'))).toEqualError(detailedError(ErrorType.CYCLE)) + }) +}) diff --git a/test/engine.spec.ts b/test/engine.spec.ts index 7f34ca7cb1..005e2c6809 100644 --- a/test/engine.spec.ts +++ b/test/engine.spec.ts @@ -1,6 +1,5 @@ -import {DetailedCellError, ErrorType, HyperFormula} from '../src' +import {DetailedCellError, ErrorType, HyperFormula, CellType, CellValueDetailedType, CellValueType} from '../src' import {AbsoluteCellRange} from '../src/AbsoluteCellRange' -import {CellType, CellValueDetailedType, CellValueType} from '../src/Cell' import {Config} from '../src/Config' import {ErrorMessage} from '../src/error-message' import {plPL} from '../src/i18n/languages' @@ -874,5 +873,4 @@ describe('#getFillRangeData', () => { expect(engine.getFillRangeData(AbsoluteCellRange.spanFrom(adr('B2', 0), 1, 1), AbsoluteCellRange.spanFrom(adr('C3', 1), 1, 1)) ).toEqual([[null]]) }) - }) diff --git a/test/optional-parameters.spec.ts b/test/optional-parameters.spec.ts index f3ab202f15..7eff1cf8a4 100644 --- a/test/optional-parameters.spec.ts +++ b/test/optional-parameters.spec.ts @@ -1,7 +1,7 @@ import {ErrorType, HyperFormula} from '../src' import {ErrorMessage} from '../src/error-message' import {InterpreterState} from '../src/interpreter/InterpreterState' -import {ArgumentTypes, FunctionPlugin, FunctionPluginTypecheck} from '../src/interpreter/plugin/FunctionPlugin' +import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck} from '../src/interpreter/plugin/FunctionPlugin' import {ProcedureAst} from '../src/parser' import {adr, detailedError} from './testUtils' @@ -10,8 +10,8 @@ class FooPlugin extends FunctionPlugin implements FunctionPluginTypecheck { - public static implementedFunctions = { - // Key of the mapping describes which function will be used to compute it - 'SQUARE': { - method: 'square', - }, - } - - public square(ast: ProcedureAst, state: InterpreterState): InternalScalarValue { - // Take ast of first argument from list of arguments - const arg = ast.args[0] - - // If there was no argument, return NA error - if (!arg) { - return new CellError(ErrorType.NA) - } - - // Compute value of argument - const argValue = this.evaluateAst(arg, state) - - if (argValue instanceof CellError) { - // If the value is some error, return that error - return argValue - } else if (typeof argValue === 'number') { - // If it's a number, compute the result - return (argValue * argValue) - } else { - // If it's some other type which doesn't make sense in terms of square (string, boolean), return VALUE error - return new CellError(ErrorType.VALUE) - } - } -} - -describe('Documentation example spec', () => { - beforeEach(() => { - HyperFormula.registerFunctionPlugin(SquarePlugin) - }) - - it('works', () => { - HyperFormula.getLanguage('enGB').extendFunctions({SQUARE: 'SQUARE'}) - const engine = HyperFormula.buildFromArray([ - ['=SQUARE(2)'], - ['=SQUARE()'], - ['=SQUARE(TRUE())'], - ['=SQUARE(1/0)'], - ]) - expect(engine.getCellValue(adr('A1'))).toEqual(4) - expect(engine.getCellValue(adr('A2'))).toEqualError(detailedError(ErrorType.NA)) - expect(engine.getCellValue(adr('A3'))).toEqualError(detailedError(ErrorType.VALUE)) - expect(engine.getCellValue(adr('A4'))).toEqualError(detailedError(ErrorType.DIV_BY_ZERO)) - }) -})