@univerjs/engine-formula 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/README.md +6 -2
  2. package/lib/cjs/index.js +1 -1
  3. package/lib/es/index.js +4431 -3502
  4. package/lib/types/basics/__tests__/regex.spec.d.ts +16 -0
  5. package/lib/types/basics/common.d.ts +9 -5
  6. package/lib/types/basics/date.d.ts +8 -0
  7. package/lib/types/basics/match-token.d.ts +5 -0
  8. package/lib/types/basics/regex.d.ts +8 -6
  9. package/lib/types/basics/runtime.d.ts +2 -1
  10. package/lib/types/basics/token-type.d.ts +1 -0
  11. package/lib/types/basics/token.d.ts +1 -0
  12. package/lib/types/commands/mutations/set-formula-calculation.mutation.d.ts +2 -2
  13. package/lib/types/engine/analysis/lexer-tree-builder.d.ts +5 -1
  14. package/lib/types/engine/analysis/parser.d.ts +0 -1
  15. package/lib/types/engine/ast-node/reference-node.d.ts +3 -3
  16. package/lib/types/engine/reference-object/base-reference-object.d.ts +2 -0
  17. package/lib/types/engine/utils/__tests__/math-kit.spec.d.ts +16 -0
  18. package/lib/types/engine/utils/__tests__/object-covert.spec.d.ts +16 -0
  19. package/lib/types/engine/utils/ast-node-tool.d.ts +18 -0
  20. package/lib/types/engine/utils/compare.d.ts +1 -0
  21. package/lib/types/engine/utils/math-kit.d.ts +7 -0
  22. package/lib/types/engine/utils/object-covert.d.ts +18 -0
  23. package/lib/types/engine/utils/prefixHandler.d.ts +24 -0
  24. package/lib/types/engine/utils/r1c1-reference.d.ts +2 -3
  25. package/lib/types/engine/utils/reference.d.ts +3 -11
  26. package/lib/types/engine/value-object/array-value-object.d.ts +26 -5
  27. package/lib/types/engine/value-object/base-value-object.d.ts +13 -0
  28. package/lib/types/engine/value-object/cube-value-object.d.ts +29 -0
  29. package/lib/types/engine/value-object/primitive-object.d.ts +3 -0
  30. package/lib/types/functions/base-function.d.ts +11 -1
  31. package/lib/types/functions/compatibility/function-map.d.ts +3 -1
  32. package/lib/types/functions/date/day/index.d.ts +1 -0
  33. package/lib/types/functions/date/month/index.d.ts +1 -0
  34. package/lib/types/functions/date/year/index.d.ts +1 -0
  35. package/lib/types/functions/information/iserr/__tests__/index.spec.d.ts +16 -0
  36. package/lib/types/functions/information/iserr/index.d.ts +20 -0
  37. package/lib/types/functions/information/iserror/__tests__/index.spec.d.ts +16 -0
  38. package/lib/types/functions/information/iserror/index.d.ts +20 -0
  39. package/lib/types/functions/information/islogical/__tests__/index.spec.d.ts +16 -0
  40. package/lib/types/functions/information/islogical/index.d.ts +20 -0
  41. package/lib/types/functions/information/isna/__tests__/index.spec.d.ts +16 -0
  42. package/lib/types/functions/information/isna/index.d.ts +20 -0
  43. package/lib/types/functions/information/isnontext/__tests__/index.spec.d.ts +16 -0
  44. package/lib/types/functions/information/isnontext/index.d.ts +20 -0
  45. package/lib/types/functions/information/isnumber/__tests__/index.spec.d.ts +16 -0
  46. package/lib/types/functions/information/isnumber/index.d.ts +20 -0
  47. package/lib/types/functions/information/isref/__tests__/index.spec.d.ts +16 -0
  48. package/lib/types/functions/information/isref/index.d.ts +22 -0
  49. package/lib/types/functions/information/istext/__tests__/index.spec.d.ts +16 -0
  50. package/lib/types/functions/information/istext/index.d.ts +20 -0
  51. package/lib/types/functions/logical/function-map.d.ts +2 -1
  52. package/lib/types/functions/logical/iferror/index.d.ts +2 -1
  53. package/lib/types/functions/lookup/column/__tests__/index.spec.d.ts +16 -0
  54. package/lib/types/functions/lookup/column/index.d.ts +21 -0
  55. package/lib/types/functions/lookup/columns/__tests__/index.spec.d.ts +16 -0
  56. package/lib/types/functions/lookup/columns/index.d.ts +20 -0
  57. package/lib/types/functions/lookup/function-map.d.ts +6 -1
  58. package/lib/types/functions/lookup/index/__test__/index.spec.d.ts +16 -0
  59. package/lib/types/functions/lookup/index/index.d.ts +24 -0
  60. package/lib/types/functions/lookup/lookup/index.d.ts +1 -0
  61. package/lib/types/functions/lookup/row/__tests__/index.spec.d.ts +16 -0
  62. package/lib/types/functions/lookup/row/index.d.ts +21 -0
  63. package/lib/types/functions/lookup/rows/__tests__/index.spec.d.ts +16 -0
  64. package/lib/types/functions/lookup/rows/index.d.ts +20 -0
  65. package/lib/types/functions/lookup/xlookup/index.d.ts +1 -1
  66. package/lib/types/functions/math/function-map.d.ts +3 -1
  67. package/lib/types/functions/math/mod/__tests__/index.spec.d.ts +16 -0
  68. package/lib/types/functions/math/mod/index.d.ts +20 -0
  69. package/lib/types/functions/math/power/__tests__/index.spec.d.ts +16 -0
  70. package/lib/types/functions/math/power/index.d.ts +2 -3
  71. package/lib/types/functions/math/product/__tests__/index.spec.d.ts +16 -0
  72. package/lib/types/functions/math/product/index.d.ts +21 -0
  73. package/lib/types/functions/math/subtotal/__tests__/index.spec.d.ts +16 -0
  74. package/lib/types/functions/math/subtotal/index.d.ts +38 -0
  75. package/lib/types/functions/math/sum/__tests__/index.spec.d.ts +16 -0
  76. package/lib/types/functions/meta/cube/index.d.ts +20 -0
  77. package/lib/types/functions/meta/function-map.d.ts +2 -2
  78. package/lib/types/functions/meta/function-names.d.ts +2 -1
  79. package/lib/types/functions/statistical/average/__tests__/index.spec.d.ts +16 -0
  80. package/lib/types/functions/statistical/count/__tests__/index.spec.d.ts +16 -0
  81. package/lib/types/functions/statistical/counta/__tests__/index.spec.d.ts +16 -0
  82. package/lib/types/functions/statistical/counta/index.d.ts +1 -1
  83. package/lib/types/functions/statistical/function-map.d.ts +2 -2
  84. package/lib/types/functions/statistical/max/__tests__/index.spec.d.ts +16 -0
  85. package/lib/types/functions/statistical/min/__tests__/index.spec.d.ts +16 -0
  86. package/lib/types/functions/statistical/stdev-p/__tests__/index.spec.d.ts +16 -0
  87. package/lib/types/functions/statistical/stdev-p/index.d.ts +20 -0
  88. package/lib/types/functions/statistical/stdev-s/__tests__/index.spec.d.ts +16 -0
  89. package/lib/types/functions/statistical/stdev-s/index.d.ts +20 -0
  90. package/lib/types/functions/statistical/stdeva/__tests__/index.spec.d.ts +16 -0
  91. package/lib/types/functions/statistical/stdeva/index.d.ts +20 -0
  92. package/lib/types/functions/statistical/stdevpa/__tests__/index.spec.d.ts +16 -0
  93. package/lib/types/functions/statistical/stdevpa/index.d.ts +20 -0
  94. package/lib/types/functions/statistical/var-p/__tests__/index.spec.d.ts +16 -0
  95. package/lib/types/functions/statistical/var-p/index.d.ts +20 -0
  96. package/lib/types/functions/statistical/var-s/__tests__/index.spec.d.ts +16 -0
  97. package/lib/types/functions/statistical/var-s/index.d.ts +20 -0
  98. package/lib/types/functions/statistical/vara/__tests__/index.spec.d.ts +16 -0
  99. package/lib/types/functions/statistical/vara/index.d.ts +20 -0
  100. package/lib/types/functions/statistical/varpa/__tests__/index.spec.d.ts +16 -0
  101. package/lib/types/functions/statistical/varpa/index.d.ts +20 -0
  102. package/lib/types/index.d.ts +4 -3
  103. package/lib/umd/index.js +1 -1
  104. package/package.json +7 -7
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { BooleanNumber, ICellData, IObjectMatrixPrimitiveType, IRange, IUnitRange, Nullable, ObjectMatrix } from '@univerjs/core';
16
+ import type { BooleanNumber, ICellData, IColumnData, IObjectArrayPrimitiveType, IObjectMatrixPrimitiveType, IRange, IRowData, IUnitRange, Nullable, ObjectMatrix } from '@univerjs/core';
17
17
  export declare const ERROR_VALUE_OBJECT_CLASS_TYPE = "errorValueObject";
