@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.
@@ -2636,8 +2636,6 @@ var Utils = (function () {
2636
2636
  let request = idbStore.put(inData);
2637
2637
  request.onsuccess = function (event) {
2638
2638
  /* 保存成功有success 字段 */
2639
- // @ts-ignore
2640
- event.target;
2641
2639
  resolve({
2642
2640
  success: true,
2643
2641
  code: that.#errorCode.success.code,
@@ -2646,8 +2644,6 @@ var Utils = (function () {
2646
2644
  });
2647
2645
  };
2648
2646
  request.onerror = function (event) {
2649
- // @ts-ignore
2650
- event.target;
2651
2647
  resolve({
2652
2648
  success: false,
2653
2649
  code: that.#errorCode.save.code,
@@ -2659,6 +2655,48 @@ var Utils = (function () {
2659
2655
  }, dbName);
2660
2656
  });
2661
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
+ }
2662
2700
  /**
2663
2701
  * 根据key获取值
2664
2702
  * @param key 数据key
@@ -2666,8 +2704,8 @@ var Utils = (function () {
2666
2704
  async get(key) {
2667
2705
  let that = this;
2668
2706
  return new Promise((resolve) => {
2669
- let dbName = that.#dbName;
2670
- that.open(function (idbStore, success) {
2707
+ let dbName = this.#dbName;
2708
+ this.open(function (idbStore, success) {
2671
2709
  /* 判断返回的数据中是否有error字段 */
2672
2710
  if (!success) {
2673
2711
  resolve({
@@ -2724,7 +2762,7 @@ var Utils = (function () {
2724
2762
  }
2725
2763
  /**
2726
2764
  * 正则获取数据
2727
- * @param key 数据键
2765
+ * @param key 数据key,可以是正则
2728
2766
  */
2729
2767
  async regexpGet(key) {
2730
2768
  let list = [];
@@ -2749,11 +2787,13 @@ var Utils = (function () {
2749
2787
  let target = event.target;
2750
2788
  let result = target.result;
2751
2789
  if (result.length !== 0) {
2752
- result.forEach((item, index) => {
2753
- if (item["key"].match(key)) {
2754
- let concatList = item["value"];
2755
- concatList["key"] = item["key"];
2756
- list = [...list, concatList];
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);
2757
2797
  }
2758
2798
  });
2759
2799
  }
@@ -2782,7 +2822,7 @@ var Utils = (function () {
2782
2822
  }
2783
2823
  /**
2784
2824
  * 删除数据
2785
- * @param {string} key 数据键
2825
+ * @param key 数据key
2786
2826
  */
2787
2827
  async delete(key) {
2788
2828
  let that = this;