@whitesev/utils 2.1.0 → 2.1.2
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.amd.js +7 -10
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +7 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +7 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +7 -10
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +7 -10
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +7 -10
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +2 -2
- package/dist/types/src/{UtilsWindowApi.d.ts → WindowApi.d.ts} +1 -1
- package/dist/types/src/indexedDB.d.ts +21 -6
- package/package.json +1 -1
- package/src/Utils.ts +14 -11
- package/src/{UtilsWindowApi.ts → WindowApi.ts} +1 -1
- package/src/indexedDB.ts +26 -15
|
@@ -12,7 +12,7 @@ import { UtilsDictionary } from "./Dictionary";
|
|
|
12
12
|
import type { DOMUtils_EventType } from "./Event";
|
|
13
13
|
import type { Vue2Object } from "./VueObject";
|
|
14
14
|
import type { UtilsAjaxHookResult } from "./AjaxHookerType";
|
|
15
|
-
import { type UtilsWindowApiOption } from "./
|
|
15
|
+
import { type UtilsWindowApiOption } from "./WindowApi";
|
|
16
16
|
export declare var unsafeWindow: Window & typeof globalThis;
|
|
17
17
|
export type JSTypeMap = {
|
|
18
18
|
string: string;
|
|
@@ -1361,7 +1361,7 @@ declare class Utils {
|
|
|
1361
1361
|
* Utils.sortListByProperty([{"time":"2022-1-1"},{"time":"2022-2-2"}],(item)=>{return item["time"]},false)
|
|
1362
1362
|
* > [{time: '2022-1-1'},{time: '2022-2-2'}]
|
|
1363
1363
|
**/
|
|
1364
|
-
sortListByProperty<T extends any
|
|
1364
|
+
sortListByProperty<T extends any>(data: T[], getPropertyValueFunc: string | ((value: T) => any), sortByDesc?: boolean): T[];
|
|
1365
1365
|
/**
|
|
1366
1366
|
* 字符串转正则,用于把字符串中不规范的字符进行转义
|
|
1367
1367
|
* @param targetString 需要进行转换的字符串
|
|
@@ -22,11 +22,14 @@ declare class indexedDB {
|
|
|
22
22
|
* @param key 数据key
|
|
23
23
|
* @param value 数据值
|
|
24
24
|
*/
|
|
25
|
-
save(key: string, value:
|
|
25
|
+
save<T extends any>(key: string, value: T): Promise<{
|
|
26
26
|
success: boolean;
|
|
27
27
|
code: number;
|
|
28
28
|
msg: string;
|
|
29
|
-
event?:
|
|
29
|
+
event?: {
|
|
30
|
+
srcElement: IDBRequest<T>;
|
|
31
|
+
target: IDBRequest<T>;
|
|
32
|
+
} & Event;
|
|
30
33
|
}>;
|
|
31
34
|
/**
|
|
32
35
|
* 根据key获取值
|
|
@@ -37,8 +40,14 @@ declare class indexedDB {
|
|
|
37
40
|
code: number;
|
|
38
41
|
msg: string;
|
|
39
42
|
data: T;
|
|
40
|
-
event?:
|
|
41
|
-
|
|
43
|
+
event?: {
|
|
44
|
+
srcElement: IDBRequest<T>;
|
|
45
|
+
target: IDBRequest<T>;
|
|
46
|
+
} & Event;
|
|
47
|
+
result?: {
|
|
48
|
+
key: string;
|
|
49
|
+
value: T;
|
|
50
|
+
};
|
|
42
51
|
}>;
|
|
43
52
|
/**
|
|
44
53
|
* 正则获取数据
|
|
@@ -49,7 +58,10 @@ declare class indexedDB {
|
|
|
49
58
|
code: number;
|
|
50
59
|
msg: string;
|
|
51
60
|
data: T[];
|
|
52
|
-
event?:
|
|
61
|
+
event?: {
|
|
62
|
+
srcElement: IDBRequest<T>;
|
|
63
|
+
target: IDBRequest<T>;
|
|
64
|
+
} & Event;
|
|
53
65
|
}>;
|
|
54
66
|
/**
|
|
55
67
|
* 删除数据
|
|
@@ -59,7 +71,10 @@ declare class indexedDB {
|
|
|
59
71
|
success: boolean;
|
|
60
72
|
code: number;
|
|
61
73
|
msg: string;
|
|
62
|
-
event?:
|
|
74
|
+
event?: {
|
|
75
|
+
srcElement: IDBRequest;
|
|
76
|
+
target: IDBRequest;
|
|
77
|
+
} & Event;
|
|
63
78
|
}>;
|
|
64
79
|
/**
|
|
65
80
|
* 删除所有数据
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { DOMUtils_EventType } from "./Event";
|
|
|
15
15
|
import type { Vue2Object } from "./VueObject";
|
|
16
16
|
import type { UtilsAjaxHookResult } from "./AjaxHookerType";
|
|
17
17
|
import { GenerateUUID } from "./UtilsCommon";
|
|
18
|
-
import {
|
|
18
|
+
import { WindowApi, type UtilsWindowApiOption } from "./WindowApi";
|
|
19
19
|
|
|
20
20
|
export declare var unsafeWindow: Window & typeof globalThis;
|
|
21
21
|
|
|
@@ -47,12 +47,12 @@ export declare interface AnyObject {
|
|
|
47
47
|
export declare interface Vue2Context extends Vue2Object {}
|
|
48
48
|
|
|
49
49
|
class Utils {
|
|
50
|
-
private windowApi:
|
|
50
|
+
private windowApi: WindowApi;
|
|
51
51
|
constructor(option?: UtilsWindowApiOption) {
|
|
52
|
-
this.windowApi = new
|
|
52
|
+
this.windowApi = new WindowApi(option);
|
|
53
53
|
}
|
|
54
54
|
/** 版本号 */
|
|
55
|
-
version = "2024.7.
|
|
55
|
+
version = "2024.7.24";
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
|
|
@@ -3602,16 +3602,16 @@ class Utils {
|
|
|
3602
3602
|
* Utils.sortListByProperty([{"time":"2022-1-1"},{"time":"2022-2-2"}],(item)=>{return item["time"]},false)
|
|
3603
3603
|
* > [{time: '2022-1-1'},{time: '2022-2-2'}]
|
|
3604
3604
|
**/
|
|
3605
|
-
sortListByProperty<T extends any
|
|
3606
|
-
data: T,
|
|
3605
|
+
sortListByProperty<T extends any>(
|
|
3606
|
+
data: T[],
|
|
3607
3607
|
getPropertyValueFunc: string | ((value: T) => any),
|
|
3608
3608
|
sortByDesc?: boolean
|
|
3609
|
-
): T;
|
|
3610
|
-
sortListByProperty<T extends any
|
|
3611
|
-
data: T,
|
|
3609
|
+
): T[];
|
|
3610
|
+
sortListByProperty<T extends any>(
|
|
3611
|
+
data: T[],
|
|
3612
3612
|
getPropertyValueFunc: string | ((value: T) => any),
|
|
3613
3613
|
sortByDesc: boolean = true
|
|
3614
|
-
): T {
|
|
3614
|
+
): T[] {
|
|
3615
3615
|
let UtilsContext = this;
|
|
3616
3616
|
if (
|
|
3617
3617
|
typeof getPropertyValueFunc !== "function" &&
|
|
@@ -3702,7 +3702,10 @@ class Utils {
|
|
|
3702
3702
|
}
|
|
3703
3703
|
if (Array.isArray(data)) {
|
|
3704
3704
|
data.sort(sortFunc);
|
|
3705
|
-
} else if (
|
|
3705
|
+
} else if (
|
|
3706
|
+
(data as any) instanceof NodeList ||
|
|
3707
|
+
UtilsContext.isJQuery(data)
|
|
3708
|
+
) {
|
|
3706
3709
|
sortNodeFunc(data as any, getDataFunc as any);
|
|
3707
3710
|
result = (getDataFunc as any)();
|
|
3708
3711
|
} else {
|
package/src/indexedDB.ts
CHANGED
|
@@ -130,15 +130,18 @@ class indexedDB {
|
|
|
130
130
|
* @param key 数据key
|
|
131
131
|
* @param value 数据值
|
|
132
132
|
*/
|
|
133
|
-
async save(
|
|
133
|
+
async save<T extends any>(
|
|
134
134
|
key: string,
|
|
135
|
-
value:
|
|
135
|
+
value: T
|
|
136
136
|
): Promise<{
|
|
137
137
|
success: boolean;
|
|
138
138
|
code: number;
|
|
139
139
|
msg: string;
|
|
140
140
|
|
|
141
|
-
event?:
|
|
141
|
+
event?: {
|
|
142
|
+
srcElement: IDBRequest<T>;
|
|
143
|
+
target: IDBRequest<T>;
|
|
144
|
+
} & Event;
|
|
142
145
|
}> {
|
|
143
146
|
let that = this;
|
|
144
147
|
return new Promise((resolve) => {
|
|
@@ -157,10 +160,8 @@ class indexedDB {
|
|
|
157
160
|
} else {
|
|
158
161
|
idbStore = idbStore as IDBObjectStore;
|
|
159
162
|
let request = idbStore.put(inData);
|
|
160
|
-
request.onsuccess = function (event:
|
|
163
|
+
request.onsuccess = function (event: any) {
|
|
161
164
|
/* 保存成功有success 字段 */
|
|
162
|
-
// @ts-ignore
|
|
163
|
-
let target = event.target as IDBRequest;
|
|
164
165
|
resolve({
|
|
165
166
|
success: true,
|
|
166
167
|
code: that.#errorCode.success.code,
|
|
@@ -169,9 +170,7 @@ class indexedDB {
|
|
|
169
170
|
event: event,
|
|
170
171
|
});
|
|
171
172
|
};
|
|
172
|
-
request.onerror = function (event:
|
|
173
|
-
// @ts-ignore
|
|
174
|
-
let target = event.target as IDBRequest;
|
|
173
|
+
request.onerror = function (event: any) {
|
|
175
174
|
resolve({
|
|
176
175
|
success: false,
|
|
177
176
|
|
|
@@ -197,13 +196,19 @@ class indexedDB {
|
|
|
197
196
|
msg: string;
|
|
198
197
|
data: T;
|
|
199
198
|
|
|
200
|
-
event?:
|
|
201
|
-
|
|
199
|
+
event?: {
|
|
200
|
+
srcElement: IDBRequest<T>;
|
|
201
|
+
target: IDBRequest<T>;
|
|
202
|
+
} & Event;
|
|
203
|
+
result?: {
|
|
204
|
+
key: string;
|
|
205
|
+
value: T;
|
|
206
|
+
};
|
|
202
207
|
}> {
|
|
203
208
|
let that = this;
|
|
204
209
|
return new Promise((resolve) => {
|
|
205
|
-
let dbName =
|
|
206
|
-
|
|
210
|
+
let dbName = this.#dbName;
|
|
211
|
+
this.open(function (idbStore, success) {
|
|
207
212
|
/* 判断返回的数据中是否有error字段 */
|
|
208
213
|
if (!success) {
|
|
209
214
|
resolve({
|
|
@@ -272,7 +277,10 @@ class indexedDB {
|
|
|
272
277
|
msg: string;
|
|
273
278
|
data: T[];
|
|
274
279
|
|
|
275
|
-
event?:
|
|
280
|
+
event?: {
|
|
281
|
+
srcElement: IDBRequest<T>;
|
|
282
|
+
target: IDBRequest<T>;
|
|
283
|
+
} & Event;
|
|
276
284
|
}> {
|
|
277
285
|
let list: T[] = [];
|
|
278
286
|
let that = this;
|
|
@@ -338,7 +346,10 @@ class indexedDB {
|
|
|
338
346
|
code: number;
|
|
339
347
|
msg: string;
|
|
340
348
|
|
|
341
|
-
event?:
|
|
349
|
+
event?: {
|
|
350
|
+
srcElement: IDBRequest;
|
|
351
|
+
target: IDBRequest;
|
|
352
|
+
} & Event;
|
|
342
353
|
}> {
|
|
343
354
|
let that = this;
|
|
344
355
|
return new Promise((resolve) => {
|