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