refactor(pure): remove duplicate regex and dead empty-string guard

This commit is contained in:
dev
2026-06-01 15:24:55 -05:00
parent e0540468c3
commit 545cf65beb
2 changed files with 2 additions and 4 deletions
+1 -4
View File
@@ -11,15 +11,12 @@ export function parseTarget(input) {
if (typeof input !== 'string') return null;
const cleaned = input.replace(/,/g, '').trim().toLowerCase();
if (cleaned === '') return null;
// Reject anything other than digits, optional decimal, and optional single trailing suffix letter
if (!/^\d+(\.\d+)?[kmbt]?$/.test(cleaned)) return null;
const match = cleaned.match(/^(\d+(?:\.\d+)?)([kmbt])?$/);
if (!match) return null;
const num = parseFloat(match[1]);
// regex permits '0'; reject it
if (!Number.isFinite(num) || num <= 0) return null;
const suffix = match[2];
+1
View File
@@ -30,4 +30,5 @@ test('parseTarget: rejects invalid input', () => {
assert.equal(parseTarget(undefined), null);
assert.equal(parseTarget('25M.5'), null);
assert.equal(parseTarget('1.5.5M'), null);
assert.equal(parseTarget('0'), null);
});