scryfall / google-sheets

Custom =SCRYFALL() function for Google Sheets
69 stars 12 forks source link

Numeric values are not numeric #21

Open skibulk opened 7 months ago

skibulk commented 7 months ago

Numbers such as prices.usd and edhrec_rank should be type cast to numbers. Failure to do so breaks a couple things in Google Sheets:

  1. "Number" formatting won't be applied, including the dollar sign and commas.
  2. Functions which compare numbers won't work, such as GTE (greater than or equal).

There are similar problems with empty strings, Booleans, and dates.

To fix this, I recommend replacing lines 90 and 91 as follows:

      if (typeof val === "string") {
        if(val == "") {
          val = null;
        } else if(val == "TRUE"){
          val = true;
        } else if(val == "FALSE"){
          val = false;
        } else if(!isNaN(val) && !isNaN(parseFloat(val))){
          val = +val;
        } else {
          let d = val.match(/^\d{4}-\d{2}-\d{2}$/);
          if(d) {
            val = new Date(val);
          } else {
            // add extra line breaks for readability
            val = val.replace(/\n/g, "\n\n");
          }
        }
      }