xframelib 0.8.7 → 0.9.0

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.
@@ -3,13 +3,13 @@
3
3
  * @param content 文本或二进制文件
4
4
  * @param filename 文件名
5
5
  */
6
- declare const Download: (content: string | any, filename: string) => void;
6
+ declare const Download: (content: ArrayBufferView | ArrayBuffer | Blob | string, filename: string) => void;
7
7
  /**
8
- * URL方式保存文件到本地
8
+ * URL方式保存文件到本地(下载文件夹下)
9
9
  * @param data 文件的blob数据
10
10
  * @param name 文件名
11
11
  */
12
- declare function SaveAs(data: string | any, name: string): void;
12
+ declare function SaveAs(data: ArrayBufferView | ArrayBuffer | Blob | string, name: string): void;
13
13
  /**
14
14
  * JSON对象下载为.json文件
15
15
  * @param jsonObject Json对象
@@ -24,4 +24,12 @@ declare const JsonDownload: (jsonObject: object, jsonID: string) => void;
24
24
  * @param fileName 文件名
25
25
  */
26
26
  declare const HttpDownload: (axios: any, requestUrl: string, fileName: string) => void;
27
- export { Download, SaveAs, JsonDownload, HttpDownload };
27
+ /**
28
+ * 对话框选择,保存选定路径的文件
29
+ * @param filename 文件名
30
+ * @param blob 文件内容
31
+ * @param done 回调函数
32
+ * @returns
33
+ */
34
+ declare function SaveToSelectedFile(filename: string, blob: Blob | File, doneCallBack: (err?: string, result?: any) => void): Promise<void>;
35
+ export { Download, SaveAs, JsonDownload, HttpDownload, SaveToSelectedFile };
@@ -0,0 +1,14 @@
1
+ export declare function parseLocalPath(path: any): {
2
+ filename: string;
3
+ directory: string;
4
+ basename: string;
5
+ extension: string;
6
+ };
7
+ export declare function getFileBase(path: any): string;
8
+ export declare function getFileExtension(path: any): string;
9
+ export declare function getPathBase(path: any): any;
10
+ export declare function replaceFileExtension(path: any, ext: any): any;
11
+ export declare function toLowerCaseExtension(name: any): any;
12
+ export declare function getCommonFileBase(names: any): any;
13
+ export declare function mergeNames(name1: string, name2: string): any;
14
+ export declare function findStringPrefix(a: string, b: string): string;
@@ -0,0 +1,27 @@
1
+ export interface IGzipFile {
2
+ name: string;
3
+ content: Uint8Array | string | ArrayBuffer;
4
+ }
5
+ /**
6
+ * Gzip压缩解压
7
+ */
8
+ export default class GzipTool {
9
+ static runningInBrowser(): boolean;
10
+ static isGzipped(arg: any): boolean;
11
+ static gzipSync(content: any, opts: any): Uint8Array<ArrayBufferLike> | undefined;
12
+ static gzipAsync(content: Uint8Array | string, opts: any): Promise<unknown>;
13
+ /**
14
+ * 直接读取压缩包文件,解压
15
+ * @param file File文件内容
16
+ * @returns
17
+ */
18
+ static readGzipFromFile(file: File): Promise<IGzipFile[]>;
19
+ /**
20
+ * 读压缩包文件内容,解压
21
+ * @param gzipfile
22
+ * @returns
23
+ */
24
+ static readGzipFile(gzipfile: IGzipFile): IGzipFile[];
25
+ static gunzipAsync(buf: any, opts: any): Promise<any>;
26
+ static gunzipSync(buf: any, filename: any): Uint8Array | string | any;
27
+ }
@@ -305,10 +305,66 @@ export default class H5Tool {
305
305
  * @returns {HTMLElement}
306
306
  */
307
307
  static createVideoHTML(url: string, className: string, container?: HTMLElement): HTMLElement;
308
+ /**
309
+ * 以Promise方式读前端文件
310
+ * @param file 文件或BLob
311
+ * @param type 类型'FileBytes'|'ArrayBuffer'|'Text'|'BinaryString'|'DataURL',默认为ArrayBuffer
312
+ * @param encoding 文本编码,默认为UTF-8
313
+ * @returns
314
+ */
315
+ static readFilePromise(file: File | Blob, type?: 'FileBytes' | 'ArrayBuffer' | 'Text' | 'BinaryString' | 'DataURL', encoding?: string): Promise<string | ArrayBuffer>;
308
316
  /**
309
317
  * 读取前端文件,为bytes二进制数组(base64编码的)
310
318
  * @param file
311
319
  * @returns
312
320
  */
313
321
  static readFileBytes(file: File | Blob): Promise<any>;
322
+ /**
323
+ * 将链式异步方法(最后一个参数为cb回调函数),改为promise异步方法
324
+ * @param asyncFun
325
+ * @param args 正常业务参数
326
+ * @returns
327
+ */
328
+ static promisify(asyncFun: Function, ...args: any[]): () => Promise<unknown>;
329
+ /**
330
+ * 异步等待多少ms
331
+ * @param ms 多少毫秒
332
+ * @returns
333
+ */
334
+ static wait(ms: number): Promise<unknown>;
335
+ /**
336
+ * 停止冒泡事件传递
337
+ * @param e
338
+ */
339
+ static blockEvent(e: any): void;
340
+ /**
341
+ * 给DIV对象绑定拖拽文件事件
342
+ * @param ele id或classname或 HtmlElement对象
343
+ * @param onDropFile 接收文件拖拽列表_回调函数
344
+ */
345
+ static bindDropFileHanlder(ele: string | Element, onDropFile: (fileList: FileList) => {}): void;
346
+ /**
347
+ * 获取正在输入或编辑内容的Element
348
+ * @returns input等
349
+ */
350
+ static getInputElement(): Element | null;
351
+ /**
352
+ * 将粘贴的文本,保存为文件
353
+ * @param content 粘贴文本内容
354
+ * @returns
355
+ */
356
+ private static guessPasteTextToFileName;
357
+ private static pasteEventHanlder;
358
+ /**
359
+ * 使用document
360
+ * 绑定粘贴事件(粘贴字符串、URL或文件)
361
+ * 不是任意DIV都可以绑定粘贴
362
+ * 如果 div 元素不可编辑,通常情况下是无法触发 paste 事件的。只有设置了 contenteditable="true" 的元素,才会在用户粘贴内容时触发该事件.
363
+ * @param onPasteCallback 粘贴的回调函数
364
+ */
365
+ static onPasteHandler(onPasteCallback: (pasteContent: string | Array<File> | undefined) => {}): void;
366
+ /**
367
+ * 移除document粘贴处理事件
368
+ */
369
+ static offPasteHandler(): void;
314
370
  }
