@whitesev/utils 2.6.3 → 2.6.4

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
@@ -234,6 +234,15 @@ class UtilsGMCookie {
234
234
  this.windowApi = Object.assign({}, windowApiOption);
235
235
  }
236
236
  }
237
+ /**
238
+ * 获取Cookie分组
239
+ */
240
+ getCookiesList() {
241
+ if (this.windowApi.document.cookie.trim() === "") {
242
+ return [];
243
+ }
244
+ return this.windowApi.document.cookie.split(";");
245
+ }
237
246
  /**
238
247
  * 获取单个cookie
239
248
  * @param cookieName cookie名
@@ -242,7 +251,7 @@ class UtilsGMCookie {
242
251
  if (typeof cookieName !== "string") {
243
252
  throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
244
253
  }
245
- let cookies = this.windowApi.document.cookie.split(";");
254
+ let cookies = this.getCookiesList();
246
255
  let findValue = undefined;
247
256
  for (const cookieItem of cookies) {
248
257
  let item = cookieItem.trim();
@@ -288,7 +297,7 @@ class UtilsGMCookie {
288
297
  path: "/",
289
298
  };
290
299
  defaultOption = utils.assign(defaultOption, option);
291
- let cookies = this.windowApi.document.cookie.split(";");
300
+ let cookies = this.getCookiesList();
292
301
  cookies.forEach((item) => {
293
302
  item = item.trim();
294
303
  let itemSplit = item.split("=");
@@ -339,7 +348,7 @@ class UtilsGMCookie {
339
348
  path: "/",
340
349
  };
341
350
  defaultOption = utils.assign(defaultOption, option);
342
- let cookies = this.windowApi.document.cookie.split(";");
351
+ let cookies = this.getCookiesList();
343
352
  cookies.forEach((item) => {
344
353
  item = item.trim();
345
354
  let itemSplit = item.split("=");
@@ -447,6 +456,9 @@ class UtilsGMCookie {
447
456
  * @param cookieStr
448
457
  */
449
458
  parseCookie(cookieStr) {
459
+ if (cookieStr.trim() === "") {
460
+ return [];
461
+ }
450
462
  let cookies = cookieStr.split(";");
451
463
  let result = [];
452
464
  for (const cookieItem of cookies) {