forked from txiuqw4/farmersworld-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
33 lines (28 loc) · 856 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export function camelize(a) {
return a.replace(/\_([a-zA-Z])/g, function($1) {
return $1.toUpperCase();
})
.replace(/\_+/g, '');
}
export function toCamelCase(data) {
return Object.keys(data).reduce((o, k) => {
o[camelize(k)] = data[k];
return o;
}, {});
}
export function delay(ms) {
return new Promise(r => setTimeout(r, ms));
}
export function calcNextClaim(assets, assetChargeTime) {
return assets.reduce(function (min, r) {
return min >= r.nextAvailability ? r.nextAvailability : min;
}, Math.floor(Date.now() / 1000 + assetChargeTime));
}
export function getClaimableAssets(assets) {
return assets.filter(
(r) => Math.ceil(r.nextAvailability - Date.now() / 1000) <= 0
);
}
export function parseBalance(value) {
return Number(value.split(" ")[0]);
}