2020-11-14 03:16:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is intended as a placeholder for utility methods unrelated
|
|
|
|
* to actual classes of the game system or of FoundryVTT
|
|
|
|
*/
|
|
|
|
export class Misc {
|
2020-11-15 02:07:41 +01:00
|
|
|
static upperFirst(text) {
|
2020-11-14 03:16:03 +01:00
|
|
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
|
|
}
|
2020-11-15 02:07:41 +01:00
|
|
|
static toSignedString(number){
|
|
|
|
const value = parseInt(number)
|
|
|
|
const isPositiveNumber = value != NaN && value > 0;
|
|
|
|
return isPositiveNumber ? "+"+number : number
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Converts the value to an integer, or to 0 if undefined/null/not representing integer
|
|
|
|
* @param {*} value value to convert to an integer using parseInt
|
|
|
|
*/
|
|
|
|
static toInt(value)
|
|
|
|
{
|
|
|
|
if (value == undefined)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const parsed = parseInt(value);
|
|
|
|
return isNaN(parsed) ? 0 : parsed;
|
|
|
|
}
|
2020-11-14 03:16:03 +01:00
|
|
|
}
|