@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.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((item, index) => {
2746
- if (item["key"].match(key)) {
2747
- let concatList = item["value"];
2748
- concatList["key"] = item["key"];
2749
- list = [...list, concatList];
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 {string} key 数据键
2822
+ * @param key 数据key
2779
2823
  */
2780
2824
  async delete(key) {
2781
2825
  let that = this;