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