name:
src/main/js/formulas/info/TYPE.ts
-rw-r--r--
1202
1import { isNull } from "../../utils/Other";
2import { F7Exception } from "../../errors/F7Exception";
3import { Grid } from "../../models/common/Grid";
4import { SheetColumnRowKey } from "../../models/common/SheetColumnRowKey";
5import { Complex } from "../../models/common/Types";
6import { Converters } from "../../utils/Converters";
7import { AbstractFormula } from "../AbstractFormula";
8import { FormulaName } from "../FormulaName";
9
10export class TYPE extends AbstractFormula {
11 static SELF: TYPE = new TYPE();
12 NAME = FormulaName.TYPE;
13
14 internal(origin: SheetColumnRowKey, ...values: Array<Complex>) {
15 AbstractFormula.checkLength(values.length, 1, this.NAME);
16 const value = this.collateralLookup(origin, values[0]);
17 if (isNull(value) || typeof value === "number") {
18 return 1;
19 }
20 if (typeof value === "string") {
21 return 2;
22 }
23 if (typeof value === "boolean") {
24 return 4;
25 }
26 if (value instanceof F7Exception) {
27 return 16;
28 }
29 if (value instanceof Grid) {
30 const grid = Converters.castAsGrid(value);
31 if (grid.isSingle()) {
32 return TYPE.SELF.run(origin, grid.get(0, 0));
33 }
34 return 64;
35 }
36 return 128;
37 }
38}