xframelib 0.8.7 → 0.8.9
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 +3 -0
- package/dist/core/Global.d.ts +5 -0
- package/dist/index.cjs +10 -10
- package/dist/index.js +10 -10
- package/dist/utils/FileDownload.d.ts +12 -4
- package/dist/utils/FilenameUtils.d.ts +14 -0
- package/dist/utils/GzipTool.d.ts +27 -0
- package/dist/utils/H5Tool.d.ts +56 -0
- package/dist/utils/IsTool.d.ts +12 -0
- package/dist/utils/ZipTool.d.ts +60 -0
- package/dist/utils/index.d.ts +4 -1
- package/package.json +2 -1
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* @param content 文本或二进制文件
|
|
4
4
|
* @param filename 文件名
|
|
5
5
|
*/
|
|
6
|
-
declare const Download: (content:
|
|
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:
|
|
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
|
-
|
|
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
|
+
}
|
package/dist/utils/H5Tool.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/utils/IsTool.d.ts
CHANGED
|
@@ -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,60 @@
|
|
|
1
|
+
import { Unzipped, FlateCallback } 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 zipfileName zip文件名
|
|
14
|
+
* @param files 压缩文件数组
|
|
15
|
+
*/
|
|
16
|
+
static saveZipFile(zipfileName: string, files: Array<IZipFile>): void;
|
|
17
|
+
/**
|
|
18
|
+
* 同步解压压缩包
|
|
19
|
+
* @param input
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
static unzipSync(input: ArrayBuffer | Uint8Array): Unzipped | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* 直接读取压缩包文件,解压
|
|
25
|
+
* @param file File文件内容
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
static readZipFromFile(file: File): Promise<IZipFile[]>;
|
|
29
|
+
/**
|
|
30
|
+
* 读压缩包文件内容,解压
|
|
31
|
+
* @param zipfile
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
static readZipFile(zipfile: {
|
|
35
|
+
content: any;
|
|
36
|
+
name: string;
|
|
37
|
+
}): Promise<IZipFile[]>;
|
|
38
|
+
/**
|
|
39
|
+
* 异步解压更快
|
|
40
|
+
* @param buf
|
|
41
|
+
* @param cb 回调函数
|
|
42
|
+
*/
|
|
43
|
+
static unzipAsync(buf: ArrayBuffer | Uint8Array, cb: (err: any, data?: Unzipped) => {}): void;
|
|
44
|
+
/**
|
|
45
|
+
* 同步压缩
|
|
46
|
+
* @param files
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
static zipSync(files: Array<IZipFile>): Uint8Array;
|
|
50
|
+
/**
|
|
51
|
+
* 异步压缩
|
|
52
|
+
* @param files
|
|
53
|
+
* @param cb
|
|
54
|
+
*/
|
|
55
|
+
static zipAsync(files: Array<IZipFile>, cb: FlateCallback): void;
|
|
56
|
+
private static fflateFilter;
|
|
57
|
+
private static fflatePostprocess;
|
|
58
|
+
private static isImportableZipPath;
|
|
59
|
+
private static fflatePreprocess;
|
|
60
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -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,5 @@ export * from './ValidateTool';
|
|
|
18
20
|
import XXTEA from './XXTEA';
|
|
19
21
|
import WaterMark from './WaterMark';
|
|
20
22
|
import { GetSignalRClient } from './SignalrClient';
|
|
21
|
-
export
|
|
23
|
+
export * from './FilenameUtils';
|
|
24
|
+
export { 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.
|
|
3
|
+
"version": "0.8.9",
|
|
4
4
|
"description": "积累的前端开发基础库",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"common": "dist/index.cjs",
|
|
@@ -34,6 +34,7 @@
|
|
|
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",
|
|
37
38
|
"localforage": "^1.10.0",
|
|
38
39
|
"loglevel": "^1.9.2",
|
|
39
40
|
"qs": "^6.13.1",
|