From 7dbf0370afe33b2c93aa91f49f794fb3a30b5a48 Mon Sep 17 00:00:00 2001 From: Cody Olsen Date: Sat, 5 Dec 2020 03:31:10 +0100 Subject: [PATCH] fix: guard against NaN in minSnap and maxSnap handlers --- src/utils.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 9231d1da..ebc91d26 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -42,10 +42,18 @@ export function processSnapPoints(unsafeSnaps: number | number[], maxHeight) { return acc }, new Set()), ] + const minSnap = Math.min(...snapPoints) + if (Number.isNaN(minSnap)) { + throw new TypeError('minSnap is NaN') + } + const maxSnap = Math.max(...snapPoints) + if (Number.isNaN(maxSnap)) { + throw new TypeError('maxSnap is NaN') + } return { snapPoints, - minSnap: Math.min(...snapPoints), - maxSnap: Math.max(...snapPoints), + minSnap, + maxSnap, } }