forked from baidu/amis
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wuduoyi
committed
Apr 1, 2024
1 parent
263355c
commit c3953e5
Showing
19 changed files
with
1,900 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,6 +274,7 @@ | |
"ISREF", | ||
"ISTEXT", | ||
"JIS", | ||
"jstat", | ||
"KURT", | ||
"LARGE", | ||
"Lbls", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/office-viewer/src/excel/formula/eval/evalCriterial.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import {Criteria} from '../parser/parseCriteria'; | ||
|
||
const type2Number = {boolean: 3, string: 2, number: 1}; | ||
|
||
type typeName = keyof typeof type2Number; | ||
|
||
type Value = string | number | boolean | undefined; | ||
|
||
function compareOp(value1: Value, infix: Criteria['op'], value2: Value) { | ||
if (!value1) { | ||
value1 = 0; | ||
} | ||
if (!value2) { | ||
value2 = 0; | ||
} | ||
|
||
if (Array.isArray(value2)) { | ||
return compareOp(value1, infix, value2[0]); | ||
} | ||
|
||
const type1 = typeof value1 as typeName, | ||
type2 = typeof value2 as typeName; | ||
|
||
if (type1 === type2) { | ||
// same type comparison | ||
switch (infix) { | ||
case '=': | ||
return value1 === value2; | ||
case '>': | ||
return value1 > value2; | ||
case '<': | ||
return value1 < value2; | ||
case '<>': | ||
return value1 !== value2; | ||
case '<=': | ||
return value1 <= value2; | ||
case '>=': | ||
return value1 >= value2; | ||
} | ||
} else { | ||
switch (infix) { | ||
case '=': | ||
return false; | ||
case '>': | ||
return type2Number[type1] > type2Number[type2]; | ||
case '<': | ||
return type2Number[type1] < type2Number[type2]; | ||
case '<>': | ||
return true; | ||
case '<=': | ||
return type2Number[type1] <= type2Number[type2]; | ||
case '>=': | ||
return type2Number[type1] >= type2Number[type2]; | ||
} | ||
} | ||
throw Error('Infix.compareOp: Should not reach here.'); | ||
} | ||
|
||
export function evalCriterial( | ||
criteria: Criteria, | ||
value: string | number | boolean | ||
): boolean { | ||
if (criteria.op === 'wc') { | ||
return criteria.match === (criteria.value as RegExp).test('' + value); | ||
} | ||
|
||
return compareOp(value, criteria.op, criteria.value as Value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.