gw2e-account-statistics 3.13.0 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,8 @@ exports.default = function (accountData) {
8
8
  wvwRank: wvwRank(accountData),
9
9
  playtime: playtime(accountData),
10
10
  playtimePerDay: playtimePerDay(accountData),
11
- _luckFromAccount: luckFromAccount(accountData)
11
+ _luckFromAccount: luckFromAccount(accountData),
12
+ totalStorageSlots: totalStorageSlots(accountData)
12
13
  };
13
14
  };
14
15
 
@@ -82,4 +83,23 @@ function luckFromAccount(accountData) {
82
83
  }
83
84
 
84
85
  return accountData.luck;
86
+ }
87
+
88
+ // Total Storage Slots on the account
89
+ function totalStorageSlots(accountData) {
90
+ if (!accountData.characters || !accountData.bank || !accountData.shared) {
91
+ return null;
92
+ }
93
+
94
+ var totalInventorySlots = accountData.characters.reduce(function (totalInventorySlots, character) {
95
+ return totalInventorySlots + (character.bags || []).filter(Boolean).reduce(function (totalLength, elem) {
96
+ return totalLength + (elem.inventory || []).length;
97
+ }, 0);
98
+ }, 0);
99
+
100
+ var totalBankSlots = accountData.bank.length || 0;
101
+
102
+ var totalSharedSlots = accountData.shared.length || 0;
103
+
104
+ return (totalInventorySlots || 0) + (totalBankSlots || 0) + (totalSharedSlots || 0);
85
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gw2e-account-statistics",
3
- "version": "3.13.0",
3
+ "version": "3.14.0",
4
4
  "description": "Calculate statistics of guildwars2 accounts",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -38,4 +38,11 @@ describe('statistics > account', () => {
38
38
  expect(accountStatistics({luck: null})._luckFromAccount).to.equal(null)
39
39
  expect(accountStatistics({luck: 120})._luckFromAccount).to.equal(120)
40
40
  })
41
+
42
+ it('can calculate total storage slots', () => {
43
+ expect(accountStatistics({}).totalStorageSlots).to.equal(null)
44
+ expect(accountStatistics({characters: null, bank: null, shared: null}).totalStorageSlots).to.equal(null)
45
+ expect(accountStatistics({characters: [], bank: null, shared: [1, 2]}).totalStorageSlots).to.equal(null)
46
+ expect(accountStatistics({characters: [{bags: [{inventory: [1, 2, 3]}]}], bank: [4, 5, 6], shared: [7, 8]}).totalStorageSlots).to.equal(8)
47
+ })
41
48
  })