@whitesev/utils 2.2.6 → 2.2.7

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
@@ -6125,7 +6125,7 @@ class Utils {
6125
6125
  });
6126
6126
  return result;
6127
6127
  }
6128
- toSearchParamsStr(obj) {
6128
+ toSearchParamsStr(obj, addPrefix) {
6129
6129
  let UtilsContext = this;
6130
6130
  let searhParamsStr = "";
6131
6131
  if (Array.isArray(obj)) {
@@ -6141,8 +6141,22 @@ class Utils {
6141
6141
  else {
6142
6142
  searhParamsStr = new URLSearchParams(Object.entries(obj)).toString();
6143
6143
  }
6144
+ if (addPrefix && !searhParamsStr.startsWith("?")) {
6145
+ searhParamsStr = "?" + searhParamsStr;
6146
+ }
6144
6147
  return searhParamsStr;
6145
6148
  }
6149
+ /**
6150
+ * 将UrlSearchParams格式的字符串转为对象
6151
+ */
6152
+ searchParamStrToObj(searhParamsStr) {
6153
+ if (typeof searhParamsStr !== "string") {
6154
+ // @ts-ignore
6155
+ return {};
6156
+ }
6157
+ // @ts-ignore
6158
+ return Object.fromEntries(new URLSearchParams(searhParamsStr));
6159
+ }
6146
6160
  /**
6147
6161
  * 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
6148
6162
  * @example