@whitesev/utils 2.1.1 → 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.
@@ -2638,8 +2638,6 @@ System.register('Utils', [], (function (exports) {
2638
2638
  let request = idbStore.put(inData);
2639
2639
  request.onsuccess = function (event) {
2640
2640
  /* 保存成功有success 字段 */
2641
- // @ts-ignore
2642
- event.target;
2643
2641
  resolve({
2644
2642
  success: true,
2645
2643
  code: that.#errorCode.success.code,
@@ -2648,8 +2646,6 @@ System.register('Utils', [], (function (exports) {
2648
2646
  });
2649
2647
  };
2650
2648
  request.onerror = function (event) {
2651
- // @ts-ignore
2652
- event.target;
2653
2649
  resolve({
2654
2650
  success: false,
2655
2651
  code: that.#errorCode.save.code,
@@ -2661,6 +2657,48 @@ System.register('Utils', [], (function (exports) {
2661
2657
  }, dbName);
2662
2658
  });
2663
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
+ }
2664
2702
  /**
2665
2703
  * 根据key获取值
2666
2704
  * @param key 数据key
@@ -2668,8 +2706,8 @@ System.register('Utils', [], (function (exports) {
2668
2706
  async get(key) {
2669
2707
  let that = this;
2670
2708
  return new Promise((resolve) => {
2671
- let dbName = that.#dbName;
2672
- that.open(function (idbStore, success) {
2709
+ let dbName = this.#dbName;
2710
+ this.open(function (idbStore, success) {
2673
2711
  /* 判断返回的数据中是否有error字段 */
2674
2712
  if (!success) {
2675
2713
  resolve({
@@ -2726,7 +2764,7 @@ System.register('Utils', [], (function (exports) {
2726
2764
  }
2727
2765
  /**
2728
2766
  * 正则获取数据
2729
- * @param key 数据键
2767
+ * @param key 数据key,可以是正则
2730
2768
  */
2731
2769
  async regexpGet(key) {
2732
2770
  let list = [];
@@ -2751,11 +2789,13 @@ System.register('Utils', [], (function (exports) {
2751
2789
  let target = event.target;
2752
2790
  let result = target.result;
2753
2791
  if (result.length !== 0) {
2754
- result.forEach((item, index) => {
2755
- if (item["key"].match(key)) {
2756
- let concatList = item["value"];
2757
- concatList["key"] = item["key"];
2758
- 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);
2759
2799
  }
2760
2800
  });
2761
2801
  }
@@ -2784,7 +2824,7 @@ System.register('Utils', [], (function (exports) {
2784
2824
  }
2785
2825
  /**
2786
2826
  * 删除数据
2787
- * @param {string} key 数据键
2827
+ * @param key 数据key
2788
2828
  */
2789
2829
  async delete(key) {
2790
2830
  let that = this;