@peng_kai/kit 0.1.14 → 0.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/package.json +17 -19
- package/utils/blockchain.ts +57 -0
- package/utils/index.ts +12 -80
- package/utils/object.ts +17 -0
- package/utils/string.ts +28 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peng_kai/kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.16",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "ISC",
|
|
@@ -13,43 +13,41 @@
|
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@tanstack/vue-query": "4.37.1",
|
|
16
|
-
"@vueuse/core": "10.
|
|
17
|
-
"ant-design-vue": "4.
|
|
18
|
-
"axios": "1.6.
|
|
16
|
+
"@vueuse/core": "10.7.2",
|
|
17
|
+
"ant-design-vue": "4.1.1",
|
|
18
|
+
"axios": "1.6.5",
|
|
19
19
|
"bignumber.js": "9.1.2",
|
|
20
20
|
"dayjs": "1.11.10",
|
|
21
21
|
"lodash-es": "4.17.21",
|
|
22
|
-
"vue": "3.
|
|
22
|
+
"vue": "3.4.15",
|
|
23
23
|
"vue-router": "4.2.5"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@babel/generator": "^7.23.
|
|
27
|
-
"@babel/parser": "^7.23.
|
|
28
|
-
"@babel/traverse": "^7.23.
|
|
29
|
-
"@babel/types": "^7.23.
|
|
26
|
+
"@babel/generator": "^7.23.6",
|
|
27
|
+
"@babel/parser": "^7.23.6",
|
|
28
|
+
"@babel/traverse": "^7.23.7",
|
|
29
|
+
"@babel/types": "^7.23.6",
|
|
30
30
|
"@tanstack/vue-query": "^4.37.1",
|
|
31
|
-
"@vueuse/core": "^10.
|
|
31
|
+
"@vueuse/core": "^10.7.2",
|
|
32
32
|
"a-calc": "^1.3.8",
|
|
33
|
-
"ant-design-vue": "^4.
|
|
34
|
-
"axios": "^1.6.
|
|
33
|
+
"ant-design-vue": "^4.1.1",
|
|
34
|
+
"axios": "^1.6.5",
|
|
35
35
|
"bignumber.js": "^9.1.2",
|
|
36
36
|
"chokidar": "^3.5.3",
|
|
37
37
|
"dayjs": "^1.11.10",
|
|
38
38
|
"fast-glob": "^3.3.2",
|
|
39
39
|
"lodash-es": "^4.17.21",
|
|
40
40
|
"nprogress": "^0.2.0",
|
|
41
|
-
"vue": "^3.
|
|
41
|
+
"vue": "^3.4.15",
|
|
42
42
|
"vue-router": "^4.2.5"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@antfu/eslint-config": "^1.2.1",
|
|
46
45
|
"@peng_kai/lint": "^0.1.0",
|
|
47
|
-
"@types/lodash-es": "^4.17.
|
|
46
|
+
"@types/lodash-es": "^4.17.12",
|
|
48
47
|
"@types/node": "18",
|
|
49
48
|
"@types/nprogress": "^0.2.3",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"vue-component-type-helpers": "^1.8.22"
|
|
49
|
+
"type-fest": "^4.9.0",
|
|
50
|
+
"typescript": "^5.3.3",
|
|
51
|
+
"vue-component-type-helpers": "^1.8.27"
|
|
54
52
|
}
|
|
55
53
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取对应链的浏览器地址
|
|
3
|
+
* @param chain 链名
|
|
4
|
+
* @param hash 哈希
|
|
5
|
+
* @param type 哈希类型
|
|
6
|
+
*/
|
|
7
|
+
export function getScanBrowser(chain: string, hash: string, type: 'transaction' | 'address' = 'transaction') {
|
|
8
|
+
type TypeMap = Partial<Record<typeof type, string>>;
|
|
9
|
+
|
|
10
|
+
const _chain = chain.toUpperCase();
|
|
11
|
+
const evmType = () => type === 'transaction' ? 'tx' : type;
|
|
12
|
+
const urlFn = {
|
|
13
|
+
'TRON': () => `https://tronscan.org/#/${type}/${hash}`,
|
|
14
|
+
'ETH': () => `https://etherscan.io/${evmType()}/${hash}`,
|
|
15
|
+
'ETHEREUM': () => `https://etherscan.io/${evmType()}/${hash}`,
|
|
16
|
+
'BSC': () => `https://bscscan.com/${evmType()}/${hash}`,
|
|
17
|
+
'BINANCE': () => `https://bscscan.com/${evmType()}/${hash}`,
|
|
18
|
+
'BNB CHAIN': () => `https://bscscan.com/${evmType()}/${hash}`,
|
|
19
|
+
'BASE': () => `https://basescan.org/${evmType()}/${hash}`,
|
|
20
|
+
'HECO': () => `https://hecoscan.io/#/${evmType}/${hash}`,
|
|
21
|
+
'POLYGON': () => `https://polygonscan.com/${evmType()}/${hash}`,
|
|
22
|
+
'OKEXCHAIN': () => `https://www.okx.com/cn/explorer/oktc/${evmType()}/${hash}`,
|
|
23
|
+
'OPBNB': () => `https://opbnbscan.com/${evmType()}/${hash}`,
|
|
24
|
+
'APTOS': () => {
|
|
25
|
+
const _type = (<TypeMap>{ transaction: 'txn', address: 'account' })[type] ?? type;
|
|
26
|
+
return `https://explorer.aptoslabs.com/${_type}/${hash}`;
|
|
27
|
+
},
|
|
28
|
+
'ARBITRUM': () => `https://arbiscan.io/${evmType()}/${hash}`,
|
|
29
|
+
'AVALANCHE': () => `https://subnets.avax.network/c-chain/${evmType()}/${hash}`,
|
|
30
|
+
'FANTOM': () => `https://ftmscan.com/${evmType()}/${hash}`,
|
|
31
|
+
'OPTIMISM': () => `https://optimistic.etherscan.io/${evmType()}/${hash}`,
|
|
32
|
+
'SUI': () => {
|
|
33
|
+
const _type = (<TypeMap>{ transaction: 'txblock' })[type] ?? type;
|
|
34
|
+
return `https://suiexplorer.com/${_type}/${hash}`;
|
|
35
|
+
},
|
|
36
|
+
'ZKSYNC': () => `https://explorer.zksync.io/${evmType()}/${hash}`,
|
|
37
|
+
'SOLANA': () => {
|
|
38
|
+
const _type = (<TypeMap>{ address: 'account', transaction: 'tx' })[type] ?? type;
|
|
39
|
+
return `https://solscan.io/${_type}/${hash}`;
|
|
40
|
+
},
|
|
41
|
+
'DOGE': () => `https://dogechain.info/${evmType()}/${hash}`,
|
|
42
|
+
'BTC': () => `https://mempool.space/${evmType()}/${hash}`,
|
|
43
|
+
}[_chain] ?? (() => '');
|
|
44
|
+
|
|
45
|
+
return urlFn();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 在新标签页打开对应链的浏览器地址
|
|
50
|
+
* @param chain 链名
|
|
51
|
+
* @param hash 哈希
|
|
52
|
+
* @param type 哈希类型
|
|
53
|
+
*/
|
|
54
|
+
export function openScanBrowser(...args: Parameters<typeof getScanBrowser>) {
|
|
55
|
+
const url = getScanBrowser(...args);
|
|
56
|
+
url && window.open(url, '_blank');
|
|
57
|
+
}
|
package/utils/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export { desensitize, randomString } from './string';
|
|
2
|
+
export { getScanBrowser, openScanBrowser } from './blockchain';
|
|
3
|
+
export { override } from './object';
|
|
4
|
+
|
|
1
5
|
export const ENV = {
|
|
2
6
|
get isDev() {
|
|
3
7
|
return (import.meta as any).env.DEV;
|
|
@@ -11,6 +15,9 @@ export const ENV = {
|
|
|
11
15
|
get isTest() {
|
|
12
16
|
return this.isDev || this.isStaging;
|
|
13
17
|
},
|
|
18
|
+
get isSSR() {
|
|
19
|
+
return typeof window === 'undefined';
|
|
20
|
+
},
|
|
14
21
|
};
|
|
15
22
|
|
|
16
23
|
/**
|
|
@@ -21,97 +28,22 @@ export function sleep(dur: number) {
|
|
|
21
28
|
return new Promise(resolve => setTimeout(resolve, dur));
|
|
22
29
|
}
|
|
23
30
|
|
|
24
|
-
/**
|
|
25
|
-
* 是否有授权 Token
|
|
26
|
-
*/
|
|
31
|
+
/** 是否有授权 Token */
|
|
27
32
|
export function hasToken() {
|
|
28
33
|
return document.cookie.includes('has_token=1');
|
|
29
34
|
}
|
|
30
35
|
|
|
36
|
+
/** 是否在 SSR 环境 */
|
|
31
37
|
export function isSSR() {
|
|
32
38
|
return typeof window === 'undefined';
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
/**
|
|
36
|
-
* 字符串脱敏,省略中间字符串
|
|
37
|
-
* @param str 字符串
|
|
38
|
-
* @param startChars 开头显示字符数量
|
|
39
|
-
* @param endChars 结尾显示字符数量
|
|
40
|
-
*/
|
|
41
|
-
export function desensitize(str: string | undefined | null, startChars = 4, endChars?: number) {
|
|
42
|
-
if (!str)
|
|
43
|
-
return '';
|
|
44
|
-
|
|
45
|
-
endChars ??= startChars;
|
|
46
|
-
|
|
47
|
-
if (startChars + endChars >= str.length)
|
|
48
|
-
return str;
|
|
49
|
-
|
|
50
|
-
const truncatedStr = `${str.substring(0, startChars)}...${str.substring(str.length - endChars)}`;
|
|
51
|
-
|
|
52
|
-
return truncatedStr;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 生成指定长度的随机字符串
|
|
57
|
-
* @param length 要生成的随机字符串的长度
|
|
58
|
-
*/
|
|
59
|
-
export function randomString(length: number) {
|
|
60
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
61
|
-
return Array.from({ length }, () => characters[Math.floor(Math.random() * characters.length)]).join('');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* 对应链的浏览器地址
|
|
66
|
-
* @param chain 链名
|
|
67
|
-
* @param hash 哈希
|
|
68
|
-
* @param type 哈希类型
|
|
69
|
-
*/
|
|
70
|
-
export function getScanBrowser(chain: string, hash: string, type: 'transaction' | 'address' = 'transaction') {
|
|
71
|
-
type TypeMap = Partial<Record<typeof type, string>>;
|
|
72
|
-
|
|
73
|
-
const _chain = chain.toUpperCase();
|
|
74
|
-
const evmType = () => type === 'transaction' ? 'tx' : type;
|
|
75
|
-
const urlFn = {
|
|
76
|
-
'TRON': () => `https://tronscan.org/#/${type}/${hash}`,
|
|
77
|
-
'ETH': () => `https://etherscan.io/${evmType()}/${hash}`,
|
|
78
|
-
'ETHEREUM': () => `https://etherscan.io/${evmType()}/${hash}`,
|
|
79
|
-
'BSC': () => `https://bscscan.com/${evmType()}/${hash}`,
|
|
80
|
-
'BINANCE': () => `https://bscscan.com/${evmType()}/${hash}`,
|
|
81
|
-
'BNB CHAIN': () => `https://bscscan.com/${evmType()}/${hash}`,
|
|
82
|
-
'BASE': () => `https://basescan.org/${evmType()}/${hash}`,
|
|
83
|
-
'HECO': () => `https://hecoscan.io/#/${evmType}/${hash}`,
|
|
84
|
-
'POLYGON': () => `https://polygonscan.com/${evmType()}/${hash}`,
|
|
85
|
-
'OKEXCHAIN': () => `https://www.okx.com/cn/explorer/oktc/${evmType()}/${hash}`,
|
|
86
|
-
'OPBNB': () => `https://opbnbscan.com/${evmType()}/${hash}`,
|
|
87
|
-
'APTOS': () => {
|
|
88
|
-
const _type = (<TypeMap>{ transaction: 'txn', address: 'account' })[type] ?? type;
|
|
89
|
-
return `https://explorer.aptoslabs.com/${_type}/${hash}`;
|
|
90
|
-
},
|
|
91
|
-
'ARBITRUM': () => `https://arbiscan.io/${evmType()}/${hash}`,
|
|
92
|
-
'AVALANCHE': () => `https://subnets.avax.network/c-chain/${evmType()}/${hash}`,
|
|
93
|
-
'FANTOM': () => `https://ftmscan.com/${evmType()}/${hash}`,
|
|
94
|
-
'OPTIMISM': () => `https://optimistic.etherscan.io/${evmType()}/${hash}`,
|
|
95
|
-
'SUI': () => {
|
|
96
|
-
const _type = (<TypeMap>{ transaction: 'txblock' })[type] ?? type;
|
|
97
|
-
return `https://suiexplorer.com/${_type}/${hash}`;
|
|
98
|
-
},
|
|
99
|
-
'ZKSYNC': () => `https://explorer.zksync.io/${evmType()}/${hash}`,
|
|
100
|
-
'SOLANA': () => {
|
|
101
|
-
const _type = (<TypeMap>{ address: 'account', transaction: 'tx' })[type] ?? type;
|
|
102
|
-
return `https://solscan.io/${_type}/${hash}`;
|
|
103
|
-
},
|
|
104
|
-
}[_chain] ?? (() => '');
|
|
105
|
-
|
|
106
|
-
return urlFn();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
41
|
/**
|
|
110
42
|
* Telegram连接
|
|
111
|
-
* @param
|
|
43
|
+
* @param id 链接
|
|
112
44
|
*/
|
|
113
|
-
export function getTelegramBrowser(
|
|
114
|
-
return `https://t.me/${
|
|
45
|
+
export function getTelegramBrowser(id: string) {
|
|
46
|
+
return `https://t.me/${id}`;
|
|
115
47
|
}
|
|
116
48
|
|
|
117
49
|
/**
|
package/utils/object.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import assign from 'lodash-es/assign';
|
|
2
|
+
import pick from 'lodash-es/pick';
|
|
3
|
+
import keys from 'lodash-es/keys';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 用一个或多个源对象的属性覆盖目标对象的属性,只会覆盖 `target` 中存在的属性,不会新增新属性
|
|
7
|
+
* @param target - 要覆盖的目标对象。
|
|
8
|
+
* @param sources - 包含要覆盖的属性的源对象。
|
|
9
|
+
* @returns 带有覆盖属性的目标对象。
|
|
10
|
+
*/
|
|
11
|
+
export function override<T extends Record<PropertyKey, any>>(
|
|
12
|
+
target: T,
|
|
13
|
+
...sources: Partial<Record<keyof T, any> & Record<PropertyKey, any>>[]
|
|
14
|
+
) {
|
|
15
|
+
const source = assign({}, ...sources);
|
|
16
|
+
return assign(target, pick(source, keys(target)));
|
|
17
|
+
}
|
package/utils/string.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 字符串脱敏,省略中间字符串
|
|
3
|
+
* @param str 字符串
|
|
4
|
+
* @param startChars 开头显示字符数量
|
|
5
|
+
* @param endChars 结尾显示字符数量
|
|
6
|
+
*/
|
|
7
|
+
export function desensitize(str: string | undefined | null, startChars = 4, endChars?: number) {
|
|
8
|
+
if (!str)
|
|
9
|
+
return '';
|
|
10
|
+
|
|
11
|
+
endChars ??= startChars;
|
|
12
|
+
|
|
13
|
+
if (startChars + endChars >= str.length)
|
|
14
|
+
return str;
|
|
15
|
+
|
|
16
|
+
const truncatedStr = `${str.substring(0, startChars)}...${str.substring(str.length - endChars)}`;
|
|
17
|
+
|
|
18
|
+
return truncatedStr;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 生成指定长度的随机字符串
|
|
23
|
+
* @param length 要生成的随机字符串的长度
|
|
24
|
+
*/
|
|
25
|
+
export function randomString(length: number) {
|
|
26
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
27
|
+
return Array.from({ length }, () => characters[Math.floor(Math.random() * characters.length)]).join('');
|
|
28
|
+
}
|