okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-0243-guifix into f-0243-rel9caf39495

main
639 B9 linesraw
1/** A number typed by a person: "0.95", ".95", "0,95" (a comma is a decimal point in many languages). null while it is not a whole number yet ("", ".", "0.", "-"). */
2export function parseDecimal(text: string): number | null {
3  const t = String(text ?? '').trim().replace(',', '.');
4  if (!/^-?(\d+\.?\d*|\.\d+)$/.test(t) || t.endsWith('.')) return null;
5  const n = Number(t);
6  return Number.isFinite(n) ? n : null;
7}
8/** Whether what is typed could still become a number: the field keeps it while the person is in the middle of "0." */
9export const partialDecimal = (text: string) => /^-?\d*[.,]?\d*$/.test(String(text ?? '').trim());