@whitesev/utils 2.1.2 → 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 +51 -7
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +51 -7
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +51 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +51 -7
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +51 -7
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +51 -7
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/indexedDB.d.ts +16 -3
- package/package.json +1 -1
- package/src/indexedDB.ts +69 -11
package/dist/index.esm.js
CHANGED
|
@@ -2652,6 +2652,48 @@ class indexedDB {
|
|
|
2652
2652
|
}, dbName);
|
|
2653
2653
|
});
|
|
2654
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
|
+
}
|
|
2655
2697
|
/**
|
|
2656
2698
|
* 根据key获取值
|
|
2657
2699
|
* @param key 数据key
|
|
@@ -2717,7 +2759,7 @@ class indexedDB {
|
|
|
2717
2759
|
}
|
|
2718
2760
|
/**
|
|
2719
2761
|
* 正则获取数据
|
|
2720
|
-
* @param key
|
|
2762
|
+
* @param key 数据key,可以是正则
|
|
2721
2763
|
*/
|
|
2722
2764
|
async regexpGet(key) {
|
|
2723
2765
|
let list = [];
|
|
@@ -2742,11 +2784,13 @@ class indexedDB {
|
|
|
2742
2784
|
let target = event.target;
|
|
2743
2785
|
let result = target.result;
|
|
2744
2786
|
if (result.length !== 0) {
|
|
2745
|
-
result.forEach((
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
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);
|
|
2750
2794
|
}
|
|
2751
2795
|
});
|
|
2752
2796
|
}
|
|
@@ -2775,7 +2819,7 @@ class indexedDB {
|
|
|
2775
2819
|
}
|
|
2776
2820
|
/**
|
|
2777
2821
|
* 删除数据
|
|
2778
|
-
* @param
|
|
2822
|
+
* @param key 数据key
|
|
2779
2823
|
*/
|
|
2780
2824
|
async delete(key) {
|
|
2781
2825
|
let that = this;
|