@ricsam/formula-engine 0.0.1
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/README.md +100 -0
- package/dist/cjs/core/ast-traverser.cjs +124 -0
- package/dist/cjs/core/ast-traverser.cjs.map +10 -0
- package/dist/cjs/core/autofill-utils.cjs +304 -0
- package/dist/cjs/core/autofill-utils.cjs.map +10 -0
- package/dist/cjs/core/engine.cjs +390 -0
- package/dist/cjs/core/engine.cjs.map +10 -0
- package/dist/cjs/core/managers/cache-manager.cjs +58 -0
- package/dist/cjs/core/managers/cache-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/dependency-manager.cjs +620 -0
- package/dist/cjs/core/managers/dependency-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/dependency-node.cjs +24 -0
- package/dist/cjs/core/managers/dependency-node.cjs.map +9 -0
- package/dist/cjs/core/managers/evaluation-manager.cjs +433 -0
- package/dist/cjs/core/managers/evaluation-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/event-manager.cjs +49 -0
- package/dist/cjs/core/managers/event-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/frontier-dependency-manager.cjs +181 -0
- package/dist/cjs/core/managers/frontier-dependency-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/index.cjs +49 -0
- package/dist/cjs/core/managers/index.cjs.map +10 -0
- package/dist/cjs/core/managers/isDependencyNode.cjs +44 -0
- package/dist/cjs/core/managers/isDependencyNode.cjs.map +10 -0
- package/dist/cjs/core/managers/named-expression-manager.cjs +379 -0
- package/dist/cjs/core/managers/named-expression-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/range-eval-order-builder.cjs +644 -0
- package/dist/cjs/core/managers/range-eval-order-builder.cjs.map +10 -0
- package/dist/cjs/core/managers/table-manager.cjs +254 -0
- package/dist/cjs/core/managers/table-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/workbook-manager.cjs +474 -0
- package/dist/cjs/core/managers/workbook-manager.cjs.map +10 -0
- package/dist/cjs/core/map-serializer.cjs +69 -0
- package/dist/cjs/core/map-serializer.cjs.map +10 -0
- package/dist/cjs/core/named-expression-renamer.cjs +88 -0
- package/dist/cjs/core/named-expression-renamer.cjs.map +10 -0
- package/dist/cjs/core/sheet-renamer.cjs +89 -0
- package/dist/cjs/core/sheet-renamer.cjs.map +10 -0
- package/dist/cjs/core/sheet-utils.cjs +39 -0
- package/dist/cjs/core/sheet-utils.cjs.map +10 -0
- package/dist/cjs/core/table-renamer.cjs +88 -0
- package/dist/cjs/core/table-renamer.cjs.map +10 -0
- package/dist/cjs/core/types.cjs +48 -0
- package/dist/cjs/core/types.cjs.map +10 -0
- package/dist/cjs/core/utils/range-serializer.cjs +65 -0
- package/dist/cjs/core/utils/range-serializer.cjs.map +10 -0
- package/dist/cjs/core/utils/spreadsheet-visualizer.cjs +142 -0
- package/dist/cjs/core/utils/spreadsheet-visualizer.cjs.map +10 -0
- package/dist/cjs/core/utils.cjs +434 -0
- package/dist/cjs/core/utils.cjs.map +10 -0
- package/dist/cjs/core/workbook-renamer.cjs +106 -0
- package/dist/cjs/core/workbook-renamer.cjs.map +10 -0
- package/dist/cjs/debug/flags.cjs +47 -0
- package/dist/cjs/debug/flags.cjs.map +10 -0
- package/dist/cjs/evaluator/arithmetic/add/add.cjs +82 -0
- package/dist/cjs/evaluator/arithmetic/add/add.cjs.map +10 -0
- package/dist/cjs/evaluator/arithmetic/divide/divide.cjs +107 -0
- package/dist/cjs/evaluator/arithmetic/divide/divide.cjs.map +10 -0
- package/dist/cjs/evaluator/arithmetic/multiply/multiply.cjs +93 -0
- package/dist/cjs/evaluator/arithmetic/multiply/multiply.cjs.map +10 -0
- package/dist/cjs/evaluator/arithmetic/power/power.cjs +125 -0
- package/dist/cjs/evaluator/arithmetic/power/power.cjs.map +10 -0
- package/dist/cjs/evaluator/arithmetic/subtract/subtract.cjs +84 -0
- package/dist/cjs/evaluator/arithmetic/subtract/subtract.cjs.map +10 -0
- package/dist/cjs/evaluator/comparison/equals.cjs +64 -0
- package/dist/cjs/evaluator/comparison/equals.cjs.map +10 -0
- package/dist/cjs/evaluator/comparison/greater-than-or-equal.cjs +61 -0
- package/dist/cjs/evaluator/comparison/greater-than-or-equal.cjs.map +10 -0
- package/dist/cjs/evaluator/comparison/greater-than.cjs +61 -0
- package/dist/cjs/evaluator/comparison/greater-than.cjs.map +10 -0
- package/dist/cjs/evaluator/comparison/less-than-or-equal.cjs +69 -0
- package/dist/cjs/evaluator/comparison/less-than-or-equal.cjs.map +10 -0
- package/dist/cjs/evaluator/comparison/less-than.cjs +68 -0
- package/dist/cjs/evaluator/comparison/less-than.cjs.map +10 -0
- package/dist/cjs/evaluator/comparison/not-equals.cjs +53 -0
- package/dist/cjs/evaluator/comparison/not-equals.cjs.map +10 -0
- package/dist/cjs/evaluator/concatenation/concatenate.cjs +72 -0
- package/dist/cjs/evaluator/concatenation/concatenate.cjs.map +10 -0
- package/dist/cjs/evaluator/dependency-nodes/ast-evaluation-node.cjs +58 -0
- package/dist/cjs/evaluator/dependency-nodes/ast-evaluation-node.cjs.map +10 -0
- package/dist/cjs/evaluator/dependency-nodes/base-eval-node.cjs +112 -0
- package/dist/cjs/evaluator/dependency-nodes/base-eval-node.cjs.map +10 -0
- package/dist/cjs/evaluator/dependency-nodes/cell-value-node.cjs +54 -0
- package/dist/cjs/evaluator/dependency-nodes/cell-value-node.cjs.map +10 -0
- package/dist/cjs/evaluator/dependency-nodes/empty-cell-evaluation-node.cjs +108 -0
- package/dist/cjs/evaluator/dependency-nodes/empty-cell-evaluation-node.cjs.map +10 -0
- package/dist/cjs/evaluator/dependency-nodes/spill-meta-node.cjs +50 -0
- package/dist/cjs/evaluator/dependency-nodes/spill-meta-node.cjs.map +10 -0
- package/dist/cjs/evaluator/evaluate-scalar-operator.cjs +254 -0
- package/dist/cjs/evaluator/evaluate-scalar-operator.cjs.map +10 -0
- package/dist/cjs/evaluator/evaluation-context.cjs +154 -0
- package/dist/cjs/evaluator/evaluation-context.cjs.map +10 -0
- package/dist/cjs/evaluator/evaluation-error.cjs +75 -0
- package/dist/cjs/evaluator/evaluation-error.cjs.map +10 -0
- package/dist/cjs/evaluator/formula-evaluator.cjs +797 -0
- package/dist/cjs/evaluator/formula-evaluator.cjs.map +10 -0
- package/dist/cjs/evaluator/range-evaluation-node.cjs +88 -0
- package/dist/cjs/evaluator/range-evaluation-node.cjs.map +10 -0
- package/dist/cjs/functions/_template/template.cjs +42 -0
- package/dist/cjs/functions/_template/template.cjs.map +10 -0
- package/dist/cjs/functions/array/sequence/sequence.cjs +315 -0
- package/dist/cjs/functions/array/sequence/sequence.cjs.map +10 -0
- package/dist/cjs/functions/criteria-parser.cjs +217 -0
- package/dist/cjs/functions/criteria-parser.cjs.map +10 -0
- package/dist/cjs/functions/criteria-utils.cjs +291 -0
- package/dist/cjs/functions/criteria-utils.cjs.map +10 -0
- package/dist/cjs/functions/function-utils.cjs +63 -0
- package/dist/cjs/functions/function-utils.cjs.map +10 -0
- package/dist/cjs/functions/index.cjs +125 -0
- package/dist/cjs/functions/index.cjs.map +10 -0
- package/dist/cjs/functions/information/cell/cell.cjs +196 -0
- package/dist/cjs/functions/information/cell/cell.cjs.map +10 -0
- package/dist/cjs/functions/information/column/column.cjs +144 -0
- package/dist/cjs/functions/information/column/column.cjs.map +10 -0
- package/dist/cjs/functions/information/row/row.cjs +150 -0
- package/dist/cjs/functions/information/row/row.cjs.map +10 -0
- package/dist/cjs/functions/logical/and/and.cjs +112 -0
- package/dist/cjs/functions/logical/and/and.cjs.map +10 -0
- package/dist/cjs/functions/logical/if/if.cjs +195 -0
- package/dist/cjs/functions/logical/if/if.cjs.map +10 -0
- package/dist/cjs/functions/logical/iferror/iferror.cjs +126 -0
- package/dist/cjs/functions/logical/iferror/iferror.cjs.map +10 -0
- package/dist/cjs/functions/logical/or/or.cjs +112 -0
- package/dist/cjs/functions/logical/or/or.cjs.map +10 -0
- package/dist/cjs/functions/lookup/count/count-utils.cjs +65 -0
- package/dist/cjs/functions/lookup/count/count-utils.cjs.map +10 -0
- package/dist/cjs/functions/lookup/count/count.cjs +48 -0
- package/dist/cjs/functions/lookup/count/count.cjs.map +10 -0
- package/dist/cjs/functions/lookup/count/countif.cjs +94 -0
- package/dist/cjs/functions/lookup/count/countif.cjs.map +10 -0
- package/dist/cjs/functions/lookup/count/countifs.cjs +63 -0
- package/dist/cjs/functions/lookup/count/countifs.cjs.map +10 -0
- package/dist/cjs/functions/lookup/index-lookup/index-lookup.cjs +187 -0
- package/dist/cjs/functions/lookup/index-lookup/index-lookup.cjs.map +10 -0
- package/dist/cjs/functions/lookup/match/match.cjs +168 -0
- package/dist/cjs/functions/lookup/match/match.cjs.map +10 -0
- package/dist/cjs/functions/lookup/xlookup/xlookup.cjs +410 -0
- package/dist/cjs/functions/lookup/xlookup/xlookup.cjs.map +10 -0
- package/dist/cjs/functions/math/average/average-utils.cjs +72 -0
- package/dist/cjs/functions/math/average/average-utils.cjs.map +10 -0
- package/dist/cjs/functions/math/average/average.cjs +48 -0
- package/dist/cjs/functions/math/average/average.cjs.map +10 -0
- package/dist/cjs/functions/math/average/averageif.cjs +83 -0
- package/dist/cjs/functions/math/average/averageif.cjs.map +10 -0
- package/dist/cjs/functions/math/average/averageifs.cjs +61 -0
- package/dist/cjs/functions/math/average/averageifs.cjs.map +10 -0
- package/dist/cjs/functions/math/ceiling/ceiling.cjs +219 -0
- package/dist/cjs/functions/math/ceiling/ceiling.cjs.map +10 -0
- package/dist/cjs/functions/math/max/max-utils.cjs +71 -0
- package/dist/cjs/functions/math/max/max-utils.cjs.map +10 -0
- package/dist/cjs/functions/math/max/max.cjs +48 -0
- package/dist/cjs/functions/math/max/max.cjs.map +10 -0
- package/dist/cjs/functions/math/max/maxif.cjs +83 -0
- package/dist/cjs/functions/math/max/maxif.cjs.map +10 -0
- package/dist/cjs/functions/math/max/maxifs.cjs +61 -0
- package/dist/cjs/functions/math/max/maxifs.cjs.map +10 -0
- package/dist/cjs/functions/math/min/min-utils.cjs +71 -0
- package/dist/cjs/functions/math/min/min-utils.cjs.map +10 -0
- package/dist/cjs/functions/math/min/min.cjs +48 -0
- package/dist/cjs/functions/math/min/min.cjs.map +10 -0
- package/dist/cjs/functions/math/min/minif.cjs +83 -0
- package/dist/cjs/functions/math/min/minif.cjs.map +10 -0
- package/dist/cjs/functions/math/min/minifs.cjs +61 -0
- package/dist/cjs/functions/math/min/minifs.cjs.map +10 -0
- package/dist/cjs/functions/math/sum/sum.cjs +48 -0
- package/dist/cjs/functions/math/sum/sum.cjs.map +10 -0
- package/dist/cjs/functions/math/sum/sumif.cjs +83 -0
- package/dist/cjs/functions/math/sum/sumif.cjs.map +10 -0
- package/dist/cjs/functions/math/sum/sumifs.cjs +60 -0
- package/dist/cjs/functions/math/sum/sumifs.cjs.map +10 -0
- package/dist/cjs/functions/math/sum/summation-utils.cjs +57 -0
- package/dist/cjs/functions/math/sum/summation-utils.cjs.map +10 -0
- package/dist/cjs/functions/reference/address/address.cjs +163 -0
- package/dist/cjs/functions/reference/address/address.cjs.map +10 -0
- package/dist/cjs/functions/reference/indirect/indirect.cjs +102 -0
- package/dist/cjs/functions/reference/indirect/indirect.cjs.map +10 -0
- package/dist/cjs/functions/reference/offset/offset.cjs +233 -0
- package/dist/cjs/functions/reference/offset/offset.cjs.map +10 -0
- package/dist/cjs/functions/text/concatenate/concatenate.cjs +167 -0
- package/dist/cjs/functions/text/concatenate/concatenate.cjs.map +10 -0
- package/dist/cjs/functions/text/exact/exact.cjs +171 -0
- package/dist/cjs/functions/text/exact/exact.cjs.map +10 -0
- package/dist/cjs/functions/text/find/find.cjs +397 -0
- package/dist/cjs/functions/text/find/find.cjs.map +10 -0
- package/dist/cjs/functions/text/left/left.cjs +109 -0
- package/dist/cjs/functions/text/left/left.cjs.map +10 -0
- package/dist/cjs/functions/text/len/len.cjs +119 -0
- package/dist/cjs/functions/text/len/len.cjs.map +10 -0
- package/dist/cjs/functions/text/mid/mid.cjs +103 -0
- package/dist/cjs/functions/text/mid/mid.cjs.map +10 -0
- package/dist/cjs/functions/text/right/right.cjs +167 -0
- package/dist/cjs/functions/text/right/right.cjs.map +10 -0
- package/dist/cjs/functions/text/text-helpers.cjs +179 -0
- package/dist/cjs/functions/text/text-helpers.cjs.map +10 -0
- package/dist/cjs/functions/text/textjoin/textjoin.cjs +173 -0
- package/dist/cjs/functions/text/textjoin/textjoin.cjs.map +10 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/parser/ast.cjs +175 -0
- package/dist/cjs/parser/ast.cjs.map +10 -0
- package/dist/cjs/parser/formatter.cjs +319 -0
- package/dist/cjs/parser/formatter.cjs.map +10 -0
- package/dist/cjs/parser/grammar.cjs +375 -0
- package/dist/cjs/parser/grammar.cjs.map +10 -0
- package/dist/cjs/parser/lexer.cjs +443 -0
- package/dist/cjs/parser/lexer.cjs.map +10 -0
- package/dist/cjs/parser/parser.cjs +1700 -0
- package/dist/cjs/parser/parser.cjs.map +10 -0
- package/dist/cjs/react/hooks.cjs +59 -0
- package/dist/cjs/react/hooks.cjs.map +10 -0
- package/dist/mjs/core/ast-traverser.mjs +94 -0
- package/dist/mjs/core/ast-traverser.mjs.map +10 -0
- package/dist/mjs/core/autofill-utils.mjs +274 -0
- package/dist/mjs/core/autofill-utils.mjs.map +10 -0
- package/dist/mjs/core/engine.mjs +366 -0
- package/dist/mjs/core/engine.mjs.map +10 -0
- package/dist/mjs/core/managers/cache-manager.mjs +27 -0
- package/dist/mjs/core/managers/cache-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/dependency-manager.mjs +593 -0
- package/dist/mjs/core/managers/dependency-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/dependency-node.mjs +2 -0
- package/dist/mjs/core/managers/dependency-node.mjs.map +9 -0
- package/dist/mjs/core/managers/evaluation-manager.mjs +415 -0
- package/dist/mjs/core/managers/evaluation-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/event-manager.mjs +18 -0
- package/dist/mjs/core/managers/event-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/frontier-dependency-manager.mjs +151 -0
- package/dist/mjs/core/managers/frontier-dependency-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/index.mjs +21 -0
- package/dist/mjs/core/managers/index.mjs.map +10 -0
- package/dist/mjs/core/managers/isDependencyNode.mjs +14 -0
- package/dist/mjs/core/managers/isDependencyNode.mjs.map +10 -0
- package/dist/mjs/core/managers/named-expression-manager.mjs +348 -0
- package/dist/mjs/core/managers/named-expression-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/range-eval-order-builder.mjs +618 -0
- package/dist/mjs/core/managers/range-eval-order-builder.mjs.map +10 -0
- package/dist/mjs/core/managers/table-manager.mjs +224 -0
- package/dist/mjs/core/managers/table-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/workbook-manager.mjs +447 -0
- package/dist/mjs/core/managers/workbook-manager.mjs.map +10 -0
- package/dist/mjs/core/map-serializer.mjs +39 -0
- package/dist/mjs/core/map-serializer.mjs.map +10 -0
- package/dist/mjs/core/named-expression-renamer.mjs +58 -0
- package/dist/mjs/core/named-expression-renamer.mjs.map +10 -0
- package/dist/mjs/core/sheet-renamer.mjs +59 -0
- package/dist/mjs/core/sheet-renamer.mjs.map +10 -0
- package/dist/mjs/core/sheet-utils.mjs +8 -0
- package/dist/mjs/core/sheet-utils.mjs.map +10 -0
- package/dist/mjs/core/table-renamer.mjs +58 -0
- package/dist/mjs/core/table-renamer.mjs.map +10 -0
- package/dist/mjs/core/types.mjs +18 -0
- package/dist/mjs/core/types.mjs.map +10 -0
- package/dist/mjs/core/utils/range-serializer.mjs +35 -0
- package/dist/mjs/core/utils/range-serializer.mjs.map +10 -0
- package/dist/mjs/core/utils/spreadsheet-visualizer.mjs +112 -0
- package/dist/mjs/core/utils/spreadsheet-visualizer.mjs.map +10 -0
- package/dist/mjs/core/utils.mjs +409 -0
- package/dist/mjs/core/utils.mjs.map +10 -0
- package/dist/mjs/core/workbook-renamer.mjs +76 -0
- package/dist/mjs/core/workbook-renamer.mjs.map +10 -0
- package/dist/mjs/debug/flags.mjs +17 -0
- package/dist/mjs/debug/flags.mjs.map +10 -0
- package/dist/mjs/evaluator/arithmetic/add/add.mjs +52 -0
- package/dist/mjs/evaluator/arithmetic/add/add.mjs.map +10 -0
- package/dist/mjs/evaluator/arithmetic/divide/divide.mjs +77 -0
- package/dist/mjs/evaluator/arithmetic/divide/divide.mjs.map +10 -0
- package/dist/mjs/evaluator/arithmetic/multiply/multiply.mjs +63 -0
- package/dist/mjs/evaluator/arithmetic/multiply/multiply.mjs.map +10 -0
- package/dist/mjs/evaluator/arithmetic/power/power.mjs +95 -0
- package/dist/mjs/evaluator/arithmetic/power/power.mjs.map +10 -0
- package/dist/mjs/evaluator/arithmetic/subtract/subtract.mjs +54 -0
- package/dist/mjs/evaluator/arithmetic/subtract/subtract.mjs.map +10 -0
- package/dist/mjs/evaluator/comparison/equals.mjs +34 -0
- package/dist/mjs/evaluator/comparison/equals.mjs.map +10 -0
- package/dist/mjs/evaluator/comparison/greater-than-or-equal.mjs +31 -0
- package/dist/mjs/evaluator/comparison/greater-than-or-equal.mjs.map +10 -0
- package/dist/mjs/evaluator/comparison/greater-than.mjs +31 -0
- package/dist/mjs/evaluator/comparison/greater-than.mjs.map +10 -0
- package/dist/mjs/evaluator/comparison/less-than-or-equal.mjs +39 -0
- package/dist/mjs/evaluator/comparison/less-than-or-equal.mjs.map +10 -0
- package/dist/mjs/evaluator/comparison/less-than.mjs +38 -0
- package/dist/mjs/evaluator/comparison/less-than.mjs.map +10 -0
- package/dist/mjs/evaluator/comparison/not-equals.mjs +23 -0
- package/dist/mjs/evaluator/comparison/not-equals.mjs.map +10 -0
- package/dist/mjs/evaluator/concatenation/concatenate.mjs +42 -0
- package/dist/mjs/evaluator/concatenation/concatenate.mjs.map +10 -0
- package/dist/mjs/evaluator/dependency-nodes/ast-evaluation-node.mjs +28 -0
- package/dist/mjs/evaluator/dependency-nodes/ast-evaluation-node.mjs.map +10 -0
- package/dist/mjs/evaluator/dependency-nodes/base-eval-node.mjs +81 -0
- package/dist/mjs/evaluator/dependency-nodes/base-eval-node.mjs.map +10 -0
- package/dist/mjs/evaluator/dependency-nodes/cell-value-node.mjs +24 -0
- package/dist/mjs/evaluator/dependency-nodes/cell-value-node.mjs.map +10 -0
- package/dist/mjs/evaluator/dependency-nodes/empty-cell-evaluation-node.mjs +78 -0
- package/dist/mjs/evaluator/dependency-nodes/empty-cell-evaluation-node.mjs.map +10 -0
- package/dist/mjs/evaluator/dependency-nodes/spill-meta-node.mjs +20 -0
- package/dist/mjs/evaluator/dependency-nodes/spill-meta-node.mjs.map +10 -0
- package/dist/mjs/evaluator/evaluate-scalar-operator.mjs +226 -0
- package/dist/mjs/evaluator/evaluate-scalar-operator.mjs.map +10 -0
- package/dist/mjs/evaluator/evaluation-context.mjs +123 -0
- package/dist/mjs/evaluator/evaluation-context.mjs.map +10 -0
- package/dist/mjs/evaluator/evaluation-error.mjs +44 -0
- package/dist/mjs/evaluator/evaluation-error.mjs.map +10 -0
- package/dist/mjs/evaluator/formula-evaluator.mjs +780 -0
- package/dist/mjs/evaluator/formula-evaluator.mjs.map +10 -0
- package/dist/mjs/evaluator/range-evaluation-node.mjs +58 -0
- package/dist/mjs/evaluator/range-evaluation-node.mjs.map +10 -0
- package/dist/mjs/functions/_template/template.mjs +12 -0
- package/dist/mjs/functions/_template/template.mjs.map +10 -0
- package/dist/mjs/functions/array/sequence/sequence.mjs +287 -0
- package/dist/mjs/functions/array/sequence/sequence.mjs.map +10 -0
- package/dist/mjs/functions/criteria-parser.mjs +187 -0
- package/dist/mjs/functions/criteria-parser.mjs.map +10 -0
- package/dist/mjs/functions/criteria-utils.mjs +268 -0
- package/dist/mjs/functions/criteria-utils.mjs.map +10 -0
- package/dist/mjs/functions/function-utils.mjs +33 -0
- package/dist/mjs/functions/function-utils.mjs.map +10 -0
- package/dist/mjs/functions/index.mjs +95 -0
- package/dist/mjs/functions/index.mjs.map +10 -0
- package/dist/mjs/functions/information/cell/cell.mjs +168 -0
- package/dist/mjs/functions/information/cell/cell.mjs.map +10 -0
- package/dist/mjs/functions/information/column/column.mjs +120 -0
- package/dist/mjs/functions/information/column/column.mjs.map +10 -0
- package/dist/mjs/functions/information/row/row.mjs +126 -0
- package/dist/mjs/functions/information/row/row.mjs.map +10 -0
- package/dist/mjs/functions/logical/and/and.mjs +84 -0
- package/dist/mjs/functions/logical/and/and.mjs.map +10 -0
- package/dist/mjs/functions/logical/if/if.mjs +167 -0
- package/dist/mjs/functions/logical/if/if.mjs.map +10 -0
- package/dist/mjs/functions/logical/iferror/iferror.mjs +98 -0
- package/dist/mjs/functions/logical/iferror/iferror.mjs.map +10 -0
- package/dist/mjs/functions/logical/or/or.mjs +84 -0
- package/dist/mjs/functions/logical/or/or.mjs.map +10 -0
- package/dist/mjs/functions/lookup/count/count-utils.mjs +35 -0
- package/dist/mjs/functions/lookup/count/count-utils.mjs.map +10 -0
- package/dist/mjs/functions/lookup/count/count.mjs +18 -0
- package/dist/mjs/functions/lookup/count/count.mjs.map +10 -0
- package/dist/mjs/functions/lookup/count/countif.mjs +68 -0
- package/dist/mjs/functions/lookup/count/countif.mjs.map +10 -0
- package/dist/mjs/functions/lookup/count/countifs.mjs +37 -0
- package/dist/mjs/functions/lookup/count/countifs.mjs.map +10 -0
- package/dist/mjs/functions/lookup/index-lookup/index-lookup.mjs +159 -0
- package/dist/mjs/functions/lookup/index-lookup/index-lookup.mjs.map +10 -0
- package/dist/mjs/functions/lookup/match/match.mjs +140 -0
- package/dist/mjs/functions/lookup/match/match.mjs.map +10 -0
- package/dist/mjs/functions/lookup/xlookup/xlookup.mjs +382 -0
- package/dist/mjs/functions/lookup/xlookup/xlookup.mjs.map +10 -0
- package/dist/mjs/functions/math/average/average-utils.mjs +44 -0
- package/dist/mjs/functions/math/average/average-utils.mjs.map +10 -0
- package/dist/mjs/functions/math/average/average.mjs +18 -0
- package/dist/mjs/functions/math/average/average.mjs.map +10 -0
- package/dist/mjs/functions/math/average/averageif.mjs +58 -0
- package/dist/mjs/functions/math/average/averageif.mjs.map +10 -0
- package/dist/mjs/functions/math/average/averageifs.mjs +35 -0
- package/dist/mjs/functions/math/average/averageifs.mjs.map +10 -0
- package/dist/mjs/functions/math/ceiling/ceiling.mjs +191 -0
- package/dist/mjs/functions/math/ceiling/ceiling.mjs.map +10 -0
- package/dist/mjs/functions/math/max/max-utils.mjs +43 -0
- package/dist/mjs/functions/math/max/max-utils.mjs.map +10 -0
- package/dist/mjs/functions/math/max/max.mjs +18 -0
- package/dist/mjs/functions/math/max/max.mjs.map +10 -0
- package/dist/mjs/functions/math/max/maxif.mjs +58 -0
- package/dist/mjs/functions/math/max/maxif.mjs.map +10 -0
- package/dist/mjs/functions/math/max/maxifs.mjs +35 -0
- package/dist/mjs/functions/math/max/maxifs.mjs.map +10 -0
- package/dist/mjs/functions/math/min/min-utils.mjs +43 -0
- package/dist/mjs/functions/math/min/min-utils.mjs.map +10 -0
- package/dist/mjs/functions/math/min/min.mjs +18 -0
- package/dist/mjs/functions/math/min/min.mjs.map +10 -0
- package/dist/mjs/functions/math/min/minif.mjs +58 -0
- package/dist/mjs/functions/math/min/minif.mjs.map +10 -0
- package/dist/mjs/functions/math/min/minifs.mjs +35 -0
- package/dist/mjs/functions/math/min/minifs.mjs.map +10 -0
- package/dist/mjs/functions/math/sum/sum.mjs +18 -0
- package/dist/mjs/functions/math/sum/sum.mjs.map +10 -0
- package/dist/mjs/functions/math/sum/sumif.mjs +58 -0
- package/dist/mjs/functions/math/sum/sumif.mjs.map +10 -0
- package/dist/mjs/functions/math/sum/sumifs.mjs +34 -0
- package/dist/mjs/functions/math/sum/sumifs.mjs.map +10 -0
- package/dist/mjs/functions/math/sum/summation-utils.mjs +27 -0
- package/dist/mjs/functions/math/sum/summation-utils.mjs.map +10 -0
- package/dist/mjs/functions/reference/address/address.mjs +135 -0
- package/dist/mjs/functions/reference/address/address.mjs.map +10 -0
- package/dist/mjs/functions/reference/indirect/indirect.mjs +74 -0
- package/dist/mjs/functions/reference/indirect/indirect.mjs.map +10 -0
- package/dist/mjs/functions/reference/offset/offset.mjs +205 -0
- package/dist/mjs/functions/reference/offset/offset.mjs.map +10 -0
- package/dist/mjs/functions/text/concatenate/concatenate.mjs +139 -0
- package/dist/mjs/functions/text/concatenate/concatenate.mjs.map +10 -0
- package/dist/mjs/functions/text/exact/exact.mjs +143 -0
- package/dist/mjs/functions/text/exact/exact.mjs.map +10 -0
- package/dist/mjs/functions/text/find/find.mjs +369 -0
- package/dist/mjs/functions/text/find/find.mjs.map +10 -0
- package/dist/mjs/functions/text/left/left.mjs +81 -0
- package/dist/mjs/functions/text/left/left.mjs.map +10 -0
- package/dist/mjs/functions/text/len/len.mjs +91 -0
- package/dist/mjs/functions/text/len/len.mjs.map +10 -0
- package/dist/mjs/functions/text/mid/mid.mjs +75 -0
- package/dist/mjs/functions/text/mid/mid.mjs.map +10 -0
- package/dist/mjs/functions/text/right/right.mjs +143 -0
- package/dist/mjs/functions/text/right/right.mjs.map +10 -0
- package/dist/mjs/functions/text/text-helpers.mjs +151 -0
- package/dist/mjs/functions/text/text-helpers.mjs.map +10 -0
- package/dist/mjs/functions/text/textjoin/textjoin.mjs +145 -0
- package/dist/mjs/functions/text/textjoin/textjoin.mjs.map +10 -0
- package/dist/mjs/package.json +5 -0
- package/dist/mjs/parser/ast.mjs +145 -0
- package/dist/mjs/parser/ast.mjs.map +10 -0
- package/dist/mjs/parser/formatter.mjs +289 -0
- package/dist/mjs/parser/formatter.mjs.map +10 -0
- package/dist/mjs/parser/grammar.mjs +345 -0
- package/dist/mjs/parser/grammar.mjs.map +10 -0
- package/dist/mjs/parser/lexer.mjs +412 -0
- package/dist/mjs/parser/lexer.mjs.map +10 -0
- package/dist/mjs/parser/parser.mjs +1692 -0
- package/dist/mjs/parser/parser.mjs.map +10 -0
- package/dist/mjs/react/hooks.mjs +16 -0
- package/dist/mjs/react/hooks.mjs.map +10 -0
- package/dist/types/core/ast-traverser.d.ts +28 -0
- package/dist/types/core/autofill-utils.d.ts +32 -0
- package/dist/types/core/engine.d.ts +184 -0
- package/dist/types/core/managers/cache-manager.d.ts +14 -0
- package/dist/types/core/managers/dependency-manager.d.ts +147 -0
- package/dist/types/core/managers/dependency-node.d.ts +13 -0
- package/dist/types/core/managers/evaluation-manager.d.ts +30 -0
- package/dist/types/core/managers/event-manager.d.ts +8 -0
- package/dist/types/core/managers/frontier-dependency-manager.d.ts +69 -0
- package/dist/types/core/managers/index.d.ts +7 -0
- package/dist/types/core/managers/isDependencyNode.d.ts +2 -0
- package/dist/types/core/managers/named-expression-manager.d.ts +101 -0
- package/dist/types/core/managers/range-eval-order-builder.d.ts +33 -0
- package/dist/types/core/managers/table-manager.d.ts +84 -0
- package/dist/types/core/managers/workbook-manager.d.ts +136 -0
- package/dist/types/core/map-serializer.d.ts +4 -0
- package/dist/types/core/named-expression-renamer.d.ts +21 -0
- package/dist/types/core/sheet-renamer.d.ts +28 -0
- package/dist/types/core/sheet-utils.d.ts +2 -0
- package/dist/types/core/table-renamer.d.ts +21 -0
- package/dist/types/core/types.d.ts +272 -0
- package/dist/types/core/utils/cell-address-parsing.test.d.ts +1 -0
- package/dist/types/core/utils/range-serializer.d.ts +22 -0
- package/dist/types/core/utils/range-serializer.test.d.ts +1 -0
- package/dist/types/core/utils/spreadsheet-visualizer.d.ts +30 -0
- package/dist/types/core/utils.d.ts +48 -0
- package/dist/types/core/workbook-renamer.d.ts +28 -0
- package/dist/types/debug/flags.d.ts +11 -0
- package/dist/types/evaluator/arithmetic/add/add.d.ts +2 -0
- package/dist/types/evaluator/arithmetic/add/add.test.d.ts +1 -0
- package/dist/types/evaluator/arithmetic/divide/divide.d.ts +2 -0
- package/dist/types/evaluator/arithmetic/divide/divide.test.d.ts +1 -0
- package/dist/types/evaluator/arithmetic/multiply/multiply.d.ts +2 -0
- package/dist/types/evaluator/arithmetic/multiply/multiply.test.d.ts +1 -0
- package/dist/types/evaluator/arithmetic/power/power.d.ts +2 -0
- package/dist/types/evaluator/arithmetic/power/power.test.d.ts +1 -0
- package/dist/types/evaluator/arithmetic/subtract/subtract.d.ts +2 -0
- package/dist/types/evaluator/arithmetic/subtract/subtract.test.d.ts +1 -0
- package/dist/types/evaluator/comparison/comparison-operators.test.d.ts +1 -0
- package/dist/types/evaluator/comparison/equals.d.ts +6 -0
- package/dist/types/evaluator/comparison/greater-than-or-equal.d.ts +6 -0
- package/dist/types/evaluator/comparison/greater-than.d.ts +6 -0
- package/dist/types/evaluator/comparison/less-than-or-equal.d.ts +6 -0
- package/dist/types/evaluator/comparison/less-than.d.ts +6 -0
- package/dist/types/evaluator/comparison/not-equals.d.ts +6 -0
- package/dist/types/evaluator/concatenation/concatenate.d.ts +6 -0
- package/dist/types/evaluator/concatenation/concatenate.test.d.ts +1 -0
- package/dist/types/evaluator/dependency-nodes/ast-evaluation-node.d.ts +12 -0
- package/dist/types/evaluator/dependency-nodes/base-eval-node.d.ts +31 -0
- package/dist/types/evaluator/dependency-nodes/cell-value-node.d.ts +10 -0
- package/dist/types/evaluator/dependency-nodes/empty-cell-evaluation-node.d.ts +17 -0
- package/dist/types/evaluator/dependency-nodes/spill-meta-node.d.ts +7 -0
- package/dist/types/evaluator/evaluate-scalar-operator.d.ts +12 -0
- package/dist/types/evaluator/evaluation-context.d.ts +66 -0
- package/dist/types/evaluator/evaluation-error.d.ts +20 -0
- package/dist/types/evaluator/formula-evaluator.d.ts +67 -0
- package/dist/types/evaluator/open-range-evaluator.test.d.ts +1 -0
- package/dist/types/evaluator/range-evaluation-node.d.ts +16 -0
- package/dist/types/functions/_template/template.d.ts +5 -0
- package/dist/types/functions/_template/template.test.d.ts +1 -0
- package/dist/types/functions/array/sequence/performance-test.d.ts +1 -0
- package/dist/types/functions/array/sequence/sequence.d.ts +14 -0
- package/dist/types/functions/array/sequence/sequence.test.d.ts +1 -0
- package/dist/types/functions/criteria-parser.d.ts +27 -0
- package/dist/types/functions/criteria-utils.d.ts +61 -0
- package/dist/types/functions/function-utils.d.ts +21 -0
- package/dist/types/functions/index.d.ts +2 -0
- package/dist/types/functions/information/cell/cell.d.ts +24 -0
- package/dist/types/functions/information/cell/cell.test.d.ts +1 -0
- package/dist/types/functions/information/column/column.d.ts +14 -0
- package/dist/types/functions/information/column/column.test.d.ts +1 -0
- package/dist/types/functions/information/row/row.d.ts +14 -0
- package/dist/types/functions/information/row/row.test.d.ts +1 -0
- package/dist/types/functions/logical/and/and.d.ts +5 -0
- package/dist/types/functions/logical/and/and.test.d.ts +1 -0
- package/dist/types/functions/logical/if/if.d.ts +5 -0
- package/dist/types/functions/logical/if/if.test.d.ts +1 -0
- package/dist/types/functions/logical/iferror/iferror.d.ts +5 -0
- package/dist/types/functions/logical/iferror/iferror.test.d.ts +1 -0
- package/dist/types/functions/logical/or/or.d.ts +5 -0
- package/dist/types/functions/logical/or/or.test.d.ts +1 -0
- package/dist/types/functions/lookup/count/count-utils.d.ts +14 -0
- package/dist/types/functions/lookup/count/count.d.ts +21 -0
- package/dist/types/functions/lookup/count/count.test.d.ts +1 -0
- package/dist/types/functions/lookup/count/countif.d.ts +26 -0
- package/dist/types/functions/lookup/count/countif.test.d.ts +1 -0
- package/dist/types/functions/lookup/count/countifs.d.ts +21 -0
- package/dist/types/functions/lookup/count/countifs.test.d.ts +1 -0
- package/dist/types/functions/lookup/index-lookup/index-lookup.d.ts +2 -0
- package/dist/types/functions/lookup/index-lookup/index-lookup.test.d.ts +1 -0
- package/dist/types/functions/lookup/match/match.d.ts +2 -0
- package/dist/types/functions/lookup/match/match.test.d.ts +1 -0
- package/dist/types/functions/lookup/xlookup/xlookup.d.ts +2 -0
- package/dist/types/functions/lookup/xlookup/xlookup.test.d.ts +1 -0
- package/dist/types/functions/math/average/average-utils.d.ts +10 -0
- package/dist/types/functions/math/average/average.d.ts +18 -0
- package/dist/types/functions/math/average/average.test.d.ts +1 -0
- package/dist/types/functions/math/average/averageif.d.ts +23 -0
- package/dist/types/functions/math/average/averageif.test.d.ts +1 -0
- package/dist/types/functions/math/average/averageifs.d.ts +21 -0
- package/dist/types/functions/math/average/averageifs.test.d.ts +1 -0
- package/dist/types/functions/math/ceiling/ceiling.d.ts +5 -0
- package/dist/types/functions/math/ceiling/ceiling.test.d.ts +1 -0
- package/dist/types/functions/math/max/max-utils.d.ts +20 -0
- package/dist/types/functions/math/max/max.d.ts +18 -0
- package/dist/types/functions/math/max/max.test.d.ts +1 -0
- package/dist/types/functions/math/max/maxif.d.ts +23 -0
- package/dist/types/functions/math/max/maxif.test.d.ts +1 -0
- package/dist/types/functions/math/max/maxifs.d.ts +21 -0
- package/dist/types/functions/math/max/maxifs.test.d.ts +1 -0
- package/dist/types/functions/math/min/min-utils.d.ts +20 -0
- package/dist/types/functions/math/min/min.d.ts +5 -0
- package/dist/types/functions/math/min/min.test.d.ts +1 -0
- package/dist/types/functions/math/min/minif.d.ts +23 -0
- package/dist/types/functions/math/min/minif.test.d.ts +1 -0
- package/dist/types/functions/math/min/minifs.d.ts +21 -0
- package/dist/types/functions/math/min/minifs.test.d.ts +1 -0
- package/dist/types/functions/math/sum/sum.d.ts +5 -0
- package/dist/types/functions/math/sum/sum.test.d.ts +1 -0
- package/dist/types/functions/math/sum/sumif.d.ts +23 -0
- package/dist/types/functions/math/sum/sumif.test.d.ts +1 -0
- package/dist/types/functions/math/sum/sumifs.d.ts +21 -0
- package/dist/types/functions/math/sum/sumifs.test.d.ts +1 -0
- package/dist/types/functions/math/sum/summation-utils.d.ts +19 -0
- package/dist/types/functions/reference/address/address.d.ts +18 -0
- package/dist/types/functions/reference/address/address.test.d.ts +1 -0
- package/dist/types/functions/reference/indirect/indirect.d.ts +20 -0
- package/dist/types/functions/reference/indirect/indirect.test.d.ts +1 -0
- package/dist/types/functions/reference/offset/offset.d.ts +23 -0
- package/dist/types/functions/reference/offset/offset.test.d.ts +1 -0
- package/dist/types/functions/text/concatenate/concatenate.d.ts +5 -0
- package/dist/types/functions/text/concatenate/concatenate.test.d.ts +1 -0
- package/dist/types/functions/text/exact/exact.d.ts +5 -0
- package/dist/types/functions/text/exact/exact.test.d.ts +1 -0
- package/dist/types/functions/text/find/find.d.ts +20 -0
- package/dist/types/functions/text/find/find.test.d.ts +1 -0
- package/dist/types/functions/text/left/left.d.ts +19 -0
- package/dist/types/functions/text/left/left.test.d.ts +1 -0
- package/dist/types/functions/text/len/len.d.ts +16 -0
- package/dist/types/functions/text/len/len.test.d.ts +1 -0
- package/dist/types/functions/text/mid/mid.d.ts +20 -0
- package/dist/types/functions/text/mid/mid.test.d.ts +1 -0
- package/dist/types/functions/text/right/right.d.ts +2 -0
- package/dist/types/functions/text/right/right.test.d.ts +1 -0
- package/dist/types/functions/text/text-helpers.d.ts +27 -0
- package/dist/types/functions/text/textjoin/textjoin.d.ts +5 -0
- package/dist/types/functions/text/textjoin/textjoin.test.d.ts +1 -0
- package/dist/types/parser/ast.d.ts +275 -0
- package/dist/types/parser/formatter.d.ts +6 -0
- package/dist/types/parser/grammar.d.ts +203 -0
- package/dist/types/parser/lexer.d.ts +144 -0
- package/dist/types/parser/parser.d.ts +159 -0
- package/dist/types/react/hooks.d.ts +5 -0
- package/package.json +41 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
+
var __toCommonJS = (from) => {
|
|
7
|
+
var entry = __moduleCache.get(from), desc;
|
|
8
|
+
if (entry)
|
|
9
|
+
return entry;
|
|
10
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
}));
|
|
16
|
+
__moduleCache.set(from, entry);
|
|
17
|
+
return entry;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/functions/lookup/count/countif.ts
|
|
30
|
+
var exports_countif = {};
|
|
31
|
+
__export(exports_countif, {
|
|
32
|
+
COUNTIF: () => COUNTIF
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(exports_countif);
|
|
35
|
+
var import_types = require("src/core/types");
|
|
36
|
+
var import_criteria_utils = require("../../criteria-utils.cjs");
|
|
37
|
+
var import_criteria_parser = require("../../criteria-parser.cjs");
|
|
38
|
+
var import_count_utils = require("./count-utils.cjs");
|
|
39
|
+
var COUNTIF = {
|
|
40
|
+
name: "COUNTIF",
|
|
41
|
+
evaluate: function(node, context) {
|
|
42
|
+
if (node.args.length !== 2) {
|
|
43
|
+
return {
|
|
44
|
+
type: "error",
|
|
45
|
+
err: import_types.FormulaError.VALUE,
|
|
46
|
+
message: "COUNTIF function takes exactly 2 arguments",
|
|
47
|
+
errAddress: context.dependencyNode
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const criteriaRangeResult = this.evaluateNode(node.args[0], context);
|
|
51
|
+
if (criteriaRangeResult.type === "error" || criteriaRangeResult.type === "awaiting-evaluation") {
|
|
52
|
+
return criteriaRangeResult;
|
|
53
|
+
}
|
|
54
|
+
const criteriaResult = this.evaluateNode(node.args[1], context);
|
|
55
|
+
if (criteriaResult.type === "error" || criteriaResult.type === "awaiting-evaluation") {
|
|
56
|
+
return criteriaResult;
|
|
57
|
+
}
|
|
58
|
+
if (criteriaResult.type !== "value") {
|
|
59
|
+
return {
|
|
60
|
+
type: "error",
|
|
61
|
+
err: import_types.FormulaError.VALUE,
|
|
62
|
+
message: "COUNTIF criteria must be a single value",
|
|
63
|
+
errAddress: context.dependencyNode
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const parsedCriteria = import_criteria_parser.parseCriteria(criteriaResult.result);
|
|
67
|
+
if (parsedCriteria.type === "error") {
|
|
68
|
+
return {
|
|
69
|
+
type: "error",
|
|
70
|
+
err: import_types.FormulaError.VALUE,
|
|
71
|
+
message: parsedCriteria.message,
|
|
72
|
+
errAddress: context.dependencyNode
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const countingEmptyCells = import_count_utils.countEmptyCells(criteriaRangeResult, parsedCriteria, context.cellAddress);
|
|
76
|
+
if (countingEmptyCells) {
|
|
77
|
+
return countingEmptyCells;
|
|
78
|
+
}
|
|
79
|
+
let count = 0;
|
|
80
|
+
const results = import_criteria_utils.processMultiCriteriaValues(this, criteriaRangeResult, [{ rangeResult: criteriaRangeResult, parsedCriteria }], context, "col-major");
|
|
81
|
+
if (results.type === "error" || results.type === "awaiting-evaluation") {
|
|
82
|
+
return results;
|
|
83
|
+
}
|
|
84
|
+
for (const result of results.values) {
|
|
85
|
+
count++;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
type: "value",
|
|
89
|
+
result: { type: "number", value: count }
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//# debugId=E5E88BF422DBEF6F64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/functions/lookup/count/countif.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {\n FormulaError,\n type FunctionDefinition,\n type FunctionEvaluationResult,\n} from \"src/core/types\";\nimport type { EvaluationContext } from \"src/evaluator/evaluation-context\";\nimport {\n processMultiCriteriaValues,\n validateSingleCriteriaArgs,\n} from \"../../criteria-utils.cjs\";\nimport { parseCriteria, matchesParsedCriteria } from \"../../criteria-parser.cjs\";\nimport { countEmptyCells } from \"./count-utils.cjs\";\n\n/**\n * COUNTIF function - Counts cells in a range that meet a criteria\n *\n * Usage: COUNTIF(range, criteria)\n *\n * range: The range of cells to evaluate\n * criteria: The criteria to match against. Can be:\n * - Exact value: \"Apple\", 42\n * - Comparison: \">10\", \"<=5\", \"<>0\"\n * - Wildcards: \"App*\", \"?ruit\"\n *\n * Examples:\n * COUNTIF(A1:A10, \"Apple\") - counts cells containing \"Apple\"\n * COUNTIF(B1:B10, \">10\") - counts cells with values greater than 10\n * COUNTIF(C1:C10, \"App*\") - counts cells starting with \"App\"\n *\n * Note:\n * - Supports type coercion for comparisons\n * - Case-sensitive string matching\n * - Wildcards: * matches any sequence, ? matches any single character\n */\n\n/**\n * COUNTIF function implementation\n */\nexport const COUNTIF: FunctionDefinition = {\n name: \"COUNTIF\",\n evaluate: function (node, context): FunctionEvaluationResult {\n // Validate arguments - COUNTIF takes exactly 2 arguments\n if (node.args.length !== 2) {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"COUNTIF function takes exactly 2 arguments\",\n errAddress: context.dependencyNode,\n };\n }\n\n // Evaluate criteria range (first argument)\n const criteriaRangeResult = this.evaluateNode(node.args[0]!, context);\n if (criteriaRangeResult.type === \"error\" || criteriaRangeResult.type === \"awaiting-evaluation\") {\n return criteriaRangeResult;\n }\n\n // Evaluate criteria (second argument)\n const criteriaResult = this.evaluateNode(node.args[1]!, context);\n if (criteriaResult.type === \"error\" || criteriaResult.type === \"awaiting-evaluation\") {\n return criteriaResult;\n }\n\n if (criteriaResult.type !== \"value\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"COUNTIF criteria must be a single value\",\n errAddress: context.dependencyNode,\n };\n }\n\n // Parse criteria\n const parsedCriteria = parseCriteria(criteriaResult.result);\n if (parsedCriteria.type === \"error\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: parsedCriteria.message,\n errAddress: context.dependencyNode,\n };\n }\n\n // Special case: counting empty cells over infinite ranges\n const countingEmptyCells = countEmptyCells(\n criteriaRangeResult,\n parsedCriteria,\n context.cellAddress\n );\n if (countingEmptyCells) {\n return countingEmptyCells;\n }\n\n // Use shared criteria processing - count all matching values (including non-numeric)\n let count = 0;\n\n const results = processMultiCriteriaValues(\n this,\n criteriaRangeResult,\n [{ rangeResult: criteriaRangeResult, parsedCriteria }],\n context,\n \"col-major\"\n );\n\n if (results.type === \"error\" || results.type === \"awaiting-evaluation\") {\n return results;\n }\n\n for (const result of results.values) {\n // COUNTIF counts all matching cells, including errors and non-numeric values\n count++;\n }\n\n return {\n type: \"value\",\n result: { type: \"number\", value: count },\n };\n },\n};\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,IAJP;AASO,IAHP;AAIqD,IAArD;AACgC,IAAhC;AA2BO,IAAM,UAA8B;AAAA,EACzC,MAAM;AAAA,EACN,UAAU,QAAS,CAAC,MAAM,SAAmC;AAAA,IAE3D,IAAI,KAAK,KAAK,WAAW,GAAG;AAAA,MAC1B,OAAO;AAAA,QACL,MAAM;AAAA,QACN,KAAK,0BAAa;AAAA,QAClB,SAAS;AAAA,QACT,YAAY,QAAQ;AAAA,MACtB;AAAA,IACF;AAAA,IAGA,MAAM,sBAAsB,KAAK,aAAa,KAAK,KAAK,IAAK,OAAO;AAAA,IACpE,IAAI,oBAAoB,SAAS,WAAW,oBAAoB,SAAS,uBAAuB;AAAA,MAC9F,OAAO;AAAA,IACT;AAAA,IAGA,MAAM,iBAAiB,KAAK,aAAa,KAAK,KAAK,IAAK,OAAO;AAAA,IAC/D,IAAI,eAAe,SAAS,WAAW,eAAe,SAAS,uBAAuB;AAAA,MACpF,OAAO;AAAA,IACT;AAAA,IAEA,IAAI,eAAe,SAAS,SAAS;AAAA,MACnC,OAAO;AAAA,QACL,MAAM;AAAA,QACN,KAAK,0BAAa;AAAA,QAClB,SAAS;AAAA,QACT,YAAY,QAAQ;AAAA,MACtB;AAAA,IACF;AAAA,IAGA,MAAM,iBAAiB,qCAAc,eAAe,MAAM;AAAA,IAC1D,IAAI,eAAe,SAAS,SAAS;AAAA,MACnC,OAAO;AAAA,QACL,MAAM;AAAA,QACN,KAAK,0BAAa;AAAA,QAClB,SAAS,eAAe;AAAA,QACxB,YAAY,QAAQ;AAAA,MACtB;AAAA,IACF;AAAA,IAGA,MAAM,qBAAqB,mCACzB,qBACA,gBACA,QAAQ,WACV;AAAA,IACA,IAAI,oBAAoB;AAAA,MACtB,OAAO;AAAA,IACT;AAAA,IAGA,IAAI,QAAQ;AAAA,IAEZ,MAAM,UAAU,iDACd,MACA,qBACA,CAAC,EAAE,aAAa,qBAAqB,eAAe,CAAC,GACrD,SACA,WACF;AAAA,IAEA,IAAI,QAAQ,SAAS,WAAW,QAAQ,SAAS,uBAAuB;AAAA,MACtE,OAAO;AAAA,IACT;AAAA,IAEA,WAAW,UAAU,QAAQ,QAAQ;AAAA,MAEnC;AAAA,IACF;AAAA,IAEA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ,EAAE,MAAM,UAAU,OAAO,MAAM;AAAA,IACzC;AAAA;AAEJ;",
|
|
8
|
+
"debugId": "E5E88BF422DBEF6F64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
+
var __toCommonJS = (from) => {
|
|
7
|
+
var entry = __moduleCache.get(from), desc;
|
|
8
|
+
if (entry)
|
|
9
|
+
return entry;
|
|
10
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
}));
|
|
16
|
+
__moduleCache.set(from, entry);
|
|
17
|
+
return entry;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/functions/lookup/count/countifs.ts
|
|
30
|
+
var exports_countifs = {};
|
|
31
|
+
__export(exports_countifs, {
|
|
32
|
+
COUNTIFS: () => COUNTIFS
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(exports_countifs);
|
|
35
|
+
var import_criteria_utils = require("../../criteria-utils.cjs");
|
|
36
|
+
var COUNTIFS = {
|
|
37
|
+
name: "COUNTIFS",
|
|
38
|
+
evaluate: function(node, context) {
|
|
39
|
+
const argError = import_criteria_utils.validateCountifsArgs(node.args.length, context);
|
|
40
|
+
if (argError) {
|
|
41
|
+
return argError;
|
|
42
|
+
}
|
|
43
|
+
const criteriaPairsResult = import_criteria_utils.parseCriteriaPairs.call(this, node, context, this.evaluateNode, 0);
|
|
44
|
+
if ("type" in criteriaPairsResult) {
|
|
45
|
+
return criteriaPairsResult;
|
|
46
|
+
}
|
|
47
|
+
const countRangeResult = criteriaPairsResult[0].rangeResult;
|
|
48
|
+
let count = 0;
|
|
49
|
+
const matchingValues = import_criteria_utils.processMultiCriteriaValues(this, countRangeResult, criteriaPairsResult, context, "col-major");
|
|
50
|
+
if (matchingValues.type === "error" || matchingValues.type === "awaiting-evaluation") {
|
|
51
|
+
return matchingValues;
|
|
52
|
+
}
|
|
53
|
+
for (const result of matchingValues.values) {
|
|
54
|
+
count++;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
type: "value",
|
|
58
|
+
result: { type: "number", value: count }
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//# debugId=E149D62B1FFDA36C64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/functions/lookup/count/countifs.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {\n FormulaError,\n type FunctionDefinition,\n type FunctionEvaluationResult,\n} from \"src/core/types\";\nimport type { EvaluationContext } from \"src/evaluator/evaluation-context\";\nimport { \n parseCriteriaPairs, \n processMultiCriteriaValues, \n validateCountifsArgs \n} from \"../../criteria-utils.cjs\";\n\n/**\n * COUNTIFS function - Counts cells that meet multiple criteria\n * \n * Usage: COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2], ...)\n * \n * criteria_range1: The first range to evaluate against criteria1\n * criteria1: The first criteria to match against\n * criteria_range2, criteria2: Optional additional criteria pairs\n * \n * Examples:\n * COUNTIFS(A1:A10, \"Apple\") - counts cells in A1:A10 that equal \"Apple\"\n * COUNTIFS(A1:A10, \"Apple\", B1:B10, \">10\") - counts where A1:A10 = \"Apple\" AND B1:B10 > 10\n * \n * Note:\n * - All criteria must be satisfied for a cell to be counted\n * - Counts all matching cells, not just numeric ones\n * - Returns 0 if no cells match all criteria\n * - Unlike other IFS functions, COUNTIFS counts the first criteria range itself\n */\nexport const COUNTIFS: FunctionDefinition = {\n name: \"COUNTIFS\",\n evaluate: function (node, context): FunctionEvaluationResult {\n // Validate arguments\n const argError = validateCountifsArgs(node.args.length, context);\n if (argError) {\n return argError;\n }\n\n // Parse criteria pairs starting from argument 0 (COUNTIFS has different syntax)\n const criteriaPairsResult = parseCriteriaPairs.call(this, node, context, this.evaluateNode, 0);\n if ('type' in criteriaPairsResult) {\n return criteriaPairsResult;\n }\n\n // The first criteria range is what we count\n const countRangeResult = criteriaPairsResult[0]!.rangeResult;\n\n // Process values with criteria using generator - count all matching cells (including non-numeric)\n let count = 0;\n\n const matchingValues = processMultiCriteriaValues(\n this,\n countRangeResult,\n criteriaPairsResult,\n context,\n \"col-major\"\n );\n \n if (matchingValues.type === \"error\" || matchingValues.type === \"awaiting-evaluation\") {\n return matchingValues;\n }\n\n for (const result of matchingValues.values) {\n // COUNTIFS counts all matching cells, including errors and non-numeric values\n count++;\n }\n\n return {\n type: \"value\",\n result: { type: \"number\", value: count },\n };\n },\n};\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,IAJP;AAyBO,IAAM,WAA+B;AAAA,EAC1C,MAAM;AAAA,EACN,UAAU,QAAS,CAAC,MAAM,SAAmC;AAAA,IAE3D,MAAM,WAAW,2CAAqB,KAAK,KAAK,QAAQ,OAAO;AAAA,IAC/D,IAAI,UAAU;AAAA,MACZ,OAAO;AAAA,IACT;AAAA,IAGA,MAAM,sBAAsB,yCAAmB,KAAK,MAAM,MAAM,SAAS,KAAK,cAAc,CAAC;AAAA,IAC7F,IAAI,UAAU,qBAAqB;AAAA,MACjC,OAAO;AAAA,IACT;AAAA,IAGA,MAAM,mBAAmB,oBAAoB,GAAI;AAAA,IAGjD,IAAI,QAAQ;AAAA,IAEZ,MAAM,iBAAiB,iDACrB,MACA,kBACA,qBACA,SACA,WACF;AAAA,IAEA,IAAI,eAAe,SAAS,WAAW,eAAe,SAAS,uBAAuB;AAAA,MACpF,OAAO;AAAA,IACT;AAAA,IAEA,WAAW,UAAU,eAAe,QAAQ;AAAA,MAE1C;AAAA,IACF;AAAA,IAEA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ,EAAE,MAAM,UAAU,OAAO,MAAM;AAAA,IACzC;AAAA;AAEJ;",
|
|
8
|
+
"debugId": "E149D62B1FFDA36C64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
+
var __toCommonJS = (from) => {
|
|
7
|
+
var entry = __moduleCache.get(from), desc;
|
|
8
|
+
if (entry)
|
|
9
|
+
return entry;
|
|
10
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
}));
|
|
16
|
+
__moduleCache.set(from, entry);
|
|
17
|
+
return entry;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/functions/lookup/index-lookup/index-lookup.ts
|
|
30
|
+
var exports_index_lookup = {};
|
|
31
|
+
__export(exports_index_lookup, {
|
|
32
|
+
INDEX: () => INDEX
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(exports_index_lookup);
|
|
35
|
+
var import_types = require("src/core/types");
|
|
36
|
+
function getValueFromArray(arrayResult, row, col, context) {
|
|
37
|
+
const dims = arrayResult.spillArea(context.cellAddress);
|
|
38
|
+
const rowIndex = row - 1;
|
|
39
|
+
const colIndex = col - 1;
|
|
40
|
+
const actualRow = dims.start.row + rowIndex;
|
|
41
|
+
const actualCol = dims.start.col + colIndex;
|
|
42
|
+
if (actualRow < 0 || dims.end.row.type === "number" && actualRow > dims.end.row.value) {
|
|
43
|
+
return {
|
|
44
|
+
type: "error",
|
|
45
|
+
err: import_types.FormulaError.REF,
|
|
46
|
+
message: `INDEX: row_num ${row} is out of range`,
|
|
47
|
+
errAddress: context.dependencyNode
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (actualCol < 0 || dims.end.col.type === "number" && actualCol > dims.end.col.value) {
|
|
51
|
+
return {
|
|
52
|
+
type: "error",
|
|
53
|
+
err: import_types.FormulaError.REF,
|
|
54
|
+
message: `INDEX: column_num ${col} is out of range`,
|
|
55
|
+
errAddress: context.dependencyNode
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const spilledAddress = {
|
|
59
|
+
colIndex: actualCol,
|
|
60
|
+
rowIndex: actualRow,
|
|
61
|
+
sheetName: context.cellAddress.sheetName,
|
|
62
|
+
workbookName: context.cellAddress.workbookName
|
|
63
|
+
};
|
|
64
|
+
const spill = {
|
|
65
|
+
address: spilledAddress,
|
|
66
|
+
spillOffset: {
|
|
67
|
+
x: actualCol - dims.start.col,
|
|
68
|
+
y: actualRow - dims.start.row
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const spillResult = arrayResult.evaluate(spill.spillOffset, context);
|
|
72
|
+
if (!spillResult) {
|
|
73
|
+
return {
|
|
74
|
+
type: "error",
|
|
75
|
+
err: import_types.FormulaError.VALUE,
|
|
76
|
+
message: "INDEX: Unable to retrieve value from array",
|
|
77
|
+
errAddress: context.dependencyNode
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (spillResult.type === "error" || spillResult.type === "awaiting-evaluation") {
|
|
81
|
+
return spillResult;
|
|
82
|
+
}
|
|
83
|
+
return spillResult.result;
|
|
84
|
+
}
|
|
85
|
+
var INDEX = {
|
|
86
|
+
name: "INDEX",
|
|
87
|
+
evaluate: function(node, context) {
|
|
88
|
+
if (node.args.length < 2 || node.args.length > 3) {
|
|
89
|
+
return {
|
|
90
|
+
type: "error",
|
|
91
|
+
err: import_types.FormulaError.VALUE,
|
|
92
|
+
message: "INDEX function takes 2 or 3 arguments",
|
|
93
|
+
errAddress: context.dependencyNode
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const arrayResult = this.evaluateNode(node.args[0], context);
|
|
97
|
+
if (arrayResult.type === "error" || arrayResult.type === "awaiting-evaluation") {
|
|
98
|
+
return arrayResult;
|
|
99
|
+
}
|
|
100
|
+
const rowNumResult = this.evaluateNode(node.args[1], context);
|
|
101
|
+
if (rowNumResult.type === "error" || rowNumResult.type === "awaiting-evaluation") {
|
|
102
|
+
return rowNumResult;
|
|
103
|
+
}
|
|
104
|
+
let colNumResult = null;
|
|
105
|
+
if (node.args[2]) {
|
|
106
|
+
colNumResult = this.evaluateNode(node.args[2], context);
|
|
107
|
+
if (colNumResult.type === "error" || colNumResult.type === "awaiting-evaluation") {
|
|
108
|
+
return colNumResult;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (rowNumResult.type === "spilled-values" || colNumResult && colNumResult.type === "spilled-values") {
|
|
112
|
+
return {
|
|
113
|
+
type: "error",
|
|
114
|
+
err: import_types.FormulaError.VALUE,
|
|
115
|
+
message: "INDEX: Spilled row_num/column_num arguments not yet implemented",
|
|
116
|
+
errAddress: context.dependencyNode
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (rowNumResult.result.type !== "number") {
|
|
120
|
+
return {
|
|
121
|
+
type: "error",
|
|
122
|
+
err: import_types.FormulaError.VALUE,
|
|
123
|
+
message: `INDEX row_num must be number, got ${rowNumResult.result.type}`,
|
|
124
|
+
errAddress: context.dependencyNode
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const colNumValue = colNumResult?.result;
|
|
128
|
+
if (colNumValue && colNumValue.type !== "number") {
|
|
129
|
+
return {
|
|
130
|
+
type: "error",
|
|
131
|
+
err: import_types.FormulaError.VALUE,
|
|
132
|
+
message: `INDEX column_num must be number, got ${colNumValue.type}`,
|
|
133
|
+
errAddress: context.dependencyNode
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const rowNum = Math.floor(rowNumResult.result.value);
|
|
137
|
+
const colNum = colNumValue ? Math.floor(colNumValue.value) : 1;
|
|
138
|
+
if (rowNum < 1) {
|
|
139
|
+
return {
|
|
140
|
+
type: "error",
|
|
141
|
+
err: import_types.FormulaError.VALUE,
|
|
142
|
+
message: `INDEX row_num must be >= 1, got ${rowNum}`,
|
|
143
|
+
errAddress: context.dependencyNode
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
if (colNum < 1) {
|
|
147
|
+
return {
|
|
148
|
+
type: "error",
|
|
149
|
+
err: import_types.FormulaError.VALUE,
|
|
150
|
+
message: `INDEX column_num must be >= 1, got ${colNum}`,
|
|
151
|
+
errAddress: context.dependencyNode
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
if (arrayResult.type === "value") {
|
|
155
|
+
if (rowNum !== 1 || colNum !== 1) {
|
|
156
|
+
return {
|
|
157
|
+
type: "error",
|
|
158
|
+
err: import_types.FormulaError.REF,
|
|
159
|
+
message: `INDEX: Single value can only be accessed at [1,1], got [${rowNum},${colNum}]`,
|
|
160
|
+
errAddress: context.dependencyNode
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
type: "value",
|
|
165
|
+
result: arrayResult.result
|
|
166
|
+
};
|
|
167
|
+
} else if (arrayResult.type === "spilled-values") {
|
|
168
|
+
const result = getValueFromArray.call(this, arrayResult, rowNum, colNum, context);
|
|
169
|
+
if (result.type === "error" || result.type === "awaiting-evaluation") {
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
type: "value",
|
|
174
|
+
result
|
|
175
|
+
};
|
|
176
|
+
} else {
|
|
177
|
+
return {
|
|
178
|
+
type: "error",
|
|
179
|
+
err: import_types.FormulaError.VALUE,
|
|
180
|
+
message: "INDEX: Invalid array argument type",
|
|
181
|
+
errAddress: context.dependencyNode
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
//# debugId=727C46D4F1FB23A264756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/functions/lookup/index-lookup/index-lookup.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {\n FormulaError,\n type CellValue,\n type FunctionDefinition,\n type FunctionEvaluationResult,\n type ValueEvaluationResult,\n type SpilledValuesEvaluationResult,\n type CellAddress,\n type SpreadsheetRange,\n type ErrorEvaluationResult,\n} from \"src/core/types\";\nimport type { FormulaEngine } from \"src/core/engine\";\nimport type { FormulaEvaluator } from \"src/evaluator/formula-evaluator\";\nimport type { EvaluationContext } from \"src/evaluator/evaluation-context\";\n\n/**\n * INDEX function - Returns a value from a table or array\n * INDEX(array, row_num, [column_num])\n *\n * STRICT TYPE CHECKING:\n * - array: range/array only\n * - row_num: number only (integer, 1-based)\n * - column_num: number only (integer, 1-based, optional)\n *\n * If array is 1-dimensional (single row or column):\n * - Only row_num is used (treats as a linear array)\n * - column_num is ignored if provided\n *\n * If array is 2-dimensional:\n * - Both row_num and column_num can be used\n * - If column_num is omitted, returns entire row\n */\n\n// Helper function to get value from array at specific position\nfunction getValueFromArray(\n this: FormulaEvaluator,\n arrayResult: SpilledValuesEvaluationResult,\n row: number,\n col: number,\n context: EvaluationContext\n): CellValue | ErrorEvaluationResult {\n const dims = arrayResult.spillArea(context.cellAddress);\n\n // Convert 1-based indices to 0-based\n const rowIndex = row - 1;\n const colIndex = col - 1;\n\n // Calculate actual cell position\n const actualRow = dims.start.row + rowIndex;\n const actualCol = dims.start.col + colIndex;\n\n // Check bounds\n if (\n actualRow < 0 ||\n (dims.end.row.type === \"number\" && actualRow > dims.end.row.value)\n ) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `INDEX: row_num ${row} is out of range`,\n errAddress: context.dependencyNode,\n };\n }\n\n if (\n actualCol < 0 ||\n (dims.end.col.type === \"number\" && actualCol > dims.end.col.value)\n ) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `INDEX: column_num ${col} is out of range`,\n errAddress: context.dependencyNode,\n };\n }\n\n const spilledAddress: CellAddress = {\n colIndex: actualCol,\n rowIndex: actualRow,\n sheetName: context.cellAddress.sheetName,\n workbookName: context.cellAddress.workbookName,\n };\n\n const spill = {\n address: spilledAddress,\n spillOffset: {\n x: actualCol - dims.start.col,\n y: actualRow - dims.start.row,\n },\n };\n\n const spillResult = arrayResult.evaluate(spill.spillOffset, context);\n\n if (!spillResult) {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"INDEX: Unable to retrieve value from array\",\n errAddress: context.dependencyNode,\n };\n }\n\n if (\n spillResult.type === \"error\" ||\n spillResult.type === \"awaiting-evaluation\"\n ) {\n return spillResult;\n }\n\n return spillResult.result;\n}\n\nexport const INDEX: FunctionDefinition = {\n name: \"INDEX\",\n evaluate: function (node, context): FunctionEvaluationResult {\n if (node.args.length < 2 || node.args.length > 3) {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"INDEX function takes 2 or 3 arguments\",\n errAddress: context.dependencyNode,\n };\n }\n\n // Evaluate array argument\n const arrayResult = this.evaluateNode(node.args[0]!, context);\n if (\n arrayResult.type === \"error\" ||\n arrayResult.type === \"awaiting-evaluation\"\n ) {\n return arrayResult;\n }\n\n // Evaluate row_num argument\n const rowNumResult = this.evaluateNode(node.args[1]!, context);\n if (\n rowNumResult.type === \"error\" ||\n rowNumResult.type === \"awaiting-evaluation\"\n ) {\n return rowNumResult;\n }\n\n // Evaluate column_num argument (optional)\n let colNumResult: FunctionEvaluationResult | null = null;\n if (node.args[2]) {\n colNumResult = this.evaluateNode(node.args[2], context);\n if (\n colNumResult.type === \"error\" ||\n colNumResult.type === \"awaiting-evaluation\"\n ) {\n return colNumResult;\n }\n }\n\n // Handle spilled arrays for row_num and col_num (not array which is expected to be a range)\n if (\n rowNumResult.type === \"spilled-values\" ||\n (colNumResult && colNumResult.type === \"spilled-values\")\n ) {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message:\n \"INDEX: Spilled row_num/column_num arguments not yet implemented\",\n errAddress: context.dependencyNode,\n };\n }\n\n // Strict type checking for row_num\n if (rowNumResult.result.type !== \"number\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `INDEX row_num must be number, got ${rowNumResult.result.type}`,\n errAddress: context.dependencyNode,\n };\n }\n\n const colNumValue = colNumResult?.result;\n\n // Strict type checking for column_num if provided\n if (colNumValue && colNumValue.type !== \"number\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `INDEX column_num must be number, got ${colNumValue.type}`,\n errAddress: context.dependencyNode,\n };\n }\n\n // Extract row and column numbers (convert to integers)\n const rowNum = Math.floor(rowNumResult.result.value);\n const colNum = colNumValue ? Math.floor(colNumValue.value) : 1;\n\n // Validate that indices are positive\n if (rowNum < 1) {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `INDEX row_num must be >= 1, got ${rowNum}`,\n errAddress: context.dependencyNode,\n };\n }\n\n if (colNum < 1) {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `INDEX column_num must be >= 1, got ${colNum}`,\n errAddress: context.dependencyNode,\n };\n }\n\n // Handle different array result types\n if (arrayResult.type === \"value\") {\n // Single value case - can only access [1,1]\n if (rowNum !== 1 || colNum !== 1) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `INDEX: Single value can only be accessed at [1,1], got [${rowNum},${colNum}]`,\n errAddress: context.dependencyNode,\n };\n }\n return {\n type: \"value\",\n result: arrayResult.result,\n } satisfies ValueEvaluationResult;\n } else if (arrayResult.type === \"spilled-values\") {\n // Array case - use helper function to get value\n const result = getValueFromArray.call(\n this,\n arrayResult,\n rowNum,\n colNum,\n context\n );\n\n if (result.type === \"error\" || result.type === \"awaiting-evaluation\") {\n return result;\n }\n\n return {\n type: \"value\",\n result,\n } satisfies ValueEvaluationResult;\n } else {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"INDEX: Invalid array argument type\",\n errAddress: context.dependencyNode,\n };\n }\n },\n};\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "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",
|
|
8
|
+
"debugId": "727C46D4F1FB23A264756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
+
var __toCommonJS = (from) => {
|
|
7
|
+
var entry = __moduleCache.get(from), desc;
|
|
8
|
+
if (entry)
|
|
9
|
+
return entry;
|
|
10
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
}));
|
|
16
|
+
__moduleCache.set(from, entry);
|
|
17
|
+
return entry;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/functions/lookup/match/match.ts
|
|
30
|
+
var exports_match = {};
|
|
31
|
+
__export(exports_match, {
|
|
32
|
+
MATCH: () => MATCH
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(exports_match);
|
|
35
|
+
var import_types = require("src/core/types");
|
|
36
|
+
function matchOperation(lookupValue, lookupArray, matchType, context, isHorizontal) {
|
|
37
|
+
if (lookupValue.type !== "string" && lookupValue.type !== "number") {
|
|
38
|
+
return {
|
|
39
|
+
type: "error",
|
|
40
|
+
err: import_types.FormulaError.VALUE,
|
|
41
|
+
message: `MATCH lookup_value must be string or number, got ${lookupValue.type}`,
|
|
42
|
+
errAddress: context.dependencyNode
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (matchType !== -1 && matchType !== 0 && matchType !== 1) {
|
|
46
|
+
return {
|
|
47
|
+
type: "error",
|
|
48
|
+
err: import_types.FormulaError.VALUE,
|
|
49
|
+
message: `MATCH match_type must be -1, 0, or 1, got ${matchType}`,
|
|
50
|
+
errAddress: context.dependencyNode
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (lookupArray.type === "awaiting-evaluation" || lookupArray.type === "error") {
|
|
54
|
+
return lookupArray;
|
|
55
|
+
}
|
|
56
|
+
for (const value of lookupArray.values) {
|
|
57
|
+
if (value.result.type === "value") {
|
|
58
|
+
if (matchType === 0) {
|
|
59
|
+
const arrayValue = value.result.result;
|
|
60
|
+
if (arrayValue.type === lookupValue.type && arrayValue.value === lookupValue.value) {
|
|
61
|
+
const position = isHorizontal ? value.relativePos.x + 1 : value.relativePos.y + 1;
|
|
62
|
+
return {
|
|
63
|
+
type: "value",
|
|
64
|
+
result: { type: "number", value: position }
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
throw new Error("MATCH: approximate match not fully implemented");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
type: "error",
|
|
74
|
+
err: import_types.FormulaError.NA,
|
|
75
|
+
message: "MATCH: lookup_value not found in lookup_array",
|
|
76
|
+
errAddress: context.dependencyNode
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
var MATCH = {
|
|
80
|
+
name: "MATCH",
|
|
81
|
+
evaluate: function(node, context) {
|
|
82
|
+
if (node.args.length < 2 || node.args.length > 3) {
|
|
83
|
+
return {
|
|
84
|
+
type: "error",
|
|
85
|
+
err: import_types.FormulaError.VALUE,
|
|
86
|
+
message: "MATCH function takes 2 or 3 arguments",
|
|
87
|
+
errAddress: context.dependencyNode
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const lookupValueResult = this.evaluateNode(node.args[0], context);
|
|
91
|
+
if (lookupValueResult.type === "error" || lookupValueResult.type === "awaiting-evaluation") {
|
|
92
|
+
return lookupValueResult;
|
|
93
|
+
}
|
|
94
|
+
const lookupArrayResult = this.evaluateNode(node.args[1], context);
|
|
95
|
+
if (lookupArrayResult.type === "error" || lookupArrayResult.type === "awaiting-evaluation") {
|
|
96
|
+
return lookupArrayResult;
|
|
97
|
+
}
|
|
98
|
+
let matchTypeResult = {
|
|
99
|
+
type: "value",
|
|
100
|
+
result: { type: "number", value: 1 }
|
|
101
|
+
};
|
|
102
|
+
if (node.args[2]) {
|
|
103
|
+
matchTypeResult = this.evaluateNode(node.args[2], context);
|
|
104
|
+
if (matchTypeResult.type === "error" || matchTypeResult.type === "awaiting-evaluation") {
|
|
105
|
+
return matchTypeResult;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (lookupValueResult.type === "spilled-values" || matchTypeResult.type === "spilled-values") {
|
|
109
|
+
return {
|
|
110
|
+
type: "error",
|
|
111
|
+
err: import_types.FormulaError.VALUE,
|
|
112
|
+
message: "MATCH: Spilled array arguments not yet implemented",
|
|
113
|
+
errAddress: context.dependencyNode
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (matchTypeResult.result.type !== "number") {
|
|
117
|
+
return {
|
|
118
|
+
type: "error",
|
|
119
|
+
err: import_types.FormulaError.VALUE,
|
|
120
|
+
message: `MATCH match_type must be number, got ${matchTypeResult.result.type}`,
|
|
121
|
+
errAddress: context.dependencyNode
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
let lookupArray = {
|
|
125
|
+
type: "awaiting-evaluation",
|
|
126
|
+
waitingFor: context.dependencyNode,
|
|
127
|
+
errAddress: context.dependencyNode
|
|
128
|
+
};
|
|
129
|
+
let isHorizontal = false;
|
|
130
|
+
if (lookupArrayResult.type === "value") {
|
|
131
|
+
lookupArray = {
|
|
132
|
+
type: "values",
|
|
133
|
+
values: [{ result: lookupArrayResult, relativePos: { x: 0, y: 0 } }]
|
|
134
|
+
};
|
|
135
|
+
isHorizontal = false;
|
|
136
|
+
} else if (lookupArrayResult.type === "spilled-values") {
|
|
137
|
+
const spillArea = lookupArrayResult.spillArea(context.cellAddress);
|
|
138
|
+
const startRow = spillArea.start.row;
|
|
139
|
+
const endRow = spillArea.end.row;
|
|
140
|
+
const startCol = spillArea.start.col;
|
|
141
|
+
const endCol = spillArea.end.col;
|
|
142
|
+
const isSingleRow = endRow.type === "number" && startRow === endRow.value;
|
|
143
|
+
const isSingleCol = endCol.type === "number" && startCol === endCol.value;
|
|
144
|
+
if (!isSingleRow && !isSingleCol) {
|
|
145
|
+
return {
|
|
146
|
+
type: "error",
|
|
147
|
+
err: import_types.FormulaError.VALUE,
|
|
148
|
+
message: "MATCH lookup_array must be a single row or single column (1D array)",
|
|
149
|
+
errAddress: context.dependencyNode
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
if (isSingleRow && isSingleCol) {
|
|
153
|
+
isHorizontal = false;
|
|
154
|
+
} else {
|
|
155
|
+
isHorizontal = isSingleRow;
|
|
156
|
+
}
|
|
157
|
+
lookupArray = lookupArrayResult.evaluateAllCells.call(this, {
|
|
158
|
+
context,
|
|
159
|
+
evaluate: lookupArrayResult.evaluate,
|
|
160
|
+
origin: context.cellAddress,
|
|
161
|
+
lookupOrder: "col-major"
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return matchOperation(lookupValueResult.result, lookupArray, Math.floor(matchTypeResult.result.value), context, isHorizontal);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
//# debugId=AA86A60C3D723EEA64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/functions/lookup/match/match.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {\n FormulaError,\n type CellValue,\n type EvaluateAllCellsResult,\n type FunctionDefinition,\n type FunctionEvaluationResult,\n} from \"src/core/types\";\nimport type { EvaluationContext } from \"src/evaluator/evaluation-context\";\n\n/**\n * MATCH function - Returns the position of a value in an array\n * MATCH(lookup_value, lookup_array, [match_type])\n * match_type: 1 = less than or equal (default), 0 = exact match, -1 = greater than or equal\n *\n * STRICT TYPE CHECKING:\n * - lookup_value: string or number only\n * - lookup_array: array of strings or numbers only\n * - match_type: number only (must be -1, 0, or 1)\n */\n\n// Helper function to perform MATCH operation\nfunction matchOperation(\n lookupValue: CellValue,\n lookupArray: EvaluateAllCellsResult,\n matchType: number,\n context: EvaluationContext,\n isHorizontal: boolean\n): FunctionEvaluationResult {\n // Strict type checking for lookup_value\n if (lookupValue.type !== \"string\" && lookupValue.type !== \"number\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `MATCH lookup_value must be string or number, got ${lookupValue.type}`,\n errAddress: context.dependencyNode,\n };\n }\n\n // Validate match_type\n if (matchType !== -1 && matchType !== 0 && matchType !== 1) {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `MATCH match_type must be -1, 0, or 1, got ${matchType}`,\n errAddress: context.dependencyNode,\n };\n }\n if (\n lookupArray.type === \"awaiting-evaluation\" ||\n lookupArray.type === \"error\"\n ) {\n return lookupArray;\n }\n\n for (const value of lookupArray.values) {\n if (value.result.type === \"value\") {\n if (matchType === 0) {\n // Exact match\n const arrayValue = value.result.result;\n\n if (\n arrayValue.type === lookupValue.type &&\n arrayValue.value === lookupValue.value\n ) {\n // For horizontal arrays (single row), use x position (column index)\n // For vertical arrays (single/multiple columns), use y position (row index)\n const position = isHorizontal\n ? value.relativePos.x + 1\n : value.relativePos.y + 1;\n\n return {\n type: \"value\",\n result: { type: \"number\", value: position },\n }; // 1-based index\n }\n } else {\n // Approximate match (1 or -1) - requires sorted array\n // For now, throw an error until we add sorting validation\n // TODO: Add proper approximate match logic with sorted array validation\n throw new Error(\"MATCH: approximate match not fully implemented\");\n }\n }\n }\n\n return {\n type: \"error\",\n err: FormulaError.NA,\n message: \"MATCH: lookup_value not found in lookup_array\",\n errAddress: context.dependencyNode,\n };\n}\n\nexport const MATCH: FunctionDefinition = {\n name: \"MATCH\",\n evaluate: function (node, context): FunctionEvaluationResult {\n if (node.args.length < 2 || node.args.length > 3) {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"MATCH function takes 2 or 3 arguments\",\n errAddress: context.dependencyNode,\n };\n }\n\n // Evaluate lookup_value\n const lookupValueResult = this.evaluateNode(node.args[0]!, context);\n if (\n lookupValueResult.type === \"error\" ||\n lookupValueResult.type === \"awaiting-evaluation\"\n ) {\n return lookupValueResult;\n }\n\n // Evaluate lookup_array\n const lookupArrayResult = this.evaluateNode(node.args[1]!, context);\n if (\n lookupArrayResult.type === \"error\" ||\n lookupArrayResult.type === \"awaiting-evaluation\"\n ) {\n return lookupArrayResult;\n }\n\n // Evaluate match_type (optional, defaults to 1)\n let matchTypeResult: FunctionEvaluationResult = {\n type: \"value\",\n result: { type: \"number\", value: 1 },\n };\n\n if (node.args[2]) {\n matchTypeResult = this.evaluateNode(node.args[2], context);\n if (\n matchTypeResult.type === \"error\" ||\n matchTypeResult.type === \"awaiting-evaluation\"\n ) {\n return matchTypeResult;\n }\n }\n\n // Handle spilled arrays for lookup_value and match_type (not lookup_array which is expected to be a range)\n if (\n lookupValueResult.type === \"spilled-values\" ||\n matchTypeResult.type === \"spilled-values\"\n ) {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"MATCH: Spilled array arguments not yet implemented\",\n errAddress: context.dependencyNode,\n };\n }\n\n // Strict type checking for match_type\n if (matchTypeResult.result.type !== \"number\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `MATCH match_type must be number, got ${matchTypeResult.result.type}`,\n errAddress: context.dependencyNode,\n };\n }\n\n // Extract lookup_array values\n let lookupArray: EvaluateAllCellsResult = {\n type: \"awaiting-evaluation\",\n waitingFor: context.dependencyNode,\n errAddress: context.dependencyNode,\n };\n let isHorizontal = false;\n\n // Handle direct range arguments (like A:A) before extracting lookup_array values\n\n // Extract lookup_array values for non-infinite ranges\n if (lookupArrayResult.type === \"value\") {\n // Single value case - treat as array with one element\n lookupArray = {\n type: \"values\",\n values: [{ result: lookupArrayResult, relativePos: { x: 0, y: 0 } }],\n };\n isHorizontal = false; // Single value, treat as vertical\n } else if (lookupArrayResult.type === \"spilled-values\") {\n // Validate that lookup_array is 1D (either single row OR single column)\n const spillArea = lookupArrayResult.spillArea(context.cellAddress);\n const startRow = spillArea.start.row;\n const endRow = spillArea.end.row;\n const startCol = spillArea.start.col;\n const endCol = spillArea.end.col;\n\n // Check if it's a single row (horizontal)\n const isSingleRow = endRow.type === \"number\" && startRow === endRow.value;\n\n // Check if it's a single column (vertical)\n const isSingleCol = endCol.type === \"number\" && startCol === endCol.value;\n\n // MATCH requires a 1D array - either single row OR single column, not both or neither\n if (!isSingleRow && !isSingleCol) {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message:\n \"MATCH lookup_array must be a single row or single column (1D array)\",\n errAddress: context.dependencyNode,\n };\n }\n\n // Cannot be both single row AND single column (that would be a single cell, which is handled)\n if (isSingleRow && isSingleCol) {\n // This is actually a single cell, which is fine\n isHorizontal = false; // Treat single cell as vertical\n } else {\n // Horizontal if it's a single row\n isHorizontal = isSingleRow;\n }\n\n // Extract values from spilled array\n lookupArray = lookupArrayResult.evaluateAllCells.call(this, {\n context,\n evaluate: lookupArrayResult.evaluate,\n origin: context.cellAddress,\n lookupOrder: \"col-major\",\n });\n }\n\n // Perform MATCH operation\n return matchOperation(\n lookupValueResult.result,\n lookupArray,\n Math.floor(matchTypeResult.result.value), // Floor to handle decimal inputs\n context,\n isHorizontal\n );\n },\n};\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "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",
|
|
8
|
+
"debugId": "AA86A60C3D723EEA64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|