@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.umd.js CHANGED
@@ -240,6 +240,15 @@
240
240
  this.windowApi = Object.assign({}, windowApiOption);
241
241
  }
242
242
  }
243
+ /**
244
+ * 获取Cookie分组
245
+ */
246
+ getCookiesList() {
247
+ if (this.windowApi.document.cookie.trim() === "") {
248
+ return [];
249
+ }
250
+ return this.windowApi.document.cookie.split(";");
251
+ }
243
252
  /**
244
253
  * 获取单个cookie
245
254
  * @param cookieName cookie名
@@ -248,7 +257,7 @@
248
257
  if (typeof cookieName !== "string") {
249
258
  throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
250
259
  }
251
- let cookies = this.windowApi.document.cookie.split(";");
260
+ let cookies = this.getCookiesList();
252
261
  let findValue = undefined;
253
262
  for (const cookieItem of cookies) {
254
263
  let item = cookieItem.trim();
@@ -294,7 +303,7 @@
294
303
  path: "/",
295
304
  };
296
305
  defaultOption = utils.assign(defaultOption, option);
297
- let cookies = this.windowApi.document.cookie.split(";");
306
+ let cookies = this.getCookiesList();
298
307
  cookies.forEach((item) => {
299
308
  item = item.trim();
300
309
  let itemSplit = item.split("=");
@@ -345,7 +354,7 @@
345
354
  path: "/",
346
355
  };
347
356
  defaultOption = utils.assign(defaultOption, option);
348
- let cookies = this.windowApi.document.cookie.split(";");
357
+ let cookies = this.getCookiesList();
349
358
  cookies.forEach((item) => {
350
359
  item = item.trim();
351
360
  let itemSplit = item.split("=");
@@ -453,6 +462,9 @@
453
462
  * @param cookieStr
454
463
  */
455
464
  parseCookie(cookieStr) {
465
+ if (cookieStr.trim() === "") {
466
+ return [];
467
+ }
456
468
  let cookies = cookieStr.split(";");
457
469
  let result = [];
458
470
  for (const cookieItem of cookies) {