zmdms-utils 0.0.19 → 0.0.20
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/common.js +4 -4
- package/dist/es/test.js +158 -2
- package/package.json +1 -1
- package/src/common.ts +4 -4
- package/src/test.js +40 -34
- package/dist/es/_virtual/_commonjsHelpers.js +0 -3
- package/dist/es/_virtual/decimal.js +0 -7
- package/dist/es/_virtual/test.js +0 -3
- package/dist/es/node_modules/decimal.js/decimal2.js +0 -4930
- package/dist/es/src/test.js +0 -106
package/dist/es/common.js
CHANGED
|
@@ -118,14 +118,14 @@ function dangerouslyXss(input) {
|
|
|
118
118
|
return "";
|
|
119
119
|
}
|
|
120
120
|
var escapedChars = {
|
|
121
|
-
lt: "",
|
|
122
|
-
gt: "",
|
|
121
|
+
lt: "<",
|
|
122
|
+
gt: ">",
|
|
123
123
|
nbsp: " ",
|
|
124
124
|
amp: "&",
|
|
125
125
|
quot: '"',
|
|
126
126
|
};
|
|
127
|
-
return input.replace(/&(amp|lt|gt|quot|nbsp);/
|
|
128
|
-
return escapedChars[
|
|
127
|
+
return input.replace(/&(amp|lt|gt|quot|nbsp);/gi, function (match, t) {
|
|
128
|
+
return escapedChars[t] || match;
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
/**
|
package/dist/es/test.js
CHANGED
|
@@ -1,2 +1,158 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function unescapeString(input) {
|
|
2
|
+
if (!input) {
|
|
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(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
|
+
|
|
53
|
+
console.log(unescapeString("&&&啊你"));
|
|
54
|
+
|
|
55
|
+
console.log(dangerouslySetXss("&&&啊你"));
|
|
56
|
+
|
|
57
|
+
console.log(dangerouslySetXss1("&&&啊你"));
|
|
58
|
+
console.log(unescapeString("1、aa>80%\n2、><\n3、ss<80%"));
|
|
59
|
+
console.log(dangerouslySetXss("1、aa>80%\n2、><\n3、ss<80%"));
|
|
60
|
+
console.log(dangerouslySetXss1("1、aa>80%\n2、><\n3、ss<80%"));
|
|
61
|
+
|
|
62
|
+
// functions and constants
|
|
63
|
+
// console.log("functions and constants");
|
|
64
|
+
// print(math.round(math.e, 3)); // 2.718
|
|
65
|
+
// print(math.atan2(3, -3) / math.pi); // 0.75
|
|
66
|
+
// print(math.log(10000, 10)); // 4
|
|
67
|
+
// print(math.sqrt(-4)); // 2i
|
|
68
|
+
// print(
|
|
69
|
+
// math.pow(
|
|
70
|
+
// [
|
|
71
|
+
// [-1, 2],
|
|
72
|
+
// [3, 1],
|
|
73
|
+
// ],
|
|
74
|
+
// 2
|
|
75
|
+
// )
|
|
76
|
+
// ); // [[7, 0], [0, 7]]
|
|
77
|
+
// print(math.derivative("x^2 + x", "x")); // 2 * x + 1
|
|
78
|
+
// console.log();
|
|
79
|
+
|
|
80
|
+
// // expressions
|
|
81
|
+
// console.log("expressions");
|
|
82
|
+
// print(math.evaluate("1.2 * (2 + 4.5)")); // 7.8
|
|
83
|
+
// print(math.evaluate("12.7 cm to inch")); // 5 inch
|
|
84
|
+
// print(math.evaluate("sin(45 deg) ^ 2")); // 0.5
|
|
85
|
+
// print(math.evaluate("9 / 3 + 2i")); // 3 + 2i
|
|
86
|
+
// print(math.evaluate("det([-1, 2; 3, 1])")); // -7
|
|
87
|
+
// print(math.evaluate("NaN + '0.2'")); // -7
|
|
88
|
+
// console.log();
|
|
89
|
+
|
|
90
|
+
// // chained operations
|
|
91
|
+
// console.log("chained operations");
|
|
92
|
+
// const a = math.chain(3).add(4).multiply(2).done();
|
|
93
|
+
// print(a); // 14
|
|
94
|
+
// console.log();
|
|
95
|
+
|
|
96
|
+
// // mixed use of different data types in functions
|
|
97
|
+
// console.log("mixed use of data types");
|
|
98
|
+
// print(math.add(4, [5, 6])); // number + Array, [9, 10]
|
|
99
|
+
// print(math.multiply(math.unit("5 mm"), 3)); // Unit * number, 15 mm
|
|
100
|
+
// print(math.subtract([2, 3, 4], 5)); // Array - number, [-3, -2, -1]
|
|
101
|
+
// print(math.add(math.matrix([2, 3]), [4, 5])); // Matrix + Array, [6, 8]
|
|
102
|
+
// console.log();
|
|
103
|
+
|
|
104
|
+
// /**
|
|
105
|
+
// * Helper function to output a value in the console. Value will be formatted.
|
|
106
|
+
// * @param {*} value
|
|
107
|
+
// */
|
|
108
|
+
// function print(value) {
|
|
109
|
+
// const precision = 14;
|
|
110
|
+
// console.log(math.format(value, precision));
|
|
111
|
+
// }
|
|
112
|
+
|
|
113
|
+
// const math = require("mathjs");
|
|
114
|
+
// function print(value) {
|
|
115
|
+
// const precision = 14;
|
|
116
|
+
// console.log(math.format(value, precision));
|
|
117
|
+
// }
|
|
118
|
+
|
|
119
|
+
// console.log(performance.now());
|
|
120
|
+
// console.log(math.add(0.1, 0.2));
|
|
121
|
+
// console.log(performance.now());
|
|
122
|
+
// console.log(performance.now());
|
|
123
|
+
// console.log(0.1 + 0.2);
|
|
124
|
+
// console.log(performance.now());
|
|
125
|
+
// const BigNumber = require("bignumber.js");
|
|
126
|
+
// console.log(performance.now());
|
|
127
|
+
// const num1 = new BigNumber(0.1);
|
|
128
|
+
// const num2 = new BigNumber(0.2);
|
|
129
|
+
|
|
130
|
+
// const result = num1.plus(num2);
|
|
131
|
+
|
|
132
|
+
// console.log(result.toString());
|
|
133
|
+
|
|
134
|
+
// console.log(performance.now());
|
|
135
|
+
|
|
136
|
+
// const Decimal = require("decimal.js");
|
|
137
|
+
|
|
138
|
+
// const num1 = new Decimal("0.1");
|
|
139
|
+
|
|
140
|
+
// console.log(num1.add(0.21).toNumber(), typeof num1.add(0.21).toNumber());
|
|
141
|
+
|
|
142
|
+
// console.log(num1.sub(0.21).toNumber(), typeof num1.sub(0.21).toNumber());
|
|
143
|
+
|
|
144
|
+
// console.log(num1.mul(0.21).toNumber(), typeof num1.mul(0.21).toNumber());
|
|
145
|
+
// Decimal.set({ precision: 5 });
|
|
146
|
+
// console.log(
|
|
147
|
+
// new Decimal(1).div(1.1).toNumber(),
|
|
148
|
+
// typeof new Decimal(1).div(1.1).toNumber()
|
|
149
|
+
// );
|
|
150
|
+
// console.log(
|
|
151
|
+
// new Decimal(1).dividedBy(1.1).toNumber(),
|
|
152
|
+
// typeof new Decimal(1).dividedBy(1.1).toNumber()
|
|
153
|
+
// );
|
|
154
|
+
|
|
155
|
+
// console.log(
|
|
156
|
+
// Number(new Decimal(1.1).toFixed(2)),
|
|
157
|
+
// typeof Number(new Decimal(1.1).toFixed(2)).toFixed(2)
|
|
158
|
+
// );
|
package/package.json
CHANGED
package/src/common.ts
CHANGED
|
@@ -125,15 +125,15 @@ export function dangerouslyXss(input: string): string {
|
|
|
125
125
|
return "";
|
|
126
126
|
}
|
|
127
127
|
const escapedChars: { [key: string]: string } = {
|
|
128
|
-
lt: "",
|
|
129
|
-
gt: "",
|
|
128
|
+
lt: "<",
|
|
129
|
+
gt: ">",
|
|
130
130
|
nbsp: " ",
|
|
131
131
|
amp: "&",
|
|
132
132
|
quot: '"',
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
return input.replace(/&(amp|lt|gt|quot|nbsp);/
|
|
136
|
-
return escapedChars[
|
|
135
|
+
return input.replace(/&(amp|lt|gt|quot|nbsp);/gi, (match, t) => {
|
|
136
|
+
return escapedChars[t] || match;
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
|
package/src/test.js
CHANGED
|
@@ -21,8 +21,8 @@ function dangerouslySetXss(input) {
|
|
|
21
21
|
return "";
|
|
22
22
|
}
|
|
23
23
|
const escapedChars = {
|
|
24
|
-
"<": "",
|
|
25
|
-
">": "",
|
|
24
|
+
"<": "<",
|
|
25
|
+
">": ">",
|
|
26
26
|
" ": " ",
|
|
27
27
|
"&": "&",
|
|
28
28
|
""": '"',
|
|
@@ -33,25 +33,31 @@ function dangerouslySetXss(input) {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function dangerouslySetXss1(
|
|
37
|
-
if (!
|
|
38
|
-
return
|
|
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;
|
|
36
|
+
function dangerouslySetXss1(input) {
|
|
37
|
+
if (!input) {
|
|
38
|
+
return "";
|
|
47
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
|
+
});
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
console.log(unescapeString("&&&啊你"));
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
console.log(dangerouslySetXss("&&&啊你"));
|
|
53
56
|
|
|
54
|
-
|
|
57
|
+
console.log(dangerouslySetXss1("&&&啊你"));
|
|
58
|
+
console.log(unescapeString("1、aa>80%\n2、><\n3、ss<80%"));
|
|
59
|
+
console.log(dangerouslySetXss("1、aa>80%\n2、><\n3、ss<80%"));
|
|
60
|
+
console.log(dangerouslySetXss1("1、aa>80%\n2、><\n3、ss<80%"));
|
|
55
61
|
|
|
56
62
|
// functions and constants
|
|
57
63
|
// console.log("functions and constants");
|
|
@@ -127,26 +133,26 @@ function dangerouslySetXss1(str) {
|
|
|
127
133
|
|
|
128
134
|
// console.log(performance.now());
|
|
129
135
|
|
|
130
|
-
const Decimal = require("decimal.js");
|
|
136
|
+
// const Decimal = require("decimal.js");
|
|
131
137
|
|
|
132
|
-
const num1 = new Decimal("0.1");
|
|
138
|
+
// const num1 = new Decimal("0.1");
|
|
133
139
|
|
|
134
|
-
console.log(num1.add(0.21).toNumber(), typeof num1.add(0.21).toNumber());
|
|
140
|
+
// console.log(num1.add(0.21).toNumber(), typeof num1.add(0.21).toNumber());
|
|
135
141
|
|
|
136
|
-
console.log(num1.sub(0.21).toNumber(), typeof num1.sub(0.21).toNumber());
|
|
142
|
+
// console.log(num1.sub(0.21).toNumber(), typeof num1.sub(0.21).toNumber());
|
|
137
143
|
|
|
138
|
-
console.log(num1.mul(0.21).toNumber(), typeof num1.mul(0.21).toNumber());
|
|
139
|
-
Decimal.set({ precision: 5 });
|
|
140
|
-
console.log(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
);
|
|
144
|
-
console.log(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
);
|
|
144
|
+
// console.log(num1.mul(0.21).toNumber(), typeof num1.mul(0.21).toNumber());
|
|
145
|
+
// Decimal.set({ precision: 5 });
|
|
146
|
+
// console.log(
|
|
147
|
+
// new Decimal(1).div(1.1).toNumber(),
|
|
148
|
+
// typeof new Decimal(1).div(1.1).toNumber()
|
|
149
|
+
// );
|
|
150
|
+
// console.log(
|
|
151
|
+
// new Decimal(1).dividedBy(1.1).toNumber(),
|
|
152
|
+
// typeof new Decimal(1).dividedBy(1.1).toNumber()
|
|
153
|
+
// );
|
|
148
154
|
|
|
149
|
-
console.log(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
);
|
|
155
|
+
// console.log(
|
|
156
|
+
// Number(new Decimal(1.1).toFixed(2)),
|
|
157
|
+
// typeof Number(new Decimal(1.1).toFixed(2)).toFixed(2)
|
|
158
|
+
// );
|
package/dist/es/_virtual/test.js
DELETED