@whitesev/utils 2.2.6 → 2.2.8

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