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