@zjlab-fe/util 0.0.1

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 ADDED
@@ -0,0 +1,38 @@
1
+ ## API
2
+
3
+ ### 下载文件
4
+
5
+ ```javascript
6
+ /**
7
+ * 下载文件
8
+ * @param url {string} 文件url
9
+ * @param openWindow {bool} 是否是新开标签页下载
10
+ */
11
+ export declare function downloadFile(url: string, openWindow?: boolean): void;
12
+ ```
13
+
14
+ ### 提取文件类型
15
+
16
+ ```javascript
17
+ /**
18
+ * 提取文件类型
19
+ * @param filePath {string} 文件路径 or 文件url
20
+ * @returns ext {string} 文件类型
21
+ */
22
+ export declare function getFileExt(filePath: string): string;
23
+ ```
24
+
25
+
26
+ ### 深度遍历对字符串进行trim操作
27
+
28
+ ```javascript
29
+ /**
30
+ * 深度遍历,对于类型是字符串的value进行trim操作
31
+ * @param obj 原始的数据
32
+ * @returns newObj trim操作后的数据
33
+ */
34
+ export declare function trimObj<T>(obj: T): T;
35
+ ```
36
+
37
+
38
+
@@ -0,0 +1 @@
1
+ import{message as n}from"antd";var t=[],e=!1;function r(r,i){i?window.open(r):(t.push(r),e||(e=!0,n.loading("文件下载中"),o()))}function o(){if(t.length>0){var r=t.shift();fetch(r).then((function(n){var t=document.createElement("a");t.style.display="none",document.body.appendChild(t),t.href=r,t.click(),document.body.removeChild(t)})).catch((function(){n.error("文件下载异常:".concat(r))})).finally((function(){setTimeout((function(){o()}),1e3)}))}else e=!1}function i(n){var t=n,e=n.indexOf("?");-1!==e&&(t=n.substring(0,e));var r=t.lastIndexOf(".");return t.substring(r+1)}function c(n){if(Array.isArray(n)){var t=[];return n.forEach((function(n){t.push(c(n))})),t}if("[object Object]"===Object.prototype.toString.call(n)){var e={};return Object.keys(n).forEach((function(t){e[t]=c(n[t])})),e}return"string"==typeof n?n.trim():n}export{r as downloadFile,i as getFileExt,c as trimObj};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var t=require("antd"),e=[],n=!1;function r(){if(e.length>0){var o=e.shift();fetch(o).then((function(t){var e=document.createElement("a");e.style.display="none",document.body.appendChild(e),e.href=o,e.click(),document.body.removeChild(e)})).catch((function(){t.message.error("文件下载异常:".concat(o))})).finally((function(){setTimeout((function(){r()}),1e3)}))}else n=!1}exports.downloadFile=function(o,i){i?window.open(o):(e.push(o),n||(n=!0,t.message.loading("文件下载中"),r()))},exports.getFileExt=function(t){var e=t,n=t.indexOf("?");-1!==n&&(e=t.substring(0,n));var r=e.lastIndexOf(".");return e.substring(r+1)},exports.trimObj=function t(e){if(Array.isArray(e)){var n=[];return e.forEach((function(e){n.push(t(e))})),n}if("[object Object]"===Object.prototype.toString.call(e)){var r={};return Object.keys(e).forEach((function(n){r[n]=t(e[n])})),r}return"string"==typeof e?e.trim():e};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 下载文件
3
+ * @param url {string} 文件url
4
+ * @param openWindow {bool} 是否是新开标签页下载
5
+ */
6
+ export declare function downloadFile(url: string, openWindow?: boolean): void;
7
+ /**
8
+ * 提取文件类型
9
+ * @param filePath {string} 文件路径 or 文件url
10
+ * @returns ext {string} 文件类型
11
+ */
12
+ export declare function getFileExt(filePath: string): string;
13
+ /**
14
+ * 深度遍历,对于类型是字符串的value进行trim操作
15
+ * @param obj 原始的数据
16
+ * @returns newObj trim操作后的数据
17
+ */
18
+ export declare function trimObj<T>(obj: T): T;
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@zjlab-fe/util",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "scripts": {
9
+ "build": "rollup -c"
10
+ },
11
+ "license": "ISC",
12
+ "devDependencies": {
13
+ "@rollup/plugin-commonjs": "^26.0.1",
14
+ "@rollup/plugin-node-resolve": "^15.2.3",
15
+ "@rollup/plugin-terser": "^0.4.4",
16
+ "@rollup/plugin-typescript": "^11.1.6",
17
+ "rollup": "^4.20.0",
18
+ "tslib": "^2.6.3",
19
+ "typescript": "^5.5.4"
20
+ },
21
+ "dependencies": {
22
+ "antd": "^5.20.0"
23
+ },
24
+ "publishConfig": {
25
+ "registry": "https://registry.npmjs.org/"
26
+ }
27
+ }