Skip to content

Commit

Permalink
Warn on unknown time unit on derivative and integral
Browse files Browse the repository at this point in the history
  • Loading branch information
dbuezas committed Jan 27, 2023
1 parent 3aa57d9 commit e7d1506
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/filters/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const filters = {
x: +xs[0],
y: NaN,
};
checkTimeUnits(unit);
return {
meta: {
...meta,
Expand All @@ -119,6 +120,7 @@ const filters = {
integrate:
(unit: keyof typeof timeUnits = "h") =>
({ xs, ys, meta }) => {
checkTimeUnits(unit);
let yAcc = 0;
let last = {
x: NaN,
Expand Down Expand Up @@ -284,3 +286,10 @@ const filters = {
},
} satisfies Record<string, (...args: any[]) => FilterFn>;
export default filters;
function checkTimeUnits(unit: string) {
if (!timeUnits[unit]) {
throw new Error(
`Unit '${unit}' is not valid, use ${Object.keys(timeUnits)}`
);
}
}

0 comments on commit e7d1506

Please sign in to comment.