Skip to content

Commit

Permalink
Properly handle cases where tradable/marketable/commodity is actually…
Browse files Browse the repository at this point in the history
… a bool
  • Loading branch information
DoctorMcKay committed Apr 17, 2024
1 parent 9d5509c commit 71c9151
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/classes/EconItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ function EconItem(item) {
this.market_actions = fixArray(this.market_actions);
this.tags = fixTags(this.tags);

this.tradable = !!parseInt(this.tradable, 10);
this.marketable = !!parseInt(this.marketable, 10);
this.commodity = !!parseInt(this.commodity, 10);
this.tradable = fixBool(this.tradable);
this.marketable = fixBool(this.marketable);
this.commodity = fixBool(this.commodity);
this.market_tradable_restriction = (this.market_tradable_restriction ? parseInt(this.market_tradable_restriction, 10) : 0);
this.market_marketable_restriction = (this.market_marketable_restriction ? parseInt(this.market_marketable_restriction, 10) : 0);

Expand All @@ -43,6 +43,10 @@ function EconItem(item) {
}
}

function fixBool(val) {
return typeof val == 'boolean' ? val : !!parseInt(val, 10);
}

function fixArray(obj) {
if (typeof obj === 'undefined' || obj == '') {
return [];
Expand Down

0 comments on commit 71c9151

Please sign in to comment.