tools-min-ns 1.18.16 → 1.18.17

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,8 @@ pnpm i tools-min-ns --save
5
5
  ```
6
6
 
7
7
  # updates
8
+ ## v1.18.17
9
+ fix: FileUtil
8
10
  ## v1.18.16
9
11
  fix: SystemUtil 流式下载
10
12
  ## v1.18.15
@@ -74,6 +74,13 @@ declare namespace DateUtil {
74
74
  * formatDateToFriendly2() => 2017年11月11日
75
75
  */
76
76
  function formatDateToFriendly3(date?: Date | number | string): string;
77
+ /**
78
+ * 格式化时间为友好格式
79
+ * @param seconds
80
+ * @example
81
+ * formatBySeconds(10) => 10秒
82
+ */
83
+ function formatBySeconds(seconds: number): string;
77
84
  /**
78
85
  * 判断是否为本周
79
86
  * @param date
@@ -233,6 +233,29 @@ var DateUtil;
233
233
  return "".concat(years, "\u5E74\u524D");
234
234
  }
235
235
  DateUtil.formatDateToFriendly3 = formatDateToFriendly3;
236
+ /**
237
+ * 格式化时间为友好格式
238
+ * @param seconds
239
+ * @example
240
+ * formatBySeconds(10) => 10秒
241
+ */
242
+ function formatBySeconds(seconds) {
243
+ if (!isFinite(seconds) || seconds < 0) return '计算中...';
244
+ var day = Math.floor(seconds / 3600 * 24);
245
+ var hours = Math.floor(seconds / 3600);
246
+ var minutes = Math.floor(seconds % 3600 / 60);
247
+ var secs = Math.floor(seconds % 60);
248
+ if (day > 0) {
249
+ return "".concat(day, "\u5929").concat(hours, "\u5C0F\u65F6").concat(minutes, "\u5206\u949F").concat(secs, "\u79D2");
250
+ } else if (hours > 0) {
251
+ return "".concat(hours, "\u5C0F\u65F6").concat(minutes, "\u5206\u949F").concat(secs, "\u79D2");
252
+ } else if (minutes > 0) {
253
+ return "".concat(minutes, "\u5206\u949F").concat(secs, "\u79D2");
254
+ } else {
255
+ return "".concat(secs, "\u79D2");
256
+ }
257
+ }
258
+ DateUtil.formatBySeconds = formatBySeconds;
236
259
  /**
237
260
  * 判断是否为本周
238
261
  * @param date
@@ -11,5 +11,6 @@ declare namespace FileUtil {
11
11
  */
12
12
  function getExt(url: string): string;
13
13
  const ellisipsFileName: (fileName: string | undefined, maxLength?: number) => string;
14
+ const getFileName: (url: string, maxLength?: number) => string | undefined;
14
15
  }
15
16
  export default FileUtil;
@@ -40,5 +40,16 @@ var FileUtil;
40
40
  }
41
41
  return fileName;
42
42
  };
43
+ var _getFileName = function _getFileName(url) {
44
+ if (!url) return;
45
+ if (url.includes('*')) return url.split('*')[1];
46
+ return url.split('/').slice(-1).toString();
47
+ };
48
+ FileUtil.getFileName = function (url, maxLength) {
49
+ if (maxLength) {
50
+ return FileUtil.ellisipsFileName(_getFileName(url), maxLength);
51
+ }
52
+ return _getFileName(url);
53
+ };
43
54
  })(FileUtil || (FileUtil = {}));
44
55
  export default FileUtil;
@@ -74,6 +74,13 @@ declare namespace DateUtil {
74
74
  * formatDateToFriendly2() => 2017年11月11日
75
75
  */
76
76
  function formatDateToFriendly3(date?: Date | number | string): string;
77
+ /**
78
+ * 格式化时间为友好格式
79
+ * @param seconds
80
+ * @example
81
+ * formatBySeconds(10) => 10秒
82
+ */
83
+ function formatBySeconds(seconds: number): string;
77
84
  /**
78
85
  * 判断是否为本周
79
86
  * @param date
@@ -243,6 +243,29 @@ var DateUtil;
243
243
  return "".concat(years, "\u5E74\u524D");
244
244
  }
245
245
  DateUtil.formatDateToFriendly3 = formatDateToFriendly3;
246
+ /**
247
+ * 格式化时间为友好格式
248
+ * @param seconds
249
+ * @example
250
+ * formatBySeconds(10) => 10秒
251
+ */
252
+ function formatBySeconds(seconds) {
253
+ if (!isFinite(seconds) || seconds < 0) return '计算中...';
254
+ var day = Math.floor(seconds / 3600 * 24);
255
+ var hours = Math.floor(seconds / 3600);
256
+ var minutes = Math.floor(seconds % 3600 / 60);
257
+ var secs = Math.floor(seconds % 60);
258
+ if (day > 0) {
259
+ return "".concat(day, "\u5929").concat(hours, "\u5C0F\u65F6").concat(minutes, "\u5206\u949F").concat(secs, "\u79D2");
260
+ } else if (hours > 0) {
261
+ return "".concat(hours, "\u5C0F\u65F6").concat(minutes, "\u5206\u949F").concat(secs, "\u79D2");
262
+ } else if (minutes > 0) {
263
+ return "".concat(minutes, "\u5206\u949F").concat(secs, "\u79D2");
264
+ } else {
265
+ return "".concat(secs, "\u79D2");
266
+ }
267
+ }
268
+ DateUtil.formatBySeconds = formatBySeconds;
246
269
  /**
247
270
  * 判断是否为本周
248
271
  * @param date
@@ -11,5 +11,6 @@ declare namespace FileUtil {
11
11
  */
12
12
  function getExt(url: string): string;
13
13
  const ellisipsFileName: (fileName: string | undefined, maxLength?: number) => string;
14
+ const getFileName: (url: string, maxLength?: number) => string | undefined;
14
15
  }
15
16
  export default FileUtil;
@@ -45,5 +45,16 @@ var FileUtil;
45
45
  }
46
46
  return fileName;
47
47
  };
48
+ var _getFileName = function _getFileName(url) {
49
+ if (!url) return;
50
+ if (url.includes('*')) return url.split('*')[1];
51
+ return url.split('/').slice(-1).toString();
52
+ };
53
+ FileUtil.getFileName = function (url, maxLength) {
54
+ if (maxLength) {
55
+ return FileUtil.ellisipsFileName(_getFileName(url), maxLength);
56
+ }
57
+ return _getFileName(url);
58
+ };
48
59
  })(FileUtil || (FileUtil = {}));
49
60
  exports.default = FileUtil;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tools-min-ns",
3
3
  "description": "工具包适用于前端以及node",
4
- "version": "1.18.16",
4
+ "version": "1.18.17",
5
5
  "main": "lib/index.js",
6
6
  "license": "MIT",
7
7
  "author": "nanshen",