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