@freelog/tools-lib 0.1.105 → 0.1.106

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 CHANGED
@@ -1,65 +1,67 @@
1
- {
2
- "name": "@freelog/tools-lib",
3
- "version": "0.1.105",
4
- "license": "MIT",
5
- "main": "dist/index.js",
6
- "typings": "dist/index.d.ts",
7
- "files": [
8
- "dist",
9
- "src"
10
- ],
11
- "engines": {
12
- "node": ">=10"
13
- },
14
- "scripts": {
15
- "start": "tsdx watch",
16
- "build": "tsdx build",
17
- "test": "tsdx test",
18
- "lint": "tsdx lint",
19
- "prepare": "tsdx build",
20
- "size": "size-limit",
21
- "analyze": "size-limit --why",
22
- "publish": "npm publish --access public"
23
- },
24
- "peerDependencies": {},
25
- "husky": {
26
- "hooks": {}
27
- },
28
- "prettier": {
29
- "printWidth": 80,
30
- "semi": true,
31
- "singleQuote": true,
32
- "trailingComma": "es5"
33
- },
34
- "author": "liu-kai-github",
35
- "module": "dist/tools-lib.esm.js",
36
- "size-limit": [
37
- {
38
- "path": "dist/tools-lib.cjs.production.min.js",
39
- "limit": "10 KB"
40
- },
41
- {
42
- "path": "dist/tools-lib.esm.js",
43
- "limit": "10 KB"
44
- }
45
- ],
46
- "devDependencies": {
47
- "@size-limit/preset-small-lib": "^4.11.0",
48
- "@types/crypto-js": "^4.0.1",
49
- "@types/nprogress": "^0.2.0",
50
- "husky": "^6.0.0",
51
- "size-limit": "^4.11.0",
52
- "tsdx": "^0.14.1",
53
- "tslib": "^2.2.0",
54
- "typescript": "^4.3.2"
55
- },
56
- "dependencies": {
57
- "@freelog/resource-policy-lang": "1.1.26",
58
- "@freelog/tools-lib": "^0.1.43",
59
- "axios": "^0.21.1",
60
- "crypto-js": "^4.0.0",
61
- "i18next": "^21.8.10",
62
- "moment": "^2.29.1",
63
- "nprogress": "^0.2.0"
64
- }
65
- }
1
+ {
2
+ "name": "@freelog/tools-lib",
3
+ "version": "0.1.106",
4
+ "license": "MIT",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "src"
10
+ ],
11
+ "engines": {
12
+ "node": ">=10"
13
+ },
14
+ "scripts": {
15
+ "start": "tsdx watch",
16
+ "build": "tsdx build",
17
+ "test": "tsdx test",
18
+ "lint": "tsdx lint",
19
+ "prepare": "tsdx build",
20
+ "size": "size-limit",
21
+ "analyze": "size-limit --why",
22
+ "publish": "npm publish --access public"
23
+ },
24
+ "peerDependencies": {},
25
+ "husky": {
26
+ "hooks": {}
27
+ },
28
+ "prettier": {
29
+ "printWidth": 80,
30
+ "semi": true,
31
+ "singleQuote": true,
32
+ "trailingComma": "es5"
33
+ },
34
+ "author": "liu-kai-github",
35
+ "module": "dist/tools-lib.esm.js",
36
+ "size-limit": [
37
+ {
38
+ "path": "dist/tools-lib.cjs.production.min.js",
39
+ "limit": "10 KB"
40
+ },
41
+ {
42
+ "path": "dist/tools-lib.esm.js",
43
+ "limit": "10 KB"
44
+ }
45
+ ],
46
+ "devDependencies": {
47
+ "@size-limit/preset-small-lib": "^4.11.0",
48
+ "@types/crypto-js": "^4.0.1",
49
+ "@types/js-cookie": "^3.0.2",
50
+ "@types/nprogress": "^0.2.0",
51
+ "husky": "^6.0.0",
52
+ "size-limit": "^4.11.0",
53
+ "tsdx": "^0.14.1",
54
+ "tslib": "^2.2.0",
55
+ "typescript": "^4.3.2"
56
+ },
57
+ "dependencies": {
58
+ "@freelog/resource-policy-lang": "1.1.26",
59
+ "@freelog/tools-lib": "^0.1.43",
60
+ "axios": "^0.21.1",
61
+ "crypto-js": "^4.0.0",
62
+ "i18next": "^21.8.10",
63
+ "js-cookie": "^3.0.1",
64
+ "moment": "^2.29.1",
65
+ "nprogress": "^0.2.0"
66
+ }
67
+ }
@@ -1,134 +1,146 @@
1
- import i18next, {Resource} from 'i18next';
2
- import axios from "axios";
3
-
4
- type LanguageKeyType = 'zh_CN' | 'en_US';
5
-
6
- const ossJsonUrl: string = 'https://freelog-i18n.oss-cn-shenzhen.aliyuncs.com/configs/i18n.json';
7
- const localStorage_i18nextLng_key: string = 'i18nextLng';
8
- const localStorage_i18nextResources_key: string = 'i18nextResources';
9
-
10
- const allLanguage = [
11
- {value: 'en_US', label: 'English'},
12
- {value: 'zh_CN', label: '简体中文'},
13
- ];
14
-
15
- let self: I18nNext;
16
-
17
- class I18nNext {
18
-
19
- private _loadingData: 'NotStart' | 'Start' | 'End' = 'NotStart';
20
- private _taskQueue: Function[] = [];
21
- private _currentLanguage: LanguageKeyType = window.localStorage.getItem(localStorage_i18nextLng_key) as null || 'zh_CN';
22
-
23
- constructor() {
24
- self = this;
25
- self.ready();
26
- }
27
-
28
- async ready() {
29
- const exc = () => {
30
- while (self._taskQueue.length > 0) {
31
- const task = self._taskQueue.shift();
32
- task && task();
33
- }
34
- };
35
- const handleTasks = async () => {
36
- if (self._loadingData === 'End') {
37
- exc();
38
- return;
39
- }
40
- if (self._loadingData === 'Start') {
41
- return;
42
- }
43
-
44
- // NO_START
45
- self._loadingData = 'Start';
46
-
47
- await self._handleData();
48
- // console.log('######');
49
- exc();
50
- };
51
- const promise = new Promise((resolve) => {
52
- self._taskQueue.push(resolve);
53
- });
54
- handleTasks();
55
- return promise;
56
- }
57
-
58
- t(key: string, options?: { [key: string]: any }) {
59
- return i18next.t(key, options);
60
- }
61
-
62
- changeLanguage(lng: LanguageKeyType) {
63
- // return i18next.changeLanguage(lng);
64
- window.localStorage.setItem(localStorage_i18nextLng_key, lng)
65
- }
66
-
67
- getAllLanguage(): typeof allLanguage {
68
- return allLanguage;
69
- }
70
-
71
- getCurrentLanguage(): LanguageKeyType {
72
- return self._currentLanguage;
73
- }
74
-
75
- private async _handleData() {
76
-
77
- const lng: string = self._currentLanguage;
78
- const resource: string | null = window.localStorage.getItem(localStorage_i18nextResources_key);
79
- let i18nextResources: Resource | null = resource ? JSON.parse(resource) : null;
80
-
81
- if (!i18nextResources) {
82
- // console.log('######892io3jlkl')
83
- i18nextResources = await self._fetchData();
84
- } else {
85
- self._fetchData();
86
- }
87
-
88
- await i18next
89
- .init({
90
- // the translations
91
- // (tip move them in a JSON file and import them,
92
- // or even better, manage them via a UI: https://react.i18next.com/guides/multiple-translation-files#manage-your-translations-with-a-management-gui)
93
- resources: i18nextResources,
94
- lng: lng, // if you're using a language detector, do not define the lng option
95
- fallbackLng: 'zh_CN',
96
-
97
- interpolation: {
98
- escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
99
- },
100
- });
101
- }
102
-
103
- private async _fetchData(): Promise<Resource> {
104
- const res: any = await axios.get(ossJsonUrl, {
105
- withCredentials: false,
106
- });
107
- // console.log(res, 'data09oiw3qjelsfkdfjlsdkfjl');
108
-
109
- const en_US: { [key: string]: string } = {};
110
- const zh_CN: { [key: string]: string } = {};
111
-
112
- for (const [key, value] of Object.entries(res)) {
113
- // console.log(key, value, 'key, value90iowsldfjlsdkj');
114
- en_US[key] = (value as any)['en_US'];
115
- zh_CN[key] = (value as any)['zh_CN'];
116
- }
117
-
118
- const result: Resource = {
119
- en_US: {
120
- translation: en_US,
121
- },
122
- zh_CN: {
123
- translation: zh_CN,
124
- },
125
- };
126
-
127
- // console.log(result, 'result093sdolkfjlsdkjl');
128
- window.localStorage.setItem(localStorage_i18nextResources_key, JSON.stringify(result));
129
-
130
- return result;
131
- }
132
- }
133
-
134
- 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 localStorage_i18nextLng_key: string = 'locale';
10
+ const localStorage_i18nextResources_key: string = 'i18nextResources';
11
+
12
+ const allLanguage = [
13
+ {value: 'en_US', label: 'English'},
14
+ {value: 'zh_CN', label: '简体中文'},
15
+ ];
16
+
17
+ let self: I18nNext;
18
+
19
+ class I18nNext {
20
+
21
+ private _loadingData: 'NotStart' | 'Start' | 'End' = 'NotStart';
22
+ private _taskQueue: Function[] = [];
23
+ // private _currentLanguage: LanguageKeyType = window.localStorage.getItem(localStorage_i18nextLng_key) as null || 'zh_CN';
24
+ private _currentLanguage: LanguageKeyType = Cookies.get(localStorage_i18nextLng_key) as undefined || 'zh_CN';
25
+
26
+ constructor() {
27
+ self = this;
28
+ self.ready();
29
+ }
30
+
31
+ async ready() {
32
+ const exc = () => {
33
+ while (self._taskQueue.length > 0) {
34
+ const task = self._taskQueue.shift();
35
+ task && task();
36
+ }
37
+ };
38
+ const handleTasks = async () => {
39
+ if (self._loadingData === 'End') {
40
+ exc();
41
+ return;
42
+ }
43
+ if (self._loadingData === 'Start') {
44
+ return;
45
+ }
46
+
47
+ // NO_START
48
+ self._loadingData = 'Start';
49
+
50
+ await self._handleData();
51
+ // console.log('######');
52
+ exc();
53
+ };
54
+ const promise = new Promise((resolve) => {
55
+ self._taskQueue.push(resolve);
56
+ });
57
+ handleTasks();
58
+ return promise;
59
+ }
60
+
61
+ t(key: string, options?: { [key: string]: any }) {
62
+ return i18next.t(key, options);
63
+ }
64
+
65
+ changeLanguage(lng: LanguageKeyType) {
66
+ // return i18next.changeLanguage(lng);
67
+ // window.localStorage.setItem(localStorage_i18nextLng_key, lng)
68
+ Cookies.set(localStorage_i18nextLng_key, lng, {
69
+ expires: 36525,
70
+ domain: FUtil.Format.completeUrlByDomain('').replace(/http(s)?:\/\//, ''),
71
+ });
72
+ }
73
+
74
+ getAllLanguage(): typeof allLanguage {
75
+ return allLanguage;
76
+ }
77
+
78
+ getCurrentLanguage(): LanguageKeyType {
79
+ return self._currentLanguage;
80
+ }
81
+
82
+ private async _handleData() {
83
+
84
+ const lng: string = self._currentLanguage;
85
+ const resource: string | null = window.localStorage.getItem(localStorage_i18nextResources_key);
86
+ // const resource: string | undefined = Cookies.get(decodeURIComponent(localStorage_i18nextResources_key));
87
+ let i18nextResources: Resource | null = resource ? JSON.parse(resource) : null;
88
+
89
+ if (!i18nextResources) {
90
+ // console.log('######892io3jlkl')
91
+ i18nextResources = await self._fetchData();
92
+ } else {
93
+ self._fetchData();
94
+ }
95
+
96
+ await i18next
97
+ .init({
98
+ // the translations
99
+ // (tip move them in a JSON file and import them,
100
+ // or even better, manage them via a UI: https://react.i18next.com/guides/multiple-translation-files#manage-your-translations-with-a-management-gui)
101
+ resources: i18nextResources,
102
+ lng: lng, // if you're using a language detector, do not define the lng option
103
+ fallbackLng: 'zh_CN',
104
+
105
+ interpolation: {
106
+ escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
107
+ },
108
+ });
109
+ }
110
+
111
+ private async _fetchData(): Promise<Resource> {
112
+ const res: any = await axios.get(ossJsonUrl, {
113
+ withCredentials: false,
114
+ });
115
+ // console.log(res, 'data09oiw3qjelsfkdfjlsdkfjl');
116
+
117
+ const en_US: { [key: string]: string } = {};
118
+ const zh_CN: { [key: string]: string } = {};
119
+
120
+ for (const [key, value] of Object.entries(res)) {
121
+ // console.log(key, value, 'key, value90iowsldfjlsdkj');
122
+ en_US[key] = (value as any)['en_US'];
123
+ zh_CN[key] = (value as any)['zh_CN'];
124
+ }
125
+
126
+ const result: Resource = {
127
+ en_US: {
128
+ translation: en_US,
129
+ },
130
+ zh_CN: {
131
+ translation: zh_CN,
132
+ },
133
+ };
134
+
135
+ // console.log(result, 'result093sdolkfjlsdkjl');
136
+ window.localStorage.setItem(localStorage_i18nextResources_key, JSON.stringify(result));
137
+ // Cookies.set(localStorage_i18nextResources_key, encodeURIComponent(JSON.stringify(result)), {
138
+ // expires: 36525,
139
+ // domain: FUtil.Format.completeUrlByDomain('').replace(/http(s)?:\/\//, ''),
140
+ // });
141
+
142
+ return result;
143
+ }
144
+ }
145
+
146
+ 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
+ };
@@ -1,35 +1,35 @@
1
- import FUtil from '../utils';
2
-
3
- // 列出翻译
4
- interface ConfigsListParamsType {
5
- key: string;
6
- content: string;
7
- tagIds: string[];
8
- status: 0 | 1 | 2 | 3; // 0:全部 1:待翻译 2:待发布 3:已发布
9
- }
10
-
11
- export function configsList(params: ConfigsListParamsType) {
12
- // console.log('####@30984i2o3jdsjflfkjsdl')
13
- return FUtil.Request({
14
- method: 'POST',
15
- url: `/v2/i18n/configs/list`,
16
- data: params,
17
- });
18
- }
19
-
20
- // oss保存的翻译
21
- // interface ConfigsListParamsType {
22
- // key: string;
23
- // content: string;
24
- // tagIds: string[];
25
- // status: 0 | 1 | 2 | 3; // 0:全部 1:待翻译 2:待发布 3:已发布
26
- // }
27
- //
28
- // export function configsList(params: ConfigsListParamsType) {
29
- // // console.log('####@30984i2o3jdsjflfkjsdl')
30
- // return FUtil.Request({
31
- // method: 'POST',
32
- // url: `/v2/i18n/configs/list`,
33
- // data: params,
34
- // });
35
- // }
1
+ import FUtil from '../utils';
2
+
3
+ // 列出翻译
4
+ interface ConfigsListParamsType {
5
+ key: string;
6
+ content: string;
7
+ tagIds: string[];
8
+ status: 0 | 1 | 2 | 3; // 0:全部 1:待翻译 2:待发布 3:已发布
9
+ }
10
+
11
+ export function configsList(params: ConfigsListParamsType) {
12
+ // console.log('####@30984i2o3jdsjflfkjsdl')
13
+ return FUtil.Request({
14
+ method: 'POST',
15
+ url: `/v2/i18n/configs/list`,
16
+ data: params,
17
+ });
18
+ }
19
+
20
+ // oss保存的翻译
21
+ // interface ConfigsListParamsType {
22
+ // key: string;
23
+ // content: string;
24
+ // tagIds: string[];
25
+ // status: 0 | 1 | 2 | 3; // 0:全部 1:待翻译 2:待发布 3:已发布
26
+ // }
27
+ //
28
+ // export function configsList(params: ConfigsListParamsType) {
29
+ // // console.log('####@30984i2o3jdsjflfkjsdl')
30
+ // return FUtil.Request({
31
+ // method: 'POST',
32
+ // url: `/v2/i18n/configs/list`,
33
+ // data: params,
34
+ // });
35
+ // }
@@ -1,35 +1,35 @@
1
- import * as Node from './nodes';
2
- import * as Exhibit from './presentables';
3
- import * as Storage from './storages';
4
- import * as Collection from './collections';
5
- import * as Resource from './resources';
6
- import * as User from './user';
7
- import * as InformalNode from './informalNodes';
8
- import * as Contract from './contracts';
9
- import * as Transaction from './transactions';
10
- import * as Captcha from './captcha';
11
- import * as Event from './events';
12
- import * as Activity from './activities';
13
- import * as TestQualification from './testQualifications';
14
- import * as Statistic from './statistics';
15
- import * as I18n from './i18n';
16
-
17
- const FServiceAPI = {
18
- Node,
19
- Exhibit,
20
- Storage,
21
- Collection,
22
- Resource,
23
- User,
24
- InformalNode,
25
- Contract,
26
- Transaction,
27
- Captcha,
28
- Event,
29
- Activity,
30
- TestQualification,
31
- Statistic,
32
- I18n,
33
- };
34
-
35
- export default FServiceAPI;
1
+ import * as Node from './nodes';
2
+ import * as Exhibit from './presentables';
3
+ import * as Storage from './storages';
4
+ import * as Collection from './collections';
5
+ import * as Resource from './resources';
6
+ import * as User from './user';
7
+ import * as InformalNode from './informalNodes';
8
+ import * as Contract from './contracts';
9
+ import * as Transaction from './transactions';
10
+ import * as Captcha from './captcha';
11
+ import * as Event from './events';
12
+ import * as Activity from './activities';
13
+ import * as TestQualification from './testQualifications';
14
+ import * as Statistic from './statistics';
15
+ import * as I18n from './i18n';
16
+
17
+ const FServiceAPI = {
18
+ Node,
19
+ Exhibit,
20
+ Storage,
21
+ Collection,
22
+ Resource,
23
+ User,
24
+ InformalNode,
25
+ Contract,
26
+ Transaction,
27
+ Captcha,
28
+ Event,
29
+ Activity,
30
+ TestQualification,
31
+ Statistic,
32
+ I18n,
33
+ };
34
+
35
+ export default FServiceAPI;
@@ -1,20 +1,20 @@
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
- // import I18n from '../i18n';
8
-
9
- const FUtil = {
10
- Format,
11
- Regexp,
12
- LinkTo,
13
- Predefined,
14
- Axios,
15
- Request: request,
16
- Tool,
17
- // i18n: new I18n(),
18
- };
19
-
20
- 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
+ // import I18n from '../i18n';
8
+
9
+ const FUtil = {
10
+ Format,
11
+ Regexp,
12
+ LinkTo,
13
+ Predefined,
14
+ Axios,
15
+ Request: request,
16
+ Tool,
17
+ // i18n: new I18n(),
18
+ };
19
+
20
+ export default FUtil;