Skip to content

Commit e7d1506

Browse files
committed
Warn on unknown time unit on derivative and integral
1 parent 3aa57d9 commit e7d1506

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/filters/filters.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const filters = {
100100
x: +xs[0],
101101
y: NaN,
102102
};
103+
checkTimeUnits(unit);
103104
return {
104105
meta: {
105106
...meta,
@@ -119,6 +120,7 @@ const filters = {
119120
integrate:
120121
(unit: keyof typeof timeUnits = "h") =>
121122
({ xs, ys, meta }) => {
123+
checkTimeUnits(unit);
122124
let yAcc = 0;
123125
let last = {
124126
x: NaN,
@@ -284,3 +286,10 @@ const filters = {
284286
},
285287
} satisfies Record<string, (...args: any[]) => FilterFn>;
286288
export default filters;
289+
function checkTimeUnits(unit: string) {
290+
if (!timeUnits[unit]) {
291+
throw new Error(
292+
`Unit '${unit}' is not valid, use ${Object.keys(timeUnits)}`
293+
);
294+
}
295+
}

0 commit comments

Comments
 (0)