Skip to content

Commit 2d6d16c

Browse files
authored
Merge pull request #284 from bids-standard/feat/minmax
feat: Support min/max of single numbers
2 parents f519b84 + d88efd6 commit 2d6d16c

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
### Changed
2+
3+
- Support `min()` and `max()` of numbers in the expression language.
4+
This allows for simpler rules when a field may be a number or array of numbers.
5+
6+
<!--
7+
### Fixed
8+
9+
- A bullet item for the Fixed category.
10+
11+
-->
12+
<!--
13+
### Deprecated
14+
15+
- A bullet item for the Deprecated category.
16+
17+
-->
18+
<!--
19+
### Removed
20+
21+
- A bullet item for the Removed category.
22+
23+
-->
24+
<!--
25+
### Security
26+
27+
- A bullet item for the Security category.
28+
29+
-->
30+
<!--
31+
### Infrastructure
32+
33+
- A bullet item for the Infrastructure category.
34+
35+
-->

src/schema/expressionLanguage.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,23 @@ export const expressionFunctions = {
7979
}
8080
return typeof operand
8181
},
82-
min: (list: number[]): number | null => {
83-
return list != null ? Math.min(...list.map(Number).filter((x) => !isNaN(x))) : null
82+
min: (list: number | number[]): number | null => {
83+
if (list == null) {
84+
return null
85+
}
86+
if (!Array.isArray(list)) {
87+
list = [list]
88+
}
89+
return Math.min(...list.map(Number).filter((x) => !isNaN(x)))
8490
},
85-
max: (list: number[]): number | null => {
86-
return list != null ? Math.max(...list.map(Number).filter((x) => !isNaN(x))) : null
91+
max: (list: number | number[]): number | null => {
92+
if (list == null) {
93+
return null
94+
}
95+
if (!Array.isArray(list)) {
96+
list = [list]
97+
}
98+
return Math.max(...list.map(Number).filter((x) => !isNaN(x)))
8799
},
88100
length: <T>(list: T[]): number | null => {
89101
if (Array.isArray(list) || typeof list == 'string') {

0 commit comments

Comments
 (0)