@freelog/tools-lib 0.1.89 → 0.1.93
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/LICENSE +20 -20
- package/README.md +103 -103
- package/dist/service-API/activities.d.ts +12 -0
- package/dist/service-API/informalNodes.d.ts +15 -45
- package/dist/service-API/policies.d.ts +2 -6
- package/dist/tools-lib.cjs.development.js +536 -926
- 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 +536 -926
- package/dist/tools-lib.esm.js.map +1 -1
- package/dist/utils/axios.d.ts +1 -4
- package/package.json +1 -1
- package/src/index.ts +7 -7
- package/src/service-API/activities.ts +32 -0
- package/src/service-API/captcha.ts +30 -30
- package/src/service-API/collections.ts +81 -81
- package/src/service-API/contracts.ts +84 -84
- package/src/service-API/events.ts +18 -18
- package/src/service-API/index.ts +29 -29
- package/src/service-API/informalNodes.ts +238 -238
- package/src/service-API/nodes.ts +65 -65
- package/src/service-API/policies.ts +39 -39
- package/src/service-API/presentables.ts +282 -282
- package/src/service-API/resources.ts +496 -496
- package/src/service-API/storages.ts +345 -345
- package/src/service-API/tools/index.ts +10 -10
- package/src/service-API/transactions.ts +109 -109
- package/src/service-API/user.ts +188 -188
- package/src/utils/axios.ts +8 -3
- package/src/utils/format.ts +89 -89
- package/src/utils/index.ts +18 -18
- package/src/utils/linkTo.ts +332 -332
- package/src/utils/predefined.ts +37 -37
- package/src/utils/regexp.ts +52 -52
- package/src/utils/tools.ts +72 -72
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/index.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import * as Format from './format';
|
|
2
|
-
import * as Regexp from './regexp';
|
|
3
|
-
import * as LinkTo from './linkTo';
|
|
4
|
-
import * as Predefined from './predefined';
|
|
5
|
-
import Axios, {request} from './axios';
|
|
6
|
-
import * as Tool from './tools';
|
|
7
|
-
|
|
8
|
-
const FUtil = {
|
|
9
|
-
Format,
|
|
10
|
-
Regexp,
|
|
11
|
-
LinkTo,
|
|
12
|
-
Predefined,
|
|
13
|
-
Axios,
|
|
14
|
-
Request: request,
|
|
15
|
-
Tool,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default FUtil;
|
|
1
|
+
import * as Format from './format';
|
|
2
|
+
import * as Regexp from './regexp';
|
|
3
|
+
import * as LinkTo from './linkTo';
|
|
4
|
+
import * as Predefined from './predefined';
|
|
5
|
+
import Axios, {request} from './axios';
|
|
6
|
+
import * as Tool from './tools';
|
|
7
|
+
|
|
8
|
+
const FUtil = {
|
|
9
|
+
Format,
|
|
10
|
+
Regexp,
|
|
11
|
+
LinkTo,
|
|
12
|
+
Predefined,
|
|
13
|
+
Axios,
|
|
14
|
+
Request: request,
|
|
15
|
+
Tool,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default FUtil;
|