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:
Vincent Vandemeulebrouck
2021-03-22 20:10:37 +01:00
parent 2b6d1d8de1
commit 25d7a447a8
14 changed files with 543 additions and 483 deletions

View File

@ -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 ?? {}
}
}