zmdms-utils 0.0.75 → 0.0.76
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/_tslib.js +87 -0
- package/dist/es/_virtual/decimal.js +7 -0
- package/dist/es/_virtual/parseTimeTest.js +3 -0
- package/dist/es/_virtual/test.js +3 -0
- package/dist/es/auth.d.ts +9 -0
- package/dist/es/auth.js +49 -0
- package/dist/es/baseUrl.d.ts +23 -0
- package/dist/es/baseUrl.js +50 -0
- package/dist/es/canvas.d.ts +6 -0
- package/dist/es/canvas.js +14 -0
- package/dist/es/common.d.ts +81 -0
- package/dist/es/common.js +304 -0
- package/dist/es/constants.d.ts +20 -0
- package/dist/es/constants.js +33 -0
- package/dist/es/crypto.d.ts +51 -0
- package/dist/es/crypto.js +97 -0
- package/dist/es/file.d.ts +127 -0
- package/dist/es/file.js +373 -0
- package/dist/es/htmlToPdf.d.ts +44 -0
- package/dist/es/htmlToPdf.js +84 -0
- package/dist/es/locales/i18n.d.ts +15 -0
- package/dist/es/locales/t-in-non-react.d.ts +17 -0
- package/dist/es/locales/t-options.d.ts +7 -0
- package/dist/es/locales/use-translation.d.ts +42 -0
- package/dist/es/mainApp.d.ts +36 -0
- package/dist/es/mainApp.js +44 -0
- package/dist/es/math.d.ts +29 -0
- package/dist/es/math.js +147 -0
- package/dist/es/microAppCreator.d.ts +46 -0
- package/dist/es/microAppCreator.js +89 -0
- 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/node_modules/html-parse-stringify/dist/html-parse-stringify.module.js +5 -0
- package/dist/es/node_modules/i18next/dist/esm/i18next.js +2242 -0
- package/dist/es/node_modules/js-base64/base64.js +273 -0
- package/dist/es/node_modules/jwt-decode/build/jwt-decode.esm.js +3 -0
- package/dist/es/node_modules/mitt/dist/mitt.js +3 -0
- package/dist/es/node_modules/pinyin-pro/dist/index.js +12627 -0
- package/dist/es/node_modules/react-i18next/dist/es/Trans.js +47 -0
- package/dist/es/node_modules/react-i18next/dist/es/TransWithoutContext.js +312 -0
- package/dist/es/node_modules/react-i18next/dist/es/context.js +18 -0
- package/dist/es/node_modules/react-i18next/dist/es/defaults.js +21 -0
- package/dist/es/node_modules/react-i18next/dist/es/i18nInstance.js +7 -0
- package/dist/es/node_modules/react-i18next/dist/es/initReactI18next.js +12 -0
- package/dist/es/node_modules/react-i18next/dist/es/unescape.js +27 -0
- package/dist/es/node_modules/react-i18next/dist/es/useTranslation.js +112 -0
- package/dist/es/node_modules/react-i18next/dist/es/utils.js +63 -0
- package/dist/es/node_modules/void-elements/index.js +23 -0
- package/dist/es/parseTime.d.ts +29 -0
- package/dist/es/parseTime.js +189 -0
- package/dist/es/parseTimeTest.js +2 -0
- package/dist/es/passwordValidate.d.ts +9 -0
- package/dist/es/passwordValidate.js +169 -0
- package/dist/es/pdf.d.ts +49 -0
- package/dist/es/pdf.js +176 -0
- package/dist/es/pinyin.js +1 -0
- package/dist/es/print.d.ts +23 -0
- package/dist/es/print.js +43 -0
- package/dist/es/qiankunUtils.d.ts +13 -0
- package/dist/es/qiankunUtils.js +32 -0
- package/dist/es/request.d.ts +87 -0
- package/dist/es/request.js +308 -0
- package/dist/es/src/locales/i18n.js +16 -0
- package/dist/es/src/locales/t-in-non-react.js +54 -0
- package/dist/es/src/locales/t-options.js +20 -0
- package/dist/es/src/locales/use-translation.js +60 -0
- package/dist/es/src/parseTimeTest.js +288 -0
- package/dist/es/src/test.js +245 -0
- package/dist/es/test.js +2 -0
- package/dist/es/validate.d.ts +26 -0
- package/dist/es/validate.js +47 -0
- package/dist/es/water.d.ts +53 -0
- package/dist/es/water.js +88 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/package.json +1 -1
- package/src/math.ts +1 -1
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import dayjs$1 from 'dayjs';
|
|
2
|
+
|
|
3
|
+
const dayjs = dayjs$1;
|
|
4
|
+
const defaultFormat = "YYYY-MM-DD";
|
|
5
|
+
function parseTime(config) {
|
|
6
|
+
const {
|
|
7
|
+
params,
|
|
8
|
+
format = defaultFormat,
|
|
9
|
+
type = "string",
|
|
10
|
+
fromKeys = [],
|
|
11
|
+
toKeys = [],
|
|
12
|
+
endType,
|
|
13
|
+
} = config;
|
|
14
|
+
|
|
15
|
+
// 获取最终结果
|
|
16
|
+
const getParseResult = parseByResult({ format, type });
|
|
17
|
+
|
|
18
|
+
// 如果传入的是一个字符串(就是单字段)
|
|
19
|
+
if (typeof params === "string" || typeof params === "number") {
|
|
20
|
+
// 1. 结果类型是一个日期对象
|
|
21
|
+
// 2. 如果结果类型是字符串,那么字符串转字符串可能的一个场景是:将一个日期格式的数据转成另外一种格式的日期
|
|
22
|
+
return getParseResult({
|
|
23
|
+
value: params,
|
|
24
|
+
endType: typeof endType === "string" ? endType : undefined,
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
// 浅拷贝一下
|
|
28
|
+
const newParams = Object.assign({}, params);
|
|
29
|
+
|
|
30
|
+
fromKeys.forEach((fromKey, index) => {
|
|
31
|
+
const toKey = toKeys[index];
|
|
32
|
+
const endTypeItem = Array.isArray(endType) ? endType[index] : endType;
|
|
33
|
+
// 1. 从一个键 转成 一个键
|
|
34
|
+
if (typeof fromKey === "string" && typeof toKey === "string") {
|
|
35
|
+
newParams[toKey] = getParseResult({
|
|
36
|
+
value: newParams[fromKey],
|
|
37
|
+
index,
|
|
38
|
+
endType: endTypeItem,
|
|
39
|
+
});
|
|
40
|
+
if (fromKey !== toKey) {
|
|
41
|
+
// 删除原有key
|
|
42
|
+
Reflect.deleteProperty(newParams, fromKey);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// 2. 从一个键 转成 两个键
|
|
46
|
+
if (typeof fromKey === "string" && typeof toKey === "object") {
|
|
47
|
+
const [toKey1, toKey2] = toKey;
|
|
48
|
+
// 初始定义转义类型 是否拼接一天的开始 一天的结束
|
|
49
|
+
let startEndType = "startOf";
|
|
50
|
+
let endEndType = "endOf";
|
|
51
|
+
if (Array.isArray(endTypeItem)) {
|
|
52
|
+
startEndType = endTypeItem[0];
|
|
53
|
+
endEndType = endTypeItem[1];
|
|
54
|
+
}
|
|
55
|
+
newParams[toKey1] = getParseResult({
|
|
56
|
+
value: newParams[fromKey]?.[0],
|
|
57
|
+
index,
|
|
58
|
+
endType: startEndType,
|
|
59
|
+
});
|
|
60
|
+
newParams[toKey2] = getParseResult({
|
|
61
|
+
value: newParams[fromKey]?.[1],
|
|
62
|
+
index,
|
|
63
|
+
endType: endEndType,
|
|
64
|
+
});
|
|
65
|
+
if (fromKey !== toKey1 && fromKey !== toKey2) {
|
|
66
|
+
Reflect.deleteProperty(newParams, fromKey);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// 3. 从两个键 转成 一个键
|
|
70
|
+
if (typeof fromKey === "object" && typeof toKey === "string") {
|
|
71
|
+
const [fromKey1, fromtKey2] = fromKey;
|
|
72
|
+
// 初始定义转义类型 是否拼接一天的开始 一天的结束
|
|
73
|
+
let startEndType = "startOf";
|
|
74
|
+
let endEndType = "endOf";
|
|
75
|
+
if (Array.isArray(endTypeItem)) {
|
|
76
|
+
startEndType = endTypeItem[0];
|
|
77
|
+
endEndType = endTypeItem[1];
|
|
78
|
+
}
|
|
79
|
+
newParams[toKey] = [
|
|
80
|
+
getParseResult({
|
|
81
|
+
value: newParams[fromKey1],
|
|
82
|
+
index,
|
|
83
|
+
endType: startEndType,
|
|
84
|
+
}),
|
|
85
|
+
getParseResult({
|
|
86
|
+
value: newParams[fromtKey2],
|
|
87
|
+
index,
|
|
88
|
+
endType: endEndType,
|
|
89
|
+
}),
|
|
90
|
+
];
|
|
91
|
+
if (fromKey1 !== toKey) {
|
|
92
|
+
Reflect.deleteProperty(newParams, fromKey1);
|
|
93
|
+
}
|
|
94
|
+
if (fromtKey2 !== toKey) {
|
|
95
|
+
Reflect.deleteProperty(newParams, fromtKey2);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// 4. 从两个键 转成 两个键
|
|
99
|
+
if (typeof fromKey === "object" && typeof toKey === "object") {
|
|
100
|
+
const [fromKey1, fromtKey2] = fromKey;
|
|
101
|
+
const [toKey1, toKey2] = toKey;
|
|
102
|
+
// 初始定义转义类型 是否拼接一天的开始 一天的结束
|
|
103
|
+
let startEndType = undefined;
|
|
104
|
+
let endEndType = undefined;
|
|
105
|
+
if (Array.isArray(endTypeItem)) {
|
|
106
|
+
startEndType = endTypeItem[0];
|
|
107
|
+
endEndType = endTypeItem[1];
|
|
108
|
+
}
|
|
109
|
+
newParams[toKey1] = getParseResult({
|
|
110
|
+
value: newParams[fromKey1],
|
|
111
|
+
index,
|
|
112
|
+
endType: startEndType,
|
|
113
|
+
});
|
|
114
|
+
newParams[toKey2] = getParseResult({
|
|
115
|
+
value: newParams[fromtKey2],
|
|
116
|
+
index,
|
|
117
|
+
endType: endEndType,
|
|
118
|
+
});
|
|
119
|
+
if (fromKey1 !== toKey1) {
|
|
120
|
+
// 删除原有key
|
|
121
|
+
Reflect.deleteProperty(newParams, fromKey1);
|
|
122
|
+
}
|
|
123
|
+
if (fromtKey2 !== toKey2) {
|
|
124
|
+
// 删除原有key
|
|
125
|
+
Reflect.deleteProperty(newParams, fromtKey2);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return newParams;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function parseByResult(option) {
|
|
135
|
+
const { format = defaultFormat, type = "string" } = option;
|
|
136
|
+
|
|
137
|
+
return (option) => {
|
|
138
|
+
const { value, index = 0, endType } = option;
|
|
139
|
+
if (!value) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
const parseType = typeof type === "string" ? type : type[index];
|
|
143
|
+
const parseFormat = typeof format === "string" ? format : format[index];
|
|
144
|
+
const parseEndType = Array.isArray(endType) ? endType[0] : endType;
|
|
145
|
+
if (parseType === "string") {
|
|
146
|
+
const dayjsValue = dayjs.isDayjs(value) ? value : dayjs(value);
|
|
147
|
+
if (parseEndType === "startOf") {
|
|
148
|
+
return dayjsValue
|
|
149
|
+
.startOf("day")
|
|
150
|
+
.format(
|
|
151
|
+
parseFormat.length === 10 ? `${parseFormat} HH:mm:ss` : parseFormat
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
if (parseEndType === "endOf") {
|
|
155
|
+
return dayjsValue
|
|
156
|
+
.endOf("day")
|
|
157
|
+
.format(
|
|
158
|
+
parseFormat.length === 10 ? `${parseFormat} HH:mm:ss` : parseFormat
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
return dayjsValue.format(parseFormat);
|
|
162
|
+
} else {
|
|
163
|
+
if (parseEndType === "startOf") {
|
|
164
|
+
return dayjs(value).startOf("day");
|
|
165
|
+
}
|
|
166
|
+
if (parseEndType === "endOf") {
|
|
167
|
+
return dayjs(value).endOf("day");
|
|
168
|
+
}
|
|
169
|
+
return dayjs(value);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 处理单字段
|
|
175
|
+
// 时间戳处理
|
|
176
|
+
// console.log(
|
|
177
|
+
// parseTime({
|
|
178
|
+
// params: Date.now(),
|
|
179
|
+
// })
|
|
180
|
+
// );
|
|
181
|
+
// 将日期格式字符串转换成dayjs
|
|
182
|
+
// console.log(
|
|
183
|
+
// parseTime({
|
|
184
|
+
// params: "2023-09-22",
|
|
185
|
+
// type: "object",
|
|
186
|
+
// })
|
|
187
|
+
// );
|
|
188
|
+
// 添加一天的开始 结束
|
|
189
|
+
// console.log(
|
|
190
|
+
// parseTime({
|
|
191
|
+
// params: "2023-09-22",
|
|
192
|
+
// endType: "startOf",
|
|
193
|
+
// })
|
|
194
|
+
// );
|
|
195
|
+
// console.log(
|
|
196
|
+
// parseTime({
|
|
197
|
+
// params: "2023-09-22",
|
|
198
|
+
// endType: "endOf",
|
|
199
|
+
// })
|
|
200
|
+
// );
|
|
201
|
+
|
|
202
|
+
// 多字段用例
|
|
203
|
+
console.log(
|
|
204
|
+
parseTime({
|
|
205
|
+
params: { time: "2023-08-11" },
|
|
206
|
+
fromKeys: ["time"],
|
|
207
|
+
toKeys: ["resultTime"],
|
|
208
|
+
endType: "endOf",
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
console.log(
|
|
212
|
+
parseTime({
|
|
213
|
+
params: { time: "2023-08-11", time1: "2023-08-12" },
|
|
214
|
+
fromKeys: ["time", "time1"],
|
|
215
|
+
toKeys: ["resultTime", "resultTime2"],
|
|
216
|
+
endType: ["startOf", "endOf"],
|
|
217
|
+
})
|
|
218
|
+
);
|
|
219
|
+
console.log(
|
|
220
|
+
parseTime({
|
|
221
|
+
params: { time: "2023-08-11", time1: "2023-08-12" },
|
|
222
|
+
fromKeys: [["time", "time1"]],
|
|
223
|
+
toKeys: ["resultTime"],
|
|
224
|
+
type: "object",
|
|
225
|
+
endType: ["startOf", "endOf"],
|
|
226
|
+
})
|
|
227
|
+
);
|
|
228
|
+
console.log(
|
|
229
|
+
parseTime({
|
|
230
|
+
params: {
|
|
231
|
+
time: "2023-08-11",
|
|
232
|
+
time1: "2023-08-12",
|
|
233
|
+
time2: "2023-08-08",
|
|
234
|
+
time3: "2023-08-01",
|
|
235
|
+
},
|
|
236
|
+
fromKeys: [["time", "time1"], "time2", "time3"],
|
|
237
|
+
toKeys: ["resultTime", ["time2Start", "time2End"], "time3Result"],
|
|
238
|
+
// type: "object",
|
|
239
|
+
endType: [
|
|
240
|
+
["endOf", "endOf"],
|
|
241
|
+
["startOf", "startOf"],
|
|
242
|
+
],
|
|
243
|
+
})
|
|
244
|
+
);
|
|
245
|
+
console.log(
|
|
246
|
+
parseTime({
|
|
247
|
+
params: {
|
|
248
|
+
time: [dayjs(), dayjs()],
|
|
249
|
+
timea: dayjs(),
|
|
250
|
+
},
|
|
251
|
+
fromKeys: ["time", "timea"],
|
|
252
|
+
toKeys: [["time1", "time2"], "timea"],
|
|
253
|
+
format: ["YYYY-MM-DD", "YYYY-MM-DD HH:mm:ss"],
|
|
254
|
+
})
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
function calculateAge(birthday) {
|
|
258
|
+
if (!birthday) {
|
|
259
|
+
console.error("请传入一个生日信息");
|
|
260
|
+
return -1;
|
|
261
|
+
}
|
|
262
|
+
const birthDate = dayjs(birthday);
|
|
263
|
+
const today = dayjs();
|
|
264
|
+
|
|
265
|
+
let age = today.year() - birthDate.year();
|
|
266
|
+
const monthDifference = today.month() - birthDate.month();
|
|
267
|
+
|
|
268
|
+
if (
|
|
269
|
+
monthDifference < 0 ||
|
|
270
|
+
(monthDifference === 0 && today.date() < birthDate.date())
|
|
271
|
+
) {
|
|
272
|
+
age -= 1;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return age;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
console.log(calculateAge()); // -1
|
|
279
|
+
console.log(calculateAge("1994-04-02")); // 29
|
|
280
|
+
console.log(calculateAge("1994-10-12")); // 28
|
|
281
|
+
console.log(calculateAge("2023-10-11")); // 0
|
|
282
|
+
console.log(calculateAge("2023-10-12")); // -1
|
|
283
|
+
console.log(calculateAge("2023-10-10")); // 0
|
|
284
|
+
console.log(calculateAge("2022-10-11")); // 1
|
|
285
|
+
console.log(calculateAge("2022-10-10")); // 1
|
|
286
|
+
console.log(calculateAge("2022-10-12")); // 0
|
|
287
|
+
console.log(calculateAge(dayjs()));
|
|
288
|
+
console.log(calculateAge(dayjs("1994-04-02")));
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import '../node_modules/decimal.js/decimal2.js';
|
|
2
|
+
import { exports as decimalExports } from '../_virtual/decimal.js';
|
|
3
|
+
|
|
4
|
+
// function unescapeString(input) {
|
|
5
|
+
// if (!input) {
|
|
6
|
+
// return "";
|
|
7
|
+
// }
|
|
8
|
+
|
|
9
|
+
// const escapedChars = {
|
|
10
|
+
// "&": "&",
|
|
11
|
+
// "<": "<",
|
|
12
|
+
// ">": ">",
|
|
13
|
+
// """: '"',
|
|
14
|
+
// "'": "'",
|
|
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
|
+
// "<": "<",
|
|
28
|
+
// ">": ">",
|
|
29
|
+
// " ": " ",
|
|
30
|
+
// "&": "&",
|
|
31
|
+
// """: '"',
|
|
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("&&&啊你"));
|
|
57
|
+
|
|
58
|
+
// console.log(dangerouslySetXss("&&&啊你"));
|
|
59
|
+
|
|
60
|
+
// console.log(dangerouslySetXss1("&&&啊你"));
|
|
61
|
+
// console.log(unescapeString("1、aa>80%\n2、><\n3、ss<80%"));
|
|
62
|
+
// console.log(dangerouslySetXss("1、aa>80%\n2、><\n3、ss<80%"));
|
|
63
|
+
// console.log(dangerouslySetXss1("1、aa>80%\n2、><\n3、ss<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();
|
|
91
|
+
|
|
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;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
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;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function divide(num1, num2, precision = 5) {
|
|
181
|
+
try {
|
|
182
|
+
const _num1 = num1 == null ? NaN : Number(num1);
|
|
183
|
+
const _num2 = num2 == null ? NaN : Number(num2);
|
|
184
|
+
// 如果两个数都是非数字 那么直接返回0
|
|
185
|
+
const result = initNum(_num1, _num2);
|
|
186
|
+
if (typeof result === "number") {
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
// FIXME: 不记得这里为什么要先设置下小数位了。
|
|
190
|
+
// 计算完后要重置下这个值要不然会影响其他值的计算
|
|
191
|
+
// Decimal.set({ precision });
|
|
192
|
+
const result1 = Number(new Decimal(_num1).div(_num2).toFixed(precision));
|
|
193
|
+
return result1;
|
|
194
|
+
// return (isNaN(_num1) ? 0 : _num1) / (isNaN(_num2) ? 0 : _num2);
|
|
195
|
+
} catch (err) {
|
|
196
|
+
console.error("计算除法出错", err);
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function plus(num1, num2) {
|
|
202
|
+
try {
|
|
203
|
+
const _num1 = num1 == null ? NaN : Number(num1);
|
|
204
|
+
const _num2 = num2 == null ? NaN : Number(num2);
|
|
205
|
+
// 如果两个数都是非数字 那么直接返回0
|
|
206
|
+
const result = initNum(_num1, _num2);
|
|
207
|
+
if (typeof result === "number") {
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
return new Decimal(_num1).add(_num2).toNumber();
|
|
211
|
+
// return (isNaN(_num1) ? 0 : _num1) + (isNaN(_num2) ? 0 : _num2);
|
|
212
|
+
} catch (err) {
|
|
213
|
+
console.error("计算加法出错", err);
|
|
214
|
+
return 0;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
console.log(times(78.11, 0.77));
|
|
219
|
+
console.log(times(7777777.77, 1.1));
|
|
220
|
+
console.log(divide(222.77111122, 2.1222111, 19));
|
|
221
|
+
console.log(divide(4, 2));
|
|
222
|
+
console.log(plus(1.1222111, 1.22233111));
|
|
223
|
+
console.log("=================");
|
|
224
|
+
// 7777777.77 * 1.1
|
|
225
|
+
const num1 = new Decimal("78.11");
|
|
226
|
+
|
|
227
|
+
// console.log(num1.add(0.21).toNumber(), typeof num1.add(0.21).toNumber());
|
|
228
|
+
|
|
229
|
+
// console.log(num1.sub(0.21).toNumber(), typeof num1.sub(0.21).toNumber());
|
|
230
|
+
|
|
231
|
+
console.log(num1.mul(0.77).toNumber(), typeof num1.mul(0.21).toNumber());
|
|
232
|
+
Decimal.set({ precision: 5 });
|
|
233
|
+
console.log(
|
|
234
|
+
new Decimal(1).div(1.1).toNumber(),
|
|
235
|
+
typeof new Decimal(1).div(1.1).toNumber()
|
|
236
|
+
);
|
|
237
|
+
console.log(
|
|
238
|
+
new Decimal(1).dividedBy(1.1).toNumber(),
|
|
239
|
+
typeof new Decimal(1).dividedBy(1.1).toNumber()
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
console.log(
|
|
243
|
+
Number(new Decimal(1.1).toFixed(2)),
|
|
244
|
+
typeof Number(new Decimal(1.1).toFixed(2)).toFixed(2)
|
|
245
|
+
);
|
package/dist/es/test.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare const strLenValidate: (type?: "s" | "m" | "l" | "ml") => {
|
|
2
|
+
regex: RegExp;
|
|
3
|
+
message: string;
|
|
4
|
+
};
|
|
5
|
+
declare const phoneValidate: {
|
|
6
|
+
regex: RegExp;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
declare const morePhoneValidate: {
|
|
10
|
+
regex: RegExp;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
declare const idCardValidate: {
|
|
14
|
+
regex: RegExp;
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
declare const emailValidate: {
|
|
18
|
+
regex: RegExp;
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
declare const isChineseValidate: {
|
|
22
|
+
regex: RegExp;
|
|
23
|
+
message: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { emailValidate, idCardValidate, isChineseValidate, morePhoneValidate, phoneValidate, strLenValidate };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var strLenValidate = function (type) {
|
|
2
|
+
if (type === void 0) { type = "s"; }
|
|
3
|
+
if (type === "m") {
|
|
4
|
+
return {
|
|
5
|
+
regex: /^\s*([\s\S]{0,400})\s*$/,
|
|
6
|
+
message: "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6400!",
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
if (type === "l") {
|
|
10
|
+
return {
|
|
11
|
+
regex: /^\s*([\s\S]{0,600})\s*$/,
|
|
12
|
+
message: "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6600!",
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (type === "ml") {
|
|
16
|
+
return {
|
|
17
|
+
regex: /^\s*([\s\S]{0,5000})\s*$/,
|
|
18
|
+
message: "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA65000!",
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
regex: /^\s*([\s\S]{0,200})\s*$/,
|
|
23
|
+
message: "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6200!",
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
var phoneValidate = {
|
|
27
|
+
regex: /^(?:\+?86-?)?(?:(?:0\d{2,3}-?)?[1-9]\d{6,7}|1[3-9]\d{9})$/,
|
|
28
|
+
message: "请输入正确的手机号!",
|
|
29
|
+
};
|
|
30
|
+
var morePhoneValidate = {
|
|
31
|
+
regex: /^(?:(?:\+?86-?)?(?:(?:0\d{2,3}-?)?[1-9]\d{6,7}|1[3-9]\d{9})(?:,\s?)?)+$/,
|
|
32
|
+
message: "请检查输入的电话号码中是否有不符合规则的号码!",
|
|
33
|
+
};
|
|
34
|
+
var idCardValidate = {
|
|
35
|
+
regex: /^[1-9]\d{5}(?:19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[1-2]\d|3[0-1])\d{3}[\dX]$/i,
|
|
36
|
+
message: "请输入正确的身份证号!",
|
|
37
|
+
};
|
|
38
|
+
var emailValidate = {
|
|
39
|
+
regex: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
|
|
40
|
+
message: "请输入正确的邮箱!",
|
|
41
|
+
};
|
|
42
|
+
var isChineseValidate = {
|
|
43
|
+
regex: /[\u4e00-\u9fa5]/,
|
|
44
|
+
message: "请输入中文!",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { emailValidate, idCardValidate, isChineseValidate, morePhoneValidate, phoneValidate, strLenValidate };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建水印
|
|
3
|
+
*/
|
|
4
|
+
declare function createWater(config: IWaterConfig): {
|
|
5
|
+
imgBase64: string;
|
|
6
|
+
canvasWidth: number;
|
|
7
|
+
canvasHeight: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* 默认配置
|
|
11
|
+
*/
|
|
12
|
+
declare function mergeWaterConfig(waterConfig?: IWaterConfig): {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
rotate: number;
|
|
16
|
+
zIndex: number;
|
|
17
|
+
content: string | string[];
|
|
18
|
+
lineSpacing: number;
|
|
19
|
+
font: {
|
|
20
|
+
color: string | CanvasGradient | CanvasPattern;
|
|
21
|
+
fontSize: number;
|
|
22
|
+
fontWeight: number | "normal" | "light" | "weight";
|
|
23
|
+
fontStyle: "none" | "normal" | "italic" | "oblique";
|
|
24
|
+
fontFamily: string;
|
|
25
|
+
textAlign: CanvasTextAlign;
|
|
26
|
+
};
|
|
27
|
+
image: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
declare function getDefaultContent(): string[] | "浙江交通集团";
|
|
30
|
+
interface IWaterConfig {
|
|
31
|
+
width?: number;
|
|
32
|
+
height?: number;
|
|
33
|
+
rotate?: number;
|
|
34
|
+
zIndex?: number;
|
|
35
|
+
image?: string;
|
|
36
|
+
content?: string | string[];
|
|
37
|
+
lineSpacing?: number;
|
|
38
|
+
font?: {
|
|
39
|
+
color?: CanvasFillStrokeStyles["fillStyle"];
|
|
40
|
+
fontSize?: number;
|
|
41
|
+
fontWeight?: "normal" | "light" | "weight" | number;
|
|
42
|
+
fontStyle?: "none" | "normal" | "italic" | "oblique";
|
|
43
|
+
fontFamily?: string;
|
|
44
|
+
textAlign?: CanvasTextAlign;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
interface IWaterResult {
|
|
48
|
+
image: string;
|
|
49
|
+
width: number;
|
|
50
|
+
height: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { IWaterConfig, IWaterResult, createWater, getDefaultContent, mergeWaterConfig };
|