@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.amd.js CHANGED
@@ -236,6 +236,15 @@ define((function () { 'use strict';
236
236
  this.windowApi = Object.assign({}, windowApiOption);
237
237
  }
238
238
  }
239
+ /**
240
+ * 获取Cookie分组
241
+ */
242
+ getCookiesList() {
243
+ if (this.windowApi.document.cookie.trim() === "") {
244
+ return [];
245
+ }
246
+ return this.windowApi.document.cookie.split(";");
247
+ }
239
248
  /**
240
249
  * 获取单个cookie
241
250
  * @param cookieName cookie名
@@ -244,7 +253,7 @@ define((function () { 'use strict';
244
253
  if (typeof cookieName !== "string") {
245
254
  throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
246
255
  }
247
- let cookies = this.windowApi.document.cookie.split(";");
256
+ let cookies = this.getCookiesList();
248
257
  let findValue = undefined;
249
258
  for (const cookieItem of cookies) {
250
259
  let item = cookieItem.trim();
@@ -290,7 +299,7 @@ define((function () { 'use strict';
290
299
  path: "/",
291
300
  };
292
301
  defaultOption = utils.assign(defaultOption, option);
293
- let cookies = this.windowApi.document.cookie.split(";");
302
+ let cookies = this.getCookiesList();
294
303
  cookies.forEach((item) => {
295
304
  item = item.trim();
296
305
  let itemSplit = item.split("=");
@@ -341,7 +350,7 @@ define((function () { 'use strict';
341
350
  path: "/",
342
351
  };
343
352
  defaultOption = utils.assign(defaultOption, option);
344
- let cookies = this.windowApi.document.cookie.split(";");
353
+ let cookies = this.getCookiesList();
345
354
  cookies.forEach((item) => {
346
355
  item = item.trim();
347
356
  let itemSplit = item.split("=");
@@ -449,6 +458,9 @@ define((function () { 'use strict';
449
458
  * @param cookieStr
450
459
  */
451
460
  parseCookie(cookieStr) {
461
+ if (cookieStr.trim() === "") {
462
+ return [];
463
+ }
452
464
  let cookies = cookieStr.split(";");
453
465
  let result = [];
454
466
  for (const cookieItem of cookies) {