@odoo/o-spreadsheet 14.0.1 → 14.0.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.
- package/dist/o-spreadsheet.cjs.js +17880 -0
- package/dist/o-spreadsheet.d.ts +4119 -0
- package/dist/o-spreadsheet.esm.js +17845 -0
- package/dist/o-spreadsheet.iife.js +17882 -0
- package/dist/o-spreadsheet.iife.min.js +1446 -0
- package/package.json +32 -9
- package/readme.md +10 -0
- package/.eslintrc.json +0 -20
- package/.husky/post-checkout +0 -9
- package/.husky/pre-commit +0 -39
- package/.prettierignore +0 -1
- package/astToFormula.patch +0 -0
- package/demo/data.js +0 -255
- package/demo/index.html +0 -9
- package/demo/libs/Chart.bundle.js +0 -20755
- package/demo/main.js +0 -101
- package/doc/readme.md +0 -46
- package/rollup.config.js +0 -23
- package/src/base_plugin.ts +0 -102
- package/src/components/autofill.ts +0 -146
- package/src/components/bottom_bar.ts +0 -199
- package/src/components/color_picker.ts +0 -150
- package/src/components/composer/autocomplete_dropdown.ts +0 -135
- package/src/components/composer/composer.ts +0 -487
- package/src/components/composer/content_editable_helper.ts +0 -146
- package/src/components/figures/chart.ts +0 -70
- package/src/components/figures/container.ts +0 -268
- package/src/components/figures/text_figure.ts +0 -36
- package/src/components/grid.ts +0 -635
- package/src/components/helpers/dom_helpers.ts +0 -7
- package/src/components/helpers/drag_and_drop.ts +0 -17
- package/src/components/icons.ts +0 -36
- package/src/components/index.ts +0 -1
- package/src/components/menu.ts +0 -288
- package/src/components/overlay.ts +0 -457
- package/src/components/scrollbar.ts +0 -22
- package/src/components/selection_input.ts +0 -168
- package/src/components/side_panel/cell_is_rule_editor.ts +0 -169
- package/src/components/side_panel/chart_panel.ts +0 -104
- package/src/components/side_panel/color_scale_rule_editor.ts +0 -145
- package/src/components/side_panel/conditional_formatting.ts +0 -396
- package/src/components/side_panel/side_panel.ts +0 -127
- package/src/components/side_panel/translations_terms.ts +0 -45
- package/src/components/spreadsheet.ts +0 -198
- package/src/components/top_bar.ts +0 -535
- package/src/constants.ts +0 -26
- package/src/data.ts +0 -149
- package/src/fonts.ts +0 -41
- package/src/formulas/compiler.ts +0 -258
- package/src/formulas/composer_tokenizer.ts +0 -70
- package/src/formulas/index.ts +0 -15
- package/src/formulas/normalize.ts +0 -52
- package/src/formulas/parser.ts +0 -280
- package/src/formulas/range_tokenizer.ts +0 -97
- package/src/formulas/tokenizer.ts +0 -242
- package/src/functions/arguments.ts +0 -114
- package/src/functions/dates.ts +0 -302
- package/src/functions/helpers.ts +0 -592
- package/src/functions/index.ts +0 -52
- package/src/functions/module_database.ts +0 -282
- package/src/functions/module_date.ts +0 -743
- package/src/functions/module_info.ts +0 -69
- package/src/functions/module_logical.ts +0 -208
- package/src/functions/module_lookup.ts +0 -185
- package/src/functions/module_math.ts +0 -1252
- package/src/functions/module_operators.ts +0 -291
- package/src/functions/module_statistical.ts +0 -882
- package/src/functions/module_text.ts +0 -370
- package/src/helpers/color.ts +0 -30
- package/src/helpers/coordinates.ts +0 -71
- package/src/helpers/grid_manipulation.ts +0 -68
- package/src/helpers/index.ts +0 -7
- package/src/helpers/misc.ts +0 -76
- package/src/helpers/numbers.ts +0 -117
- package/src/helpers/uuid.ts +0 -19
- package/src/helpers/zones.ts +0 -263
- package/src/history.ts +0 -186
- package/src/index.ts +0 -84
- package/src/model.ts +0 -261
- package/src/plugins/autofill.ts +0 -412
- package/src/plugins/chart.ts +0 -404
- package/src/plugins/clipboard.ts +0 -461
- package/src/plugins/conditional_format.ts +0 -445
- package/src/plugins/core.ts +0 -1502
- package/src/plugins/edition.ts +0 -157
- package/src/plugins/evaluation.ts +0 -428
- package/src/plugins/figures.ts +0 -123
- package/src/plugins/formatting.ts +0 -630
- package/src/plugins/highlight.ts +0 -187
- package/src/plugins/index.ts +0 -32
- package/src/plugins/merge.ts +0 -524
- package/src/plugins/renderer.ts +0 -571
- package/src/plugins/selection.ts +0 -562
- package/src/plugins/selection_inputs.ts +0 -326
- package/src/registries/autofill_modifiers.ts +0 -76
- package/src/registries/autofill_rules.ts +0 -98
- package/src/registries/figure_registry.ts +0 -30
- package/src/registries/index.ts +0 -7
- package/src/registries/menu_items_registry.ts +0 -110
- package/src/registries/menus/cell_menu_registry.ts +0 -79
- package/src/registries/menus/col_menu_registry.ts +0 -63
- package/src/registries/menus/index.ts +0 -6
- package/src/registries/menus/menu_items_actions.ts +0 -425
- package/src/registries/menus/row_menu_registry.ts +0 -63
- package/src/registries/menus/sheet_menu_registry.ts +0 -75
- package/src/registries/menus/topbar_menu_registry.ts +0 -204
- package/src/registries/side_panel_registry.ts +0 -26
- package/src/registries/topbar_component_registry.ts +0 -12
- package/src/registry.ts +0 -51
- package/src/translation.ts +0 -44
- package/src/types/autofill.ts +0 -48
- package/src/types/chart.ts +0 -26
- package/src/types/commands.ts +0 -716
- package/src/types/conditional_formatting.ts +0 -124
- package/src/types/env.ts +0 -13
- package/src/types/functions.ts +0 -35
- package/src/types/getters.ts +0 -103
- package/src/types/index.ts +0 -20
- package/src/types/misc.ts +0 -143
- package/src/types/rendering.ts +0 -41
- package/src/types/workbook_data.ts +0 -62
- package/tests/__mocks__/uuid.ts +0 -7
- package/tests/canvas.mock.ts +0 -34
- package/tests/components/__mocks__/content_editable_helper.ts +0 -79
- package/tests/components/__mocks__/scrollbar.ts +0 -18
- package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +0 -29
- package/tests/components/__snapshots__/bottom_bar_test.ts.snap +0 -75
- package/tests/components/__snapshots__/context_menu_test.ts.snap +0 -88
- package/tests/components/__snapshots__/grid_test.ts.snap +0 -60
- package/tests/components/__snapshots__/spreadsheet_test.ts.snap +0 -455
- package/tests/components/__snapshots__/top_bar_test.ts.snap +0 -705
- package/tests/components/autocomplete_dropdown_test.ts +0 -315
- package/tests/components/autofill_test.ts +0 -167
- package/tests/components/bottom_bar_test.ts +0 -262
- package/tests/components/chart_side_panel_test.ts +0 -123
- package/tests/components/composer_test.ts +0 -400
- package/tests/components/context_menu_test.ts +0 -825
- package/tests/components/grid_manipulation_test.ts +0 -163
- package/tests/components/grid_test.ts +0 -581
- package/tests/components/overlay_test.ts +0 -541
- package/tests/components/selection_input_test.ts +0 -259
- package/tests/components/side_panel_test.ts +0 -148
- package/tests/components/spreadsheet_test.ts +0 -194
- package/tests/components/top_bar_test.ts +0 -427
- package/tests/data_test.ts +0 -175
- package/tests/dom_helper.ts +0 -42
- package/tests/formulas/__snapshots__/compiler_test.ts.snap +0 -302
- package/tests/formulas/compiler_test.ts +0 -266
- package/tests/formulas/composer_tokenizer_test.ts +0 -137
- package/tests/formulas/expressions_test.ts +0 -57
- package/tests/formulas/formulas_test.ts +0 -80
- package/tests/formulas/normalize_test.ts +0 -82
- package/tests/formulas/parser_test.ts +0 -224
- package/tests/formulas/range_tokenizer_test.ts +0 -187
- package/tests/formulas/tokenizer_test.ts +0 -164
- package/tests/functions/arguments_test.ts +0 -141
- package/tests/functions/dates_test.ts +0 -1081
- package/tests/functions/functions_test.ts +0 -53
- package/tests/functions/helper_test.ts +0 -98
- package/tests/functions/module_database_test.ts +0 -311
- package/tests/functions/module_date_test.ts +0 -941
- package/tests/functions/module_info_test.ts +0 -139
- package/tests/functions/module_logical_test.ts +0 -369
- package/tests/functions/module_lookup_test.ts +0 -541
- package/tests/functions/module_math_test.ts +0 -2482
- package/tests/functions/module_operators_test.ts +0 -955
- package/tests/functions/module_statistical_test.ts +0 -2014
- package/tests/functions/module_text_test.ts +0 -667
- package/tests/helpers/coordinates_test.ts +0 -25
- package/tests/helpers/misc_test.ts +0 -95
- package/tests/helpers/numbers_test.ts +0 -196
- package/tests/helpers/zones_test.ts +0 -97
- package/tests/helpers.ts +0 -384
- package/tests/menu_items_registry_test.ts +0 -540
- package/tests/model/plugins/__snapshots__/chart_test.ts.snap +0 -90
- package/tests/model/plugins/chart_test.ts +0 -562
- package/tests/model_test.ts +0 -82
- package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +0 -131
- package/tests/plugins/__snapshots__/renderer_test.ts.snap +0 -371
- package/tests/plugins/autofill_test.ts +0 -457
- package/tests/plugins/borders_test.ts +0 -295
- package/tests/plugins/clipboard_test.ts +0 -1180
- package/tests/plugins/conditional_formatting_test.ts +0 -1253
- package/tests/plugins/core_test.ts +0 -614
- package/tests/plugins/edition_test.ts +0 -100
- package/tests/plugins/evaluation_async_test.ts +0 -332
- package/tests/plugins/evaluation_dates_test.ts +0 -79
- package/tests/plugins/evaluation_test.ts +0 -901
- package/tests/plugins/figures_test.ts +0 -327
- package/tests/plugins/formatting_test.ts +0 -391
- package/tests/plugins/grid_manipulation_test.ts +0 -1366
- package/tests/plugins/highlight_test.ts +0 -413
- package/tests/plugins/history_test.ts +0 -142
- package/tests/plugins/import_export_test.ts +0 -276
- package/tests/plugins/merges_test.ts +0 -490
- package/tests/plugins/navigation_test.ts +0 -181
- package/tests/plugins/plugins/evaluation_test.ts +0 -111
- package/tests/plugins/renderer_test.ts +0 -598
- package/tests/plugins/resizing_test.ts +0 -152
- package/tests/plugins/selection_input_test.ts +0 -409
- package/tests/plugins/selection_test.ts +0 -442
- package/tests/plugins/sheets_test.ts +0 -643
- package/tests/plugins/style_test.ts +0 -90
- package/tsconfig.json +0 -22
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { _lt } from "../translation";
|
|
2
|
-
import { FunctionDescription } from "../types";
|
|
3
|
-
import { args } from "./arguments";
|
|
4
|
-
|
|
5
|
-
// -----------------------------------------------------------------------------
|
|
6
|
-
// ISERROR
|
|
7
|
-
// -----------------------------------------------------------------------------
|
|
8
|
-
export const ISERROR: FunctionDescription = {
|
|
9
|
-
description: _lt("Whether a value is an error."),
|
|
10
|
-
args: args(`value (any, lazy) ${_lt("The value to be verified as an error type.")}`),
|
|
11
|
-
returns: ["BOOLEAN"],
|
|
12
|
-
compute: function (value: () => any): boolean {
|
|
13
|
-
try {
|
|
14
|
-
value();
|
|
15
|
-
return false;
|
|
16
|
-
} catch (e) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// -----------------------------------------------------------------------------
|
|
23
|
-
// ISLOGICAL
|
|
24
|
-
// -----------------------------------------------------------------------------
|
|
25
|
-
export const ISLOGICAL: FunctionDescription = {
|
|
26
|
-
description: _lt("Whether a value is `true` or `false`."),
|
|
27
|
-
args: args(`value (any) ${_lt("The value to be verified as a logical TRUE or FALSE.")}`),
|
|
28
|
-
returns: ["BOOLEAN"],
|
|
29
|
-
compute: function (value: any): boolean {
|
|
30
|
-
return typeof value === "boolean";
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// -----------------------------------------------------------------------------
|
|
35
|
-
// ISNONTEXT
|
|
36
|
-
// -----------------------------------------------------------------------------
|
|
37
|
-
export const ISNONTEXT: FunctionDescription = {
|
|
38
|
-
description: _lt("Whether a value is non-textual."),
|
|
39
|
-
args: args(`value (any) ${_lt("The value to be checked.")}`),
|
|
40
|
-
returns: ["BOOLEAN"],
|
|
41
|
-
compute: function (value: any): boolean {
|
|
42
|
-
return typeof value !== "string";
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// -----------------------------------------------------------------------------
|
|
47
|
-
// ISNUMBER
|
|
48
|
-
// -----------------------------------------------------------------------------
|
|
49
|
-
|
|
50
|
-
export const ISNUMBER: FunctionDescription = {
|
|
51
|
-
description: _lt("Whether a value is a number."),
|
|
52
|
-
args: args(`value (any) ${_lt("The value to be verified as a number.")}`),
|
|
53
|
-
returns: ["BOOLEAN"],
|
|
54
|
-
compute: function (value: any): boolean {
|
|
55
|
-
return typeof value === "number";
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// -----------------------------------------------------------------------------
|
|
60
|
-
// ISTEXT
|
|
61
|
-
// -----------------------------------------------------------------------------
|
|
62
|
-
export const ISTEXT: FunctionDescription = {
|
|
63
|
-
description: _lt("Whether a value is text."),
|
|
64
|
-
args: args(`value (any) ${_lt("The value to be verified as text.")}`),
|
|
65
|
-
returns: ["BOOLEAN"],
|
|
66
|
-
compute: function (value: any): boolean {
|
|
67
|
-
return typeof value === "string";
|
|
68
|
-
},
|
|
69
|
-
};
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { _lt } from "../translation";
|
|
2
|
-
import { FunctionDescription } from "../types";
|
|
3
|
-
import { args } from "./arguments";
|
|
4
|
-
import { toBoolean, visitBooleans } from "./helpers";
|
|
5
|
-
|
|
6
|
-
// -----------------------------------------------------------------------------
|
|
7
|
-
// WAIT
|
|
8
|
-
// -----------------------------------------------------------------------------
|
|
9
|
-
export const WAIT: FunctionDescription = {
|
|
10
|
-
description: _lt("Wait"),
|
|
11
|
-
args: args(`ms (number) ${_lt("wait time in milliseconds")}`),
|
|
12
|
-
returns: ["ANY"],
|
|
13
|
-
async: true,
|
|
14
|
-
compute: function (delay) {
|
|
15
|
-
return new Promise(function (resolve, reject) {
|
|
16
|
-
setTimeout(function () {
|
|
17
|
-
resolve(delay);
|
|
18
|
-
}, delay);
|
|
19
|
-
});
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// -----------------------------------------------------------------------------
|
|
24
|
-
// AND
|
|
25
|
-
// -----------------------------------------------------------------------------
|
|
26
|
-
export const AND: FunctionDescription = {
|
|
27
|
-
description: _lt("Logical `and` operator."),
|
|
28
|
-
args: args(`
|
|
29
|
-
logical_expression1 (boolean, range<boolean>) ${_lt(
|
|
30
|
-
"An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value."
|
|
31
|
-
)}
|
|
32
|
-
logical_expression2 (boolean, range<boolean>, optional, repeating) ${_lt(
|
|
33
|
-
"More expressions that represent logical values."
|
|
34
|
-
)}
|
|
35
|
-
`),
|
|
36
|
-
returns: ["BOOLEAN"],
|
|
37
|
-
compute: function (): boolean {
|
|
38
|
-
let result = true;
|
|
39
|
-
let foundBoolean = false;
|
|
40
|
-
visitBooleans(arguments, (b) => {
|
|
41
|
-
result = result && b;
|
|
42
|
-
foundBoolean = true;
|
|
43
|
-
return result;
|
|
44
|
-
});
|
|
45
|
-
if (!foundBoolean) {
|
|
46
|
-
throw new Error(_lt(`AND has no valid input data.`));
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// -----------------------------------------------------------------------------
|
|
53
|
-
// IF
|
|
54
|
-
// -----------------------------------------------------------------------------
|
|
55
|
-
export const IF: FunctionDescription = {
|
|
56
|
-
description: _lt("Returns value depending on logical expression."),
|
|
57
|
-
args: args(`
|
|
58
|
-
logical_expression (boolean) ${_lt(
|
|
59
|
-
"An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE."
|
|
60
|
-
)}
|
|
61
|
-
value_if_true (any, lazy) ${_lt(
|
|
62
|
-
"The value the function returns if logical_expression is TRUE."
|
|
63
|
-
)}
|
|
64
|
-
value_if_false (any, lazy, optional, default=FALSE) ${_lt(
|
|
65
|
-
"The value the function returns if logical_expression is FALSE."
|
|
66
|
-
)}
|
|
67
|
-
`),
|
|
68
|
-
returns: ["ANY"],
|
|
69
|
-
compute: function (
|
|
70
|
-
logical_expression: any,
|
|
71
|
-
value_if_true: () => any,
|
|
72
|
-
value_if_false: () => any = () => false
|
|
73
|
-
): any {
|
|
74
|
-
const result = toBoolean(logical_expression) ? value_if_true() : value_if_false();
|
|
75
|
-
return result === null ? "" : result;
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// -----------------------------------------------------------------------------
|
|
80
|
-
// IFERROR
|
|
81
|
-
// -----------------------------------------------------------------------------
|
|
82
|
-
export const IFERROR: FunctionDescription = {
|
|
83
|
-
description: _lt("Value if it is not an error, otherwise 2nd argument."),
|
|
84
|
-
args: args(`
|
|
85
|
-
value (any, lazy) ${_lt("The value to return if value itself is not an error.")}
|
|
86
|
-
value_if_error (any, lazy, optional, default="") ${_lt(
|
|
87
|
-
"The value the function returns if value is an error."
|
|
88
|
-
)}
|
|
89
|
-
`),
|
|
90
|
-
returns: ["ANY"],
|
|
91
|
-
compute: function (value: () => any, value_if_error: () => any = () => ""): any {
|
|
92
|
-
let result;
|
|
93
|
-
try {
|
|
94
|
-
result = value();
|
|
95
|
-
} catch (e) {
|
|
96
|
-
result = value_if_error();
|
|
97
|
-
}
|
|
98
|
-
return result === null ? "" : result;
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// -----------------------------------------------------------------------------
|
|
103
|
-
// IFS
|
|
104
|
-
// -----------------------------------------------------------------------------
|
|
105
|
-
export const IFS: FunctionDescription = {
|
|
106
|
-
description: _lt("Returns a value depending on multiple logical expressions."),
|
|
107
|
-
args: args(`
|
|
108
|
-
condition1 (boolean, lazy) ${_lt(
|
|
109
|
-
"The first condition to be evaluated. This can be a boolean, a number, an array, or a reference to any of those."
|
|
110
|
-
)}
|
|
111
|
-
value1 (any, lazy) ${_lt("The returned value if condition1 is TRUE.")}
|
|
112
|
-
additional_values (any, lazy, optional, repeating) ${_lt(
|
|
113
|
-
"Additional conditions and values to be evaluated if the previous ones are FALSE."
|
|
114
|
-
)}
|
|
115
|
-
`),
|
|
116
|
-
// @compatibility: on google sheets, args definitions are next:
|
|
117
|
-
// condition1 (boolean) The first condition to be evaluated. This can be a boolean, a number, an array, or a reference to any of those.
|
|
118
|
-
// value1 (any) The returned value if condition1 is TRUE.
|
|
119
|
-
// condition2 (boolean, optional, repeating) Additional conditions to be evaluated if the previous ones are FALSE.
|
|
120
|
-
// value2 (any, optional, repeating) Additional values to be returned if their corresponding conditions are TRUE.
|
|
121
|
-
returns: ["ANY"],
|
|
122
|
-
compute: function (): any {
|
|
123
|
-
if (arguments.length % 2 === 1) {
|
|
124
|
-
throw new Error(_lt(`Wrong number of arguments. Expected an even number of arguments.`));
|
|
125
|
-
}
|
|
126
|
-
for (let n = 0; n < arguments.length - 1; n += 2) {
|
|
127
|
-
if (toBoolean(arguments[n]())) {
|
|
128
|
-
return arguments[n + 1]();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
throw new Error(_lt(`No match.`));
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// -----------------------------------------------------------------------------
|
|
136
|
-
// NOT
|
|
137
|
-
// -----------------------------------------------------------------------------
|
|
138
|
-
export const NOT: FunctionDescription = {
|
|
139
|
-
description: _lt("Returns opposite of provided logical value."),
|
|
140
|
-
args: args(
|
|
141
|
-
`logical_expression (boolean) ${_lt(
|
|
142
|
-
"An expression or reference to a cell holding an expression that represents some logical value."
|
|
143
|
-
)}
|
|
144
|
-
`
|
|
145
|
-
),
|
|
146
|
-
returns: ["BOOLEAN"],
|
|
147
|
-
compute: function (logical_expression: any): boolean {
|
|
148
|
-
return !toBoolean(logical_expression);
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
// -----------------------------------------------------------------------------
|
|
153
|
-
// OR
|
|
154
|
-
// -----------------------------------------------------------------------------
|
|
155
|
-
export const OR: FunctionDescription = {
|
|
156
|
-
description: _lt("Logical `or` operator."),
|
|
157
|
-
args: args(`
|
|
158
|
-
logical_expression1 (boolean, range<boolean>) ${_lt(
|
|
159
|
-
"An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value."
|
|
160
|
-
)}
|
|
161
|
-
logical_expression2 (boolean, range<boolean>, optional, repeating) ${_lt(
|
|
162
|
-
"More expressions that evaluate to logical values."
|
|
163
|
-
)}
|
|
164
|
-
`),
|
|
165
|
-
returns: ["BOOLEAN"],
|
|
166
|
-
compute: function (): boolean {
|
|
167
|
-
let result = false;
|
|
168
|
-
let foundBoolean = false;
|
|
169
|
-
visitBooleans(arguments, (b) => {
|
|
170
|
-
result = result || b;
|
|
171
|
-
foundBoolean = true;
|
|
172
|
-
return !result;
|
|
173
|
-
});
|
|
174
|
-
if (!foundBoolean) {
|
|
175
|
-
throw new Error(_lt(`OR has no valid input data.`));
|
|
176
|
-
}
|
|
177
|
-
return result;
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// -----------------------------------------------------------------------------
|
|
182
|
-
// XOR
|
|
183
|
-
// -----------------------------------------------------------------------------
|
|
184
|
-
export const XOR: FunctionDescription = {
|
|
185
|
-
description: _lt("Logical `xor` operator."),
|
|
186
|
-
args: args(`
|
|
187
|
-
logical_expression1 (boolean, range<boolean>) ${_lt(
|
|
188
|
-
"An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value."
|
|
189
|
-
)}
|
|
190
|
-
logical_expression2 (boolean, range<boolean>, optional, repeating) ${_lt(
|
|
191
|
-
"More expressions that evaluate to logical values."
|
|
192
|
-
)}
|
|
193
|
-
`),
|
|
194
|
-
returns: ["BOOLEAN"],
|
|
195
|
-
compute: function (): boolean {
|
|
196
|
-
let result = false;
|
|
197
|
-
let foundBoolean = false;
|
|
198
|
-
visitBooleans(arguments, (b) => {
|
|
199
|
-
result = result ? !b : b;
|
|
200
|
-
foundBoolean = true;
|
|
201
|
-
return true;
|
|
202
|
-
});
|
|
203
|
-
if (!foundBoolean) {
|
|
204
|
-
throw new Error(_lt(`XOR has no valid input data.`));
|
|
205
|
-
}
|
|
206
|
-
return result;
|
|
207
|
-
},
|
|
208
|
-
};
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { _lt } from "../translation";
|
|
2
|
-
import { FunctionDescription } from "../types";
|
|
3
|
-
import { args } from "./arguments";
|
|
4
|
-
import { formatDateTime } from "./dates";
|
|
5
|
-
import {
|
|
6
|
-
dichotomicPredecessorSearch,
|
|
7
|
-
dichotomicSuccessorSearch,
|
|
8
|
-
extractDateValue,
|
|
9
|
-
toBoolean,
|
|
10
|
-
toNumber,
|
|
11
|
-
} from "./helpers";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Perform a linear search and return the index of the perfect match.
|
|
15
|
-
* -1 is returned if no value is found.
|
|
16
|
-
*
|
|
17
|
-
* Example:
|
|
18
|
-
* - [3, 6, 10], 3 => 0
|
|
19
|
-
* - [3, 6, 10], 6 => 1
|
|
20
|
-
* - [3, 6, 10], 9 => -1
|
|
21
|
-
* - [3, 6, 10], 2 => -1
|
|
22
|
-
*/
|
|
23
|
-
function linearSearch(range: any[], target: any): number {
|
|
24
|
-
for (let i = 0; i < range.length; i++) {
|
|
25
|
-
if (range[i] === target) {
|
|
26
|
-
return i;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
// no value is found, -1 is returned
|
|
30
|
-
return -1;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// -----------------------------------------------------------------------------
|
|
34
|
-
// LOOKUP
|
|
35
|
-
// -----------------------------------------------------------------------------
|
|
36
|
-
|
|
37
|
-
export const LOOKUP: FunctionDescription = {
|
|
38
|
-
description: _lt(`Look up a value.`),
|
|
39
|
-
args: args(`
|
|
40
|
-
search_key (any) ${_lt("The value to search for. For example, 42, 'Cats', or I24.")}
|
|
41
|
-
search_array (any, range) ${_lt(
|
|
42
|
-
"One method of using this function is to provide a single sorted row or column search_array to look through for the search_key with a second argument result_range. The other way is to combine these two arguments into one search_array where the first row or column is searched and a value is returned from the last row or column in the array. If search_key is not found, a non-exact match may be returned."
|
|
43
|
-
)}
|
|
44
|
-
result_range (any, range, optional) ${_lt(
|
|
45
|
-
"The range from which to return a result. The value returned corresponds to the location where search_key is found in search_range. This range must be only a single row or column and should not be used if using the search_result_array method."
|
|
46
|
-
)}
|
|
47
|
-
`),
|
|
48
|
-
returns: ["ANY"],
|
|
49
|
-
compute: function (search_key: any, search_array: any, result_range: any = undefined): any {
|
|
50
|
-
const verticalSearch = search_array[0].length >= search_array.length;
|
|
51
|
-
const searchRange = (verticalSearch ? search_array[0] : search_array.map((c) => c[0])).map(
|
|
52
|
-
(el) => extractDateValue(el)
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const key = extractDateValue(search_key);
|
|
56
|
-
const index = dichotomicPredecessorSearch(searchRange, key);
|
|
57
|
-
if (index === -1) {
|
|
58
|
-
const value =
|
|
59
|
-
typeof search_key === "object" && search_key.jsDate
|
|
60
|
-
? formatDateTime(search_key)
|
|
61
|
-
: search_key;
|
|
62
|
-
throw new Error(_lt("Did not find value '%s' in LOOKUP evaluation.", value));
|
|
63
|
-
}
|
|
64
|
-
if (result_range === undefined) {
|
|
65
|
-
return verticalSearch ? search_array.pop()[index] : search_array[index].pop();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const nbCol = result_range.length;
|
|
69
|
-
const nbRow = result_range[0].length;
|
|
70
|
-
if (nbCol > 1 && nbRow > 1) {
|
|
71
|
-
throw new Error(_lt(`LOOKUP range must be a single row or a single column.`));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (nbCol > 1) {
|
|
75
|
-
if (nbCol - 1 < index) {
|
|
76
|
-
throw new Error(
|
|
77
|
-
_lt("LOOKUP evaluates to an out of range row value %s.", (index + 1).toString())
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
return result_range[index][0];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (nbRow - 1 < index) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
_lt("LOOKUP evaluates to an out of range column value %s.", (index + 1).toString())
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
return result_range[0][index];
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// -----------------------------------------------------------------------------
|
|
93
|
-
// MATCH
|
|
94
|
-
// -----------------------------------------------------------------------------
|
|
95
|
-
|
|
96
|
-
export const MATCH: FunctionDescription = {
|
|
97
|
-
description: _lt(`Position of item in range that matches value.`),
|
|
98
|
-
args: args(`
|
|
99
|
-
search_key (any) ${_lt("The value to search for. For example, 42, 'Cats', or I24.")}
|
|
100
|
-
range (any, range) ${_lt("The one-dimensional array to be searched.")}
|
|
101
|
-
search_type (number, optional, default=1) ${_lt(
|
|
102
|
-
"The search method. 1 (default) finds the largest value less than or equal to search_key when range is sorted in ascending order. 0 finds the exact value when range is unsorted. -1 finds the smallest value greater than or equal to search_key when range is sorted in descending order."
|
|
103
|
-
)}
|
|
104
|
-
`),
|
|
105
|
-
returns: ["NUMBER"],
|
|
106
|
-
compute: function (search_key: any, range: any[], search_type: any = 1): number {
|
|
107
|
-
let _searchType = toNumber(search_type);
|
|
108
|
-
const nbCol = range.length;
|
|
109
|
-
const nbRow = range[0].length;
|
|
110
|
-
if (nbCol > 1 && nbRow > 1) {
|
|
111
|
-
throw new Error(_lt(`MATCH range must be a single row or a single column.`));
|
|
112
|
-
}
|
|
113
|
-
let index = -1;
|
|
114
|
-
range = range.flat().map((el) => extractDateValue(el));
|
|
115
|
-
const key = extractDateValue(search_key);
|
|
116
|
-
_searchType = Math.sign(_searchType);
|
|
117
|
-
switch (_searchType) {
|
|
118
|
-
case 1:
|
|
119
|
-
index = dichotomicPredecessorSearch(range, key);
|
|
120
|
-
break;
|
|
121
|
-
case 0:
|
|
122
|
-
index = linearSearch(range, key);
|
|
123
|
-
break;
|
|
124
|
-
case -1:
|
|
125
|
-
index = dichotomicSuccessorSearch(range, key);
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
if (index > -1) {
|
|
129
|
-
return index + 1;
|
|
130
|
-
} else {
|
|
131
|
-
const value =
|
|
132
|
-
typeof search_key === "object" && search_key.jsDate
|
|
133
|
-
? formatDateTime(search_key)
|
|
134
|
-
: search_key;
|
|
135
|
-
throw new Error(_lt("Did not find value '%s' in MATCH evaluation.", value));
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// -----------------------------------------------------------------------------
|
|
141
|
-
// VLOOKUP
|
|
142
|
-
// -----------------------------------------------------------------------------
|
|
143
|
-
|
|
144
|
-
export const VLOOKUP: FunctionDescription = {
|
|
145
|
-
description: _lt(`Vertical lookup.`),
|
|
146
|
-
args: args(`
|
|
147
|
-
search_key (any) ${_lt("The value to search for. For example, 42, 'Cats', or I24.")}
|
|
148
|
-
range (any, range) ${_lt(
|
|
149
|
-
"The range to consider for the search. The first column in the range is searched for the key specified in search_key."
|
|
150
|
-
)}
|
|
151
|
-
index (number) ${_lt(
|
|
152
|
-
"The column index of the value to be returned, where the first column in range is numbered 1."
|
|
153
|
-
)}
|
|
154
|
-
is_sorted (boolean, optional, default = TRUE) ${_lt(
|
|
155
|
-
"Indicates whether the column to be searched [the first column of the specified range] is sorted, in which case the closest match for search_key will be returned."
|
|
156
|
-
)}
|
|
157
|
-
`),
|
|
158
|
-
returns: ["ANY"],
|
|
159
|
-
compute: function (search_key: any, range: any[], index: any, is_sorted: any = true): any {
|
|
160
|
-
const _index = Math.trunc(toNumber(index));
|
|
161
|
-
if (_index < 1 || range.length < _index) {
|
|
162
|
-
throw new Error(_lt(`VLOOKUP evaluates to an out of bounds range.`));
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const _isSorted = toBoolean(is_sorted);
|
|
166
|
-
const firstCol = range[0].map((el) => extractDateValue(el));
|
|
167
|
-
const key = extractDateValue(search_key);
|
|
168
|
-
let lineIndex;
|
|
169
|
-
if (_isSorted) {
|
|
170
|
-
lineIndex = dichotomicPredecessorSearch(firstCol, key);
|
|
171
|
-
} else {
|
|
172
|
-
lineIndex = linearSearch(firstCol, key);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (lineIndex > -1) {
|
|
176
|
-
return range[_index - 1][lineIndex];
|
|
177
|
-
} else {
|
|
178
|
-
const value =
|
|
179
|
-
typeof search_key === "object" && search_key.jsDate
|
|
180
|
-
? formatDateTime(search_key)
|
|
181
|
-
: search_key;
|
|
182
|
-
throw new Error(_lt("Did not find value '%s' in VLOOKUP evaluation.", value));
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
};
|