web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

index.ts (490B)


      1 export const parse_int = (val: string, fallback: number = 0): number => {
      2     const num = parseInt(val);
      3     return isNaN(num) ? fallback : num;
      4 };
      5 
      6 export const parse_float = (val: string, fallback: number = 0): number => {
      7     const num = parseFloat(val);
      8     return isNaN(num) ? fallback : num;
      9 };
     10 
     11 export const num_str = (num: number): string => num.toString();
     12 
     13 export const num_interval_range = (min: number, max: number): number => Math.floor(Math.random() * (max - min + 1)) + min;