diff --git a/src/lib/utils/valueParser.ts b/src/lib/utils/valueParser.ts index 3b8fcf5..389f3ec 100644 --- a/src/lib/utils/valueParser.ts +++ b/src/lib/utils/valueParser.ts @@ -11,15 +11,18 @@ const PREFIX: Record = { }; // Parses a human value string into a base-SI number (Farads, Ohms, Henrys, Hz). +// - u and µ are both accepted as micro (1e-6) +// - Hz must come before H in the alternation to avoid "kHz" being parsed as kH (kiloHenry) +// - No /i flag: m (milli) and M (mega) are case-sensitive +// - Unit is optional: "10k" and "100u" parse correctly without a trailing letter // Returns null if unparseable (e.g. part codes like "BC547", "1N4148"). export function parseValueNumeric(value: string | null | undefined): number | null { if (!value) return null; const s = value.trim(); - // Match: digits, optional decimal, optional SI prefix, optional unit letters - // Handles: "100µF", "10kΩ", "4.7uH", "32.768kHz", "47R", "1M", "220" - const match = s.match(/^([0-9]+(?:\.[0-9]+)?)\s*([pnuµmkKMG]?)\s*([FHhzΩRω]|Hz|hz|Ohm|ohm)?/i); + // Match: number + optional SI prefix + optional unit (Hz before H to avoid early match) + const match = s.match(/^(\d+(?:\.\d+)?)\s*([pnuµmkKMG]?)\s*(Hz|Ohm|[FHΩRf])?/); if (!match) return null; const num = parseFloat(match[1]); diff --git a/src/routes/(app)/parts/new/+page.server.ts b/src/routes/(app)/parts/new/+page.server.ts index 6130c1b..b4a7631 100644 --- a/src/routes/(app)/parts/new/+page.server.ts +++ b/src/routes/(app)/parts/new/+page.server.ts @@ -41,7 +41,7 @@ export const actions: Actions = { const data = result.data; - const [part] = await db + await db .insert(parts) .values({ name: data.name || null, @@ -58,9 +58,8 @@ export const actions: Actions = { unit: data.unit, locationId: data.locationId || null, notes: data.notes || null - }) - .returning({ id: parts.id }); + }); - redirect(303, `/parts/${part!.id}`); + redirect(303, '/parts'); } };