zmdms-utils 0.0.63 → 0.0.65

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.
@@ -1,71 +1,203 @@
1
- import dayjs$1 from 'dayjs';
1
+ import '../node_modules/decimal.js/decimal2.js';
2
+ import { exports as decimalExports } from '../_virtual/decimal.js';
2
3
 
3
- function unescapeString(input) {
4
- if (!input) {
5
- return "";
6
- }
4
+ // function unescapeString(input) {
5
+ // if (!input) {
6
+ // return "";
7
+ // }
7
8
 
8
- const escapedChars = {
9
- "&": "&",
10
- "&lt;": "<",
11
- "&gt;": ">",
12
- "&quot;": '"',
13
- "&#039;": "'",
14
- };
15
-
16
- return input.replace(/&(amp|lt|gt|quot|#039);/g, (match) => {
17
- return escapedChars[match] || match;
18
- });
19
- }
9
+ // const escapedChars = {
10
+ // "&amp;": "&",
11
+ // "&lt;": "<",
12
+ // "&gt;": ">",
13
+ // "&quot;": '"',
14
+ // "&#039;": "'",
15
+ // };
16
+
17
+ // return input.replace(/&(amp|lt|gt|quot|#039);/g, (match) => {
18
+ // return escapedChars[match] || match;
19
+ // });
20
+ // }
21
+
22
+ // function dangerouslySetXss(input) {
23
+ // if (!input) {
24
+ // return "";
25
+ // }
26
+ // const escapedChars = {
27
+ // "&lt;": "<",
28
+ // "&gt;": ">",
29
+ // "&nbsp;": " ",
30
+ // "&amp;": "&",
31
+ // "&quot;": '"',
32
+ // };
33
+
34
+ // return input.replace(/&(amp|lt|gt|quot|nbsp);/g, (match) => {
35
+ // return escapedChars[match] || match;
36
+ // });
37
+ // }
38
+
39
+ // function dangerouslySetXss1(input) {
40
+ // if (!input) {
41
+ // return "";
42
+ // }
43
+ // const escapedChars = {
44
+ // lt: "<",
45
+ // gt: ">",
46
+ // nbsp: " ",
47
+ // amp: "&",
48
+ // quot: '"',
49
+ // };
50
+
51
+ // return input.replace(/&(amp|lt|gt|quot|nbsp);/gi, (match, t) => {
52
+ // return escapedChars[t] || match;
53
+ // });
54
+ // }
55
+
56
+ // console.log(unescapeString("&amp;&amp;&amp;啊你"));
57
+
58
+ // console.log(dangerouslySetXss("&amp;&amp;&amp;啊你"));
59
+
60
+ // console.log(dangerouslySetXss1("&amp;&amp;&amp;啊你"));
61
+ // console.log(unescapeString("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
62
+ // console.log(dangerouslySetXss("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
63
+ // console.log(dangerouslySetXss1("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
64
+
65
+ // const dayjs = require("dayjs");
66
+
67
+ // const a = dayjs("2023-01-01 11:11").startOf("day");
68
+ // const formattedDate = a.format("YYYY-MM-DD HH:mm:ss");
69
+
70
+ // const b = dayjs("2023-01-01").endOf("day");
71
+ // const formattedDate1 = b.format("YYYY-MM-DD HH:mm:ss");
72
+ // console.log(formattedDate, formattedDate1);
73
+
74
+ // functions and constants
75
+ // console.log("functions and constants");
76
+ // print(math.round(math.e, 3)); // 2.718
77
+ // print(math.atan2(3, -3) / math.pi); // 0.75
78
+ // print(math.log(10000, 10)); // 4
79
+ // print(math.sqrt(-4)); // 2i
80
+ // print(
81
+ // math.pow(
82
+ // [
83
+ // [-1, 2],
84
+ // [3, 1],
85
+ // ],
86
+ // 2
87
+ // )
88
+ // ); // [[7, 0], [0, 7]]
89
+ // print(math.derivative("x^2 + x", "x")); // 2 * x + 1
90
+ // console.log();
20
91
 