@@ -99,3 +99,15 @@ export declare function isMap(source: unknown): boolean;
99
99
  * @returns
100
100
  */
101
101
  export declare const isValidURL: (url: string) => boolean;
102
+ /**
103
+ * 文本内容是否是JSON
104
+ * @param content
105
+ * @returns
106
+ */
107
+ export declare function isStringLikeJson(content: string): boolean;
108
+ /**
109
+ * 文本内容是KML
110
+ * @param content
111
+ * @returns
112
+ */
113
+ export declare function isStringLikeKml(content: string): boolean;
@@ -0,0 +1,78 @@
1
+ import { Unzipped } from "fflate";
2
+ export interface IZipFile {
3
+ filename: string;
4
+ content: Uint8Array | string | ArrayBuffer;
5
+ }
6
+ /**
7
+ * zip压缩和解压
8
+ */
9
+ export default class ZipTool {
10
+ static runningInBrowser(): boolean;
11
+ /**
12
+ * 解决文件名乱码问题
13
+ * @param str 乱码字符串
14
+ * @returns
15
+ */
16
+ static encodeGBK(str: string): string;
17
+ /**
18
+ * 直接从文件列表数组,进行压缩文件
19
+ * @param zipfileName
20
+ * @param files
21
+ */
22
+ static saveZipFromFiles(zipfileName: string, files: Array<File>): Promise<void>;
23
+ /**
24
+ * 保存文件到本地
25
+ * @param zipfileName zip文件名
26
+ * @param files 压缩文件数组
27
+ */
28
+ static saveZipFile(zipfileName: string, files: Array<IZipFile>): void;
29
+ /**
30
+ * 同步方式压缩文件
31
+ * @param zipfileName
32
+ * @param files
33
+ */
34
+ static saveZipFileSync(zipfileName: string, files: Array<IZipFile>): boolean;
35
+ /**
36
+ * 同步解压压缩包
37
+ * @param input
38
+ * @returns
39
+ */
40
+ static unzipSync(input: ArrayBuffer | Uint8Array): Unzipped | undefined;
41
+ /**
42
+ * 直接读取压缩包文件,解压
43
+ * @param file File文件内容
44
+ * @returns
45
+ */
46
+ static readZipFromFile(file: File): Promise<IZipFile[]>;
47
+ /**
48
+ * 读压缩包文件内容,解压
49
+ * @param zipfile
50
+ * @returns
51
+ */
52
+ static readZipFile(zipfile: {
53
+ content: any;
54
+ name: string;
55
+ }): Promise<IZipFile[]>;
56
+ /**
57
+ * 异步解压更快
58
+ * @param buf
59
+ * @param cb 回调函数
60
+ */
61
+ static unzipAsync(buf: ArrayBuffer | Uint8Array, cb: (err: any, data?: Unzipped) => {}): void;
62
+ /**
63
+ * 同步压缩
64
+ * @param files
65
+ * @returns
66
+ */
67
+ private static zipSync;
68
+ /**
69
+ * 异步压缩,回调返回:Uint8Array
70
+ * @param files
71
+ * @param cb 回调返回:Uint8Array
72
+ */
73
+ private static zipAsync;
74
+ private static fflateFilter;
75
+ private static fflatePostprocess;
76
+ private static isImportableZipPath;
77
+ private static fflatePreprocess;
78
+ }
@@ -2,6 +2,8 @@ import H5Tool from './H5Tool';
2
2
  import StringUtils from './StringUtils';
