@whitesev/utils 2.1.1 → 2.1.3
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 +53 -13
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +53 -13
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +53 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +53 -13
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +53 -13
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +53 -13
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/indexedDB.d.ts +37 -9
- package/package.json +1 -1
- package/src/indexedDB.ts +95 -26
package/dist/index.esm.js
CHANGED
|
@@ -2633,8 +2633,6 @@ class indexedDB {
|
|
|
2633
2633
|
let request = idbStore.put(inData);
|
|
2634
2634
|
request.onsuccess = function (event) {
|
|
2635
2635
|
/* 保存成功有success 字段 */
|
|
2636
|
-
// @ts-ignore
|
|
2637
|
-
event.target;
|
|
2638
2636
|
resolve({
|
|
2639
2637
|
success: true,
|
|
2640
2638
|
code: that.#errorCode.success.code,
|
|
@@ -2643,8 +2641,6 @@ class indexedDB {
|
|
|
2643
2641
|
});
|
|
2644
2642
|
};
|
|
2645
2643
|
request.onerror = function (event) {
|
|
2646
|
-
// @ts-ignore
|
|
2647
|
-
event.target;
|
|
2648
2644
|
resolve({
|
|
2649
2645
|
success: false,
|
|
2650
2646
|
code: that.#errorCode.save.code,
|
|
@@ -2656,6 +2652,48 @@ class indexedDB {
|
|
|
2656
2652
|
}, dbName);
|
|
2657
2653
|
});
|
|
2658
2654
|
}
|
|
2655
|
+
/**
|
|
2656
|
+
* 判断是否存在该数据
|
|
2657
|
+
* @param key 数据key
|
|
2658
|
+
*/
|
|
2659
|
+
async has(key) {
|
|
2660
|
+
let that = this;
|
|
2661
|
+
return new Promise((resolve) => {
|
|
2662
|
+
let dbName = this.#dbName;
|
|
2663
|
+
this.open(function (idbStore, success) {
|
|
2664
|
+
/* 判断返回的数据中是否有error字段 */
|
|
2665
|
+
if (!success) {
|
|
2666
|
+
resolve({
|
|
2667
|
+
success: false,
|
|
2668
|
+
code: that.#errorCode.get.code,
|
|
2669
|
+
msg: that.#errorCode.get.msg,
|
|
2670
|
+
});
|
|
2671
|
+
}
|
|
2672
|
+
else {
|
|
2673
|
+
idbStore = idbStore;
|
|
2674
|
+
let request = idbStore.get(key);
|
|
2675
|
+
request.onsuccess = function (event) {
|
|
2676
|
+
/* result 返回的是 {key: string, value: any} */
|
|
2677
|
+
/* 键值对存储 */
|
|
2678
|
+
resolve({
|
|
2679
|
+
success: true,
|
|
2680
|
+
code: that.#errorCode.success.code,
|
|
2681
|
+
msg: that.#errorCode.success.msg,
|
|
2682
|
+
event: event,
|
|
2683
|
+
});
|
|
2684
|
+
};
|
|
2685
|
+
request.onerror = function (event) {
|
|
2686
|
+
resolve({
|
|
2687
|
+
success: false,
|
|
2688
|
+
code: that.#errorCode.get.code,
|
|
2689
|
+
msg: that.#errorCode.get.msg,
|
|
2690
|
+
event: event,
|
|
2691
|
+
});
|
|
2692
|
+
};
|
|
2693
|
+
}
|
|
2694
|
+
}, dbName);
|
|
2695
|
+
});
|
|
2696
|
+
}
|
|
2659
2697
|
/**
|
|
2660
2698
|
* 根据key获取值
|
|
2661
2699
|
* @param key 数据key
|
|
@@ -2663,8 +2701,8 @@ class indexedDB {
|
|
|
2663
2701
|
async get(key) {
|
|
2664
2702
|
let that = this;
|
|
2665
2703
|
return new Promise((resolve) => {
|
|
2666
|
-
let dbName =
|
|
2667
|
-
|
|
2704
|
+
let dbName = this.#dbName;
|
|
2705
|
+
this.open(function (idbStore, success) {
|
|
2668
2706
|
/* 判断返回的数据中是否有error字段 */
|
|
2669
2707
|
if (!success) {
|
|
2670
2708
|
resolve({
|
|
@@ -2721,7 +2759,7 @@ class indexedDB {
|
|
|
2721
2759
|
}
|
|
2722
2760
|
/**
|
|
2723
2761
|
* 正则获取数据
|
|
2724
|
-
* @param key
|
|
2762
|
+
* @param key 数据key,可以是正则
|
|
2725
2763
|
*/
|
|
2726
2764
|
async regexpGet(key) {
|
|
2727
2765
|
let list = [];
|
|
@@ -2746,11 +2784,13 @@ class indexedDB {
|
|
|
2746
2784
|
let target = event.target;
|
|
2747
2785
|
let result = target.result;
|
|
2748
2786
|
if (result.length !== 0) {
|
|
2749
|
-
result.forEach((
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2787
|
+
result.forEach((dataItem, index) => {
|
|
2788
|
+
// 当前项的key
|
|
2789
|
+
let __key = dataItem["key"];
|
|
2790
|
+
// 当前项的value
|
|
2791
|
+
let __value = dataItem["value"];
|
|
2792
|
+
if (__key.match(key)) {
|
|
2793
|
+
list = list.concat(__value);
|
|
2754
2794
|
}
|
|
2755
2795
|
});
|
|
2756
2796
|
}
|
|
@@ -2779,7 +2819,7 @@ class indexedDB {
|
|
|
2779
2819
|
}
|
|
2780
2820
|
/**
|
|
2781
2821
|
* 删除数据
|
|
2782
|
-
* @param
|
|
2822
|
+
* @param key 数据key
|
|
2783
2823
|
*/
|
|
2784
2824
|
async delete(key) {
|
|
2785
2825
|
let that = this;
|