okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
9caf39495
main
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 { 3const t = String ( text ?? '' ). trim (). replace ( ',' , '.' ); 4if ( ! /^-?(\d+\.?\d*|\.\d+)$ / . test ( t ) || t . endsWith ( '.' )) return null ; 5const n = Number ( t ); 6return 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 ());