@cripty2001/utils 0.0.26 → 0.0.27
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/index.d.ts +1 -0
- package/dist/index.js +12 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare function loop(cb: () => Promise<void>, interval: number, onError?
|
|
|
22
22
|
export declare function isEqual(a: any, b: any): boolean;
|
|
23
23
|
export declare function arrayStep(from: number, to: number, step: number): number[];
|
|
24
24
|
export declare function copyToClipboard(text: string): void;
|
|
25
|
+
export declare function download(data: string | Blob, filename: string, mimeType?: string): void;
|
|
25
26
|
export declare function stableLog(obj: any, message?: string): void;
|
|
26
27
|
export declare function parseQuery(query: string | Record<string, any> | URLSearchParams, fields: string[]): {
|
|
27
28
|
extracted: URLSearchParams;
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.loop = loop;
|
|
|
9
9
|
exports.isEqual = isEqual;
|
|
10
10
|
exports.arrayStep = arrayStep;
|
|
11
11
|
exports.copyToClipboard = copyToClipboard;
|
|
12
|
+
exports.download = download;
|
|
12
13
|
exports.stableLog = stableLog;
|
|
13
14
|
exports.parseQuery = parseQuery;
|
|
14
15
|
exports.randBetween = randBetween;
|
|
@@ -86,6 +87,17 @@ function arrayStep(from, to, step) {
|
|
|
86
87
|
function copyToClipboard(text) {
|
|
87
88
|
navigator.clipboard.writeText(text);
|
|
88
89
|
}
|
|
90
|
+
function download(data, filename, mimeType = 'application/octet-stream') {
|
|
91
|
+
const blob = data instanceof Blob ? data : new Blob([data], { type: mimeType });
|
|
92
|
+
const url = URL.createObjectURL(blob);
|
|
93
|
+
const a = document.createElement('a');
|
|
94
|
+
a.href = url;
|
|
95
|
+
a.download = filename;
|
|
96
|
+
document.body.appendChild(a);
|
|
97
|
+
a.click();
|
|
98
|
+
document.body.removeChild(a);
|
|
99
|
+
URL.revokeObjectURL(url);
|
|
100
|
+
}
|
|
89
101
|
function stableLog(obj, message = '') {
|
|
90
102
|
console.log(message, JSON.parse(JSON.stringify(obj)));
|
|
91
103
|
}
|
package/package.json
CHANGED