@fangzhongya/utils 0.0.38 → 0.0.39
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/basic/index.cjs +1 -1
- package/dist/basic/index.js +1 -1
- package/dist/{chunk-SZ3EQ45X.js → chunk-CFR7GIIL.js} +8 -4
- package/dist/{chunk-TTIQUN2J.cjs → chunk-PGENJCCV.cjs} +12 -8
- package/dist/chunk-PW76Z25D.cjs +249 -0
- package/dist/{chunk-OZWQIUPS.cjs → chunk-UHKL2RG3.cjs} +5 -5
- package/dist/{chunk-L5HSTRIG.js → chunk-YKNGDK4I.js} +4 -4
- package/dist/chunk-ZLEU2YQ2.js +249 -0
- package/dist/{index-DQTqufH0.d.ts → index-9-f0oXM3.d.ts} +4 -2
- package/dist/{index-CTT_peAX.d.cts → index-_GH04n6g.d.cts} +4 -2
- package/dist/index.cjs +28 -28
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +31 -31
- package/dist/judge/index.cjs +6 -6
- package/dist/judge/index.js +5 -5
- package/dist/judge/matchs.cjs +3 -3
- package/dist/judge/matchs.js +2 -2
- package/dist/load/index.cjs +3 -3
- package/dist/load/index.js +4 -4
- package/dist/window/download.cjs +6 -2
- package/dist/window/download.d.cts +41 -19
- package/dist/window/download.d.ts +41 -19
- package/dist/window/download.js +5 -1
- package/dist/window/index.cjs +8 -4
- package/dist/window/index.d.cts +1 -1
- package/dist/window/index.d.ts +1 -1
- package/dist/window/index.js +9 -5
- package/package.json +1 -1
- package/dist/chunk-LHMAKOVB.cjs +0 -123
- package/dist/chunk-UQM7IS4W.js +0 -123
- package/dist/{chunk-IAKHOOY7.js → chunk-F4P3HMNK.js} +3 -3
- package/dist/{chunk-NGQKVTCR.cjs → chunk-T22I7TJQ.cjs} +3 -3
- package/dist/{chunk-FRGDQOX4.js → chunk-T2QKEABG.js} +3 -3
- package/dist/{chunk-BD6DK4QK.cjs → chunk-XXS5G6S6.cjs} +2 -2
package/dist/window/index.js
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
import "../chunk-
|
|
2
|
-
import {
|
|
3
|
-
copy
|
|
4
|
-
} from "../chunk-W45DTA4D.js";
|
|
1
|
+
import "../chunk-CFR7GIIL.js";
|
|
5
2
|
import {
|
|
6
3
|
downloadCSV,
|
|
7
4
|
downloadFile,
|
|
8
5
|
downloadFromURL,
|
|
6
|
+
downloadImage,
|
|
9
7
|
downloadJSON,
|
|
8
|
+
downloadMultipleFiles,
|
|
10
9
|
downloadText,
|
|
11
10
|
downloadViaAJAX
|
|
12
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-ZLEU2YQ2.js";
|
|
13
12
|
import {
|
|
14
13
|
getAllParams,
|
|
15
14
|
getParam,
|
|
16
15
|
getUrlParam,
|
|
17
16
|
getUrlParams
|
|
18
17
|
} from "../chunk-MCT2IB67.js";
|
|
18
|
+
import {
|
|
19
|
+
copy
|
|
20
|
+
} from "../chunk-W45DTA4D.js";
|
|
19
21
|
import "../chunk-MLKGABMK.js";
|
|
20
22
|
export {
|
|
21
23
|
copy,
|
|
22
24
|
downloadCSV,
|
|
23
25
|
downloadFile,
|
|
24
26
|
downloadFromURL,
|
|
27
|
+
downloadImage,
|
|
25
28
|
downloadJSON,
|
|
29
|
+
downloadMultipleFiles,
|
|
26
30
|
downloadText,
|
|
27
31
|
downloadViaAJAX,
|
|
28
32
|
getAllParams,
|
package/package.json
CHANGED
package/dist/chunk-LHMAKOVB.cjs
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// packages/window/download.ts
|
|
2
|
-
function downloadFile(data, options = {}) {
|
|
3
|
-
const {
|
|
4
|
-
filename = "download",
|
|
5
|
-
mimeType = "application/octet-stream",
|
|
6
|
-
charset = "utf-8",
|
|
7
|
-
bom = ""
|
|
8
|
-
} = options;
|
|
9
|
-
try {
|
|
10
|
-
let blobData;
|
|
11
|
-
if (data instanceof Blob) {
|
|
12
|
-
blobData = data;
|
|
13
|
-
} else if (typeof data === "object") {
|
|
14
|
-
const jsonString = JSON.stringify(data, null, 2);
|
|
15
|
-
blobData = bom + jsonString;
|
|
16
|
-
} else if (typeof data === "string") {
|
|
17
|
-
blobData = bom + data;
|
|
18
|
-
} else {
|
|
19
|
-
blobData = data;
|
|
20
|
-
}
|
|
21
|
-
const blob = new Blob([blobData], {
|
|
22
|
-
type: `${mimeType};charset=${charset}`
|
|
23
|
-
});
|
|
24
|
-
const blobUrl = URL.createObjectURL(blob);
|
|
25
|
-
const link = document.createElement("a");
|
|
26
|
-
link.href = blobUrl;
|
|
27
|
-
link.download = filename;
|
|
28
|
-
document.body.appendChild(link);
|
|
29
|
-
link.click();
|
|
30
|
-
document.body.removeChild(link);
|
|
31
|
-
URL.revokeObjectURL(blobUrl);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error("\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25:", error);
|
|
34
|
-
throw new Error(
|
|
35
|
-
`\u4E0B\u8F7D\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function downloadText(text, filename = "text.txt", mimeType = "text/plain") {
|
|
40
|
-
downloadFile(text, { filename, mimeType });
|
|
41
|
-
}
|
|
42
|
-
function downloadJSON(jsonData, filename = "data.json") {
|
|
43
|
-
downloadFile(jsonData, {
|
|
44
|
-
filename,
|
|
45
|
-
mimeType: "application/json"
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function downloadCSV(data, filename = "data.csv", headers) {
|
|
49
|
-
let csvContent = "";
|
|
50
|
-
if (Array.isArray(data) && data.length > 0) {
|
|
51
|
-
if (Array.isArray(data[0])) {
|
|
52
|
-
const rows = data;
|
|
53
|
-
csvContent = rows.map(
|
|
54
|
-
(row) => row.map((cell) => `"${String(cell).replace(/"/g, '""')}"`).join(",")
|
|
55
|
-
).join("\n");
|
|
56
|
-
} else if (typeof data[0] === "object") {
|
|
57
|
-
const objects = data;
|
|
58
|
-
const objectHeaders = headers || Object.keys(objects[0]);
|
|
59
|
-
csvContent = objectHeaders.map((header) => `"${String(header).replace(/"/g, '""')}"`).join(",") + "\n";
|
|
60
|
-
csvContent += objects.map(
|
|
61
|
-
(obj) => objectHeaders.map(
|
|
62
|
-
(header) => `"${String(obj[header] || "").replace(
|
|
63
|
-
/"/g,
|
|
64
|
-
'""'
|
|
65
|
-
)}"`
|
|
66
|
-
).join(",")
|
|
67
|
-
).join("\n");
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
downloadFile(csvContent, {
|
|
71
|
-
filename,
|
|
72
|
-
mimeType: "text/csv"
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
function downloadFromURL(url, filename) {
|
|
76
|
-
const link = document.createElement("a");
|
|
77
|
-
link.href = url;
|
|
78
|
-
if (filename) {
|
|
79
|
-
link.download = filename;
|
|
80
|
-
}
|
|
81
|
-
document.body.appendChild(link);
|
|
82
|
-
link.click();
|
|
83
|
-
document.body.removeChild(link);
|
|
84
|
-
}
|
|
85
|
-
async function downloadViaAJAX(url, filename, options = {}) {
|
|
86
|
-
try {
|
|
87
|
-
const response = await fetch(url, {
|
|
88
|
-
method: "GET",
|
|
89
|
-
...options
|
|
90
|
-
});
|
|
91
|
-
if (!response.ok) {
|
|
92
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
93
|
-
}
|
|
94
|
-
const blob = await response.blob();
|
|
95
|
-
let finalFilename = filename;
|
|
96
|
-
if (!finalFilename) {
|
|
97
|
-
const contentDisposition = response.headers.get(
|
|
98
|
-
"content-disposition"
|
|
99
|
-
);
|
|
100
|
-
if (contentDisposition) {
|
|
101
|
-
const filenameMatch = contentDisposition.match(/filename="?(.+?)"?$/);
|
|
102
|
-
if (filenameMatch) {
|
|
103
|
-
finalFilename = filenameMatch[1];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
downloadFile(blob, { filename: finalFilename });
|
|
108
|
-
} catch (error) {
|
|
109
|
-
console.error("AJAX \u4E0B\u8F7D\u5931\u8D25:", error);
|
|
110
|
-
throw new Error(
|
|
111
|
-
`\u4E0B\u8F7D\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
exports.downloadFile = downloadFile; exports.downloadText = downloadText; exports.downloadJSON = downloadJSON; exports.downloadCSV = downloadCSV; exports.downloadFromURL = downloadFromURL; exports.downloadViaAJAX = downloadViaAJAX;
|
package/dist/chunk-UQM7IS4W.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// packages/window/download.ts
|
|
2
|
-
function downloadFile(data, options = {}) {
|
|
3
|
-
const {
|
|
4
|
-
filename = "download",
|
|
5
|
-
mimeType = "application/octet-stream",
|
|
6
|
-
charset = "utf-8",
|
|
7
|
-
bom = ""
|
|
8
|
-
} = options;
|
|
9
|
-
try {
|
|
10
|
-
let blobData;
|
|
11
|
-
if (data instanceof Blob) {
|
|
12
|
-
blobData = data;
|
|
13
|
-
} else if (typeof data === "object") {
|
|
14
|
-
const jsonString = JSON.stringify(data, null, 2);
|
|
15
|
-
blobData = bom + jsonString;
|
|
16
|
-
} else if (typeof data === "string") {
|
|
17
|
-
blobData = bom + data;
|
|
18
|
-
} else {
|
|
19
|
-
blobData = data;
|
|
20
|
-
}
|
|
21
|
-
const blob = new Blob([blobData], {
|
|
22
|
-
type: `${mimeType};charset=${charset}`
|
|
23
|
-
});
|
|
24
|
-
const blobUrl = URL.createObjectURL(blob);
|
|
25
|
-
const link = document.createElement("a");
|
|
26
|
-
link.href = blobUrl;
|
|
27
|
-
link.download = filename;
|
|
28
|
-
document.body.appendChild(link);
|
|
29
|
-
link.click();
|
|
30
|
-
document.body.removeChild(link);
|
|
31
|
-
URL.revokeObjectURL(blobUrl);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error("\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25:", error);
|
|
34
|
-
throw new Error(
|
|
35
|
-
`\u4E0B\u8F7D\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function downloadText(text, filename = "text.txt", mimeType = "text/plain") {
|
|
40
|
-
downloadFile(text, { filename, mimeType });
|
|
41
|
-
}
|
|
42
|
-
function downloadJSON(jsonData, filename = "data.json") {
|
|
43
|
-
downloadFile(jsonData, {
|
|
44
|
-
filename,
|
|
45
|
-
mimeType: "application/json"
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function downloadCSV(data, filename = "data.csv", headers) {
|
|
49
|
-
let csvContent = "";
|
|
50
|
-
if (Array.isArray(data) && data.length > 0) {
|
|
51
|
-
if (Array.isArray(data[0])) {
|
|
52
|
-
const rows = data;
|
|
53
|
-
csvContent = rows.map(
|
|
54
|
-
(row) => row.map((cell) => `"${String(cell).replace(/"/g, '""')}"`).join(",")
|
|
55
|
-
).join("\n");
|
|
56
|
-
} else if (typeof data[0] === "object") {
|
|
57
|
-
const objects = data;
|
|
58
|
-
const objectHeaders = headers || Object.keys(objects[0]);
|
|
59
|
-
csvContent = objectHeaders.map((header) => `"${String(header).replace(/"/g, '""')}"`).join(",") + "\n";
|
|
60
|
-
csvContent += objects.map(
|
|
61
|
-
(obj) => objectHeaders.map(
|
|
62
|
-
(header) => `"${String(obj[header] || "").replace(
|
|
63
|
-
/"/g,
|
|
64
|
-
'""'
|
|
65
|
-
)}"`
|
|
66
|
-
).join(",")
|
|
67
|
-
).join("\n");
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
downloadFile(csvContent, {
|
|
71
|
-
filename,
|
|
72
|
-
mimeType: "text/csv"
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
function downloadFromURL(url, filename) {
|
|
76
|
-
const link = document.createElement("a");
|
|
77
|
-
link.href = url;
|
|
78
|
-
if (filename) {
|
|
79
|
-
link.download = filename;
|
|
80
|
-
}
|
|
81
|
-
document.body.appendChild(link);
|
|
82
|
-
link.click();
|
|
83
|
-
document.body.removeChild(link);
|
|
84
|
-
}
|
|
85
|
-
async function downloadViaAJAX(url, filename, options = {}) {
|
|
86
|
-
try {
|
|
87
|
-
const response = await fetch(url, {
|
|
88
|
-
method: "GET",
|
|
89
|
-
...options
|
|
90
|
-
});
|
|
91
|
-
if (!response.ok) {
|
|
92
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
93
|
-
}
|
|
94
|
-
const blob = await response.blob();
|
|
95
|
-
let finalFilename = filename;
|
|
96
|
-
if (!finalFilename) {
|
|
97
|
-
const contentDisposition = response.headers.get(
|
|
98
|
-
"content-disposition"
|
|
99
|
-
);
|
|
100
|
-
if (contentDisposition) {
|
|
101
|
-
const filenameMatch = contentDisposition.match(/filename="?(.+?)"?$/);
|
|
102
|
-
if (filenameMatch) {
|
|
103
|
-
finalFilename = filenameMatch[1];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
downloadFile(blob, { filename: finalFilename });
|
|
108
|
-
} catch (error) {
|
|
109
|
-
console.error("AJAX \u4E0B\u8F7D\u5931\u8D25:", error);
|
|
110
|
-
throw new Error(
|
|
111
|
-
`\u4E0B\u8F7D\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export {
|
|
117
|
-
downloadFile,
|
|
118
|
-
downloadText,
|
|
119
|
-
downloadJSON,
|
|
120
|
-
downloadCSV,
|
|
121
|
-
downloadFromURL,
|
|
122
|
-
downloadViaAJAX
|
|
123
|
-
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkYGJOBIEOcjs = require('./chunk-YGJOBIEO.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkZZEFL2TEcjs = require('./chunk-ZZEFL2TE.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunk2BY5RQHUcjs = require('./chunk-2BY5RQHU.cjs');
|
|
10
10
|
|
|
11
11
|
// packages/judge/matchs.ts
|
|
12
12
|
function matchs(key, matchs2, type) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
matchsEnd
|
|
3
|
+
} from "./chunk-YNOFNHEK.js";
|
|
1
4
|
import {
|
|
2
5
|
matchsStart
|
|
3
6
|
} from "./chunk-S6JRKYPY.js";
|
|
4
7
|
import {
|
|
5
8
|
matchsWhole
|
|
6
9
|
} from "./chunk-IRGCP7KH.js";
|
|
7
|
-
import {
|
|
8
|
-
matchsEnd
|
|
9
|
-
} from "./chunk-YNOFNHEK.js";
|
|
10
10
|
|
|
11
11
|
// packages/judge/matchs.ts
|
|
12
12
|
function matchs(key, matchs2, type) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFP5ETUFZcjs = require('./chunk-FP5ETUFZ.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkHCEAYQHScjs = require('./chunk-HCEAYQHS.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
|