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