mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-05-27 12:55:20 -07:00
21 lines
461 B
TypeScript
21 lines
461 B
TypeScript
export type OptionalNumberInputParseResult =
|
|
| {
|
|
ok: true;
|
|
value: number | undefined;
|
|
}
|
|
| {
|
|
ok: false;
|
|
};
|
|
|
|
export function parseOptionalNumberInputValue(value: string): OptionalNumberInputParseResult {
|
|
const raw = value.trim();
|
|
if (raw.length === 0) {
|
|
return { ok: true, value: undefined };
|
|
}
|
|
const next = Number(raw);
|
|
if (!Number.isFinite(next)) {
|
|
return { ok: false };
|
|
}
|
|
return { ok: true, value: next };
|
|
}
|