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