@freelog/tools-lib 0.1.56 → 0.1.58
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/dist/tools-lib.cjs.development.js +5 -2
- package/dist/tools-lib.cjs.development.js.map +1 -1
- package/dist/tools-lib.cjs.production.min.js +1 -1
- package/dist/tools-lib.cjs.production.min.js.map +1 -1
- package/dist/tools-lib.esm.js +5 -2
- package/dist/tools-lib.esm.js.map +1 -1
- package/dist/utils/regexp.d.ts +1 -0
- package/package.json +1 -1
- package/src/utils/format.ts +89 -89
- package/src/utils/regexp.ts +8 -5
package/dist/utils/regexp.d.ts
CHANGED
package/package.json
CHANGED
package/src/utils/format.ts
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import moment from 'moment';
|
|
2
|
-
import {report} from '@freelog/resource-policy-lang/dist';
|
|
3
|
-
import {ContractEntity} from '@freelog/resource-policy-lang/dist/tools/ContractTool';
|
|
4
|
-
|
|
5
|
-
const {compile} = require('@freelog/resource-policy-lang');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 将对应的字节数,转换为易读单位数量
|
|
9
|
-
* @param bytes
|
|
10
|
-
* @return {string}
|
|
11
|
-
*/
|
|
12
|
-
export function humanizeSize(bytes: number): string {
|
|
13
|
-
// console.log('dddhumanizeSizesdfsd');
|
|
14
|
-
if (bytes <= 0) {
|
|
15
|
-
return '0 B';
|
|
16
|
-
}
|
|
17
|
-
const unitArr = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
18
|
-
const index = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
19
|
-
const size = Math.round((bytes / Math.pow(1024, index)) * 100) / 100; //保留的小数位数
|
|
20
|
-
return size + ' ' + unitArr[index];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 格式化日期时间
|
|
25
|
-
*/
|
|
26
|
-
export function formatDateTime(date: string, showTime: boolean = false) {
|
|
27
|
-
return moment(date).format('YYYY/MM/DD' + (showTime ? ' HH:mm' : ''));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 根据传入的子域名拼合成完整的适合的url
|
|
32
|
-
* @param domain 要组合的三级域名
|
|
33
|
-
*/
|
|
34
|
-
export function completeUrlByDomain(domain: string): string {
|
|
35
|
-
let origin: string = `http://${domain}.testfreelog.com`;
|
|
36
|
-
|
|
37
|
-
if (window.location.origin.includes('.freelog.com')) {
|
|
38
|
-
origin = `https://${domain}.freelog.com`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return origin;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 根据策略代码和标的物类型,生成对应的翻译
|
|
46
|
-
* @param code 策略代码
|
|
47
|
-
* @param targetType 标的物类型
|
|
48
|
-
*/
|
|
49
|
-
export async function policyCodeTranslationToText(code: string, targetType: string): Promise<{
|
|
50
|
-
error: string[] | null;
|
|
51
|
-
text?: string;
|
|
52
|
-
}> {
|
|
53
|
-
try {
|
|
54
|
-
const result = await compile(
|
|
55
|
-
code,
|
|
56
|
-
targetType,
|
|
57
|
-
completeUrlByDomain('qi'),
|
|
58
|
-
window.location.origin.endsWith('.freelog.com') ? 'prod' : 'dev',
|
|
59
|
-
);
|
|
60
|
-
const contract: ContractEntity = {
|
|
61
|
-
audiences: result.state_machine.audiences,
|
|
62
|
-
fsmStates: Object.entries<any>(result.state_machine.states)
|
|
63
|
-
.map((st) => {
|
|
64
|
-
return {
|
|
65
|
-
name: st[0],
|
|
66
|
-
serviceStates: st[1].serviceStates,
|
|
67
|
-
events: st[1].transitions.map((ts: any) => {
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
id: ts.code,
|
|
71
|
-
name: ts.name,
|
|
72
|
-
args: ts.args,
|
|
73
|
-
state: ts.toState,
|
|
74
|
-
};
|
|
75
|
-
}),
|
|
76
|
-
};
|
|
77
|
-
}),
|
|
78
|
-
};
|
|
79
|
-
const rrr = report(contract);
|
|
80
|
-
return {
|
|
81
|
-
error: null,
|
|
82
|
-
text: rrr.audienceInfos[0].content + rrr.content,
|
|
83
|
-
};
|
|
84
|
-
} catch (err) {
|
|
85
|
-
return {
|
|
86
|
-
error: [err.message],
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import {report} from '@freelog/resource-policy-lang/dist';
|
|
3
|
+
import {ContractEntity} from '@freelog/resource-policy-lang/dist/tools/ContractTool';
|
|
4
|
+
|
|
5
|
+
const {compile} = require('@freelog/resource-policy-lang');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 将对应的字节数,转换为易读单位数量
|
|
9
|
+
* @param bytes
|
|
10
|
+
* @return {string}
|
|
11
|
+
*/
|
|
12
|
+
export function humanizeSize(bytes: number): string {
|
|
13
|
+
// console.log('dddhumanizeSizesdfsd');
|
|
14
|
+
if (bytes <= 0) {
|
|
15
|
+
return '0 B';
|
|
16
|
+
}
|
|
17
|
+
const unitArr = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
18
|
+
const index = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
19
|
+
const size = Math.round((bytes / Math.pow(1024, index)) * 100) / 100; //保留的小数位数
|
|
20
|
+
return size + ' ' + unitArr[index];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 格式化日期时间
|
|
25
|
+
*/
|
|
26
|
+
export function formatDateTime(date: string, showTime: boolean = false) {
|
|
27
|
+
return moment(date).format('YYYY/MM/DD' + (showTime ? ' HH:mm' : ''));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 根据传入的子域名拼合成完整的适合的url
|
|
32
|
+
* @param domain 要组合的三级域名
|
|
33
|
+
*/
|
|
34
|
+
export function completeUrlByDomain(domain: string): string {
|
|
35
|
+
let origin: string = `http://${domain}.testfreelog.com`;
|
|
36
|
+
|
|
37
|
+
if (window.location.origin.includes('.freelog.com')) {
|
|
38
|
+
origin = `https://${domain}.freelog.com`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return origin;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 根据策略代码和标的物类型,生成对应的翻译
|
|
46
|
+
* @param code 策略代码
|
|
47
|
+
* @param targetType 标的物类型
|
|
48
|
+
*/
|
|
49
|
+
export async function policyCodeTranslationToText(code: string, targetType: string): Promise<{
|
|
50
|
+
error: string[] | null;
|
|
51
|
+
text?: string;
|
|
52
|
+
}> {
|
|
53
|
+
try {
|
|
54
|
+
const result = await compile(
|
|
55
|
+
code,
|
|
56
|
+
targetType,
|
|
57
|
+
completeUrlByDomain('qi'),
|
|
58
|
+
window.location.origin.endsWith('.freelog.com') ? 'prod' : 'dev',
|
|
59
|
+
);
|
|
60
|
+
const contract: ContractEntity = {
|
|
61
|
+
audiences: result.state_machine.audiences,
|
|
62
|
+
fsmStates: Object.entries<any>(result.state_machine.states)
|
|
63
|
+
.map((st) => {
|
|
64
|
+
return {
|
|
65
|
+
name: st[0],
|
|
66
|
+
serviceStates: st[1].serviceStates,
|
|
67
|
+
events: st[1].transitions.map((ts: any) => {
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
id: ts.code,
|
|
71
|
+
name: ts.name,
|
|
72
|
+
args: ts.args,
|
|
73
|
+
state: ts.toState,
|
|
74
|
+
};
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
}),
|
|
78
|
+
};
|
|
79
|
+
const rrr = report(contract);
|
|
80
|
+
return {
|
|
81
|
+
error: null,
|
|
82
|
+
text: rrr.audienceInfos[0].content + rrr.content,
|
|
83
|
+
};
|
|
84
|
+
} catch (err) {
|
|
85
|
+
return {
|
|
86
|
+
error: [err.message],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/utils/regexp.ts
CHANGED
|
@@ -14,22 +14,25 @@ export const CUSTOM_KEY: RegExp = /^[a-zA-Z0-9_]{1,20}$/;
|
|
|
14
14
|
export const NODE_NAME: RegExp = /^[\u4E00-\u9FA5|a-zA-Z0-9]{2,24}$/;
|
|
15
15
|
|
|
16
16
|
// 节点地址
|
|
17
|
-
export const NODE_DOMAIN = /^(?!-)[a-z0-9-]{4,24}(?<!-)$/;
|
|
17
|
+
export const NODE_DOMAIN: RegExp = /^(?!-)[a-z0-9-]{4,24}(?<!-)$/;
|
|
18
18
|
|
|
19
19
|
// 支付密码
|
|
20
|
-
export const PAY_PASSWORD = /^\d{6}$/;
|
|
20
|
+
export const PAY_PASSWORD: RegExp = /^\d{6}$/;
|
|
21
21
|
|
|
22
22
|
// 手机号码
|
|
23
23
|
export const MOBILE_PHONE_NUMBER = /^1[345789]\d{9}$/;
|
|
24
24
|
// export const TELEPHONE_NUMBER = /^((13[0-9])|(14[5-9])|(15([0-3]|[5-9]))|(16[6-7])|(17[1-8])|(18[0-9])|(19[1|3])|(19[5|6])|(19[8|9]))\d{8}$/
|
|
25
25
|
|
|
26
26
|
// 邮箱地址
|
|
27
|
-
export const EMAIL_ADDRESS = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
|
|
27
|
+
export const EMAIL_ADDRESS: RegExp = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
|
|
28
28
|
|
|
29
29
|
// 用户名
|
|
30
30
|
// export const USERNAME = /^(?!-)[A-Za-z0-9-]{1,30}(?<!-)$/;
|
|
31
|
-
export const USERNAME = /^(?!-)[A-Za-z0-9-]{1,30}(?<!-)$/;
|
|
31
|
+
export const USERNAME: RegExp = /^(?!-)[A-Za-z0-9-]{1,30}(?<!-)$/;
|
|
32
32
|
|
|
33
33
|
// 用户密码
|
|
34
34
|
// export const PASSWORD = /^(?=.*[a-zA-Z])(?=.*[0-9]).{6,24}$/;
|
|
35
|
-
export const PASSWORD = /^(?=.*[0-9])(?=.*[a-zA-Z])(.{6,24})$/;
|
|
35
|
+
export const PASSWORD: RegExp = /^(?=.*[0-9])(?=.*[a-zA-Z])(.{6,24})$/;
|
|
36
|
+
|
|
37
|
+
// 自然数
|
|
38
|
+
export const NATURAL_NUMBER: RegExp = /^[0-9]*$/;
|