tools-min-ns 1.18.20 → 1.18.28

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/README.md CHANGED
@@ -5,6 +5,30 @@ pnpm i tools-min-ns --save
5
5
  ```
6
6
 
7
7
  # updates
8
+ ## v1.18.28
9
+ fix: mgop 鸿蒙这种原生桥/容器环境里,如果请求层异步读取 headers 引用
10
+ ## v1.18.27
11
+ add: NumberUtil.correctNumberInputStr
12
+ ## v1.18.26
13
+ fix: TransferUtil.numPlusUnit负数处理
14
+ ## v1.18.25
15
+ fix: DateUtil.formatBySeconds
16
+ ## v1.18.24
17
+ fix: maskIDCard
18
+
19
+ ## v1.18.23
20
+ fix: getFileSizeByBytes
21
+ ## v1.18.22
22
+ add: DateUtil.getSectionTimeList
23
+
24
+ ## v1.18.21
25
+ add: BaseUtil.compareVersions
26
+ add: BaseUtil.isVersionGreater
27
+ add: BaseUtil.isVersionEqual
28
+ add: TransferUtil.blendHexWithAlpha
29
+ add: TransferUtil.hexToRgba
30
+ fix: ObjectUtil.mergeParams
31
+
8
32
  ## v1.18.20
9
33
  fix: 解密失败为undefined
10
34
 
@@ -95,5 +95,20 @@ declare namespace BaseUtil {
95
95
  * isNotEmpty(null) => false
96
96
  */
97
97
  const isNotEmpty: (obj: any) => boolean;
98
+ /**
99
+ * 比较两个版本号
100
+ * @param version1 第一个版本号
101
+ * @param version2 第二个版本号
102
+ * @returns 1: version1 > version2, -1: version1 < version2, 0: version1 = version2
103
+ */
104
+ function compareVersions(version1: string, version2: string): number;
105
+ /**
106
+ * 判断version1是否大于version2
107
+ */
108
+ function isVersionGreater(version1: string | undefined, version2: string | undefined): boolean;
109
+ /**
110
+ * 判断两个版本是否相等
111
+ */
112
+ function isVersionEqual(version1: string | undefined, version2: string | undefined): boolean;
98
113
  }
99
114
  export default BaseUtil;
@@ -154,5 +154,50 @@ var BaseUtil;
154
154
  BaseUtil.isNotEmpty = function (obj) {
155
155
  return !BaseUtil.isEmpty(obj);
156
156
  };
157
+ /**
158
+ * 比较两个版本号
159
+ * @param version1 第一个版本号
160
+ * @param version2 第二个版本号
161
+ * @returns 1: version1 > version2, -1: version1 < version2, 0: version1 = version2
162
+ */
163
+ function compareVersions(version1, version2) {
164
+ // 移除可能存在的 'v' 前缀
165
+ var v1 = version1.replace(/^v/, '');
166
+ var v2 = version2.replace(/^v/, '');
167
+ // 分割版本号并转换为数字数组
168
+ var parts1 = v1.split('.').map(function (part) {
169
+ return parseInt(part, 10);
170
+ });
171
+ var parts2 = v2.split('.').map(function (part) {
172
+ return parseInt(part, 10);
173
+ });
174
+ // 确保两个数组长度相同,短的用0补齐
175
+ var maxLength = Math.max(parts1.length, parts2.length);
176
+ while (parts1.length < maxLength) parts1.push(0);
177
+ while (parts2.length < maxLength) parts2.push(0);
178
+ // 逐位比较
179
+ for (var i = 0; i < maxLength; i++) {
180
+ if (parts1[i] > parts2[i]) return 1;
181
+ if (parts1[i] < parts2[i]) return -1;
182
+ }
183
+ return 0;
184
+ }
185
+ BaseUtil.compareVersions = compareVersions;
186
+ /**
187
+ * 判断version1是否大于version2
188
+ */
189
+ function isVersionGreater(version1, version2) {
190
+ if (!version1 || !version2) return false;
191
+ return compareVersions(version1, version2) > 0;
192
+ }
193
+ BaseUtil.isVersionGreater = isVersionGreater;
194
+ /**
195
+ * 判断两个版本是否相等
196
+ */
197
+ function isVersionEqual(version1, version2) {
198
+ if (!version1 || !version2) return false;
199
+ return compareVersions(version1, version2) === 0;
200
+ }
201
+ BaseUtil.isVersionEqual = isVersionEqual;
157
202
  })(BaseUtil || (BaseUtil = {}));
158
203
  export default BaseUtil;
@@ -275,9 +275,6 @@ var CheckUtil;
275
275
  if (len === void 0) {
276
276
  len = 16;
277
277
  }
278
- if (!CheckUtil.idcardIsValid(idcard)) {
279
- return idcard;
280
- }
281
278
  if (start < 0) {
282
279
  start = 0;
283
280
  }
@@ -244,6 +244,14 @@ declare namespace DateUtil {
244
244
  endTime: Date | string;
245
245
  time?: string | Date | undefined;
246
246
  }, format?: string) => boolean;
247
+ /**
248
+ * 补全时间区间数组
249
+ * @param {string} time1 '16:00:00'
250
+ * @param {string} time2 '16:00:02'
251
+ * @param {string} outFormat "HH:mm:ss" 输出的格式
252
+ * @returns {string[]} ['16:00:00','16:00:01','16:00:02']
253
+ */
254
+ function getSectionTimeList(time1: string, time2: string, outFormat?: string): string[];
247
255
  /**
248
256
  * 补全日期区间数组
249
257
  * @param {string} day1 '2022-01-01'
@@ -241,8 +241,8 @@ var DateUtil;
241
241
  */
242
242
  function formatBySeconds(seconds) {
243
243
  if (!isFinite(seconds) || seconds < 0) return '计算中...';
244
- var day = Math.floor(seconds / 3600 * 24);
245
- var hours = Math.floor(seconds / 3600);
244
+ var day = Math.floor(seconds / 86400);
245
+ var hours = Math.floor(seconds % 86400 / 3600);
246
246
  var minutes = Math.floor(seconds % 3600 / 60);
247
247
  var secs = Math.floor(seconds % 60);
248
248
  if (day > 0) {
@@ -673,6 +673,54 @@ var DateUtil;
673
673
  time = _a === void 0 ? new Date() : _a;
674
674
  return DateUtil.timestamp(beginTime, format) < DateUtil.timestamp(time, format) && DateUtil.timestamp(time, format) < DateUtil.timestamp(endTime, format);
675
675
  };
676
+ /**
677
+ * 补全时间区间数组
678
+ * @param {string} time1 '16:00:00'
679
+ * @param {string} time2 '16:00:02'
680
+ * @param {string} outFormat "HH:mm:ss" 输出的格式
681
+ * @returns {string[]} ['16:00:00','16:00:01','16:00:02']
682
+ */
683
+ function getSectionTimeList(time1, time2, outFormat) {
684
+ if (outFormat === void 0) {
685
+ outFormat = 'HH:mm:ss';
686
+ }
687
+ // 将时间字符串转换为秒数
688
+ var timeToSeconds = function timeToSeconds(timeStr) {
689
+ var _a = __read(timeStr.split(':').map(Number), 3),
690
+ hours = _a[0],
691
+ minutes = _a[1],
692
+ seconds = _a[2];
693
+ return hours * 3600 + minutes * 60 + seconds;
694
+ };
695
+ // 将秒数转换为时间字符串
696
+ var secondsToTime = function secondsToTime(totalSeconds, format) {
697
+ // 确保秒数在24小时范围内
698
+ var normalizedSeconds = (totalSeconds % 86400 + 86400) % 86400;
699
+ var hours = Math.floor(normalizedSeconds / 3600);
700
+ var minutes = Math.floor(normalizedSeconds % 3600 / 60);
701
+ var seconds = normalizedSeconds % 60;
702
+ // 使用正则表达式替换格式模板
703
+ return format.replace(/HH/g, hours.toString().padStart(2, '0')) // 两位小时
704
+ .replace(/H/g, hours.toString()) // 一位小时
705
+ .replace(/mm/g, minutes.toString().padStart(2, '0')) // 两位分钟
706
+ .replace(/m/g, minutes.toString()) // 一位分钟
707
+ .replace(/ss/g, seconds.toString().padStart(2, '0')) // 两位秒
708
+ .replace(/s/g, seconds.toString()); // 一位秒
709
+ };
710
+ var startSeconds = timeToSeconds(time1);
711
+ var endSeconds = timeToSeconds(time2);
712
+ // 处理跨日期情况(如果结束时间小于开始时间,说明跨了一天)
713
+ if (endSeconds < startSeconds) {
714
+ endSeconds += 86400; // 加上一天的秒数
715
+ }
716
+ var result = [];
717
+ // 从开始时间到结束时间,每秒递增
718
+ for (var i = startSeconds; i <= endSeconds; i++) {
719
+ result.push(secondsToTime(i, outFormat));
720
+ }
721
+ return result;
722
+ }
723
+ DateUtil.getSectionTimeList = getSectionTimeList;
676
724
  /**
677
725
  * 补全日期区间数组
678
726
  * @param {string} day1 '2022-01-01'
@@ -57,6 +57,13 @@ declare namespace NumberUtil {
57
57
  * @returns 不是string|number 返回0
58
58
  */
59
59
  function correctNumberInput(val: any, n?: number): number;
60
+ /**
61
+ * 保留n位小数(补全小数位数)
62
+ * @param val 任意类型
63
+ * @param n 小数位数 默认为2
64
+ * @returns 返回 "0.00",否则返回对应小数位数的字符串
65
+ */
66
+ function correctNumberInputStr(val: any, n?: number): string;
60
67
  /**
61
68
  * 解决两个数相加精度丢失问题
62
69
  * @param a 任意类型
@@ -142,6 +142,19 @@ var NumberUtil;
142
142
  return NumberUtil.isaFinite(num) ? num : 0;
143
143
  }
144
144
  NumberUtil.correctNumberInput = correctNumberInput;
145
+ /**
146
+ * 保留n位小数(补全小数位数)
147
+ * @param val 任意类型
148
+ * @param n 小数位数 默认为2
149
+ * @returns 返回 "0.00",否则返回对应小数位数的字符串
150
+ */
151
+ function correctNumberInputStr(val, n) {
152
+ if (n === void 0) {
153
+ n = 2;
154
+ }
155
+ return Number(correctNumberInput(val, n)).toFixed(n);
156
+ }
157
+ NumberUtil.correctNumberInputStr = correctNumberInputStr;
145
158
  /**
146
159
  * 解决两个数相加精度丢失问题
147
160
  * @param a 任意类型
@@ -128,31 +128,39 @@ var ObjectUtil;
128
128
  var isAObj = BaseUtil.isObject(paramsA);
129
129
  var isBObj = BaseUtil.isObject(paramsB);
130
130
  if (!isAObj && !isBObj) return {};
131
- if (BaseUtil.isEmpty(paramsA) || !isAObj) return paramsB;
132
- if (BaseUtil.isEmpty(paramsB) || !isBObj) return paramsA;
133
- var dataAllMap = new Map();
134
- Object.entries(paramsA || {}).forEach(function (_a) {
135
- var _b = __read(_a, 2),
136
- k = _b[0],
137
- v = _b[1];
138
- dataAllMap.set(k, v);
139
- }); //浅拷贝A属性
140
- Object.entries(paramsB || {}).forEach(function (_a) {
131
+ if (BaseUtil.isEmpty(paramsA) || !isAObj) return deepClone(paramsB);
132
+ if (BaseUtil.isEmpty(paramsB) || !isBObj) return deepClone(paramsA);
133
+ return deepMerge(paramsA, paramsB);
134
+ }
135
+ ObjectUtil.mergeParams = mergeParams;
136
+ /**
137
+ * 深度合并两个对象
138
+ * @param target 目标对象(优先级高)
139
+ * @param source 源对象
140
+ * @returns 合并后的新对象
141
+ */
142
+ function deepMerge(target, source) {
143
+ var result = deepClone(target);
144
+ if (!BaseUtil.isObject(source)) {
145
+ return result;
146
+ }
147
+ Object.entries(source || {}).forEach(function (_a) {
141
148
  var _b = __read(_a, 2),
142
- k = _b[0],
143
- v = _b[1];
144
- // dataBMap.set(k, v);
145
- if ([undefined, null].includes(dataAllMap.get(k))) {
146
- dataAllMap.set(k, v);
149
+ key = _b[0],
150
+ sourceValue = _b[1];
151
+ var targetValue = result[key];
152
+ // 如果目标对象中该属性为 null 或 undefined,直接使用源对象的值
153
+ if ([undefined, null].includes(targetValue)) {
154
+ result[key] = deepClone(sourceValue);
147
155
  }
156
+ // 如果两个都是对象,则递归合并
157
+ else if (BaseUtil.isObject(targetValue) && BaseUtil.isObject(sourceValue)) {
158
+ result[key] = deepMerge(targetValue, sourceValue);
159
+ }
160
+ // 其他情况保持目标对象的值(A优先级高于B)
148
161
  });
149
- var newData = {};
150
- dataAllMap.forEach(function (v, k) {
151
- newData[k] = v;
152
- });
153
- return newData;
162
+ return result;
154
163
  }
155
- ObjectUtil.mergeParams = mergeParams;
156
164
  /**
157
165
  * 获取对象的唯一hash
158
166
  * @param obj
@@ -129,8 +129,7 @@ var Mgop = /*#__PURE__*/function () {
129
129
  url = _this$processRequestU.url,
130
130
  query = _this$processRequestU.query;
131
131
  /* 合并 defaultHeader 和 传入的header */
132
- var headers = defaultHeader;
133
- Object.assign(headers, this.config.header, {
132
+ var headers = Object.assign({}, defaultHeader, this.config.header, {
134
133
  'Content-Type': 'application/json'
135
134
  });
136
135
  var _this$config$data = this.config.data,
@@ -231,7 +230,7 @@ var Mgop = /*#__PURE__*/function () {
231
230
  return Mgop;
232
231
  }();
233
232
  export function setDefaultHeader(header) {
234
- defaultHeader = header;
233
+ defaultHeader = Object.assign({}, header);
235
234
  }
236
235
  export default function (params) {
237
236
  debug(_NAME_, 'call mgop with param', params);
@@ -61,6 +61,6 @@ export default function (options) {
61
61
  var afterOptions = Object.assign({}, DEFAULT_REQUEST_OPTIONS, options, {
62
62
  method: (options.method || 'GET').toUpperCase()
63
63
  });
64
- options.headers = normalizeHeaders(options.headers || {});
64
+ afterOptions.headers = normalizeHeaders(afterOptions.headers || {});
65
65
  return dutyChain(handleWeex.bind(null, afterOptions), handleWeb.bind(null, afterOptions), handleMiniApp.bind(null, afterOptions), handleBytedanceMiniprogram.bind(null, afterOptions), handleWeChatMiniprogram.bind(null, afterOptions));
66
66
  }
@@ -96,5 +96,20 @@ declare namespace TransferUtil {
96
96
  * @param n - 保留小数默认2
97
97
  */
98
98
  const getFileSizeByBytes: (bytes: number, n?: number, render?: ((num: number, unit: string) => any) | undefined) => any;
99
+ /**
100
+ * 十六进制转rgba
101
+ * @param hex
102
+ * @param alpha
103
+ * @returns
104
+ */
105
+ function hexToRgba(hex: string, alpha?: number): string;
106
+ /**
107
+ * 颜色混合计算
108
+ * @param hex
109
+ * @param alpha
110
+ * @param backgroundColor
111
+ * @returns 背景下与带透明度的#xxx颜色视觉效果相近的不透明十六进制颜色
112
+ */
113
+ function blendHexWithAlpha(hex: string, alpha: number, backgroundColor?: string): string | undefined;
99
114
  }
100
115
  export default TransferUtil;
@@ -260,9 +260,11 @@ var TransferUtil;
260
260
  if (index === void 0) {
261
261
  index = 2;
262
262
  }
263
- if (!/^(0|[1-9]\d*)(\.\d+)?$/.test("".concat(value))) {
263
+ if (!BaseUtil.isNumber(value)) {
264
264
  return ''; //暂无数据
265
265
  }
266
+ var firStr = value < 0 ? '-' : '';
267
+ value = Math.abs(value);
266
268
  var newValue = ['', '', ''];
267
269
  var fr = 1000;
268
270
  var num = 3;
@@ -304,7 +306,7 @@ var TransferUtil;
304
306
  newValue[1] = '';
305
307
  newValue[0] = "".concat(value);
306
308
  }
307
- return newValue.join('');
309
+ return firStr + newValue.join('');
308
310
  }
309
311
  TransferUtil.numPlusUnit = numPlusUnit;
310
312
  /**
@@ -313,10 +315,10 @@ var TransferUtil;
313
315
  * @param n - 保留小数默认2
314
316
  */
315
317
  TransferUtil.getFileSizeByBytes = function (bytes, n, render) {
316
- var _a;
318
+ var _a, _b;
317
319
  var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
318
320
  if (bytes === 0) {
319
- return '0B';
321
+ return (_a = render === null || render === void 0 ? void 0 : render(0, 'B')) !== null && _a !== void 0 ? _a : '0B';
320
322
  }
321
323
  var i = Math.floor(Math.log(bytes) / Math.log(1024));
322
324
  if (i === 0) {
@@ -324,7 +326,84 @@ var TransferUtil;
324
326
  }
325
327
  var num = NumberUtil.correctNumberInput(bytes / Math.pow(1024, i), n);
326
328
  var unit = sizes[i];
327
- return (_a = render === null || render === void 0 ? void 0 : render(num, unit)) !== null && _a !== void 0 ? _a : num + unit;
329
+ return (_b = render === null || render === void 0 ? void 0 : render(num, unit)) !== null && _b !== void 0 ? _b : num + unit;
328
330
  };
331
+ /**
332
+ * 十六进制转rgba
333
+ * @param hex
334
+ * @param alpha
335
+ * @returns
336
+ */
337
+ function hexToRgba(hex, alpha) {
338
+ if (alpha === void 0) {
339
+ alpha = 1;
340
+ }
341
+ // 移除#号(如果存在)
342
+ // eslint-disable-next-line no-param-reassign
343
+ hex = hex.replace('#', '');
344
+ // 确保是6位十六进制
345
+ if (hex.length === 3) {
346
+ // eslint-disable-next-line no-param-reassign
347
+ hex = hex.split('').map(function (char) {
348
+ return char + char;
349
+ }).join('');
350
+ }
351
+ // 提取RGB值
352
+ var r = parseInt(hex.substring(0, 2), 16);
353
+ var g = parseInt(hex.substring(2, 4), 16);
354
+ var b = parseInt(hex.substring(4, 6), 16);
355
+ // 返回rgba格式
356
+ return "rgba(".concat(r, ",").concat(g, ",").concat(b, ",").concat(alpha, ")");
357
+ }
358
+ TransferUtil.hexToRgba = hexToRgba;
359
+ /**
360
+ * 颜色混合计算
361
+ * @param hex
362
+ * @param alpha
363
+ * @param backgroundColor
364
+ * @returns 背景下与带透明度的#xxx颜色视觉效果相近的不透明十六进制颜色
365
+ */
366
+ function blendHexWithAlpha(hex, alpha, backgroundColor) {
367
+ if (backgroundColor === void 0) {
368
+ backgroundColor = '#ffffff';
369
+ }
370
+ if (!hex || !alpha) return undefined;
371
+ // 移除#号
372
+ // eslint-disable-next-line no-param-reassign
373
+ hex = hex.replace('#', '');
374
+ // eslint-disable-next-line no-param-reassign
375
+ backgroundColor = backgroundColor.replace('#', '');
376
+ // 确保是6位十六进制
377
+ if (hex.length === 3) {
378
+ // eslint-disable-next-line no-param-reassign
379
+ hex = hex.split('').map(function (char) {
380
+ return char + char;
381
+ }).join('');
382
+ }
383
+ if (backgroundColor.length === 3) {
384
+ // eslint-disable-next-line no-param-reassign
385
+ backgroundColor = backgroundColor.split('').map(function (char) {
386
+ return char + char;
387
+ }).join('');
388
+ }
389
+ // 提取前景色RGB值
390
+ var fgR = parseInt(hex.substring(0, 2), 16);
391
+ var fgG = parseInt(hex.substring(2, 4), 16);
392
+ var fgB = parseInt(hex.substring(4, 6), 16);
393
+ // 提取背景色RGB值
394
+ var bgR = parseInt(backgroundColor.substring(0, 2), 16);
395
+ var bgG = parseInt(backgroundColor.substring(2, 4), 16);
396
+ var bgB = parseInt(backgroundColor.substring(4, 6), 16);
397
+ // 颜色混合公式:result = foreground * alpha + background * (1 - alpha)
398
+ var blendedR = Math.round(fgR * alpha + bgR * (1 - alpha));
399
+ var blendedG = Math.round(fgG * alpha + bgG * (1 - alpha));
400
+ var blendedB = Math.round(fgB * alpha + bgB * (1 - alpha));
401
+ // 转换回十六进制
402
+ var toHex = function toHex(value) {
403
+ return value.toString(16).padStart(2, '0').toLowerCase();
404
+ };
405
+ return "#".concat(toHex(blendedR)).concat(toHex(blendedG)).concat(toHex(blendedB));
406
+ }
407
+ TransferUtil.blendHexWithAlpha = blendHexWithAlpha;
329
408
  })(TransferUtil || (TransferUtil = {}));
330
409
  export default TransferUtil;
@@ -95,5 +95,20 @@ declare namespace BaseUtil {
95
95
  * isNotEmpty(null) => false
96
96
  */
97
97
  const isNotEmpty: (obj: any) => boolean;
98
+ /**
99
+ * 比较两个版本号
100
+ * @param version1 第一个版本号
101
+ * @param version2 第二个版本号
102
+ * @returns 1: version1 > version2, -1: version1 < version2, 0: version1 = version2
103
+ */
104
+ function compareVersions(version1: string, version2: string): number;
105
+ /**
106
+ * 判断version1是否大于version2
107
+ */
108
+ function isVersionGreater(version1: string | undefined, version2: string | undefined): boolean;
109
+ /**
110
+ * 判断两个版本是否相等
111
+ */
112
+ function isVersionEqual(version1: string | undefined, version2: string | undefined): boolean;
98
113
  }
99
114
  export default BaseUtil;
@@ -159,5 +159,50 @@ var BaseUtil;
159
159
  BaseUtil.isNotEmpty = function (obj) {
160
160
  return !BaseUtil.isEmpty(obj);
161
161
  };
162
+ /**
163
+ * 比较两个版本号
164
+ * @param version1 第一个版本号
165
+ * @param version2 第二个版本号
166
+ * @returns 1: version1 > version2, -1: version1 < version2, 0: version1 = version2
167
+ */
168
+ function compareVersions(version1, version2) {
169
+ // 移除可能存在的 'v' 前缀
170
+ var v1 = version1.replace(/^v/, '');
171
+ var v2 = version2.replace(/^v/, '');
172
+ // 分割版本号并转换为数字数组
173
+ var parts1 = v1.split('.').map(function (part) {
174
+ return parseInt(part, 10);
175
+ });
176
+ var parts2 = v2.split('.').map(function (part) {
177
+ return parseInt(part, 10);
178
+ });
179
+ // 确保两个数组长度相同,短的用0补齐
180
+ var maxLength = Math.max(parts1.length, parts2.length);
181
+ while (parts1.length < maxLength) parts1.push(0);
182
+ while (parts2.length < maxLength) parts2.push(0);
183
+ // 逐位比较
184
+ for (var i = 0; i < maxLength; i++) {
185
+ if (parts1[i] > parts2[i]) return 1;
186
+ if (parts1[i] < parts2[i]) return -1;
187
+ }
188
+ return 0;
189
+ }
190
+ BaseUtil.compareVersions = compareVersions;
191
+ /**
192
+ * 判断version1是否大于version2
193
+ */
194
+ function isVersionGreater(version1, version2) {
195
+ if (!version1 || !version2) return false;
196
+ return compareVersions(version1, version2) > 0;
197
+ }
198
+ BaseUtil.isVersionGreater = isVersionGreater;
199
+ /**
200
+ * 判断两个版本是否相等
201
+ */
202
+ function isVersionEqual(version1, version2) {
203
+ if (!version1 || !version2) return false;
204
+ return compareVersions(version1, version2) === 0;
205
+ }
206
+ BaseUtil.isVersionEqual = isVersionEqual;
162
207
  })(BaseUtil || (BaseUtil = {}));
163
208
  exports.default = BaseUtil;
@@ -285,9 +285,6 @@ var CheckUtil;
285
285
  if (len === void 0) {
286
286
  len = 16;
287
287
  }
288
- if (!CheckUtil.idcardIsValid(idcard)) {
289
- return idcard;
290
- }
291
288
  if (start < 0) {
292
289
  start = 0;
293
290
  }
@@ -244,6 +244,14 @@ declare namespace DateUtil {
244
244
  endTime: Date | string;
245
245
  time?: string | Date | undefined;
246
246
  }, format?: string) => boolean;
247
+ /**
248
+ * 补全时间区间数组
249
+ * @param {string} time1 '16:00:00'
250
+ * @param {string} time2 '16:00:02'
251
+ * @param {string} outFormat "HH:mm:ss" 输出的格式
252
+ * @returns {string[]} ['16:00:00','16:00:01','16:00:02']
253
+ */
254
+ function getSectionTimeList(time1: string, time2: string, outFormat?: string): string[];
247
255
  /**
248
256
  * 补全日期区间数组
249
257
  * @param {string} day1 '2022-01-01'
@@ -251,8 +251,8 @@ var DateUtil;
251
251
  */
252
252
  function formatBySeconds(seconds) {
253
253
  if (!isFinite(seconds) || seconds < 0) return '计算中...';
254
- var day = Math.floor(seconds / 3600 * 24);
255
- var hours = Math.floor(seconds / 3600);
254
+ var day = Math.floor(seconds / 86400);
255
+ var hours = Math.floor(seconds % 86400 / 3600);
256
256
  var minutes = Math.floor(seconds % 3600 / 60);
257
257
  var secs = Math.floor(seconds % 60);
258
258
  if (day > 0) {
@@ -683,6 +683,54 @@ var DateUtil;
683
683
  time = _a === void 0 ? new Date() : _a;
684
684
  return DateUtil.timestamp(beginTime, format) < DateUtil.timestamp(time, format) && DateUtil.timestamp(time, format) < DateUtil.timestamp(endTime, format);
685
685
  };
686
+ /**
687
+ * 补全时间区间数组
688
+ * @param {string} time1 '16:00:00'
689
+ * @param {string} time2 '16:00:02'
690
+ * @param {string} outFormat "HH:mm:ss" 输出的格式
691
+ * @returns {string[]} ['16:00:00','16:00:01','16:00:02']
692
+ */
693
+ function getSectionTimeList(time1, time2, outFormat) {
694
+ if (outFormat === void 0) {
695
+ outFormat = 'HH:mm:ss';
696
+ }
697
+ // 将时间字符串转换为秒数
698
+ var timeToSeconds = function timeToSeconds(timeStr) {
699
+ var _a = __read(timeStr.split(':').map(Number), 3),
700
+ hours = _a[0],
701
+ minutes = _a[1],
702
+ seconds = _a[2];
703
+ return hours * 3600 + minutes * 60 + seconds;
704
+ };
705
+ // 将秒数转换为时间字符串
706
+ var secondsToTime = function secondsToTime(totalSeconds, format) {
707
+ // 确保秒数在24小时范围内
708
+ var normalizedSeconds = (totalSeconds % 86400 + 86400) % 86400;
709
+ var hours = Math.floor(normalizedSeconds / 3600);
710
+ var minutes = Math.floor(normalizedSeconds % 3600 / 60);
711
+ var seconds = normalizedSeconds % 60;
712
+ // 使用正则表达式替换格式模板
713
+ return format.replace(/HH/g, hours.toString().padStart(2, '0')) // 两位小时
714
+ .replace(/H/g, hours.toString()) // 一位小时
715
+ .replace(/mm/g, minutes.toString().padStart(2, '0')) // 两位分钟
716
+ .replace(/m/g, minutes.toString()) // 一位分钟
717
+ .replace(/ss/g, seconds.toString().padStart(2, '0')) // 两位秒
718
+ .replace(/s/g, seconds.toString()); // 一位秒
719
+ };
720
+ var startSeconds = timeToSeconds(time1);
721
+ var endSeconds = timeToSeconds(time2);
722
+ // 处理跨日期情况(如果结束时间小于开始时间,说明跨了一天)
723
+ if (endSeconds < startSeconds) {
724
+ endSeconds += 86400; // 加上一天的秒数
725
+ }
726
+ var result = [];
727
+ // 从开始时间到结束时间,每秒递增
728
+ for (var i = startSeconds; i <= endSeconds; i++) {
729
+ result.push(secondsToTime(i, outFormat));
730
+ }
731
+ return result;
732
+ }
733
+ DateUtil.getSectionTimeList = getSectionTimeList;
686
734
  /**
687
735
  * 补全日期区间数组
688
736
  * @param {string} day1 '2022-01-01'
@@ -57,6 +57,13 @@ declare namespace NumberUtil {
57
57
  * @returns 不是string|number 返回0
58
58
  */
59
59
  function correctNumberInput(val: any, n?: number): number;
60
+ /**
61
+ * 保留n位小数(补全小数位数)
62
+ * @param val 任意类型
63
+ * @param n 小数位数 默认为2
64
+ * @returns 返回 "0.00",否则返回对应小数位数的字符串
65
+ */
66
+ function correctNumberInputStr(val: any, n?: number): string;
60
67
  /**
61
68
  * 解决两个数相加精度丢失问题
62
69
  * @param a 任意类型
@@ -152,6 +152,19 @@ var NumberUtil;
152
152
  return NumberUtil.isaFinite(num) ? num : 0;
153
153
  }
154
154
  NumberUtil.correctNumberInput = correctNumberInput;
155
+ /**
156
+ * 保留n位小数(补全小数位数)
157
+ * @param val 任意类型
158
+ * @param n 小数位数 默认为2
159
+ * @returns 返回 "0.00",否则返回对应小数位数的字符串
160
+ */
161
+ function correctNumberInputStr(val, n) {
162
+ if (n === void 0) {
163
+ n = 2;
164
+ }
165
+ return Number(correctNumberInput(val, n)).toFixed(n);
166
+ }
167
+ NumberUtil.correctNumberInputStr = correctNumberInputStr;
155
168
  /**
156
169
  * 解决两个数相加精度丢失问题
157
170
  * @param a 任意类型
@@ -138,31 +138,39 @@ var ObjectUtil;
138
138
  var isAObj = BaseUtil_1.default.isObject(paramsA);
139
139
  var isBObj = BaseUtil_1.default.isObject(paramsB);
140
140
  if (!isAObj && !isBObj) return {};
141
- if (BaseUtil_1.default.isEmpty(paramsA) || !isAObj) return paramsB;
142
- if (BaseUtil_1.default.isEmpty(paramsB) || !isBObj) return paramsA;
143
- var dataAllMap = new Map();
144
- Object.entries(paramsA || {}).forEach(function (_a) {
145
- var _b = __read(_a, 2),
146
- k = _b[0],
147
- v = _b[1];
148
- dataAllMap.set(k, v);
149
- }); //浅拷贝A属性
150
- Object.entries(paramsB || {}).forEach(function (_a) {
141
+ if (BaseUtil_1.default.isEmpty(paramsA) || !isAObj) return deepClone(paramsB);
142
+ if (BaseUtil_1.default.isEmpty(paramsB) || !isBObj) return deepClone(paramsA);
143
+ return deepMerge(paramsA, paramsB);
144
+ }
145
+ ObjectUtil.mergeParams = mergeParams;
146
+ /**
147
+ * 深度合并两个对象
148
+ * @param target 目标对象(优先级高)
149
+ * @param source 源对象
150
+ * @returns 合并后的新对象
151
+ */
152
+ function deepMerge(target, source) {
153
+ var result = deepClone(target);
154
+ if (!BaseUtil_1.default.isObject(source)) {
155
+ return result;
156
+ }
157
+ Object.entries(source || {}).forEach(function (_a) {
151
158
  var _b = __read(_a, 2),
152
- k = _b[0],
153
- v = _b[1];
154
- // dataBMap.set(k, v);
155
- if ([undefined, null].includes(dataAllMap.get(k))) {
156
- dataAllMap.set(k, v);
159
+ key = _b[0],
160
+ sourceValue = _b[1];
161
+ var targetValue = result[key];
162
+ // 如果目标对象中该属性为 null 或 undefined,直接使用源对象的值
163
+ if ([undefined, null].includes(targetValue)) {
164
+ result[key] = deepClone(sourceValue);
157
165
  }
166
+ // 如果两个都是对象,则递归合并
167
+ else if (BaseUtil_1.default.isObject(targetValue) && BaseUtil_1.default.isObject(sourceValue)) {
168
+ result[key] = deepMerge(targetValue, sourceValue);
169
+ }
170
+ // 其他情况保持目标对象的值(A优先级高于B)
158
171
  });
159
- var newData = {};
160
- dataAllMap.forEach(function (v, k) {
161
- newData[k] = v;
162
- });
163
- return newData;
172
+ return result;
164
173
  }
165
- ObjectUtil.mergeParams = mergeParams;
166
174
  /**
167
175
  * 获取对象的唯一hash
168
176
  * @param obj
@@ -140,8 +140,7 @@ var Mgop = /*#__PURE__*/function () {
140
140
  url = _this$processRequestU.url,
141
141
  query = _this$processRequestU.query;
142
142
  /* 合并 defaultHeader 和 传入的header */
143
- var headers = defaultHeader;
144
- Object.assign(headers, this.config.header, {
143
+ var headers = Object.assign({}, defaultHeader, this.config.header, {
145
144
  'Content-Type': 'application/json'
146
145
  });
147
146
  var _this$config$data = this.config.data,
@@ -242,7 +241,7 @@ var Mgop = /*#__PURE__*/function () {
242
241
  return Mgop;
243
242
  }();
244
243
  function setDefaultHeader(header) {
245
- defaultHeader = header;
244
+ defaultHeader = Object.assign({}, header);
246
245
  }
247
246
  exports.setDefaultHeader = setDefaultHeader;
248
247
  function default_1(params) {
@@ -71,7 +71,7 @@ function default_1(options) {
71
71
  var afterOptions = Object.assign({}, types_1.DEFAULT_REQUEST_OPTIONS, options, {
72
72
  method: (options.method || 'GET').toUpperCase()
73
73
  });
74
- options.headers = (0, utils_1.normalizeHeaders)(options.headers || {});
74
+ afterOptions.headers = (0, utils_1.normalizeHeaders)(afterOptions.headers || {});
75
75
  return dutyChain(handleWeex.bind(null, afterOptions), handleWeb.bind(null, afterOptions), handleMiniApp.bind(null, afterOptions), handleBytedanceMiniprogram.bind(null, afterOptions), handleWeChatMiniprogram.bind(null, afterOptions));
76
76
  }
77
77
  exports.default = default_1;
@@ -96,5 +96,20 @@ declare namespace TransferUtil {
96
96
  * @param n - 保留小数默认2
97
97
  */
98
98
  const getFileSizeByBytes: (bytes: number, n?: number, render?: ((num: number, unit: string) => any) | undefined) => any;
99
+ /**
100
+ * 十六进制转rgba
101
+ * @param hex
102
+ * @param alpha
103
+ * @returns
104
+ */
105
+ function hexToRgba(hex: string, alpha?: number): string;
106
+ /**
107
+ * 颜色混合计算
108
+ * @param hex
109
+ * @param alpha
110
+ * @param backgroundColor
111
+ * @returns 背景下与带透明度的#xxx颜色视觉效果相近的不透明十六进制颜色
112
+ */
113
+ function blendHexWithAlpha(hex: string, alpha: number, backgroundColor?: string): string | undefined;
99
114
  }
100
115
  export default TransferUtil;
@@ -270,9 +270,11 @@ var TransferUtil;
270
270
  if (index === void 0) {
271
271
  index = 2;
272
272
  }
273
- if (!/^(0|[1-9]\d*)(\.\d+)?$/.test("".concat(value))) {
273
+ if (!BaseUtil_1.default.isNumber(value)) {
274
274
  return ''; //暂无数据
275
275
  }
276
+ var firStr = value < 0 ? '-' : '';
277
+ value = Math.abs(value);
276
278
  var newValue = ['', '', ''];
277
279
  var fr = 1000;
278
280
  var num = 3;
@@ -314,7 +316,7 @@ var TransferUtil;
314
316
  newValue[1] = '';
315
317
  newValue[0] = "".concat(value);
316
318
  }
317
- return newValue.join('');
319
+ return firStr + newValue.join('');
318
320
  }
319
321
  TransferUtil.numPlusUnit = numPlusUnit;
320
322
  /**
@@ -323,10 +325,10 @@ var TransferUtil;
323
325
  * @param n - 保留小数默认2
324
326
  */
325
327
  TransferUtil.getFileSizeByBytes = function (bytes, n, render) {
326
- var _a;
328
+ var _a, _b;
327
329
  var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
328
330
  if (bytes === 0) {
329
- return '0B';
331
+ return (_a = render === null || render === void 0 ? void 0 : render(0, 'B')) !== null && _a !== void 0 ? _a : '0B';
330
332
  }
331
333
  var i = Math.floor(Math.log(bytes) / Math.log(1024));
332
334
  if (i === 0) {
@@ -334,7 +336,84 @@ var TransferUtil;
334
336
  }
335
337
  var num = NumberUtil_1.default.correctNumberInput(bytes / Math.pow(1024, i), n);
336
338
  var unit = sizes[i];
337
- return (_a = render === null || render === void 0 ? void 0 : render(num, unit)) !== null && _a !== void 0 ? _a : num + unit;
339
+ return (_b = render === null || render === void 0 ? void 0 : render(num, unit)) !== null && _b !== void 0 ? _b : num + unit;
338
340
  };
341
+ /**
342
+ * 十六进制转rgba
343
+ * @param hex
344
+ * @param alpha
345
+ * @returns
346
+ */
347
+ function hexToRgba(hex, alpha) {
348
+ if (alpha === void 0) {
349
+ alpha = 1;
350
+ }
351
+ // 移除#号(如果存在)
352
+ // eslint-disable-next-line no-param-reassign
353
+ hex = hex.replace('#', '');
354
+ // 确保是6位十六进制
355
+ if (hex.length === 3) {
356
+ // eslint-disable-next-line no-param-reassign
357
+ hex = hex.split('').map(function (char) {
358
+ return char + char;
359
+ }).join('');
360
+ }
361
+ // 提取RGB值
362
+ var r = parseInt(hex.substring(0, 2), 16);
363
+ var g = parseInt(hex.substring(2, 4), 16);
364
+ var b = parseInt(hex.substring(4, 6), 16);
365
+ // 返回rgba格式
366
+ return "rgba(".concat(r, ",").concat(g, ",").concat(b, ",").concat(alpha, ")");
367
+ }
368
+ TransferUtil.hexToRgba = hexToRgba;
369
+ /**
370
+ * 颜色混合计算
371
+ * @param hex
372
+ * @param alpha
373
+ * @param backgroundColor
374
+ * @returns 背景下与带透明度的#xxx颜色视觉效果相近的不透明十六进制颜色
375
+ */
376
+ function blendHexWithAlpha(hex, alpha, backgroundColor) {
377
+ if (backgroundColor === void 0) {
378
+ backgroundColor = '#ffffff';
379
+ }
380
+ if (!hex || !alpha) return undefined;
381
+ // 移除#号
382
+ // eslint-disable-next-line no-param-reassign
383
+ hex = hex.replace('#', '');
384
+ // eslint-disable-next-line no-param-reassign
385
+ backgroundColor = backgroundColor.replace('#', '');
386
+ // 确保是6位十六进制
387
+ if (hex.length === 3) {
388
+ // eslint-disable-next-line no-param-reassign
389
+ hex = hex.split('').map(function (char) {
390
+ return char + char;
391
+ }).join('');
392
+ }
393
+ if (backgroundColor.length === 3) {
394
+ // eslint-disable-next-line no-param-reassign
395
+ backgroundColor = backgroundColor.split('').map(function (char) {
396
+ return char + char;
397
+ }).join('');
398
+ }
399
+ // 提取前景色RGB值
400
+ var fgR = parseInt(hex.substring(0, 2), 16);
401
+ var fgG = parseInt(hex.substring(2, 4), 16);
402
+ var fgB = parseInt(hex.substring(4, 6), 16);
403
+ // 提取背景色RGB值
404
+ var bgR = parseInt(backgroundColor.substring(0, 2), 16);
405
+ var bgG = parseInt(backgroundColor.substring(2, 4), 16);
406
+ var bgB = parseInt(backgroundColor.substring(4, 6), 16);
407
+ // 颜色混合公式:result = foreground * alpha + background * (1 - alpha)
408
+ var blendedR = Math.round(fgR * alpha + bgR * (1 - alpha));
409
+ var blendedG = Math.round(fgG * alpha + bgG * (1 - alpha));
410
+ var blendedB = Math.round(fgB * alpha + bgB * (1 - alpha));
411
+ // 转换回十六进制
412
+ var toHex = function toHex(value) {
413
+ return value.toString(16).padStart(2, '0').toLowerCase();
414
+ };
415
+ return "#".concat(toHex(blendedR)).concat(toHex(blendedG)).concat(toHex(blendedB));
416
+ }
417
+ TransferUtil.blendHexWithAlpha = blendHexWithAlpha;
339
418
  })(TransferUtil || (TransferUtil = {}));
340
419
  exports.default = TransferUtil;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tools-min-ns",
3
3
  "description": "工具包适用于前端以及node",
4
- "version": "1.18.20",
4
+ "version": "1.18.28",
5
5
  "main": "lib/index.js",
6
6
  "license": "MIT",
7
7
  "author": "nanshen",