3
3
  import StorageHelper, { storage } from './Storage';
4
4
  import uuid, { newGuid } from './uuid';
5
+ import ZipTool from './ZipTool';
6
+ import GzipTool from './GzipTool';
5
7
  export * from './Color';
6
8
  export * from './FileDownload';
7
9
  export * from './Time';
@@ -18,4 +20,6 @@ export * from './ValidateTool';
18
20
  import XXTEA from './XXTEA';
19
21
  import WaterMark from './WaterMark';
20
22
  import { GetSignalRClient } from './SignalrClient';
21
- export { GetSignalRClient, WaterMark, XXTEA, H5Tool, StringUtils, StorageHelper as Storage, storage, uuid, newGuid };
23
+ import iconv from 'iconv-lite';
24
+ export * from './FilenameUtils';
25
+ export { iconv, GetSignalRClient, WaterMark, XXTEA, H5Tool, StringUtils, StorageHelper as Storage, storage, uuid, newGuid, ZipTool, GzipTool };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xframelib",
3
- "version": "0.8.7",
3
+ "version": "0.9.0",
4
4
  "description": "积累的前端开发基础库",
5
5
  "main": "dist/index.js",
6
6
  "common": "dist/index.cjs",
@@ -34,6 +34,8 @@
34
34
  "@iconify/vue": "^4.2.0",
35
35
  "@microsoft/signalr": "^8.0.7",
36
36
  "axios": "^1.7.9",
37
+ "fflate": "^0.8.2",
38
+ "iconv-lite": "^0.6.3",
37
39
  "localforage": "^1.10.0",
38
40
  "loglevel": "^1.9.2",
39
41
  "qs": "^6.13.1",