zmdms-utils 0.0.16 → 0.0.18
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/es/_virtual/_commonjsHelpers.js +3 -0
- package/dist/es/_virtual/decimal.js +7 -0
- package/dist/es/_virtual/test.js +3 -0
- package/dist/es/common.d.ts +7 -1
- package/dist/es/common.js +9 -1
- package/dist/es/file.d.ts +1 -0
- package/dist/es/file.js +7 -6
- package/dist/es/math.d.ts +2 -2
- package/dist/es/math.js +64 -13
- package/dist/es/node_modules/decimal.js/decimal.js +4896 -0
- package/dist/es/node_modules/decimal.js/decimal2.js +4930 -0
- package/dist/es/src/test.js +106 -0
- package/dist/es/test.js +2 -54
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -1
- package/src/common.ts +9 -0
- package/src/file.ts +7 -6
- package/src/index.ts +1 -0
- package/src/math.ts +65 -14
- package/src/test.js +101 -3
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import '../node_modules/decimal.js/decimal2.js';
|
|
2
|
+
import { exports as decimalExports } from '../_virtual/decimal.js';
|
|
3
|
+
|
|
4
|
+
// console.log(unescapeString("&&&啊你"));
|
|
5
|
+
|
|
6
|
+
// console.log(dangerouslySetXss("&&&啊你"));
|
|
7
|
+
|
|
8
|
+
// console.log(dangerouslySetXss1("&&&啊你"));
|
|
9
|
+
|
|
10
|
+
// functions and constants
|
|
11
|
+
// console.log("functions and constants");
|
|
12
|
+
// print(math.round(math.e, 3)); // 2.718
|
|
13
|
+
// print(math.atan2(3, -3) / math.pi); // 0.75
|
|
14
|
+
// print(math.log(10000, 10)); // 4
|
|
15
|
+
// print(math.sqrt(-4)); // 2i
|
|
16
|
+
// print(
|
|
17
|
+
// math.pow(
|
|
18
|
+
// [
|
|
19
|
+
// [-1, 2],
|
|
20
|
+
// [3, 1],
|
|
21
|
+
// ],
|
|
22
|
+
// 2
|
|
23
|
+
// )
|
|
24
|
+
// ); // [[7, 0], [0, 7]]
|
|
25
|
+
// print(math.derivative("x^2 + x", "x")); // 2 * x + 1
|
|
26
|
+
// console.log();
|
|
27
|
+
|
|
28
|
+
// // expressions
|
|
29
|
+
// console.log("expressions");
|
|
30
|
+
// print(math.evaluate("1.2 * (2 + 4.5)")); // 7.8
|
|
31
|
+
// print(math.evaluate("12.7 cm to inch")); // 5 inch
|
|
32
|
+
// print(math.evaluate("sin(45 deg) ^ 2")); // 0.5
|
|
33
|
+
// print(math.evaluate("9 / 3 + 2i")); // 3 + 2i
|
|
34
|
+
// print(math.evaluate("det([-1, 2; 3, 1])")); // -7
|
|
35
|
+
// print(math.evaluate("NaN + '0.2'")); // -7
|
|
36
|
+
// console.log();
|
|
37
|
+
|
|
38
|
+
// // chained operations
|
|
39
|
+
// console.log("chained operations");
|
|
40
|
+
// const a = math.chain(3).add(4).multiply(2).done();
|
|
41
|
+
// print(a); // 14
|
|
42
|
+
// console.log();
|
|
43
|
+
|
|
44
|
+
// // mixed use of different data types in functions
|
|
45
|
+
// console.log("mixed use of data types");
|
|
46
|
+
// print(math.add(4, [5, 6])); // number + Array, [9, 10]
|
|
47
|
+
// print(math.multiply(math.unit("5 mm"), 3)); // Unit * number, 15 mm
|
|
48
|
+
// print(math.subtract([2, 3, 4], 5)); // Array - number, [-3, -2, -1]
|
|
49
|
+
// print(math.add(math.matrix([2, 3]), [4, 5])); // Matrix + Array, [6, 8]
|
|
50
|
+
// console.log();
|
|
51
|
+
|
|
52
|
+
// /**
|
|
53
|
+
// * Helper function to output a value in the console. Value will be formatted.
|
|
54
|
+
// * @param {*} value
|
|
55
|
+
// */
|
|
56
|
+
// function print(value) {
|
|
57
|
+
// const precision = 14;
|
|
58
|
+
// console.log(math.format(value, precision));
|
|
59
|
+
// }
|
|
60
|
+
|
|
61
|
+
// const math = require("mathjs");
|
|
62
|
+
// function print(value) {
|
|
63
|
+
// const precision = 14;
|
|
64
|
+
// console.log(math.format(value, precision));
|
|
65
|
+
// }
|
|
66
|
+
|
|
67
|
+
// console.log(performance.now());
|
|
68
|
+
// console.log(math.add(0.1, 0.2));
|
|
69
|
+
// console.log(performance.now());
|
|
70
|
+
// console.log(performance.now());
|
|
71
|
+
// console.log(0.1 + 0.2);
|
|
72
|
+
// console.log(performance.now());
|
|
73
|
+
// const BigNumber = require("bignumber.js");
|
|
74
|
+
// console.log(performance.now());
|
|
75
|
+
// const num1 = new BigNumber(0.1);
|
|
76
|
+
// const num2 = new BigNumber(0.2);
|
|
77
|
+
|
|
78
|
+
// const result = num1.plus(num2);
|
|
79
|
+
|
|
80
|
+
// console.log(result.toString());
|
|
81
|
+
|
|
82
|
+
// console.log(performance.now());
|
|
83
|
+
|
|
84
|
+
const Decimal = decimalExports;
|
|
85
|
+
|
|
86
|
+
const num1 = new Decimal("0.1");
|
|
87
|
+
|
|
88
|
+
console.log(num1.add(0.21).toNumber(), typeof num1.add(0.21).toNumber());
|
|
89
|
+
|
|
90
|
+
console.log(num1.sub(0.21).toNumber(), typeof num1.sub(0.21).toNumber());
|
|
91
|
+
|
|
92
|
+
console.log(num1.mul(0.21).toNumber(), typeof num1.mul(0.21).toNumber());
|
|
93
|
+
Decimal.set({ precision: 5 });
|
|
94
|
+
console.log(
|
|
95
|
+
new Decimal(1).div(1.1).toNumber(),
|
|
96
|
+
typeof new Decimal(1).div(1.1).toNumber()
|
|
97
|
+
);
|
|
98
|
+
console.log(
|
|
99
|
+
new Decimal(1).dividedBy(1.1).toNumber(),
|
|
100
|
+
typeof new Decimal(1).dividedBy(1.1).toNumber()
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
console.log(
|
|
104
|
+
Number(new Decimal(1.1).toFixed(2)),
|
|
105
|
+
typeof Number(new Decimal(1.1).toFixed(2)).toFixed(2)
|
|
106
|
+
);
|
package/dist/es/test.js
CHANGED
|
@@ -1,54 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return "";
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const escapedChars = {
|
|
7
|
-
"&": "&",
|
|
8
|
-
"<": "<",
|
|
9
|
-
">": ">",
|
|
10
|
-
""": '"',
|
|
11
|
-
"'": "'",
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
return input.replace(/&(amp|lt|gt|quot|#039);/g, (match) => {
|
|
15
|
-
return escapedChars[match] || match;
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function dangerouslySetXss(input) {
|
|
20
|
-
if (!input) {
|
|
21
|
-
return "";
|
|
22
|
-
}
|
|
23
|
-
const escapedChars = {
|
|
24
|
-
"<": "",
|
|
25
|
-
">": "",
|
|
26
|
-
" ": " ",
|
|
27
|
-
"&": "&",
|
|
28
|
-
""": '"',
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
return input.replace(/&(amp|lt|gt|quot|nbsp);/g, (match) => {
|
|
32
|
-
return escapedChars[match] || match;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function dangerouslySetXss1(str) {
|
|
37
|
-
if (!str) {
|
|
38
|
-
return str;
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const arrEntities = { lt: "", gt: "", nbsp: " ", amp: "&", quot: '"' };
|
|
42
|
-
return str?.replace?.(/&(lt|gt|nbsp|amp|quot);/gi, function (all, t) {
|
|
43
|
-
return arrEntities[t];
|
|
44
|
-
});
|
|
45
|
-
} catch (err) {
|
|
46
|
-
return str;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
console.log(unescapeString("&&&啊你"));
|
|
51
|
-
|
|
52
|
-
console.log(dangerouslySetXss("&&&啊你"));
|
|
53
|
-
|
|
54
|
-
console.log(dangerouslySetXss1("&&&啊你"));
|
|
1
|
+
import './src/test.js';
|
|
2
|
+
export { __exports as default } from './_virtual/test.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { getToken, removeToken, setToken } from './es/auth.js';
|
|
|
5
5
|
export { AxiosRequest, IOptions, IOtherOptions } from './es/request.js';
|
|
6
6
|
export { getBaseUrl } from './es/baseUrl.js';
|
|
7
7
|
export { Crypto, md5 } from './es/crypto.js';
|
|
8
|
-
export { addThousedSeparator, copyToClipboard, dangerouslyXss, delay, emitter, getFileExtension, isImageExtension, parseQueryParams, specialString, unescapeString } from './es/common.js';
|
|
8
|
+
export { addThousedSeparator, copyToClipboard, dangerouslyXss, delay, emitter, getFileExtension, isImageExtension, isNonEmpty, parseQueryParams, specialString, unescapeString } from './es/common.js';
|
|
9
9
|
export { divide, exactRound, formatUnit, minus, plus, times } from './es/math.js';
|
|
10
10
|
export { validatePassword } from './es/passwordValidate.js';
|
|
11
11
|
export { emailValidate, idCardValidate, morePhoneValidate, phoneValidate, strLenValidate } from './es/validate.js';
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export { getToken, removeToken, setToken } from './es/auth.js';
|
|
|
5
5
|
export { AxiosRequest } from './es/request.js';
|
|
6
6
|
export { getBaseUrl } from './es/baseUrl.js';
|
|
7
7
|
export { Crypto, md5 } from './es/crypto.js';
|
|
8
|
-
export { addThousedSeparator, copyToClipboard, dangerouslyXss, delay, emitter, getFileExtension, isImageExtension, parseQueryParams, specialString, unescapeString } from './es/common.js';
|
|
8
|
+
export { addThousedSeparator, copyToClipboard, dangerouslyXss, delay, emitter, getFileExtension, isImageExtension, isNonEmpty, parseQueryParams, specialString, unescapeString } from './es/common.js';
|
|
9
9
|
export { divide, exactRound, formatUnit, minus, plus, times } from './es/math.js';
|
|
10
10
|
export { validatePassword } from './es/passwordValidate.js';
|
|
11
11
|
export { emailValidate, idCardValidate, morePhoneValidate, phoneValidate, strLenValidate } from './es/validate.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zmdms-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"qiankun": "^2.10.8"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"decimal.js": "^10.4.3",
|
|
21
22
|
"mitt": "^3.0.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
package/src/common.ts
CHANGED
|
@@ -211,3 +211,12 @@ export function isImageExtension(extension: string): boolean {
|
|
|
211
211
|
|
|
212
212
|
return imageExtensions.includes(extension.toLowerCase());
|
|
213
213
|
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 判断值是否为非空
|
|
217
|
+
* @param number 传入一个值
|
|
218
|
+
* @returns
|
|
219
|
+
*/
|
|
220
|
+
export function isNonEmpty(number: any) {
|
|
221
|
+
return number !== null && number !== undefined;
|
|
222
|
+
}
|
package/src/file.ts
CHANGED
|
@@ -39,7 +39,7 @@ export function downloadFile(
|
|
|
39
39
|
} else {
|
|
40
40
|
xhr.open(
|
|
41
41
|
"GET",
|
|
42
|
-
`${apiBaseURL}/api/zmdms-resource/oss/endpoint/download-file/${fileId}?Zmdms-Auth
|
|
42
|
+
`${apiBaseURL}/api/zmdms-resource/oss/endpoint/download-file/${fileId}?Zmdms-Auth=${token}&addWaterMark=${waterMark}`,
|
|
43
43
|
true
|
|
44
44
|
);
|
|
45
45
|
}
|
|
@@ -183,13 +183,13 @@ export function previewFile(
|
|
|
183
183
|
window.open(
|
|
184
184
|
`${apiBaseURL}/picturesAttchPreview?attachIds=${
|
|
185
185
|
attachIds ? `${fileId},${attachIds}` : fileId
|
|
186
|
-
}&Zmdms-Auth
|
|
186
|
+
}&Zmdms-Auth=${token}` +
|
|
187
187
|
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
|
|
188
188
|
);
|
|
189
189
|
} else {
|
|
190
190
|
// 普通预览
|
|
191
191
|
window.open(
|
|
192
|
-
`${apiBaseURL}/attchPreview?attachId=${fileId}&Zmdms-Auth
|
|
192
|
+
`${apiBaseURL}/attchPreview?attachId=${fileId}&Zmdms-Auth=${token}&officePreviewType=pdf` +
|
|
193
193
|
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
|
|
194
194
|
);
|
|
195
195
|
}
|
|
@@ -264,7 +264,7 @@ export function createDownloadLink(
|
|
|
264
264
|
if (open) {
|
|
265
265
|
return `${apiBaseURL}/api/zmdms-resource/oss/endpoint/public/download-file/${fileId}`;
|
|
266
266
|
}
|
|
267
|
-
return `${apiBaseURL}/api/zmdms-resource/oss/endpoint/download-file/${fileId}?Zmdms-Auth
|
|
267
|
+
return `${apiBaseURL}/api/zmdms-resource/oss/endpoint/download-file/${fileId}?Zmdms-Auth=${token}`;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
/**
|
|
@@ -298,7 +298,7 @@ export function createOriginalLink(
|
|
|
298
298
|
// 所以将文件名 与 文件id组合来生成不同的文件名
|
|
299
299
|
previewFileName = `${filePreName}-${fileId}.${fileExtension}`;
|
|
300
300
|
return (
|
|
301
|
-
`${apiBaseURL}/attchPreview?attachId=${fileId}&Zmdms-Auth
|
|
301
|
+
`${apiBaseURL}/attchPreview?attachId=${fileId}&Zmdms-Auth=${token}&officePreviewType=pdf` +
|
|
302
302
|
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
|
|
303
303
|
);
|
|
304
304
|
}
|
|
@@ -312,6 +312,7 @@ export function createOriginalLink(
|
|
|
312
312
|
* @param options.authToken {string} token 非必传
|
|
313
313
|
* @param options.scale {number} 缩略比
|
|
314
314
|
* @returns
|
|
315
|
+
* createThumbnailLink('1', 'z', { API_BASEURL: 1 })
|
|
315
316
|
*/
|
|
316
317
|
export function createThumbnailLink(
|
|
317
318
|
fileId: string,
|
|
@@ -320,7 +321,7 @@ export function createThumbnailLink(
|
|
|
320
321
|
) {
|
|
321
322
|
const { API_BASEURL, authToken, scale = 0.5 } = options;
|
|
322
323
|
const { token, apiBaseURL } = getBasicInfo(API_BASEURL || "", authToken);
|
|
323
|
-
return `${apiBaseURL}/api/zmdms-resource/oss/endpoint/thumbnail/${fileId}?scale=${scale}&Zmdms-Auth
|
|
324
|
+
return `${apiBaseURL}/api/zmdms-resource/oss/endpoint/thumbnail/${fileId}?scale=${scale}&Zmdms-Auth=${token}`;
|
|
324
325
|
}
|
|
325
326
|
|
|
326
327
|
/**
|
package/src/index.ts
CHANGED
package/src/math.ts
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
type numType = number | string;
|
|
3
|
+
/**
|
|
4
|
+
* 如果传入的数,有非数字的情况 那么忽略这个数
|
|
5
|
+
* 非数字的情况包括 null undefined
|
|
6
|
+
* 因为null转数字的结果是 0 可能会影响计算结果。
|
|
7
|
+
* 而这个可能不符合预期
|
|
8
|
+
*/
|
|
9
|
+
function initNum(num1: any, num2: any) {
|
|
10
|
+
// 如果两个数都是非数字 那么直接返回0
|
|
11
|
+
if (isNaN(num1) && isNaN(num2)) {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
if (isNaN(num1)) {
|
|
15
|
+
return num2;
|
|
16
|
+
}
|
|
17
|
+
if (isNaN(num2)) {
|
|
18
|
+
return num1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
2
22
|
/**
|
|
3
23
|
* 加法
|
|
4
24
|
*/
|
|
5
25
|
export function plus(num1: numType, num2: numType) {
|
|
6
26
|
try {
|
|
7
|
-
const _num1 = Number(num1);
|
|
8
|
-
const _num2 = Number(num2);
|
|
9
|
-
|
|
27
|
+
const _num1 = num1 == null ? NaN : Number(num1);
|
|
28
|
+
const _num2 = num2 == null ? NaN : Number(num2);
|
|
29
|
+
// 如果两个数都是非数字 那么直接返回0
|
|
30
|
+
const result = initNum(_num1, _num2);
|
|
31
|
+
if (typeof result === "number") {
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
return new Decimal(_num1).add(_num2).toNumber();
|
|
35
|
+
// return (isNaN(_num1) ? 0 : _num1) + (isNaN(_num2) ? 0 : _num2);
|
|
10
36
|
} catch (err) {
|
|
11
37
|
console.error("计算加法出错", err);
|
|
12
38
|
return 0;
|
|
@@ -18,9 +44,15 @@ export function plus(num1: numType, num2: numType) {
|
|
|
18
44
|
*/
|
|
19
45
|
export function minus(num1: numType, num2: numType) {
|
|
20
46
|
try {
|
|
21
|
-
const _num1 = Number(num1);
|
|
22
|
-
const _num2 = Number(num2);
|
|
23
|
-
|
|
47
|
+
const _num1 = num1 == null ? NaN : Number(num1);
|
|
48
|
+
const _num2 = num2 == null ? NaN : Number(num2);
|
|
49
|
+
// 如果两个数都是非数字 那么直接返回0
|
|
50
|
+
const result = initNum(_num1, _num2);
|
|
51
|
+
if (typeof result === "number") {
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
return new Decimal(_num1).sub(_num2).toNumber();
|
|
55
|
+
// return (isNaN(_num1) ? 0 : _num1) - (isNaN(_num2) ? 0 : _num2);
|
|
24
56
|
} catch (err) {
|
|
25
57
|
console.error("计算减法出错", err);
|
|
26
58
|
return 0;
|
|
@@ -32,9 +64,15 @@ export function minus(num1: numType, num2: numType) {
|
|
|
32
64
|
*/
|
|
33
65
|
export function times(num1: numType, num2: numType) {
|
|
34
66
|
try {
|
|
35
|
-
const _num1 = Number(num1);
|
|
36
|
-
const _num2 = Number(num2);
|
|
37
|
-
|
|
67
|
+
const _num1 = num1 == null ? NaN : Number(num1);
|
|
68
|
+
const _num2 = num2 == null ? NaN : Number(num2);
|
|
69
|
+
// 如果两个数都是非数字 那么直接返回0
|
|
70
|
+
const result = initNum(_num1, _num2);
|
|
71
|
+
if (typeof result === "number") {
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
return new Decimal(_num1).mul(_num2).toNumber();
|
|
75
|
+
// return (isNaN(_num1) ? 0 : _num1) * (isNaN(_num2) ? 0 : _num2);
|
|
38
76
|
} catch (err) {
|
|
39
77
|
console.error("计算乘法出错", err);
|
|
40
78
|
return 0;
|
|
@@ -46,9 +84,16 @@ export function times(num1: numType, num2: numType) {
|
|
|
46
84
|
*/
|
|
47
85
|
export function divide(num1: numType, num2: numType) {
|
|
48
86
|
try {
|
|
49
|
-
const _num1 = Number(num1);
|
|
50
|
-
const _num2 = Number(num2);
|
|
51
|
-
|
|
87
|
+
const _num1 = num1 == null ? NaN : Number(num1);
|
|
88
|
+
const _num2 = num2 == null ? NaN : Number(num2);
|
|
89
|
+
// 如果两个数都是非数字 那么直接返回0
|
|
90
|
+
const result = initNum(_num1, _num2);
|
|
91
|
+
if (typeof result === "number") {
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
Decimal.set({ precision: 5 });
|
|
95
|
+
return new Decimal(_num1).div(_num2).toNumber();
|
|
96
|
+
// return (isNaN(_num1) ? 0 : _num1) / (isNaN(_num2) ? 0 : _num2);
|
|
52
97
|
} catch (err) {
|
|
53
98
|
console.error("计算除法出错", err);
|
|
54
99
|
return 0;
|
|
@@ -60,7 +105,13 @@ export function divide(num1: numType, num2: numType) {
|
|
|
60
105
|
*/
|
|
61
106
|
export function exactRound(num: numType, ratio: number) {
|
|
62
107
|
try {
|
|
63
|
-
|
|
108
|
+
const _num1 = num == null ? NaN : Number(num);
|
|
109
|
+
if (isNaN(_num1)) {
|
|
110
|
+
return 0;
|
|
111
|
+
// return (0).toFixed(ratio);
|
|
112
|
+
}
|
|
113
|
+
return new Decimal(num).toFixed(ratio);
|
|
114
|
+
// return Number(num).toFixed(ratio);
|
|
64
115
|
} catch (err) {
|
|
65
116
|
return num;
|
|
66
117
|
}
|
package/src/test.js
CHANGED
|
@@ -47,8 +47,106 @@ function dangerouslySetXss1(str) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
console.log(unescapeString("&&&啊你"));
|
|
50
|
+
// console.log(unescapeString("&&&啊你"));
|
|
51
51
|
|
|
52
|
-
console.log(dangerouslySetXss("&&&啊你"));
|
|
52
|
+
// console.log(dangerouslySetXss("&&&啊你"));
|
|
53
53
|
|
|
54
|
-
console.log(dangerouslySetXss1("&&&啊你"));
|
|
54
|
+
// console.log(dangerouslySetXss1("&&&啊你"));
|
|
55
|
+
|
|
56
|
+
// functions and constants
|
|
57
|
+
// console.log("functions and constants");
|
|
58
|
+
// print(math.round(math.e, 3)); // 2.718
|
|
59
|
+
// print(math.atan2(3, -3) / math.pi); // 0.75
|
|
60
|
+
// print(math.log(10000, 10)); // 4
|
|
61
|
+
// print(math.sqrt(-4)); // 2i
|
|
62
|
+
// print(
|
|
63
|
+
// math.pow(
|
|
64
|
+
// [
|
|
65
|
+
// [-1, 2],
|
|
66
|
+
// [3, 1],
|
|
67
|
+
// ],
|
|
68
|
+
// 2
|
|
69
|
+
// )
|
|
70
|
+
// ); // [[7, 0], [0, 7]]
|
|
71
|
+
// print(math.derivative("x^2 + x", "x")); // 2 * x + 1
|
|
72
|
+
// console.log();
|
|
73
|
+
|
|
74
|
+
// // expressions
|
|
75
|
+
// console.log("expressions");
|
|
76
|
+
// print(math.evaluate("1.2 * (2 + 4.5)")); // 7.8
|
|
77
|
+
// print(math.evaluate("12.7 cm to inch")); // 5 inch
|
|
78
|
+
// print(math.evaluate("sin(45 deg) ^ 2")); // 0.5
|
|
79
|
+
// print(math.evaluate("9 / 3 + 2i")); // 3 + 2i
|
|
80
|
+
// print(math.evaluate("det([-1, 2; 3, 1])")); // -7
|
|
81
|
+
// print(math.evaluate("NaN + '0.2'")); // -7
|
|
82
|
+
// console.log();
|
|
83
|
+
|
|
84
|
+
// // chained operations
|
|
85
|
+
// console.log("chained operations");
|
|
86
|
+
// const a = math.chain(3).add(4).multiply(2).done();
|
|
87
|
+
// print(a); // 14
|
|
88
|
+
// console.log();
|
|
89
|
+
|
|
90
|
+
// // mixed use of different data types in functions
|
|
91
|
+
// console.log("mixed use of data types");
|
|
92
|
+
// print(math.add(4, [5, 6])); // number + Array, [9, 10]
|
|
93
|
+
// print(math.multiply(math.unit("5 mm"), 3)); // Unit * number, 15 mm
|
|
94
|
+
// print(math.subtract([2, 3, 4], 5)); // Array - number, [-3, -2, -1]
|
|
95
|
+
// print(math.add(math.matrix([2, 3]), [4, 5])); // Matrix + Array, [6, 8]
|
|
96
|
+
// console.log();
|
|
97
|
+
|
|
98
|
+
// /**
|
|
99
|
+
// * Helper function to output a value in the console. Value will be formatted.
|
|
100
|
+
// * @param {*} value
|
|
101
|
+
// */
|
|
102
|
+
// function print(value) {
|
|
103
|
+
// const precision = 14;
|
|
104
|
+
// console.log(math.format(value, precision));
|
|
105
|
+
// }
|
|
106
|
+
|
|
107
|
+
// const math = require("mathjs");
|
|
108
|
+
// function print(value) {
|
|
109
|
+
// const precision = 14;
|
|
110
|
+
// console.log(math.format(value, precision));
|
|
111
|
+
// }
|
|
112
|
+
|
|
113
|
+
// console.log(performance.now());
|
|
114
|
+
// console.log(math.add(0.1, 0.2));
|
|
115
|
+
// console.log(performance.now());
|
|
116
|
+
// console.log(performance.now());
|
|
117
|
+
// console.log(0.1 + 0.2);
|
|
118
|
+
// console.log(performance.now());
|
|
119
|
+
// const BigNumber = require("bignumber.js");
|
|
120
|
+
// console.log(performance.now());
|
|
121
|
+
// const num1 = new BigNumber(0.1);
|
|
122
|
+
// const num2 = new BigNumber(0.2);
|
|
123
|
+
|
|
124
|
+
// const result = num1.plus(num2);
|
|
125
|
+
|
|
126
|
+
// console.log(result.toString());
|
|
127
|
+
|
|
128
|
+
// console.log(performance.now());
|
|
129
|
+
|
|
130
|
+
const Decimal = require("decimal.js");
|
|
131
|
+
|
|
132
|
+
const num1 = new Decimal("0.1");
|
|
133
|
+
|
|
134
|
+
console.log(num1.add(0.21).toNumber(), typeof num1.add(0.21).toNumber());
|
|
135
|
+
|
|
136
|
+
console.log(num1.sub(0.21).toNumber(), typeof num1.sub(0.21).toNumber());
|
|
137
|
+
|
|
138
|
+
console.log(num1.mul(0.21).toNumber(), typeof num1.mul(0.21).toNumber());
|
|
139
|
+
Decimal.set({ precision: 5 });
|
|
140
|
+
console.log(
|
|
141
|
+
new Decimal(1).div(1.1).toNumber(),
|
|
142
|
+
typeof new Decimal(1).div(1.1).toNumber()
|
|
143
|
+
);
|
|
144
|
+
console.log(
|
|
145
|
+
new Decimal(1).dividedBy(1.1).toNumber(),
|
|
146
|
+
typeof new Decimal(1).dividedBy(1.1).toNumber()
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
console.log(
|
|
150
|
+
Number(new Decimal(1.1).toFixed(2)),
|
|
151
|
+
typeof Number(new Decimal(1.1).toFixed(2)).toFixed(2)
|
|
152
|
+
);
|