From 4e91572c96daf50291cb9bfe58713ed22b940ed2 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 30 May 2024 10:14:27 -0700 Subject: [PATCH] hello: Add safety assertions. Signed-off-by: Anders Kaseorg --- web/src/portico/hello.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web/src/portico/hello.ts b/web/src/portico/hello.ts index 60dc9d1ed1..e5a2a57273 100644 --- a/web/src/portico/hello.ts +++ b/web/src/portico/hello.ts @@ -1,12 +1,13 @@ -// Mark this as a module for ESLint and Webpack. -export {}; +import assert from "minimalistic-assert"; function get_new_rand(old_random_int: number, max: number): number { + assert(max >= 2); const random_int = Math.floor(Math.random() * max); return random_int === old_random_int ? get_new_rand(random_int, max) : random_int; } function get_random_item_from_array(array: T[]): T { + assert(array.length >= 1); return array[Math.floor(Math.random() * array.length)]; }