From 17c55f3e89557863dd3f272ae31d0a167b700bf4 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Thu, 2 Apr 2026 20:52:50 +0200 Subject: [PATCH] Add functions for reading finite numbers and positive integers from draft --- src/app/App.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/app/App.tsx b/src/app/App.tsx index ba124bd4..e2cccf3f 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -287,6 +287,26 @@ function readNonNegativeNumberDraft(source: string, label: string): number { return value; } +function readFiniteNumberDraft(source: string, label: string): number { + const value = Number(source); + + if (!Number.isFinite(value)) { + throw new Error(`${label} must be a finite number.`); + } + + return value; +} + +function readPositiveIntegerDraft(source: string, label: string): number { + const value = Number(source); + + if (!Number.isFinite(value) || value <= 0 || !Number.isInteger(value)) { + throw new Error(`${label} must be a positive integer.`); + } + + return value; +} + function readPositiveNumberDraft(source: string, label: string): number { const value = Number(source);