Skip to content

Commit

Permalink
fix for #158 by returning NaN when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Dec 5, 2023
1 parent 30a659c commit fa4db16
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions js/csq.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ var CSQ = function (info_csq, csq_names, numeric_fields) {

return new Proxy(csq, {
get: function (target, name) {
if (name in target._names) {
var result = target._values[target._names[name]];
if (target._numeric_fields[name]) {
result = parseFloat(result);
}
if (!(name in target._names)) {
throw "unknown CSQ field: " + name;
}

return result
var result = target._values[target._names[name]];
if (target._numeric_fields[name]) {
if(result.length == 0 || isNaN(result)) {
result = NaN
} else {
try {
result = parseFloat(result);
} catch(e) { result = NaN }
}
}
throw "unknown CSQ field: " + name;
return result
}
});
};
Expand All @@ -31,4 +37,4 @@ function CSQs(csq_string, vcf_csq, numeric_fields) {

csqs = csq_string.split(',');
return csqs.map(function (csq) { return new CSQ(csq, vcf_csq, numeric_fields); });
}
}

0 comments on commit fa4db16

Please sign in to comment.