@blocklet/launcher-util 2.1.15 → 2.1.16
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.
- package/lib/constant.js +25 -0
- package/lib/util.js +8 -22
- package/package.json +2 -2
package/lib/constant.js
CHANGED
|
@@ -57,6 +57,7 @@ const SERVERLESS_INSTANCE_STATUS = {
|
|
|
57
57
|
launching: 10,
|
|
58
58
|
running: 20,
|
|
59
59
|
expired: 30,
|
|
60
|
+
terminated: 40,
|
|
60
61
|
};
|
|
61
62
|
|
|
62
63
|
const toMap = (staus) =>
|
|
@@ -76,6 +77,29 @@ const fromPlanStatus = fromStatus(planStatusMap);
|
|
|
76
77
|
const NFT_TYPE_SERVERLESS = 'BlockletServerServerlessNFT';
|
|
77
78
|
const BLOCKLET_SERVER_OWNERSHIP_NFT = 'BlockletServerOwnershipNFT';
|
|
78
79
|
|
|
80
|
+
const TIME_LOCALE = {
|
|
81
|
+
en: {
|
|
82
|
+
h: 'hour',
|
|
83
|
+
hs: 'hours',
|
|
84
|
+
d: ' day',
|
|
85
|
+
ds: ' days',
|
|
86
|
+
m: ' month',
|
|
87
|
+
ms: ' months',
|
|
88
|
+
y: ' year',
|
|
89
|
+
ys: ' years',
|
|
90
|
+
},
|
|
91
|
+
zh: {
|
|
92
|
+
h: '小时',
|
|
93
|
+
hs: '小时',
|
|
94
|
+
d: '天',
|
|
95
|
+
ds: '天',
|
|
96
|
+
m: '个月',
|
|
97
|
+
ms: '个月',
|
|
98
|
+
y: '年',
|
|
99
|
+
ys: '年',
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
79
103
|
module.exports = Object.freeze({
|
|
80
104
|
SKU_STATUS: Object.freeze({
|
|
81
105
|
DISABLED: 0,
|
|
@@ -122,4 +146,5 @@ module.exports = Object.freeze({
|
|
|
122
146
|
SERVERLESS_INSTANCE_STATUS,
|
|
123
147
|
LAUNCH_STATUS,
|
|
124
148
|
SERVERLESS_RETAIN_DAYS: 30,
|
|
149
|
+
TIME_LOCALE,
|
|
125
150
|
});
|
package/lib/util.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
require('moment-timezone');
|
|
2
|
+
require('moment/locale/zh-cn');
|
|
2
3
|
const moment = require('moment');
|
|
3
4
|
const joinURL = require('url-join');
|
|
4
5
|
const get = require('lodash.get');
|
|
5
6
|
const { BN, fromUnitToToken, fromTokenToUnit } = require('@ocap/util');
|
|
7
|
+
const { TIME_LOCALE } = require('./constant');
|
|
6
8
|
|
|
7
9
|
const calculatePrice = (duration, unitPrice, from) => {
|
|
8
10
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -17,25 +19,6 @@ const calculatePrice = (duration, unitPrice, from) => {
|
|
|
17
19
|
return Number(fromUnitToToken(total).toString());
|
|
18
20
|
};
|
|
19
21
|
|
|
20
|
-
const DURATION_LOCALE = {
|
|
21
|
-
en: {
|
|
22
|
-
d: ' day',
|
|
23
|
-
ds: ' days',
|
|
24
|
-
m: ' month',
|
|
25
|
-
ms: ' months',
|
|
26
|
-
y: ' year',
|
|
27
|
-
ys: ' years',
|
|
28
|
-
},
|
|
29
|
-
zh: {
|
|
30
|
-
d: '天',
|
|
31
|
-
ds: '天',
|
|
32
|
-
m: '个月',
|
|
33
|
-
ms: '个月',
|
|
34
|
-
y: '年',
|
|
35
|
-
ys: '年',
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
|
|
39
22
|
const formatPeriod = (duration) => {
|
|
40
23
|
const value = Number(duration.slice(0, duration.length - 1));
|
|
41
24
|
const unit = duration[duration.length - 1];
|
|
@@ -44,13 +27,13 @@ const formatPeriod = (duration) => {
|
|
|
44
27
|
};
|
|
45
28
|
|
|
46
29
|
const prettyDurationUnit = ({ value, unit }, locale) => {
|
|
47
|
-
if (!Object.keys(
|
|
30
|
+
if (!Object.keys(TIME_LOCALE).includes(locale)) {
|
|
48
31
|
// eslint-disable-next-line no-param-reassign
|
|
49
32
|
locale = 'en';
|
|
50
33
|
}
|
|
51
34
|
|
|
52
35
|
const localeKey = value > 1 ? `${unit}s` : unit;
|
|
53
|
-
return
|
|
36
|
+
return TIME_LOCALE[locale][localeKey.toLowerCase()];
|
|
54
37
|
};
|
|
55
38
|
|
|
56
39
|
const prettyDuration = ({ value, unit }, locale) => {
|
|
@@ -115,6 +98,8 @@ const getBlockletDisplayName = (blocklet) => get(blocklet, 'title') || get(block
|
|
|
115
98
|
|
|
116
99
|
const getBlockletAdminURL = (appURL) => joinURL(appURL, '/.well-known/service/admin/overview');
|
|
117
100
|
|
|
101
|
+
const isDateExpired = (expirationDate) => !!expirationDate && new Date(expirationDate).getTime() <= Date.now();
|
|
102
|
+
|
|
118
103
|
module.exports = {
|
|
119
104
|
formatPeriod,
|
|
120
105
|
calculatePrice,
|
|
@@ -122,8 +107,9 @@ module.exports = {
|
|
|
122
107
|
prettyDuration,
|
|
123
108
|
formatDatetime,
|
|
124
109
|
formatUtcDatetime,
|
|
125
|
-
|
|
110
|
+
isDateExpired,
|
|
126
111
|
sortArrayByDate,
|
|
112
|
+
getSort,
|
|
127
113
|
getExplorerUrl,
|
|
128
114
|
getBlockletDisplayName,
|
|
129
115
|
getBlockletAdminURL,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/launcher-util",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.16",
|
|
4
4
|
"description": "Common constants",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"constant"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"jest": "^27.5.1"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "f0dd5911eb4cb82e77834487caf061b6e2fd562b"
|
|
50
50
|
}
|