21
- function dangerouslySetXss(input) {
22
- if (!input) {
23
- return "";
92
+ // // expressions
93
+ // console.log("expressions");
94
+ // print(math.evaluate("1.2 * (2 + 4.5)")); // 7.8
95
+ // print(math.evaluate("12.7 cm to inch")); // 5 inch
96
+ // print(math.evaluate("sin(45 deg) ^ 2")); // 0.5
97
+ // print(math.evaluate("9 / 3 + 2i")); // 3 + 2i
98
+ // print(math.evaluate("det([-1, 2; 3, 1])")); // -7
99
+ // print(math.evaluate("NaN + '0.2'")); // -7
100
+ // console.log();
101
+
102
+ // // chained operations
103
+ // console.log("chained operations");
104
+ // const a = math.chain(3).add(4).multiply(2).done();
105
+ // print(a); // 14
106
+ // console.log();
107
+
108
+ // // mixed use of different data types in functions
109
+ // console.log("mixed use of data types");
110
+ // print(math.add(4, [5, 6])); // number + Array, [9, 10]
111
+ // print(math.multiply(math.unit("5 mm"), 3)); // Unit * number, 15 mm
112
+ // print(math.subtract([2, 3, 4], 5)); // Array - number, [-3, -2, -1]
113
+ // print(math.add(math.matrix([2, 3]), [4, 5])); // Matrix + Array, [6, 8]
114
+ // console.log();
115
+
116
+ // /**
117
+ // * Helper function to output a value in the console. Value will be formatted.
118
+ // * @param {*} value
119
+ // */
120
+ // function print(value) {
121
+ // const precision = 14;
122
+ // console.log(math.format(value, precision));
123
+ // }
124
+
125
+ // const math = require("mathjs");
126
+ // function print(value) {
127
+ // const precision = 14;
128
+ // console.log(math.format(value, precision));
129
+ // }
130
+
131
+ // console.log(performance.now());
132
+ // console.log(math.add(0.1, 0.2));
133
+ // console.log(performance.now());
134
+ // console.log(performance.now());
135
+ // console.log(0.1 + 0.2);
136
+ // console.log(performance.now());
137
+ // const BigNumber = require("bignumber.js");
138
+ // console.log(performance.now());
139
+ // const num1 = new BigNumber(0.1);
140
+ // const num2 = new BigNumber(0.2);
141
+
142
+ // const result = num1.plus(num2);
143
+
144
+ // console.log(result.toString());
145
+
146
+ // console.log(performance.now());
147
+
148
+ const Decimal = decimalExports;
149
+
150
+ function initNum(num1, num2) {
151
+ // 如果两个数都是非数字 那么直接返回0
152
+ if (isNaN(num1) && isNaN(num2)) {
153
+ return 0;
154
+ }
155
+ if (isNaN(num1)) {
156
+ return num2;
157
+ }
158
+ if (isNaN(num2)) {
159
+ return num1;
24
160
  }
25
- const escapedChars = {
26
- "&lt;": "<",
27
- "&gt;": ">",
28
- "&nbsp;": " ",
29
- "&amp;": "&",
30
- "&quot;": '"',
31
- };
32
-
33
- return input.replace(/&(amp|lt|gt|quot|nbsp);/g, (match) => {
34
- return escapedChars[match] || match;
35
- });
36
161
  }
37
162
 
38
- function dangerouslySetXss1(input) {
39
- if (!input) {
40
- return "";
163
+ function times(num1, num2) {
164
+ try {
165
+ const _num1 = num1 == null ? NaN : Number(num1);
166
+ const _num2 = num2 == null ? NaN : Number(num2);
167
+ // 如果两个数都是非数字 那么直接返回0
168
+ const result = initNum(_num1, _num2);
169
+ if (typeof result === "number") {
170
+ return result;
171
+ }
172
+ return new Decimal(_num1).mul(_num2).toNumber();
173
+ // return (isNaN(_num1) ? 0 : _num1) * (isNaN(_num2) ? 0 : _num2);
174
+ } catch (err) {
175
+ console.error("计算乘法出错", err);
176
+ return 0;
41
177
  }
42
- const escapedChars = {
43
- lt: "<",
44
- gt: ">",
45
- nbsp: " ",
46
- amp: "&",
47
- quot: '"',
48
- };
49
-
50
- return input.replace(/&(amp|lt|gt|quot|nbsp);/gi, (match, t) => {
51
- return escapedChars[t] || match;
52
- });
53
178
  }
54
179
 
55
- console.log(unescapeString("&amp;&amp;&amp;啊你"));
56
-
57
- console.log(dangerouslySetXss("&amp;&amp;&amp;啊你"));
180
+ console.log(times(78.11, 0.77));
181
+ console.log(times(7777777.77, 1.1));
182
+ // 7777777.77 * 1.1
183
+ const num1 = new Decimal("78.11");
58
184
 
59
- console.log(dangerouslySetXss1("&amp;&amp;&amp;啊你"));
60
- console.log(unescapeString("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
61
- console.log(dangerouslySetXss("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
62
- console.log(dangerouslySetXss1("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
185
+ // console.log(num1.add(0.21).toNumber(), typeof num1.add(0.21).toNumber());
63
186
 
64
- const dayjs = dayjs$1;
187
+ // console.log(num1.sub(0.21).toNumber(), typeof num1.sub(0.21).toNumber());
65
188
 
66
- const a = dayjs("2023-01-01 11:11").startOf("day");
67
- const formattedDate = a.format("YYYY-MM-DD HH:mm:ss");
189
+ console.log(num1.mul(0.77).toNumber(), typeof num1.mul(0.21).toNumber());
190
+ Decimal.set({ precision: 5 });
191
+ console.log(
192
+ new Decimal(1).div(1.1).toNumber(),
193
+ typeof new Decimal(1).div(1.1).toNumber()
194
+ );
195
+ console.log(
196
+ new Decimal(1).dividedBy(1.1).toNumber(),
197
+ typeof new Decimal(1).dividedBy(1.1).toNumber()
198
+ );
68
199
 
69
- const b = dayjs("2023-01-01").endOf("day");
70
- const formattedDate1 = b.format("YYYY-MM-DD HH:mm:ss");
71
- console.log(formattedDate, formattedDate1);
200
+ console.log(
201
+ Number(new Decimal(1.1).toFixed(2)),
202
+ typeof Number(new Decimal(1.1).toFixed(2)).toFixed(2)
203
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-utils",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/baseUrl.ts CHANGED
@@ -61,10 +61,10 @@ export function getBaseUrl(processObj: any, options?: IOptions) {
61
61
  // 退出登录地址
62
62
  const logoutUrl: any = {
63
63
  dev: processObj[`${logoutKey}_DEV`] || "/login",
64
- test: processObj[`${logoutKey}_DEV`] || "/login",
64
+ test: processObj[`${logoutKey}_TEST`] || "/login",
65
65
  stage:
66
- processObj[`${logoutKey}_DEV`] || "http://testportal.cncico.com:8099/",
67
- prod: processObj[`${logoutKey}_DEV`] || "http://newportal.cncico.com/",
66
+ processObj[`${logoutKey}_STAGE`] || "http://testportal.cncico.com:8099/",
67
+ prod: processObj[`${logoutKey}_PROD`] || "http://newportal.cncico.com/",
68
68
  };
69
69
 
70
70
  const currentKey = ENV.toLowerCase() || "prod";
package/src/constants.ts CHANGED
@@ -26,8 +26,8 @@ export const EMITTER_TYPE = {
26
26
 
27
27
  // token key 值
28
28
  // export const TOKEN_KEY = "Zmdms-Auth";
29
- export const TOKEN_KEY = "Cicoms-Auth";
29
+ export const TOKEN_KEY = (window as any).__TOKEN_KEY__ || "Cicoms-Auth";
30
30
 
31
31
  // 基础前缀
32
32
  // export const BASIC_KEY = "zmdms";
33
- export const BASIC_KEY = "cicoms";
33
+ export const BASIC_KEY = (window as any).__BASIC_KEY__ || "cicoms";
package/src/test.js CHANGED
@@ -1,72 +1,72 @@
1
- function unescapeString(input) {
2
- if (!input) {
3
- return "";
4
- }
5
-
6
- const escapedChars = {
7
- "&amp;": "&",
8
- "&lt;": "<",
9
- "&gt;": ">",
10
- "&quot;": '"',
11
- "&#039;": "'",
12
- };
13
-
14
- return input.replace(/&(amp|lt|gt|quot|#039);/g, (match) => {
15
- return escapedChars[match] || match;
16
- });
17
- }
1
+ // function unescapeString(input) {
2
+ // if (!input) {
3
+ // return "";
4
+ // }
5
+
6
+ // const escapedChars = {
7
+ // "&amp;": "&",
8
+ // "&lt;": "<",
9
+ // "&gt;": ">",
10
+ // "&quot;": '"',
11
+ // "&#039;": "'",
12
+ // };
13
+
14
+ // return input.replace(/&(amp|lt|gt|quot|#039);/g, (match) => {
15
+ // return escapedChars[match] || match;
16
+ // });
17
+ // }
18
18
 
19
- function dangerouslySetXss(input) {
20
- if (!input) {
21
- return "";
22
- }
23
- const escapedChars = {
24
- "&lt;": "<",
25
- "&gt;": ">",
26
- "&nbsp;": " ",
27
- "&amp;": "&",
28
- "&quot;": '"',
29
- };
30
-
31
- return input.replace(/&(amp|lt|gt|quot|nbsp);/g, (match) => {
32
- return escapedChars[match] || match;
33
- });
34
- }
19
+ // function dangerouslySetXss(input) {
20
+ // if (!input) {
21
+ // return "";
22
+ // }
23
+ // const escapedChars = {
24
+ // "&lt;": "<",
25
+ // "&gt;": ">",
26
+ // "&nbsp;": " ",
27
+ // "&amp;": "&",
28
+ // "&quot;": '"',
29
+ // };
30
+
31
+ // return input.replace(/&(amp|lt|gt|quot|nbsp);/g, (match) => {
32
+ // return escapedChars[match] || match;
33
+ // });
34
+ // }
35
35
 
36
- function dangerouslySetXss1(input) {
37
- if (!input) {
38
- return "";
39
- }
40
- const escapedChars = {
41
- lt: "<",
42
- gt: ">",
43
- nbsp: " ",
44
- amp: "&",
45
- quot: '"',
46
- };
47
-
48
- return input.replace(/&(amp|lt|gt|quot|nbsp);/gi, (match, t) => {
49
- return escapedChars[t] || match;
50
- });
51
- }
36
+ // function dangerouslySetXss1(input) {
37
+ // if (!input) {
38
+ // return "";
39
+ // }
40
+ // const escapedChars = {
41
+ // lt: "<",
42
+ // gt: ">",
43
+ // nbsp: " ",
44
+ // amp: "&",
45
+ // quot: '"',
46
+ // };
47
+
48
+ // return input.replace(/&(amp|lt|gt|quot|nbsp);/gi, (match, t) => {
49
+ // return escapedChars[t] || match;
50
+ // });
51
+ // }
52
52
 
53
- console.log(unescapeString("&amp;&amp;&amp;啊你"));
53
+ // console.log(unescapeString("&amp;&amp;&amp;啊你"));
54
54
 
55
- console.log(dangerouslySetXss("&amp;&amp;&amp;啊你"));
55
+ // console.log(dangerouslySetXss("&amp;&amp;&amp;啊你"));
56
56
 
57
- console.log(dangerouslySetXss1("&amp;&amp;&amp;啊你"));
58
- console.log(unescapeString("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
59
- console.log(dangerouslySetXss("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
60
- console.log(dangerouslySetXss1("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
57
+ // console.log(dangerouslySetXss1("&amp;&amp;&amp;啊你"));
58
+ // console.log(unescapeString("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
59
+ // console.log(dangerouslySetXss("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
60
+ // console.log(dangerouslySetXss1("1、aa&gt;80%\n2、&gt;&lt;\n3、ss&lt;80%"));
61
61
 
62
- const dayjs = require("dayjs");
62
+ // const dayjs = require("dayjs");
63
63
 
64
- const a = dayjs("2023-01-01 11:11").startOf("day");
65
- const formattedDate = a.format("YYYY-MM-DD HH:mm:ss");
64
+ // const a = dayjs("2023-01-01 11:11").startOf("day");
65
+ // const formattedDate = a.format("YYYY-MM-DD HH:mm:ss");
66
66
 
67
- const b = dayjs("2023-01-01").endOf("day");
68
- const formattedDate1 = b.format("YYYY-MM-DD HH:mm:ss");
69
- console.log(formattedDate, formattedDate1);
67
+ // const b = dayjs("2023-01-01").endOf("day");
68
+ // const formattedDate1 = b.format("YYYY-MM-DD HH:mm:ss");
69
+ // console.log(formattedDate, formattedDate1);
70
70
 
71
71
  // functions and constants
72
72
  // console.log("functions and constants");
@@ -142,26 +142,59 @@ console.log(formattedDate, formattedDate1);
142
142
 
143
143
  // console.log(performance.now());
144
144
 
145
- // const Decimal = require("decimal.js");
145
+ const Decimal = require("decimal.js");
146
+
147
+ function initNum(num1, num2) {
148
+ // 如果两个数都是非数字 那么直接返回0
149
+ if (isNaN(num1) && isNaN(num2)) {
150
+ return 0;
151
+ }
152
+ if (isNaN(num1)) {
153
+ return num2;
154
+ }
155
+ if (isNaN(num2)) {
156
+ return num1;
157
+ }
158
+ }
159
+
160
+ function times(num1, num2) {
161
+ try {
162
+ const _num1 = num1 == null ? NaN : Number(num1);
163
+ const _num2 = num2 == null ? NaN : Number(num2);
164
+ // 如果两个数都是非数字 那么直接返回0
165
+ const result = initNum(_num1, _num2);
166
+ if (typeof result === "number") {
167
+ return result;
168
+ }
169
+ return new Decimal(_num1).mul(_num2).toNumber();
170
+ // return (isNaN(_num1) ? 0 : _num1) * (isNaN(_num2) ? 0 : _num2);
171
+ } catch (err) {
172
+ console.error("计算乘法出错", err);
173
+ return 0;
174
+ }
175
+ }
146
176
 
147
- // const num1 = new Decimal("0.1");
177
+ console.log(times(78.11, 0.77));
178
+ console.log(times(7777777.77, 1.1));
179
+ // 7777777.77 * 1.1
180
+ const num1 = new Decimal("78.11");
148
181
 
149
182
  // console.log(num1.add(0.21).toNumber(), typeof num1.add(0.21).toNumber());
150
183
 
151
184
  // console.log(num1.sub(0.21).toNumber(), typeof num1.sub(0.21).toNumber());
152
185
 
153
- // console.log(num1.mul(0.21).toNumber(), typeof num1.mul(0.21).toNumber());
154
- // Decimal.set({ precision: 5 });
155
- // console.log(
156
- // new Decimal(1).div(1.1).toNumber(),
157
- // typeof new Decimal(1).div(1.1).toNumber()
158
- // );
159
- // console.log(
160
- // new Decimal(1).dividedBy(1.1).toNumber(),
161
- // typeof new Decimal(1).dividedBy(1.1).toNumber()
162
- // );
163
-
164
- // console.log(
165
- // Number(new Decimal(1.1).toFixed(2)),
166
- // typeof Number(new Decimal(1.1).toFixed(2)).toFixed(2)
167
- // );
186
+ console.log(num1.mul(0.77).toNumber(), typeof num1.mul(0.21).toNumber());
187
+ Decimal.set({ precision: 5 });
188
+ console.log(
189
+ new Decimal(1).div(1.1).toNumber(),
190
+ typeof new Decimal(1).div(1.1).toNumber()
191
+ );
192
+ console.log(
193
+ new Decimal(1).dividedBy(1.1).toNumber(),
194
+ typeof new Decimal(1).dividedBy(1.1).toNumber()
195
+ );
196
+
197
+ console.log(
198
+ Number(new Decimal(1.1).toFixed(2)),
199
+ typeof Number(new Decimal(1.1).toFixed(2)).toFixed(2)
200
+ );