18
18
  export declare const ASYNC_OBJECT_CLASS_TYPE = "asyncObject";
19
19
  export declare const REFERENCE_OBJECT_CLASS_TYPE = "referenceObject";
@@ -30,6 +30,8 @@ export interface ISheetItem {
30
30
  cellData: ObjectMatrix<ICellData>;
31
31
  rowCount: number;
32
32
  columnCount: number;
33
+ rowData: IObjectArrayPrimitiveType<Partial<IRowData>>;
34
+ columnData: IObjectArrayPrimitiveType<Partial<IColumnData>>;
33
35
  }
34
36
  export interface ISheetData {
35
37
  [sheetId: string]: ISheetItem;
@@ -46,6 +48,11 @@ export interface IRuntimeUnitDataType {
46
48
  [sheetId: string]: ObjectMatrix<Nullable<ICellData>>;
47
49
  }>;
48
50
  }
51
+ export interface IRuntimeUnitDataPrimitiveType {
52
+ [unitId: string]: Nullable<{
53
+ [sheetId: string]: IObjectMatrixPrimitiveType<Nullable<ICellData>>;
54
+ }>;
55
+ }
49
56
  export interface IRuntimeOtherUnitDataType {
50
57
  [unitId: string]: Nullable<{
51
58
  [sheetId: string]: Nullable<{
@@ -80,10 +87,7 @@ export interface IFeatureDirtyRangeType {
80
87
  [sheetId: string]: IRange[];
81
88
  }>;
82
89
  }
83
- export interface IArrayFormulaUnitCellType {
84
- [unitId: string]: Nullable<{
85
- [sheetId: string]: IObjectMatrixPrimitiveType<Nullable<ICellData>>;
86
- }>;
90
+ export interface IArrayFormulaUnitCellType extends IRuntimeUnitDataPrimitiveType {
87
91
  }
88
92
  export interface IFormulaData {
89
93
  [unitId: string]: Nullable<{
@@ -28,3 +28,11 @@ export declare const DEFFAULT_DATE_FORMAT = "yyyy-mm-dd;@";
28
28
  export declare function excelDateSerial(date: Date): number;
29
29
  export declare function excelSerialToDate(serial: number): Date;
30
30
  export declare function formatDateDefault(date: Date): string;
31
+ /**
32
+ * Validate date string
33
+ *
34
+ * TODO @Dushusir: Internationalization and more format support, can be reused when editing and saving cells, like "2020年1月1日"
35
+ * @param dateStr
36
+ * @returns
37
+ */
38
+ export declare function isValidDateStr(dateStr: string): boolean;
@@ -18,3 +18,8 @@ export declare const FORMULA_LEXER_TOKENS: (operatorToken | suffixToken | compar
18
18
  export declare function isFormulaLexerToken(str: string): boolean;
19
19
  export declare function includeFormulaLexerToken(str: string): boolean;
20
20
  export declare function normalizeSheetName(sheetName: string): string;
21
+ /**
22
+ * Determine whether the character is a token keyword for the formula engine.
23
+ * @param char
24
+ */
25
+ export declare function matchRefDrawToken(char: string): boolean;
@@ -13,16 +13,18 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ export declare const UNIT_NAME_REGEX = "\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\]";
16
17
  export declare const SHEET_NAME_REGEX = "((?![\\[\\]\\/?*\\\\]).)*!";
17
18
  export declare const ABSOLUTE_SYMBOL = "$";
18
19
  export declare const RANGE_SYMBOL = "\\s*?:\\s*?";
20
+ export declare const UNIT_NAME_SHEET_NAME_REGEX = "'?(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?'?";
19
21
  export declare const SIMPLE_SINGLE_RANGE_REGEX = "\\$?[A-Za-z]+\\$?[0-9]+";
20
- export declare const REFERENCE_MULTIPLE_RANGE_REGEX = "^(@)?(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?\\$?[A-Za-z]+\\$?[0-9]+\\s*?:\\s*?\\$?[A-Za-z]+\\$?[0-9]+$";
21
- export declare const REFERENCE_SINGLE_RANGE_REGEX = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?\\s*?\\$?[A-Za-z]+\\$?[0-9]+(#)?$";
22
- export declare const REFERENCE_REGEX_ROW = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?\\$?[0-9]+\\s*?:\\s*?\\$?[0-9]+$";
23
- export declare const REFERENCE_REGEX_COLUMN = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?\\$?[A-Za-z]+\\s*?:\\s*?\\$?[A-Za-z]+$";
24
- export declare const REFERENCE_REGEX_SINGLE_ROW = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?\\s*?\\$?[0-9]+$";
25
- export declare const REFERENCE_REGEX_SINGLE_COLUMN = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?\\s*?\\$?[A-Za-z]+$";
22
+ export declare const REFERENCE_MULTIPLE_RANGE_REGEX = "^(@)?'?(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?'?\\$?[A-Za-z]+\\$?[0-9]+\\s*?:\\s*?\\$?[A-Za-z]+\\$?[0-9]+$";
23
+ export declare const REFERENCE_SINGLE_RANGE_REGEX = "^'?(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?'?\\s*?\\$?[A-Za-z]+\\$?[0-9]+(#)?$";
24
+ export declare const REFERENCE_REGEX_ROW = "^'?(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?'?\\$?[0-9]+\\s*?:\\s*?\\$?[0-9]+$";
25
+ export declare const REFERENCE_REGEX_COLUMN = "^'?(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?'?\\$?[A-Za-z]+\\s*?:\\s*?\\$?[A-Za-z]+$";
26
+ export declare const REFERENCE_REGEX_SINGLE_ROW = "^'?(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?'?\\s*?\\$?[0-9]+$";
27
+ export declare const REFERENCE_REGEX_SINGLE_COLUMN = "^'?(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?(((?![\\[\\]\\/?*\\\\]).)*!)?'?\\s*?\\$?[A-Za-z]+$";
26
28
  export declare const REFERENCE_TABLE_ALL_COLUMN_REGEX = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+$";
27
29
  export declare const REFERENCE_TABLE_SINGLE_COLUMN_REGEX = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+(\\[((?<!#).)*\\]|\\[\\[#.+\\]\\s*?,\\s*?\\[((?<!#).)*\\]\\])+$";
28
30
  export declare const REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX = "^(\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\])?((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+(\\[\\[((?<!#).)*\\]\\s*?:\\s*?\\[((?<!#).)*\\]\\])?$|^((?![~!@#$%^&*()_+<>?:,./;\u2019\uFF0C\u3002\u3001\u2018\uFF1A\u201C\u300A\u300B\uFF1F~\uFF01@#\uFFE5%\u2026\u2026\uFF08\uFF09\u3010\u3011\\[\\]\\/\\\\]).)+(\\[\\[#.+\\]\\s*?,\\s*?\\[((?<!#).)*\\]\\s*?:\\s*?\\[((?<!#).)*\\]\\])?$";
@@ -13,5 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { IArrayFormulaUnitCellType, IRuntimeUnitDataType } from './common';
16
+ import type { IArrayFormulaUnitCellType, IRuntimeUnitDataPrimitiveType, IRuntimeUnitDataType } from './common';
17
17
  export declare function convertUnitDataToRuntime(unitData: IArrayFormulaUnitCellType): IRuntimeUnitDataType;
18
+ export declare function convertRuntimeToUnitData(unitData: IRuntimeUnitDataType): IRuntimeUnitDataPrimitiveType;
@@ -20,3 +20,4 @@ export declare const DEFAULT_TOKEN_TYPE_LAMBDA_RUNTIME_PARAMETER = "LR_1";
20
20
  export declare const DEFAULT_TOKEN_TYPE_LAMBDA_OMIT_PARAMETER = "LO_1";
21
21
  export declare const DEFAULT_TOKEN_LET_FUNCTION_NAME = "LET";
22
22
  export declare const DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME = "LAMBDA";
23
+ export declare const DEFAULT_TOKEN_CUBE_FUNCTION_NAME = "CUBE";
@@ -59,3 +59,4 @@ export declare enum prefixToken {
59
59
  AT = "@",
60
60
  MINUS = "-"
61
61
  }
62
+ export declare const SPACE_TOKEN = " ";
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { IExecutionOptions, IMutation, IUnitRange, Nullable } from '@univerjs/core';
17
- import type { IDirtyUnitFeatureMap, IDirtyUnitSheetNameMap, INumfmtItemMap, IRuntimeOtherUnitDataType, IRuntimeUnitDataType } from '../../basics/common';
17
+ import type { IDirtyUnitFeatureMap, IDirtyUnitSheetNameMap, INumfmtItemMap, IRuntimeOtherUnitDataType, IRuntimeUnitDataPrimitiveType } from '../../basics/common';
18
18
  import type { FormulaExecutedStateType, IExecutionInProgressParams } from '../../services/runtime.service';
19
19
  export interface ISetFormulaCalculationStartMutation {
20
20
  dirtyRanges: IUnitRange[];
@@ -38,7 +38,7 @@ export interface ISetFormulaCalculationNotificationMutation {
38
38
  }
39
39
  export declare const SetFormulaCalculationNotificationMutation: IMutation<ISetFormulaCalculationNotificationMutation>;
40
40
  export interface ISetFormulaCalculationResultMutation {
41
- unitData: IRuntimeUnitDataType;
41
+ unitData: IRuntimeUnitDataPrimitiveType;
42
42
  unitOtherData: IRuntimeOtherUnitDataType;
43
43
  }
44
44
  export declare const SetFormulaCalculationResultMutation: IMutation<ISetFormulaCalculationResultMutation>;
@@ -52,7 +52,6 @@ export declare class LexerTreeBuilder extends Disposable {
52
52
  /**
53
53
  * Estimate the number of right brackets that need to be automatically added to the end of the formula.
54
54
  * @param formulaString
55
- * @returns
56
55
  */
57
56
  checkIfAddBracket(formulaString: string): number;
58
57
  sequenceNodesBuilder(formulaString: string): (string | ISequenceNode)[] | undefined;
@@ -72,6 +71,10 @@ export declare class LexerTreeBuilder extends Disposable {
72
71
  hasDefinedName: boolean;
73
72
  }): ErrorType.VALUE | LexerNode | (string | LexerNode)[] | undefined;
74
73
  private _suffixExpressionHandler;
74
+ private _checkCloseBracket;
75
+ private _checkOpenBracket;
76
+ private _checkOperator;
77
+ private _deletePlusForPreNode;
75
78
  private _resetCurrentLexerNode;
76
79
  private _resetSegment;
77
80
  private _openBracket;
@@ -79,6 +82,7 @@ export declare class LexerTreeBuilder extends Disposable {
79
82
  private _openSquareBracket;
80
83
  private _closeSquareBracket;
81
84
  private _getCurrentBracket;
85
+ private _changeCurrentBracket;
82
86
  private _openBraces;
83
87
  private _closeBraces;
84
88
  private _openSingleQuotation;
@@ -48,7 +48,6 @@ export declare class AstTreeBuilder extends Disposable {
48
48
  parse(lexerNode: LexerNode, refOffsetX?: number, refOffsetY?: number): Nullable<BaseAstNode>;
49
49
  private _lambdaParameterHandler;
50
50
  private _changeLetToLambda;
51
- private _getTopParent;
52
51
  private _parse;
53
52
  private _checkAstNode;
54
53
  private _initializeAstNode;
@@ -18,9 +18,9 @@ import { Injector } from '@wendellhu/redi';
18
18
  import { IDefinedNamesService } from '../../services/defined-names.service';
19
19
  import { IFormulaRuntimeService } from '../../services/runtime.service';
20
20
  import { ISuperTableService } from '../../services/super-table.service';
21
- import { Lexer } from '../analysis/lexer';
22
21
  import { LexerNode } from '../analysis/lexer-node';
23
22
  import type { BaseReferenceObject } from '../reference-object/base-reference-object';
23
+ import { IFunctionService } from '../../services/function.service';
24
24
  import { BaseAstNode } from './base-ast-node';
25
25
  import { BaseAstNodeFactory } from './base-ast-node-factory';
26
26
  import { NodeType } from './node-type';
@@ -37,9 +37,9 @@ export declare class ReferenceNodeFactory extends BaseAstNodeFactory {
37
37
  private readonly _definedNamesService;
38
38
  private readonly _superTableService;
39
39
  private readonly _formulaRuntimeService;
40
- private readonly _lexer;
40
+ private readonly _functionService;
41
41
  private readonly _injector;
42
- constructor(_definedNamesService: IDefinedNamesService, _superTableService: ISuperTableService, _formulaRuntimeService: IFormulaRuntimeService, _lexer: Lexer, _injector: Injector);
42
+ constructor(_definedNamesService: IDefinedNamesService, _superTableService: ISuperTableService, _formulaRuntimeService: IFormulaRuntimeService, _functionService: IFunctionService, _injector: Injector);
43
43
  get zIndex(): number;
44
44
  checkAndCreateNodeType(param: LexerNode | string): ReferenceNode | undefined;
45
45
  }
@@ -89,6 +89,8 @@ export declare class BaseReferenceObject extends ObjectClassType {
89
89
  setNumfmtItemData(numfmtItemData: INumfmtItemMap): void;
90
90
  getRowCount(): number;
91
91
  getColumnCount(): number;
92
+ getRowData(): import("@univerjs/core").IObjectArrayPrimitiveType<Partial<import("@univerjs/core").IRowData>>;
93
+ getColumnData(): import("@univerjs/core").IObjectArrayPrimitiveType<Partial<import("@univerjs/core").IColumnData>>;
92
94
  isCell(): boolean;
93
95
  isColumn(): boolean;
94
96
  isRow(): boolean;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { Nullable } from '@univerjs/core';
17
+ import type { BaseAstNode } from '../ast-node/base-ast-node';
18
+ export declare function getAstNodeTopParent(node: BaseAstNode): Nullable<BaseAstNode>;
@@ -28,3 +28,4 @@ export declare function isWildcard(str: string): boolean;
28
28
  export declare function isMatchWildcard(currentValue: string, value: string): boolean;
29
29
  export declare function replaceWildcard(value: string): string;
30
30
  export declare function compareWithWildcard(currentValue: string, value: string, operator: compareToken): boolean;
31
+ export declare function escapeRegExp(str: string): string;
@@ -27,4 +27,11 @@ export declare function multiply(a: number, b: number): number;
27
27
  export declare function round(base: number, precision: number): number;
28
28
  export declare function floor(base: number, precision: number): number;
29
29
  export declare function ceil(base: number, precision: number): number;
30
+ export declare function mod(base: number, divisor: number): number;
30
31
  export declare function pow(base: number, exponent: number): number;
32
+ /**
33
+ * Excel can display numbers with up to about 15 digits of precision. This includes the sum of the integer part and the decimal part
34
+ * @param input
35
+ * @returns
36
+ */
37
+ export declare function truncateNumber(input: number | string): number;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { BaseValueObject } from '../value-object/base-value-object';
17
+ import { NumberValueObject } from '../value-object/primitive-object';
18
+ export declare function convertTonNumber(valueObject: BaseValueObject): NumberValueObject;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { Injector } from '@wendellhu/redi';
17
+ import type { Nullable } from '@univerjs/core';
18
+ import type { IFunctionService } from '../../services/function.service';
19
+ import { PrefixNode } from '../ast-node/prefix-node';
20
+ export declare function prefixHandler(tokenTrim: string, functionService: IFunctionService, injector: Injector): {
21
+ tokenTrim: string;
22
+ minusPrefixNode: Nullable<PrefixNode>;
23
+ atPrefixNode: Nullable<PrefixNode>;
24
+ };
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { type IRange } from '@univerjs/core';
17
- import type { IGridRangeName } from './reference';
18
- export declare function deserializeRangeForR1C1(refString: string, currentRow?: number, currentColumn?: number): IGridRangeName;
16
+ import type { IRange, IUnitRangeName } from '@univerjs/core';
17
+ export declare function deserializeRangeForR1C1(refString: string, currentRow?: number, currentColumn?: number): IUnitRangeName;
19
18
  export declare function serializeRangeToR1C1(range: IRange): string;
@@ -13,14 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { IRange } from '@univerjs/core';
16
+ import type { IRange, IUnitRangeName } from '@univerjs/core';
17
17
  import { AbsoluteRefType } from '@univerjs/core';
18
- export declare const UNIT_NAME_REGEX = "\\[([^\\[\\]\\/?:\"<>|*\\\\]+)\\]";
19
- export interface IGridRangeName {
20
- unitId: string;
21
- sheetName: string;
22
- range: IRange;
23
- }
24
18
  export interface IAbsoluteRefTypeForRange {
25
19
  startAbsoluteRefType: AbsoluteRefType;
26
20
  endAbsoluteRefType?: AbsoluteRefType;
@@ -44,7 +38,6 @@ export declare function serializeRange(range: IRange): string;
44
38
  * Serialize an `IRange` and a sheetID into a string.
45
39
  * @param sheetName
46
40
  * @param range
47
- * @returns
48
41
  */
49
42
  export declare function serializeRangeWithSheet(sheetName: string, range: IRange): string;
50
43
  /**
@@ -52,16 +45,15 @@ export declare function serializeRangeWithSheet(sheetName: string, range: IRange
52
45
  * @param unit unitId or unitName
53
46
  * @param sheetName
54
47
  * @param range
55
- * @returns
56
48
  */
57
49
  export declare function serializeRangeWithSpreadsheet(unit: string, sheetName: string, range: IRange): string;
58
- export declare function serializeRangeToRefString(gridRangeName: IGridRangeName): string;
50
+ export declare function serializeRangeToRefString(gridRangeName: IUnitRangeName): string;
59
51
  export declare function handleRefStringInfo(refString: string): {
60
52
  refBody: string;
61
53
  sheetName: string;
62
54
  unitId: string;
63
55
  };
64
- export declare function deserializeRangeWithSheet(refString: string): IGridRangeName;
56
+ export declare function deserializeRangeWithSheet(refString: string): IUnitRangeName;
65
57
  /**
66
58
  * Determine whether the sheet name needs to be wrapped in quotes
67
59
  * Excel will quote the worksheet name if any of the following is true:
@@ -128,6 +128,8 @@ export declare class ArrayValueObject extends BaseValueObject {
128
128
  minus(valueObject: BaseValueObject): BaseValueObject;
129
129
  multiply(valueObject: BaseValueObject): BaseValueObject;
130
130
  divided(valueObject: BaseValueObject): BaseValueObject;
131
+ mod(valueObject: BaseValueObject): BaseValueObject;
132
+ modInverse(valueObject: BaseValueObject): BaseValueObject;
131
133
  compare(valueObject: BaseValueObject, operator: compareToken): BaseValueObject;
132
134
  concatenateFront(valueObject: BaseValueObject): BaseValueObject;
133
135
  concatenateBack(valueObject: BaseValueObject): BaseValueObject;
@@ -155,18 +157,37 @@ export declare class ArrayValueObject extends BaseValueObject {
155
157
  atanh(): BaseValueObject;
156
158
  atan2(valueObject: BaseValueObject): BaseValueObject;
157
159
  atan2Inverse(valueObject: BaseValueObject): BaseValueObject;
158
- mean(): BaseValueObject;
160
+ mean(ddof?: number): BaseValueObject;
159
161
  median(): BaseValueObject;
160
- var(): BaseValueObject;
161
162
  /**
162
- * STDEV.P: ddof=0, ignore strings and booleans
163
- * STDEV.S: ddof=1, ignore strings and booleans
163
+ * ┌──────────────┬────────────────────────────────┬───────────────────┐
164
+ * Function │ Ignore logical values and text │ Type │
165
+ * ├──────────────┼────────────────────────────────┼───────────────────┤
166
+ * │ VAR.S (VAR) │ TRUE │ sample │
167
+ * │ VAR.P (VARP) │ TRUE │ entire population │
168
+ * │ VARA │ FALSE │ sample │
169
+ * │ VARPA │ FALSE │ entire population │
170
+ * └──────────────┴────────────────────────────────┴───────────────────┘
171
+ *
172
+ * for VARPA and VARA, strings and FALSE are counted as 0, TRUE is counted as 1
173
+ * for VAR.S/VAR, or VAR.P/VARP, strings,TRUE and FALSE are ignored
174
+ * Since sum ignores strings and booleans, they are ignored here too, and VAR.S and VAR.P are used more
175
+ *
176
+ * VAR.S assumes that its arguments are a sample of the population, like numpy.var(data, ddof=1)
177
+ * VAR.P assumes that its arguments are the entire population, like numpy.var(data, ddof=0)
178
+ * numpy.var uses ddof=0 (Delta Degrees of Freedom) by default, so we use ddof=0 here
179
+ *
180
+ */
181
+ var(ddof?: number): BaseValueObject;
182
+ /**
183
+ * STDEV.P (STDEVP): ddof=0, ignore strings and booleans
184
+ * STDEV.S (STDEV): ddof=1, ignore strings and booleans
164
185
  *
165
186
  * STDEVPA: ddof=0,
166
187
  * STDEVA: ddof=1,
167
188
  * @returns
168
189
  */
169
- std(): BaseValueObject;
190
+ std(ddof?: number): BaseValueObject;
170
191
  log(): BaseValueObject;
171
192
  log10(): BaseValueObject;
172
193
  exp(): BaseValueObject;
@@ -46,6 +46,7 @@ export declare class BaseValueObject extends ObjectClassType {
46
46
  getArrayValue(): BaseValueObject[][];
47
47
  setValue(value: string | number | boolean): void;
48
48
  setArrayValue(value: BaseValueObject[][]): void;
49
+ isCube(): boolean;
49
50
  isArray(): boolean;
50
51
  isString(): boolean;
51
52
  isNumber(): boolean;
@@ -65,7 +66,18 @@ export declare class BaseValueObject extends ObjectClassType {
65
66
  minus(valueObject: BaseValueObject): BaseValueObject;
66
67
  multiply(valueObject: BaseValueObject): BaseValueObject;
67
68
  divided(valueObject: BaseValueObject): BaseValueObject;
69
+ mod(valueObject: BaseValueObject): BaseValueObject;
70
+ /**
71
+ * return every value in the array after the callback function, excluding the error value
72
+ * @param callbackFn
73
+ * @returns
74
+ */
68
75
  map(callbackFn: callbackMapFnType): BaseValueObject;
76
+ /**
77
+ * return every value in the array after the callback function
78
+ * @param callbackFn
79
+ * @returns
80
+ */
69
81
  mapValue(callbackFn: callbackMapFnType): BaseValueObject;
70
82
  product(valueObject: BaseValueObject, callbackFn: callbackProductFnType): BaseValueObject;
71
83
  compare(valueObject: BaseValueObject, operator: compareToken): BaseValueObject;
@@ -81,6 +93,7 @@ export declare class BaseValueObject extends ObjectClassType {
81
93
  minusBy(value: string | number | boolean): BaseValueObject;
82
94
  multiplyBy(value: string | number | boolean): BaseValueObject;
83
95
  dividedBy(value: string | number | boolean): BaseValueObject;
96
+ modInverse(valueObject: BaseValueObject): BaseValueObject;
84
97
  compareBy(value: string | number | boolean, operator: compareToken): BaseValueObject;
85
98
  concatenate(value: string | number | boolean, concatenateType?: ConcatenateType): string;
86
99
  pow(valueObject: BaseValueObject): BaseValueObject;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ArrayValueObject } from './array-value-object';
17
+ import { BaseValueObject } from './base-value-object';
18
+ import { NumberValueObject } from './primitive-object';
19
+ export declare class CubeValueObject extends BaseValueObject {
20
+ isCube(): boolean;
21
+ private _values;
22
+ constructor(values: ArrayValueObject[]);
23
+ sum(): NumberValueObject;
24
+ max(): NumberValueObject;
25
+ min(): NumberValueObject;
26
+ count(): NumberValueObject;
27
+ countA(): NumberValueObject;
28
+ countBlank(): NumberValueObject;
29
+ }
@@ -22,6 +22,7 @@ export declare class NullValueObject extends BaseValueObject {
22
22
  minus(valueObject: BaseValueObject): BaseValueObject;
23
23
  multiply(valueObject: BaseValueObject): BaseValueObject;
24
24
  divided(valueObject: BaseValueObject): BaseValueObject;
25
+ mod(valueObject: BaseValueObject): BaseValueObject;
25
26
  compare(valueObject: BaseValueObject, operator: compareToken): BaseValueObject;
26
27
  concatenateFront(valueObject: BaseValueObject): BaseValueObject;
27
28
  concatenateBack(valueObject: BaseValueObject): BaseValueObject;
@@ -63,6 +64,7 @@ export declare class BooleanValueObject extends BaseValueObject {
63
64
  minus(valueObject: BaseValueObject): BaseValueObject;
64
65
  multiply(valueObject: BaseValueObject): BaseValueObject;
65
66
  divided(valueObject: BaseValueObject): BaseValueObject;
67
+ mod(valueObject: BaseValueObject): BaseValueObject;
66
68
  compare(valueObject: BaseValueObject, operator: compareToken): BaseValueObject;
67
69
  concatenateFront(valueObject: BaseValueObject): BaseValueObject;
68
70
  concatenateBack(valueObject: BaseValueObject): BaseValueObject;
@@ -102,6 +104,7 @@ export declare class NumberValueObject extends BaseValueObject {
102
104
  minus(valueObject: BaseValueObject): BaseValueObject;
103
105
  multiply(valueObject: BaseValueObject): BaseValueObject;
104
106
  divided(valueObject: BaseValueObject): BaseValueObject;
107
+ mod(valueObject: BaseValueObject): BaseValueObject;
105
108
  concatenateFront(valueObject: BaseValueObject): BaseValueObject;
106
109
  concatenateBack(valueObject: BaseValueObject): BaseValueObject;
107
110
  compare(valueObject: BaseValueObject, operator: compareToken): BaseValueObject;
@@ -21,13 +21,21 @@ import type { ArrayBinarySearchType } from '../engine/utils/compare';
21
21
  import { ArrayOrderSearchType } from '../engine/utils/compare';
22
22
  import type { ArrayValueObject } from '../engine/value-object/array-value-object';
23
23
  import { type BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object';
24
- import type { PrimitiveValueType } from '../engine/value-object/primitive-object';
24
+ import { type PrimitiveValueType } from '../engine/value-object/primitive-object';
25
25
  export declare class BaseFunction extends Disposable {
26
26
  private _name;
27
27
  private _unitId;
28
28
  private _subUnitId;
29
29
  private _row;
30
30
  private _column;
31
+ /**
32
+ * Whether the function needs to expand the parameters
33
+ */
34
+ needsExpandParams: boolean;
35
+ /**
36
+ * Whether the function needs to pass in reference object
37
+ */
38
+ needsReferenceObject: boolean;
31
39
  constructor(_name: IFunctionNames);
32
40
  get name(): IFunctionNames;
33
41
  get unitId(): Nullable<string>;
@@ -82,4 +90,6 @@ export declare class BaseFunction extends Disposable {
82
90
  equalSearchExpand(value: BaseValueObject, searchArray: ArrayValueObject, resultArray: ArrayValueObject, isFirst?: boolean, axis?: number): ErrorValueObject | ArrayValueObject | undefined;
83
91
  fuzzySearchExpand(value: BaseValueObject, searchArray: ArrayValueObject, resultArray: ArrayValueObject, isFirst?: boolean, axis?: number): ErrorValueObject | ArrayValueObject | undefined;
84
92
  orderSearchExpand(value: BaseValueObject, searchArray: ArrayValueObject, resultArray: ArrayValueObject, searchType?: ArrayOrderSearchType, isDesc?: boolean, axis?: number): ErrorValueObject | ArrayValueObject | undefined;
93
+ flattenArray(variants: BaseValueObject[], ignoreLogicalValuesAndText?: boolean): ArrayValueObject | BaseValueObject;
94
+ private _includingLogicalValuesAndText;
85
95
  }
@@ -13,4 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const functionCompatibility: never[];
16
+ import { StdevS } from '../statistical/stdev-s';
17
+ import { FUNCTION_NAMES_COMPATIBILITY } from './function-names';
18
+ export declare const functionCompatibility: (FUNCTION_NAMES_COMPATIBILITY | typeof StdevS)[][];
@@ -17,4 +17,5 @@ import type { BaseValueObject } from '../../../engine/value-object/base-value-ob
17
17
  import { BaseFunction } from '../../base-function';
18
18
  export declare class Day extends BaseFunction {
19
19
  calculate(serialNumber: BaseValueObject): BaseValueObject;
20
+ private _handleSingleObject;
20
21
  }
@@ -17,4 +17,5 @@ import type { BaseValueObject } from '../../../engine/value-object/base-value-ob
17
17
  import { BaseFunction } from '../../base-function';
18
18
  export declare class Month extends BaseFunction {
19
19
  calculate(serialNumber: BaseValueObject): BaseValueObject;
20
+ private _handleSingleObject;
20
21
  }
@@ -17,4 +17,5 @@ import type { BaseValueObject } from '../../../engine/value-object/base-value-ob
17
17
  import { BaseFunction } from '../../base-function';
18
18
  export declare class Year extends BaseFunction {
19
19
  calculate(serialNumber: BaseValueObject): BaseValueObject;
20
+ private _handleSingleObject;
20
21
  }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};