@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.umd.js
CHANGED
|
@@ -2658,6 +2658,48 @@
|
|
|
2658
2658
|
}, dbName);
|
|
2659
2659
|
});
|
|
2660
2660
|
}
|
|
2661
|
+
/**
|
|
2662
|
+
* 判断是否存在该数据
|
|
2663
|
+
* @param key 数据key
|
|
2664
|
+
*/
|
|
2665
|
+
async has(key) {
|
|
2666
|
+
let that = this;
|
|
2667
|
+
return new Promise((resolve) => {
|
|
2668
|
+
let dbName = this.#dbName;
|
|
2669
|
+
this.open(function (idbStore, success) {
|
|
2670
|
+
/* 判断返回的数据中是否有error字段 */
|
|
2671
|
+
if (!success) {
|
|
2672
|
+
resolve({
|
|
2673
|
+
success: false,
|
|
2674
|
+
code: that.#errorCode.get.code,
|
|
2675
|
+
msg: that.#errorCode.get.msg,
|
|
2676
|
+
});
|
|
2677
|
+
}
|
|
2678
|
+
else {
|
|
2679
|
+
idbStore = idbStore;
|
|
2680
|
+
let request = idbStore.get(key);
|
|
2681
|
+
request.onsuccess = function (event) {
|
|
2682
|
+
/* result 返回的是 {key: string, value: any} */
|
|
2683
|
+
/* 键值对存储 */
|
|
2684
|
+
resolve({
|
|
2685
|
+
success: true,
|
|
2686
|
+
code: that.#errorCode.success.code,
|
|
2687
|
+
msg: that.#errorCode.success.msg,
|
|
2688
|
+
event: event,
|
|
2689
|
+
});
|
|
2690
|
+
};
|
|
2691
|
+
request.onerror = function (event) {
|
|
2692
|
+
resolve({
|
|
2693
|
+
success: false,
|
|
2694
|
+
code: that.#errorCode.get.code,
|
|
2695
|
+
msg: that.#errorCode.get.msg,
|
|
2696
|
+
event: event,
|
|
2697
|
+
});
|
|
2698
|
+
};
|
|
2699
|
+
}
|
|
2700
|
+
}, dbName);
|
|
2701
|
+
});
|
|
2702
|
+
}
|
|
2661
2703
|
/**
|
|
2662
2704
|
* 根据key获取值
|
|
2663
2705
|
* @param key 数据key
|
|
@@ -2723,7 +2765,7 @@
|
|
|
2723
2765
|
}
|
|
2724
2766
|
/**
|
|
2725
2767
|
* 正则获取数据
|
|
2726
|
-
* @param key
|
|
2768
|
+
* @param key 数据key,可以是正则
|
|
2727
2769
|
*/
|
|
2728
2770
|
async regexpGet(key) {
|
|
2729
2771
|
let list = [];
|
|
@@ -2748,11 +2790,13 @@
|
|
|
2748
2790
|
let target = event.target;
|
|
2749
2791
|
let result = target.result;
|
|
2750
2792
|
if (result.length !== 0) {
|
|
2751
|
-
result.forEach((
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2793
|
+
result.forEach((dataItem, index) => {
|
|
2794
|
+
// 当前项的key
|
|
2795
|
+
let __key = dataItem["key"];
|
|
2796
|
+
// 当前项的value
|
|
2797
|
+
let __value = dataItem["value"];
|
|
2798
|
+
if (__key.match(key)) {
|
|
2799
|
+
list = list.concat(__value);
|
|
2756
2800
|
}
|
|
2757
2801
|
});
|
|
2758
2802
|
}
|
|
@@ -2781,7 +2825,7 @@
|
|
|
2781
2825
|
}
|
|
2782
2826
|
/**
|
|
2783
2827
|
* 删除数据
|
|
2784
|
-
* @param
|
|
2828
|
+
* @param key 数据key
|
|
2785
2829
|
*/
|
|
2786
2830
|
async delete(key) {
|
|
2787
2831
|
let that = this;
|