Preparation access documentData
Ajout de méthode Misc.data pour accéder aux data des Actor/Item Dans le cas où on est sur un Actor/Item, retourne le document (noeud data) Dans les autres cas, retourne l'objet lkui même (donc, le document) Du coup, on devrait pouvoir facilement changer en 0.8.0
This commit is contained in:
@ -6,26 +6,24 @@
|
||||
export class Misc {
|
||||
static isFunction(v) {
|
||||
return v && {}.toString.call(v) === '[object Function]';
|
||||
}
|
||||
}
|
||||
|
||||
static upperFirst(text) {
|
||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
}
|
||||
|
||||
static toSignedString(number){
|
||||
static toSignedString(number) {
|
||||
const value = parseInt(number)
|
||||
const isPositiveNumber = value != NaN && value > 0;
|
||||
return isPositiveNumber ? "+"+number : number
|
||||
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)
|
||||
{
|
||||
static toInt(value) {
|
||||
if (value == undefined) {
|
||||
return 0;
|
||||
}
|
||||
const parsed = parseInt(value);
|
||||
@ -78,4 +76,25 @@ export class Misc {
|
||||
return [...new Set(array)];
|
||||
}
|
||||
|
||||
static actorData(actor) {
|
||||
return Misc.data(actor);
|
||||
}
|
||||
|
||||
static itemData(item) {
|
||||
return Misc.data(item);
|
||||
}
|
||||
|
||||
static data(it) {
|
||||
if (it instanceof Item) {
|
||||
return it.data;
|
||||
}
|
||||
if (it instanceof Actor) {
|
||||
return it.data;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
static templateData(it) {
|
||||
return Misc.data(it)?.data ?? {}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user