@freelog/tools-lib 0.1.132 → 0.1.133
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/policies.d.ts +1 -1
- package/dist/service-API/recombinations/index.d.ts +4 -1
- package/dist/tools-lib.cjs.development.js +214 -197
- 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 +214 -197
- package/dist/tools-lib.esm.js.map +1 -1
- package/dist/utils/format.d.ts +0 -4
- package/package.json +1 -1
- package/src/i18n/I18nNext.ts +154 -154
- package/src/i18n/index.ts +7 -7
- package/src/index.ts +9 -9
- package/src/service-API/activities.ts +231 -231
- package/src/service-API/captcha.ts +30 -30
- package/src/service-API/collections.ts +81 -81
- package/src/service-API/contracts.ts +101 -101
- package/src/service-API/events.ts +18 -18
- package/src/service-API/i18n.ts +35 -35
- package/src/service-API/index.ts +39 -39
- package/src/service-API/informalNodes.ts +238 -238
- package/src/service-API/nodes.ts +65 -65
- package/src/service-API/policies.ts +75 -72
- package/src/service-API/presentables.ts +287 -287
- package/src/service-API/recombinations/index.ts +92 -69
- package/src/service-API/resources.ts +532 -532
- package/src/service-API/statistics.ts +20 -20
- package/src/service-API/storages.ts +358 -358
- package/src/service-API/testQualifications.ts +109 -109
- package/src/service-API/tools/index.ts +10 -10
- package/src/service-API/transactions.ts +109 -109
- package/src/service-API/user.ts +270 -270
- package/src/utils/axios.ts +145 -145
- package/src/utils/format.ts +98 -98
- package/src/utils/index.ts +20 -20
- package/src/utils/linkTo.ts +399 -399
- package/src/utils/predefined.ts +37 -37
- package/src/utils/regexp.ts +52 -52
- package/src/utils/tools.ts +85 -85
package/dist/utils/format.d.ts
CHANGED
|
@@ -18,10 +18,6 @@ export declare function completeUrlByDomain(domain: string): string;
|
|
|
18
18
|
* @param code 策略代码
|
|
19
19
|
* @param targetType 标的物类型
|
|
20
20
|
*/
|
|
21
|
-
export declare function policyCodeTranslationToText(code: string, targetType: string): Promise<{
|
|
22
|
-
error: string[] | null;
|
|
23
|
-
text?: string;
|
|
24
|
-
}>;
|
|
25
21
|
/**
|
|
26
22
|
* 将资源类型关键字数组,转换成标准展示文字
|
|
27
23
|
* @param arr 关键字数组
|
package/package.json
CHANGED
package/src/i18n/I18nNext.ts
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
import i18next, {Resource} from 'i18next';
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import Cookies from 'js-cookie';
|
|
4
|
-
import FUtil from '../utils';
|
|
5
|
-
|
|
6
|
-
type LanguageKeyType = 'zh_CN' | 'en_US';
|
|
7
|
-
|
|
8
|
-
const ossJsonUrl: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs/i18n.json';
|
|
9
|
-
const ossJsonUrl_Test: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs-test/i18n.json';
|
|
10
|
-
const localStorage_i18nextLng_key: string = 'locale';
|
|
11
|
-
const localStorage_i18nextResources_key: string = 'i18nextResources';
|
|
12
|
-
|
|
13
|
-
const allLanguage = [
|
|
14
|
-
{value: 'en_US', label: 'English'},
|
|
15
|
-
{value: 'zh_CN', label: '简体中文'},
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
class I18nNext {
|
|
19
|
-
|
|
20
|
-
private _loadingData: 'NotStart' | 'Start' | 'End' = 'NotStart';
|
|
21
|
-
private _taskQueue: Function[] = [];
|
|
22
|
-
// private _currentLanguage: LanguageKeyType = window.localStorage.getItem(localStorage_i18nextLng_key) as null || 'zh_CN';
|
|
23
|
-
private _currentLanguage: LanguageKeyType = Cookies.get(localStorage_i18nextLng_key) as undefined || 'zh_CN';
|
|
24
|
-
|
|
25
|
-
constructor() {
|
|
26
|
-
this.ready();
|
|
27
|
-
|
|
28
|
-
this.ready = this.ready.bind(this);
|
|
29
|
-
this.t = this.t.bind(this);
|
|
30
|
-
this.changeLanguage = this.changeLanguage.bind(this);
|
|
31
|
-
this.getAllLanguage = this.getAllLanguage.bind(this);
|
|
32
|
-
this.getCurrentLanguage = this.getCurrentLanguage.bind(this);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async ready(this: I18nNext) {
|
|
36
|
-
const exc = () => {
|
|
37
|
-
while (this._taskQueue.length > 0) {
|
|
38
|
-
const task = this._taskQueue.shift();
|
|
39
|
-
task && task();
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const handleTasks = async () => {
|
|
43
|
-
// console.log(this._loadingData, 'this._loadingData90iowejflksdfjlsdk');
|
|
44
|
-
if (this._loadingData === 'End') {
|
|
45
|
-
exc();
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (this._loadingData === 'Start') {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// NO_START
|
|
53
|
-
this._loadingData = 'Start';
|
|
54
|
-
|
|
55
|
-
await this._handleData();
|
|
56
|
-
// console.log('######');
|
|
57
|
-
exc();
|
|
58
|
-
};
|
|
59
|
-
const promise = new Promise((resolve) => {
|
|
60
|
-
this._taskQueue.push(resolve);
|
|
61
|
-
});
|
|
62
|
-
handleTasks();
|
|
63
|
-
return promise;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
t(this: I18nNext, key: string, options?: { [key: string]: any }) {
|
|
67
|
-
return i18next.t(key, options);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
changeLanguage(this: I18nNext, lng: LanguageKeyType) {
|
|
71
|
-
// return i18next.changeLanguage(lng);
|
|
72
|
-
// window.localStorage.setItem(localStorage_i18nextLng_key, lng)
|
|
73
|
-
Cookies.set(localStorage_i18nextLng_key, lng, {
|
|
74
|
-
expires: 36525,
|
|
75
|
-
domain: FUtil.Format.completeUrlByDomain('').replace(/http(s)?:\/\//, ''),
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getAllLanguage(this: I18nNext): typeof allLanguage {
|
|
80
|
-
return allLanguage;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
getCurrentLanguage(this: I18nNext): LanguageKeyType {
|
|
84
|
-
return this._currentLanguage;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private async _handleData(this: I18nNext) {
|
|
88
|
-
|
|
89
|
-
const lng: string = this._currentLanguage;
|
|
90
|
-
const resource: string | null = window.localStorage.getItem(localStorage_i18nextResources_key);
|
|
91
|
-
// const resource: string | undefined = Cookies.get(decodeURIComponent(localStorage_i18nextResources_key));
|
|
92
|
-
let i18nextResources: Resource | null = resource ? JSON.parse(resource) : null;
|
|
93
|
-
|
|
94
|
-
if (!i18nextResources) {
|
|
95
|
-
// console.log('######892io3jlkl')
|
|
96
|
-
i18nextResources = await this._fetchData();
|
|
97
|
-
} else {
|
|
98
|
-
this._fetchData();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
await i18next
|
|
102
|
-
.init({
|
|
103
|
-
// the translations
|
|
104
|
-
// (tip move them in a JSON file and import them,
|
|
105
|
-
// or even better, manage them via a UI: https://react.i18next.com/guides/multiple-translation-files#manage-your-translations-with-a-management-gui)
|
|
106
|
-
resources: i18nextResources,
|
|
107
|
-
lng: lng, // if you're using a language detector, do not define the lng option
|
|
108
|
-
fallbackLng: 'zh_CN',
|
|
109
|
-
|
|
110
|
-
interpolation: {
|
|
111
|
-
escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
|
|
112
|
-
prefix: '{',
|
|
113
|
-
suffix: '}',
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
this._loadingData = 'End';
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private async _fetchData(this: I18nNext): Promise<Resource> {
|
|
120
|
-
const res: any = await axios.get(window.location.origin.includes('.freelog.com') ? ossJsonUrl : ossJsonUrl_Test, {
|
|
121
|
-
withCredentials: false,
|
|
122
|
-
});
|
|
123
|
-
// console.log(res, 'data09oiw3qjelsfkdfjlsdkfjl');
|
|
124
|
-
|
|
125
|
-
const en_US: { [key: string]: string } = {};
|
|
126
|
-
const zh_CN: { [key: string]: string } = {};
|
|
127
|
-
|
|
128
|
-
for (const [key, value] of Object.entries(res)) {
|
|
129
|
-
// console.log(key, value, 'key, value90iowsldfjlsdkj');
|
|
130
|
-
en_US[key] = (value as any)['en_US'];
|
|
131
|
-
zh_CN[key] = (value as any)['zh_CN'];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const result: Resource = {
|
|
135
|
-
en_US: {
|
|
136
|
-
translation: en_US,
|
|
137
|
-
},
|
|
138
|
-
zh_CN: {
|
|
139
|
-
translation: zh_CN,
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
// console.log(result, 'result093sdolkfjlsdkjl');
|
|
144
|
-
window.localStorage.setItem(localStorage_i18nextResources_key, JSON.stringify(result));
|
|
145
|
-
// Cookies.set(localStorage_i18nextResources_key, encodeURIComponent(JSON.stringify(result)), {
|
|
146
|
-
// expires: 36525,
|
|
147
|
-
// domain: FUtil.Format.completeUrlByDomain('').replace(/http(s)?:\/\//, ''),
|
|
148
|
-
// });
|
|
149
|
-
|
|
150
|
-
return result;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export default I18nNext;
|
|
1
|
+
import i18next, {Resource} from 'i18next';
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import Cookies from 'js-cookie';
|
|
4
|
+
import FUtil from '../utils';
|
|
5
|
+
|
|
6
|
+
type LanguageKeyType = 'zh_CN' | 'en_US';
|
|
7
|
+
|
|
8
|
+
const ossJsonUrl: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs/i18n.json';
|
|
9
|
+
const ossJsonUrl_Test: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs-test/i18n.json';
|
|
10
|
+
const localStorage_i18nextLng_key: string = 'locale';
|
|
11
|
+
const localStorage_i18nextResources_key: string = 'i18nextResources';
|
|
12
|
+
|
|
13
|
+
const allLanguage = [
|
|
14
|
+
{value: 'en_US', label: 'English'},
|
|
15
|
+
{value: 'zh_CN', label: '简体中文'},
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
class I18nNext {
|
|
19
|
+
|
|
20
|
+
private _loadingData: 'NotStart' | 'Start' | 'End' = 'NotStart';
|
|
21
|
+
private _taskQueue: Function[] = [];
|
|
22
|
+
// private _currentLanguage: LanguageKeyType = window.localStorage.getItem(localStorage_i18nextLng_key) as null || 'zh_CN';
|
|
23
|
+
private _currentLanguage: LanguageKeyType = Cookies.get(localStorage_i18nextLng_key) as undefined || 'zh_CN';
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
this.ready();
|
|
27
|
+
|
|
28
|
+
this.ready = this.ready.bind(this);
|
|
29
|
+
this.t = this.t.bind(this);
|
|
30
|
+
this.changeLanguage = this.changeLanguage.bind(this);
|
|
31
|
+
this.getAllLanguage = this.getAllLanguage.bind(this);
|
|
32
|
+
this.getCurrentLanguage = this.getCurrentLanguage.bind(this);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async ready(this: I18nNext) {
|
|
36
|
+
const exc = () => {
|
|
37
|
+
while (this._taskQueue.length > 0) {
|
|
38
|
+
const task = this._taskQueue.shift();
|
|
39
|
+
task && task();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const handleTasks = async () => {
|
|
43
|
+
// console.log(this._loadingData, 'this._loadingData90iowejflksdfjlsdk');
|
|
44
|
+
if (this._loadingData === 'End') {
|
|
45
|
+
exc();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (this._loadingData === 'Start') {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// NO_START
|
|
53
|
+
this._loadingData = 'Start';
|
|
54
|
+
|
|
55
|
+
await this._handleData();
|
|
56
|
+
// console.log('######');
|
|
57
|
+
exc();
|
|
58
|
+
};
|
|
59
|
+
const promise = new Promise((resolve) => {
|
|
60
|
+
this._taskQueue.push(resolve);
|
|
61
|
+
});
|
|
62
|
+
handleTasks();
|
|
63
|
+
return promise;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
t(this: I18nNext, key: string, options?: { [key: string]: any }) {
|
|
67
|
+
return i18next.t(key, options);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
changeLanguage(this: I18nNext, lng: LanguageKeyType) {
|
|
71
|
+
// return i18next.changeLanguage(lng);
|
|
72
|
+
// window.localStorage.setItem(localStorage_i18nextLng_key, lng)
|
|
73
|
+
Cookies.set(localStorage_i18nextLng_key, lng, {
|
|
74
|
+
expires: 36525,
|
|
75
|
+
domain: FUtil.Format.completeUrlByDomain('').replace(/http(s)?:\/\//, ''),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getAllLanguage(this: I18nNext): typeof allLanguage {
|
|
80
|
+
return allLanguage;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getCurrentLanguage(this: I18nNext): LanguageKeyType {
|
|
84
|
+
return this._currentLanguage;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private async _handleData(this: I18nNext) {
|
|
88
|
+
|
|
89
|
+
const lng: string = this._currentLanguage;
|
|
90
|
+
const resource: string | null = window.localStorage.getItem(localStorage_i18nextResources_key);
|
|
91
|
+
// const resource: string | undefined = Cookies.get(decodeURIComponent(localStorage_i18nextResources_key));
|
|
92
|
+
let i18nextResources: Resource | null = resource ? JSON.parse(resource) : null;
|
|
93
|
+
|
|
94
|
+
if (!i18nextResources) {
|
|
95
|
+
// console.log('######892io3jlkl')
|
|
96
|
+
i18nextResources = await this._fetchData();
|
|
97
|
+
} else {
|
|
98
|
+
this._fetchData();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
await i18next
|
|
102
|
+
.init({
|
|
103
|
+
// the translations
|
|
104
|
+
// (tip move them in a JSON file and import them,
|
|
105
|
+
// or even better, manage them via a UI: https://react.i18next.com/guides/multiple-translation-files#manage-your-translations-with-a-management-gui)
|
|
106
|
+
resources: i18nextResources,
|
|
107
|
+
lng: lng, // if you're using a language detector, do not define the lng option
|
|
108
|
+
fallbackLng: 'zh_CN',
|
|
109
|
+
|
|
110
|
+
interpolation: {
|
|
111
|
+
escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
|
|
112
|
+
prefix: '{',
|
|
113
|
+
suffix: '}',
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
this._loadingData = 'End';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private async _fetchData(this: I18nNext): Promise<Resource> {
|
|
120
|
+
const res: any = await axios.get(window.location.origin.includes('.freelog.com') ? ossJsonUrl : ossJsonUrl_Test, {
|
|
121
|
+
withCredentials: false,
|
|
122
|
+
});
|
|
123
|
+
// console.log(res, 'data09oiw3qjelsfkdfjlsdkfjl');
|
|
124
|
+
|
|
125
|
+
const en_US: { [key: string]: string } = {};
|
|
126
|
+
const zh_CN: { [key: string]: string } = {};
|
|
127
|
+
|
|
128
|
+
for (const [key, value] of Object.entries(res)) {
|
|
129
|
+
// console.log(key, value, 'key, value90iowsldfjlsdkj');
|
|
130
|
+
en_US[key] = (value as any)['en_US'];
|
|
131
|
+
zh_CN[key] = (value as any)['zh_CN'];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const result: Resource = {
|
|
135
|
+
en_US: {
|
|
136
|
+
translation: en_US,
|
|
137
|
+
},
|
|
138
|
+
zh_CN: {
|
|
139
|
+
translation: zh_CN,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// console.log(result, 'result093sdolkfjlsdkjl');
|
|
144
|
+
window.localStorage.setItem(localStorage_i18nextResources_key, JSON.stringify(result));
|
|
145
|
+
// Cookies.set(localStorage_i18nextResources_key, encodeURIComponent(JSON.stringify(result)), {
|
|
146
|
+
// expires: 36525,
|
|
147
|
+
// domain: FUtil.Format.completeUrlByDomain('').replace(/http(s)?:\/\//, ''),
|
|
148
|
+
// });
|
|
149
|
+
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export default I18nNext;
|
package/src/i18n/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import I18nNext from './I18nNext';
|
|
2
|
-
|
|
3
|
-
const FI18n = {
|
|
4
|
-
i18nNext: new I18nNext(),
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export default FI18n;
|
|
1
|
+
import I18nNext from './I18nNext';
|
|
2
|
+
|
|
3
|
+
const FI18n = {
|
|
4
|
+
i18nNext: new I18nNext(),
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export default FI18n;
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import FUtil from './utils';
|
|
2
|
-
import FServiceAPI from './service-API';
|
|
3
|
-
import FI18n from './i18n';
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
FUtil,
|
|
7
|
-
FServiceAPI,
|
|
8
|
-
FI18n,
|
|
9
|
-
};
|
|
1
|
+
import FUtil from './utils';
|
|
2
|
+
import FServiceAPI from './service-API';
|
|
3
|
+
import FI18n from './i18n';
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
FUtil,
|
|
7
|
+
FServiceAPI,
|
|
8
|
+
FI18n,
|
|
9
|
+
};
|