@whitesev/utils 2.6.2 → 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.
@@ -237,6 +237,15 @@ var Utils = (function () {
237
237
  this.windowApi = Object.assign({}, windowApiOption);
238
238
  }
239
239
  }
240
+ /**
241
+ * 获取Cookie分组
242
+ */
243
+ getCookiesList() {
244
+ if (this.windowApi.document.cookie.trim() === "") {
245
+ return [];
246
+ }
247
+ return this.windowApi.document.cookie.split(";");
248
+ }
240
249
  /**
241
250
  * 获取单个cookie
242
251
  * @param cookieName cookie名
@@ -245,7 +254,7 @@ var Utils = (function () {
245
254
  if (typeof cookieName !== "string") {
246
255
  throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
247
256
  }
248
- let cookies = this.windowApi.document.cookie.split(";");
257
+ let cookies = this.getCookiesList();
249
258
  let findValue = undefined;
250
259
  for (const cookieItem of cookies) {
251
260
  let item = cookieItem.trim();
@@ -291,7 +300,7 @@ var Utils = (function () {
291
300
  path: "/",
292
301
  };
293
302
  defaultOption = utils.assign(defaultOption, option);
294
- let cookies = this.windowApi.document.cookie.split(";");
303
+ let cookies = this.getCookiesList();
295
304
  cookies.forEach((item) => {
296
305
  item = item.trim();
297
306
  let itemSplit = item.split("=");
@@ -342,7 +351,7 @@ var Utils = (function () {
342
351
  path: "/",
343
352
  };
344
353
  defaultOption = utils.assign(defaultOption, option);
345
- let cookies = this.windowApi.document.cookie.split(";");
354
+ let cookies = this.getCookiesList();
346
355
  cookies.forEach((item) => {
347
356
  item = item.trim();
348
357
  let itemSplit = item.split("=");
@@ -381,7 +390,7 @@ var Utils = (function () {
381
390
  url: this.windowApi.window.location.href,
382
391
  name: "",
383
392
  value: "",
384
- domain: this.windowApi.window.location.hostname,
393
+ domain: "",
385
394
  path: "/",
386
395
  secure: true,
387
396
  httpOnly: false,
@@ -400,6 +409,9 @@ var Utils = (function () {
400
409
  ";expires=" +
401
410
  new Date(life).toGMTString() +
402
411
  "; path=/";
412
+ if (utils.isNotNull(defaultOption.domain)) {
413
+ cookieStr += "; domain=" + defaultOption.domain;
414
+ }
403
415
  this.windowApi.document.cookie = cookieStr;
404
416
  }
405
417
  catch (error) {
@@ -423,10 +435,13 @@ var Utils = (function () {
423
435
  url: this.windowApi.window.location.href,
424
436
  name: "",
425
437
  path: "/",
426
- firstPartyDomain: this.windowApi.window.location.hostname,
438
+ firstPartyDomain: "",
427
439
  };
428
440
  defaultOption = utils.assign(defaultOption, option);
429
- let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}; domain=${defaultOption.firstPartyDomain};`;
441
+ let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}`;
442
+ if (utils.isNotNull(defaultOption.firstPartyDomain)) {
443
+ cookieStr += `; domain=${defaultOption.firstPartyDomain};`;
444
+ }
430
445
  this.windowApi.document.cookie = cookieStr;
431
446
  }
432
447
  catch (error) {
@@ -444,6 +459,9 @@ var Utils = (function () {
444
459
  * @param cookieStr
445
460
  */
446
461
  parseCookie(cookieStr) {
462
+ if (cookieStr.trim() === "") {
463
+ return [];
464
+ }
447
465
  let cookies = cookieStr.split(";");
448
466
  let result = [];
449
467
  for (const cookieItem of cookies) {
@@ -5038,7 +5056,7 @@ var Utils = (function () {
5038
5056
  this.windowApi = new WindowApi(option);
5039
5057
  }
5040
5058
  /** 版本号 */
5041
- version = "2025.3.24";
5059
+ version = "2025.3.25";
5042
5060
  addStyle(cssText) {
5043
5061
  if (typeof cssText !== "string") {
5044
5062
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");