@qxs-bns/utils 0.0.16 → 0.0.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/es/index.mjs +8 -8
- package/es/src/date-transfer.d.ts +9 -18
- package/es/src/date-transfer.mjs +11 -56
- package/es/src/date-transfer.mjs.map +1 -1
- package/lib/index.js +1 -1
- package/lib/src/date-transfer.d.ts +9 -18
- package/lib/src/date-transfer.js +1 -1
- package/lib/src/date-transfer.js.map +1 -1
- package/package.json +1 -1
package/es/index.mjs
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { ArgoLog as r } from "./src/argo-log.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { formatDuration as t } from "./src/date-transfer.mjs";
|
|
3
3
|
import { isMobile as p } from "./src/device.mjs";
|
|
4
4
|
import { createVideoUploader as a, downloadFile as l } from "./src/file-operations.mjs";
|
|
5
|
-
import { JsonToExcel as
|
|
5
|
+
import { JsonToExcel as f, excelToJson as x } from "./src/json.mjs";
|
|
6
6
|
import { OssError as g, OssUploader as c, generateSignedUrl as S, uploadFile as O } from "./src/oss-uploader.mjs";
|
|
7
|
-
import { Storage as
|
|
8
|
-
import { isBoolean as w, isElement as E, isImageByMimeType as J, isJSONString as
|
|
7
|
+
import { Storage as b } from "./src/storage.mjs";
|
|
8
|
+
import { isBoolean as w, isElement as E, isImageByMimeType as J, isJSONString as T, isNumber as y, isPlainObject as A, isUndefined as B, isWindow as F } from "./src/types.mjs";
|
|
9
9
|
import { ApiService as N } from "./src/use-api.mjs";
|
|
10
10
|
import { watermark as k } from "./src/watermark.mjs";
|
|
11
11
|
export {
|
|
12
12
|
N as ApiService,
|
|
13
13
|
r as ArgoLog,
|
|
14
|
-
|
|
14
|
+
f as JsonToExcel,
|
|
15
15
|
g as OssError,
|
|
16
16
|
c as OssUploader,
|
|
17
|
-
|
|
17
|
+
b as Storage,
|
|
18
18
|
a as createVideoUploader,
|
|
19
19
|
l as downloadFile,
|
|
20
20
|
x as excelToJson,
|
|
21
|
-
t as
|
|
21
|
+
t as formatDuration,
|
|
22
22
|
S as generateSignedUrl,
|
|
23
23
|
w as isBoolean,
|
|
24
24
|
E as isElement,
|
|
25
25
|
J as isImageByMimeType,
|
|
26
|
-
|
|
26
|
+
T as isJSONString,
|
|
27
27
|
p as isMobile,
|
|
28
28
|
y as isNumber,
|
|
29
29
|
A as isPlainObject,
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param
|
|
4
|
-
* @
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @param {boolean} options.showTime - 是否显示时间部分,默认true
|
|
11
|
-
* @returns {string} 格式化后的时间字符串
|
|
2
|
+
* 智能格式化毫秒时间
|
|
3
|
+
* @param ms 毫秒数
|
|
4
|
+
* @returns 格式化后的时间字符串
|
|
5
|
+
*
|
|
6
|
+
* 规则:
|
|
7
|
+
* 1. 小于1小时:显示 MM:SS
|
|
8
|
+
* 2. 小于24小时:显示 HH:MM:SS
|
|
9
|
+
* 3. 大于等于24小时:显示 x天x小时x分钟
|
|
12
10
|
*/
|
|
13
|
-
export declare function
|
|
14
|
-
isMs?: boolean | undefined;
|
|
15
|
-
format?: string | undefined;
|
|
16
|
-
separator?: string | undefined;
|
|
17
|
-
complete?: boolean | undefined;
|
|
18
|
-
showDate?: boolean | undefined;
|
|
19
|
-
showTime?: boolean | undefined;
|
|
20
|
-
}): string;
|
|
11
|
+
export declare function formatDuration(ms: number): string;
|
package/es/src/date-transfer.mjs
CHANGED
|
@@ -1,62 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
day: 864e5,
|
|
7
|
-
month: 2592e6,
|
|
8
|
-
year: 31536e6
|
|
9
|
-
},
|
|
10
|
-
units: {
|
|
11
|
-
year: 31536e6,
|
|
12
|
-
month: 2592e6,
|
|
13
|
-
day: 864e5,
|
|
14
|
-
hour: 36e5,
|
|
15
|
-
minute: 6e4,
|
|
16
|
-
second: 1e3
|
|
17
|
-
},
|
|
18
|
-
labels: {
|
|
19
|
-
relative: {
|
|
20
|
-
justNow: "刚刚",
|
|
21
|
-
seconds: "几秒前",
|
|
22
|
-
minutes: "分钟前",
|
|
23
|
-
hours: "小时前",
|
|
24
|
-
days: "天前",
|
|
25
|
-
months: "个月前",
|
|
26
|
-
years: "年前"
|
|
27
|
-
}
|
|
1
|
+
function m(e) {
|
|
2
|
+
const c = Math.floor(e / 1e3), n = Math.floor(c / 60), s = Math.floor(n / 60), i = Math.floor(s / 24), t = (o) => o.toString().padStart(2, "0");
|
|
3
|
+
if (s < 1) {
|
|
4
|
+
const o = t(n % 60), a = t(c % 60);
|
|
5
|
+
return `${o}:${a}`;
|
|
28
6
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
format: $ = "duration",
|
|
33
|
-
separator: d = ":",
|
|
34
|
-
complete: y = !1,
|
|
35
|
-
showDate: M = !0,
|
|
36
|
-
showTime: w = !0
|
|
37
|
-
} = {}) {
|
|
38
|
-
let e;
|
|
39
|
-
if (typeof u == "number")
|
|
40
|
-
e = m ? u : u * 1e3;
|
|
41
|
-
else {
|
|
42
|
-
const r = Date.now(), t = new Date(u).getTime();
|
|
43
|
-
e = $ === "relative" ? r - t : t;
|
|
44
|
-
}
|
|
45
|
-
if (Number.isNaN(e) || e < 0)
|
|
46
|
-
throw new Error("无效的时间输入");
|
|
47
|
-
if ($ === "relative") {
|
|
48
|
-
const { justNow: r, seconds: t, minutes: f, hours: N, days: p, months: S, years: T } = c.labels.relative, o = c.thresholds;
|
|
49
|
-
return e < o.second ? r : e < o.minute ? t : e < o.hour ? `${Math.floor(e / o.minute)}${f}` : e < o.day ? `${Math.floor(e / o.hour)}${N}` : e < o.month ? `${Math.floor(e / o.day)}${p}` : e < o.year ? `${Math.floor(e / o.month)}${S}` : `${Math.floor(e / o.year)}${T}`;
|
|
50
|
-
}
|
|
51
|
-
const h = [], i = Math.floor(e / 1e3), l = Math.floor(i / (24 * 3600)), a = Math.floor(i % (24 * 3600) / 3600), s = Math.floor(i % 3600 / 60), n = i % 60;
|
|
52
|
-
if (M && l > 0 && h.push(`${l}天`), w) {
|
|
53
|
-
const r = (f) => String(f).padStart(2, "0");
|
|
54
|
-
let t = "";
|
|
55
|
-
y ? t = `${r(a)}${d}${r(s)}${d}${r(n)}` : l > 0 ? (t = a > 0 ? `${a}小时` : "", t += s > 0 ? `${s}分钟` : "") : a > 0 ? (t = `${a}小时`, t += s > 0 ? `${s}分钟` : "", t += n > 0 ? `${n}秒` : "") : s > 0 ? (t = `${s}分钟`, t += n > 0 ? `${n}秒` : "") : t = `${n}秒`, t && h.push(t);
|
|
7
|
+
if (i < 1) {
|
|
8
|
+
const o = t(s), a = t(n % 60), h = t(c % 60);
|
|
9
|
+
return `${o}:${a}:${h}`;
|
|
56
10
|
}
|
|
57
|
-
|
|
11
|
+
const u = s % 24, f = n % 60, r = [];
|
|
12
|
+
return i > 0 && r.push(`${i}天`), u > 0 && r.push(`${u}小时`), f > 0 && r.push(`${f}分钟`), r.join("");
|
|
58
13
|
}
|
|
59
14
|
export {
|
|
60
|
-
|
|
15
|
+
m as formatDuration
|
|
61
16
|
};
|
|
62
17
|
//# sourceMappingURL=date-transfer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-transfer.mjs","sources":["../../../../packages/utils/src/date-transfer.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"date-transfer.mjs","sources":["../../../../packages/utils/src/date-transfer.ts"],"sourcesContent":["/**\n * 智能格式化毫秒时间\n * @param ms 毫秒数\n * @returns 格式化后的时间字符串\n *\n * 规则:\n * 1. 小于1小时:显示 MM:SS\n * 2. 小于24小时:显示 HH:MM:SS\n * 3. 大于等于24小时:显示 x天x小时x分钟\n */\nexport function formatDuration(ms: number): string {\n const seconds = Math.floor(ms / 1000)\n const minutes = Math.floor(seconds / 60)\n const hours = Math.floor(minutes / 60)\n const days = Math.floor(hours / 24)\n\n const pad = (num: number) => num.toString().padStart(2, '0')\n\n // 如果时间小于1小时,返回 MM:SS\n if (hours < 1) {\n const mm = pad(minutes % 60)\n const ss = pad(seconds % 60)\n return `${mm}:${ss}`\n }\n\n // 如果时间小于24小时,返回 HH:MM:SS\n if (days < 1) {\n const hh = pad(hours)\n const mm = pad(minutes % 60)\n const ss = pad(seconds % 60)\n return `${hh}:${mm}:${ss}`\n }\n\n // 如果时间大于等于24小时,返回 x天x小时x分钟\n const remainingHours = hours % 24\n const remainingMinutes = minutes % 60\n\n const parts = []\n if (days > 0) {\n parts.push(`${days}天`)\n }\n if (remainingHours > 0) {\n parts.push(`${remainingHours}小时`)\n }\n if (remainingMinutes > 0) {\n parts.push(`${remainingMinutes}分钟`)\n }\n\n return parts.join('')\n}\n"],"names":["formatDuration","ms","seconds","minutes","hours","days","pad","num","mm","ss","hh","remainingHours","remainingMinutes","parts"],"mappings":"AAUO,SAASA,EAAeC,GAAoB;AACjD,QAAMC,IAAU,KAAK,MAAMD,IAAK,GAAI,GAC9BE,IAAU,KAAK,MAAMD,IAAU,EAAE,GACjCE,IAAQ,KAAK,MAAMD,IAAU,EAAE,GAC/BE,IAAO,KAAK,MAAMD,IAAQ,EAAE,GAE5BE,IAAM,CAACC,MAAgBA,EAAI,WAAW,SAAS,GAAG,GAAG;AAG3D,MAAIH,IAAQ,GAAG;AACP,UAAAI,IAAKF,EAAIH,IAAU,EAAE,GACrBM,IAAKH,EAAIJ,IAAU,EAAE;AACpB,WAAA,GAAGM,CAAE,IAAIC,CAAE;AAAA,EAAA;AAIpB,MAAIJ,IAAO,GAAG;AACN,UAAAK,IAAKJ,EAAIF,CAAK,GACdI,IAAKF,EAAIH,IAAU,EAAE,GACrBM,IAAKH,EAAIJ,IAAU,EAAE;AAC3B,WAAO,GAAGQ,CAAE,IAAIF,CAAE,IAAIC,CAAE;AAAA,EAAA;AAI1B,QAAME,IAAiBP,IAAQ,IACzBQ,IAAmBT,IAAU,IAE7BU,IAAQ,CAAC;AACf,SAAIR,IAAO,KACHQ,EAAA,KAAK,GAAGR,CAAI,GAAG,GAEnBM,IAAiB,KACbE,EAAA,KAAK,GAAGF,CAAc,IAAI,GAE9BC,IAAmB,KACfC,EAAA,KAAK,GAAGD,CAAgB,IAAI,GAG7BC,EAAM,KAAK,EAAE;AACtB;"}
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./src/argo-log.js"),n=require("./src/date-transfer.js"),t=require("./src/device.js"),i=require("./src/file-operations.js"),o=require("./src/json.js"),r=require("./src/oss-uploader.js"),a=require("./src/storage.js"),e=require("./src/types.js"),l=require("./src/use-api.js"),d=require("./src/watermark.js");exports.ArgoLog=s.ArgoLog;exports.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./src/argo-log.js"),n=require("./src/date-transfer.js"),t=require("./src/device.js"),i=require("./src/file-operations.js"),o=require("./src/json.js"),r=require("./src/oss-uploader.js"),a=require("./src/storage.js"),e=require("./src/types.js"),l=require("./src/use-api.js"),d=require("./src/watermark.js");exports.ArgoLog=s.ArgoLog;exports.formatDuration=n.formatDuration;exports.isMobile=t.isMobile;exports.createVideoUploader=i.createVideoUploader;exports.downloadFile=i.downloadFile;exports.JsonToExcel=o.JsonToExcel;exports.excelToJson=o.excelToJson;exports.OssError=r.OssError;exports.OssUploader=r.OssUploader;exports.generateSignedUrl=r.generateSignedUrl;exports.uploadFile=r.uploadFile;exports.Storage=a.Storage;exports.isBoolean=e.isBoolean;exports.isElement=e.isElement;exports.isImageByMimeType=e.isImageByMimeType;exports.isJSONString=e.isJSONString;exports.isNumber=e.isNumber;exports.isPlainObject=e.isPlainObject;exports.isUndefined=e.isUndefined;exports.isWindow=e.isWindow;exports.ApiService=l.ApiService;exports.watermark=d.watermark;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param
|
|
4
|
-
* @
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @param {boolean} options.showTime - 是否显示时间部分,默认true
|
|
11
|
-
* @returns {string} 格式化后的时间字符串
|
|
2
|
+
* 智能格式化毫秒时间
|
|
3
|
+
* @param ms 毫秒数
|
|
4
|
+
* @returns 格式化后的时间字符串
|
|
5
|
+
*
|
|
6
|
+
* 规则:
|
|
7
|
+
* 1. 小于1小时:显示 MM:SS
|
|
8
|
+
* 2. 小于24小时:显示 HH:MM:SS
|
|
9
|
+
* 3. 大于等于24小时:显示 x天x小时x分钟
|
|
12
10
|
*/
|
|
13
|
-
export declare function
|
|
14
|
-
isMs?: boolean | undefined;
|
|
15
|
-
format?: string | undefined;
|
|
16
|
-
separator?: string | undefined;
|
|
17
|
-
complete?: boolean | undefined;
|
|
18
|
-
showDate?: boolean | undefined;
|
|
19
|
-
showTime?: boolean | undefined;
|
|
20
|
-
}): string;
|
|
11
|
+
export declare function formatDuration(ms: number): string;
|
package/lib/src/date-transfer.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function m(f){const i=Math.floor(f/1e3),n=Math.floor(i/60),s=Math.floor(n/60),a=Math.floor(s/24),t=o=>o.toString().padStart(2,"0");if(s<1){const o=t(n%60),c=t(i%60);return`${o}:${c}`}if(a<1){const o=t(s),c=t(n%60),h=t(i%60);return`${o}:${c}:${h}`}const e=s%24,u=n%60,r=[];return a>0&&r.push(`${a}天`),e>0&&r.push(`${e}小时`),u>0&&r.push(`${u}分钟`),r.join("")}exports.formatDuration=m;
|
|
2
2
|
//# sourceMappingURL=date-transfer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-transfer.js","sources":["../../../../packages/utils/src/date-transfer.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"date-transfer.js","sources":["../../../../packages/utils/src/date-transfer.ts"],"sourcesContent":["/**\n * 智能格式化毫秒时间\n * @param ms 毫秒数\n * @returns 格式化后的时间字符串\n *\n * 规则:\n * 1. 小于1小时:显示 MM:SS\n * 2. 小于24小时:显示 HH:MM:SS\n * 3. 大于等于24小时:显示 x天x小时x分钟\n */\nexport function formatDuration(ms: number): string {\n const seconds = Math.floor(ms / 1000)\n const minutes = Math.floor(seconds / 60)\n const hours = Math.floor(minutes / 60)\n const days = Math.floor(hours / 24)\n\n const pad = (num: number) => num.toString().padStart(2, '0')\n\n // 如果时间小于1小时,返回 MM:SS\n if (hours < 1) {\n const mm = pad(minutes % 60)\n const ss = pad(seconds % 60)\n return `${mm}:${ss}`\n }\n\n // 如果时间小于24小时,返回 HH:MM:SS\n if (days < 1) {\n const hh = pad(hours)\n const mm = pad(minutes % 60)\n const ss = pad(seconds % 60)\n return `${hh}:${mm}:${ss}`\n }\n\n // 如果时间大于等于24小时,返回 x天x小时x分钟\n const remainingHours = hours % 24\n const remainingMinutes = minutes % 60\n\n const parts = []\n if (days > 0) {\n parts.push(`${days}天`)\n }\n if (remainingHours > 0) {\n parts.push(`${remainingHours}小时`)\n }\n if (remainingMinutes > 0) {\n parts.push(`${remainingMinutes}分钟`)\n }\n\n return parts.join('')\n}\n"],"names":["formatDuration","ms","seconds","minutes","hours","days","pad","num","mm","ss","hh","remainingHours","remainingMinutes","parts"],"mappings":"gFAUO,SAASA,EAAeC,EAAoB,CACjD,MAAMC,EAAU,KAAK,MAAMD,EAAK,GAAI,EAC9BE,EAAU,KAAK,MAAMD,EAAU,EAAE,EACjCE,EAAQ,KAAK,MAAMD,EAAU,EAAE,EAC/BE,EAAO,KAAK,MAAMD,EAAQ,EAAE,EAE5BE,EAAOC,GAAgBA,EAAI,WAAW,SAAS,EAAG,GAAG,EAG3D,GAAIH,EAAQ,EAAG,CACP,MAAAI,EAAKF,EAAIH,EAAU,EAAE,EACrBM,EAAKH,EAAIJ,EAAU,EAAE,EACpB,MAAA,GAAGM,CAAE,IAAIC,CAAE,EAAA,CAIpB,GAAIJ,EAAO,EAAG,CACN,MAAAK,EAAKJ,EAAIF,CAAK,EACdI,EAAKF,EAAIH,EAAU,EAAE,EACrBM,EAAKH,EAAIJ,EAAU,EAAE,EAC3B,MAAO,GAAGQ,CAAE,IAAIF,CAAE,IAAIC,CAAE,EAAA,CAI1B,MAAME,EAAiBP,EAAQ,GACzBQ,EAAmBT,EAAU,GAE7BU,EAAQ,CAAC,EACf,OAAIR,EAAO,GACHQ,EAAA,KAAK,GAAGR,CAAI,GAAG,EAEnBM,EAAiB,GACbE,EAAA,KAAK,GAAGF,CAAc,IAAI,EAE9BC,EAAmB,GACfC,EAAA,KAAK,GAAGD,CAAgB,IAAI,EAG7BC,EAAM,KAAK,EAAE,CACtB"}
|