From 8f24ffe3101c04100bfa79183f9cdf2e81588f5b Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Sat, 16 May 2026 00:23:22 +0000 Subject: [PATCH] [Refactor] Simplify tryParseInt utility Refactor the tryParseInt utility in packages/cli-kit/src/public/common/string.ts to use early returns and explicit Number namespace methods for better clarity and consistency. --- .jules/refactor.md | 0 packages/cli-kit/src/public/common/string.ts | 11 +++-------- 2 files changed, 3 insertions(+), 8 deletions(-) create mode 100644 .jules/refactor.md diff --git a/.jules/refactor.md b/.jules/refactor.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/cli-kit/src/public/common/string.ts b/packages/cli-kit/src/public/common/string.ts index 0e3e295df4d..8ead23e1437 100644 --- a/packages/cli-kit/src/public/common/string.ts +++ b/packages/cli-kit/src/public/common/string.ts @@ -234,14 +234,9 @@ export function pluralize< * @returns The int if it was able to convert, otherwise undefined. */ export function tryParseInt(maybeInt: string | undefined): number | undefined { - let asInt: number | undefined - if (maybeInt !== undefined) { - asInt = parseInt(maybeInt, 10) - if (isNaN(asInt)) { - asInt = undefined - } - } - return asInt + if (maybeInt === undefined) return undefined + const asInt = Number.parseInt(maybeInt, 10) + return Number.isNaN(asInt) ? undefined : asInt } /**