refactor: extract pick() helper, deduplicate random selection

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-08 21:42:11 +00:00
co-authored by Claude Opus 4.6
parent 88ceba43b0
commit ea716c1f0e
3 changed files with 30 additions and 19 deletions
+10
View File
@@ -0,0 +1,10 @@
/** Pick a random element from an array */
export function pick<T>(arr: T[]): T {
return arr[Math.floor(Math.random() * arr.length)]
}
/** Wrap an unknown thrown value into an Error */
export function toError(err: unknown): Error {
if (err instanceof Error) return err
return new Error(String(err))
}