@yysports/tools 0.1.8 → 0.1.10
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/Utils/file.d.ts +9 -1
- package/dist/Utils/file.js +20 -2
- package/lib/Utils/file.d.ts +9 -1
- package/lib/Utils/file.js +15 -4
- package/package.json +14 -14
package/dist/Utils/file.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { compressAccuratelyConfig } from 'image-conversion';
|
|
2
|
-
export declare const downloadFile: (href: string, fileName?: string) => void;
|
|
2
|
+
export declare const downloadFile: (href: string, fileName?: string, target?: '_blank' | '_self' | '_parent' | '_top') => void;
|
|
3
3
|
export declare const compressImg: (file: Blob, config?: number | compressAccuratelyConfig | undefined) => Promise<Blob>;
|
|
4
4
|
/**
|
|
5
5
|
* 检查文件类型
|
|
@@ -8,3 +8,11 @@ export declare const compressImg: (file: Blob, config?: number | compressAccurat
|
|
|
8
8
|
* @returns
|
|
9
9
|
*/
|
|
10
10
|
export declare const checkFileType: (file: File, accept: string) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 获取图片分辨率
|
|
13
|
+
* @param file File 图片文件对象
|
|
14
|
+
*/
|
|
15
|
+
export declare const getImageResolution: (file: File) => Promise<{
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}>;
|
package/dist/Utils/file.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { compressAccurately } from 'image-conversion';
|
|
2
2
|
export var downloadFile = function downloadFile(href, fileName) {
|
|
3
|
+
var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '_blank';
|
|
3
4
|
var aEle = document.createElement('a');
|
|
4
|
-
aEle.target =
|
|
5
|
+
aEle.target = target;
|
|
5
6
|
aEle.href = href;
|
|
6
7
|
aEle.download = fileName || '';
|
|
7
8
|
aEle.click();
|
|
@@ -15,7 +16,7 @@ export var compressImg = function compressImg(file, config) {
|
|
|
15
16
|
* 检查文件类型
|
|
16
17
|
* @param file File 文件对象
|
|
17
18
|
* @param accept string 文件类型,使用“,”分割,如:image/png,image/jpeg
|
|
18
|
-
* @returns
|
|
19
|
+
* @returns
|
|
19
20
|
*/
|
|
20
21
|
export var checkFileType = function checkFileType(file, accept) {
|
|
21
22
|
if (accept) {
|
|
@@ -27,4 +28,21 @@ export var checkFileType = function checkFileType(file, accept) {
|
|
|
27
28
|
return acceptList.includes(fileType);
|
|
28
29
|
}
|
|
29
30
|
return true;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 获取图片分辨率
|
|
35
|
+
* @param file File 图片文件对象
|
|
36
|
+
*/
|
|
37
|
+
export var getImageResolution = function getImageResolution(file) {
|
|
38
|
+
return new Promise(function (resolve) {
|
|
39
|
+
var img = new Image();
|
|
40
|
+
img.src = URL.createObjectURL(file);
|
|
41
|
+
img.onload = function () {
|
|
42
|
+
resolve({
|
|
43
|
+
width: img.width,
|
|
44
|
+
height: img.height
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
});
|
|
30
48
|
};
|
package/lib/Utils/file.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { compressAccuratelyConfig } from 'image-conversion';
|
|
2
|
-
export declare const downloadFile: (href: string, fileName?: string) => void;
|
|
2
|
+
export declare const downloadFile: (href: string, fileName?: string, target?: '_blank' | '_self' | '_parent' | '_top') => void;
|
|
3
3
|
export declare const compressImg: (file: Blob, config?: number | compressAccuratelyConfig | undefined) => Promise<Blob>;
|
|
4
4
|
/**
|
|
5
5
|
* 检查文件类型
|
|
@@ -8,3 +8,11 @@ export declare const compressImg: (file: Blob, config?: number | compressAccurat
|
|
|
8
8
|
* @returns
|
|
9
9
|
*/
|
|
10
10
|
export declare const checkFileType: (file: File, accept: string) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 获取图片分辨率
|
|
13
|
+
* @param file File 图片文件对象
|
|
14
|
+
*/
|
|
15
|
+
export declare const getImageResolution: (file: File) => Promise<{
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}>;
|
package/lib/Utils/file.js
CHANGED
|
@@ -21,13 +21,14 @@ var file_exports = {};
|
|
|
21
21
|
__export(file_exports, {
|
|
22
22
|
checkFileType: () => checkFileType,
|
|
23
23
|
compressImg: () => compressImg,
|
|
24
|
-
downloadFile: () => downloadFile
|
|
24
|
+
downloadFile: () => downloadFile,
|
|
25
|
+
getImageResolution: () => getImageResolution
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(file_exports);
|
|
27
28
|
var import_image_conversion = require("image-conversion");
|
|
28
|
-
var downloadFile = (href, fileName) => {
|
|
29
|
+
var downloadFile = (href, fileName, target = "_blank") => {
|
|
29
30
|
const aEle = document.createElement("a");
|
|
30
|
-
aEle.target =
|
|
31
|
+
aEle.target = target;
|
|
31
32
|
aEle.href = href;
|
|
32
33
|
aEle.download = fileName || "";
|
|
33
34
|
aEle.click();
|
|
@@ -42,9 +43,19 @@ var checkFileType = (file, accept) => {
|
|
|
42
43
|
}
|
|
43
44
|
return true;
|
|
44
45
|
};
|
|
46
|
+
var getImageResolution = (file) => {
|
|
47
|
+
return new Promise((resolve) => {
|
|
48
|
+
const img = new Image();
|
|
49
|
+
img.src = URL.createObjectURL(file);
|
|
50
|
+
img.onload = () => {
|
|
51
|
+
resolve({ width: img.width, height: img.height });
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
};
|
|
45
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
46
56
|
0 && (module.exports = {
|
|
47
57
|
checkFileType,
|
|
48
58
|
compressImg,
|
|
49
|
-
downloadFile
|
|
59
|
+
downloadFile,
|
|
60
|
+
getImageResolution
|
|
50
61
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yysports/tools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "常用工具函数库",
|
|
5
5
|
"homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -64,25 +64,25 @@
|
|
|
64
64
|
"pako": "^2.1.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@ant-design/pro-components": "^2.7.
|
|
68
|
-
"@commitlint/cli": "^19.
|
|
69
|
-
"@commitlint/config-conventional": "^19.
|
|
67
|
+
"@ant-design/pro-components": "^2.7.16",
|
|
68
|
+
"@commitlint/cli": "^19.4.1",
|
|
69
|
+
"@commitlint/config-conventional": "^19.4.1",
|
|
70
70
|
"@types/pako": "^2.0.3",
|
|
71
|
-
"@types/react": "^18.3.
|
|
71
|
+
"@types/react": "^18.3.5",
|
|
72
72
|
"@types/react-dom": "^18.3.0",
|
|
73
|
-
"@umijs/lint": "^4.3.
|
|
74
|
-
"antd": "^5.
|
|
75
|
-
"dumi": "^2.4.
|
|
76
|
-
"eslint": "^9.
|
|
77
|
-
"father": "^4.
|
|
78
|
-
"husky": "^9.
|
|
79
|
-
"lint-staged": "^15.2.
|
|
73
|
+
"@umijs/lint": "^4.3.20",
|
|
74
|
+
"antd": "^5.20.6",
|
|
75
|
+
"dumi": "^2.4.10",
|
|
76
|
+
"eslint": "^9.10.0",
|
|
77
|
+
"father": "^4.5.0",
|
|
78
|
+
"husky": "^9.1.5",
|
|
79
|
+
"lint-staged": "^15.2.10",
|
|
80
80
|
"prettier": "^3.3.3",
|
|
81
81
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
82
|
-
"prettier-plugin-packagejson": "^2.5.
|
|
82
|
+
"prettier-plugin-packagejson": "^2.5.2",
|
|
83
83
|
"react": "^18.3.1",
|
|
84
84
|
"react-dom": "^18.3.1",
|
|
85
|
-
"stylelint": "^16.
|
|
85
|
+
"stylelint": "^16.9.0"
|
|
86
86
|
},
|
|
87
87
|
"publishConfig": {
|
|
88
88
|
"access": "public"
|