@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.
- package/dist/index.amd.js +25 -7
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +25 -7
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +25 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +25 -7
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +25 -7
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +25 -7
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/UtilsGMCookie.d.ts +4 -0
- package/dist/types/src/types/UtilsGMCookie.d.ts +2 -2
- package/package.json +1 -1
- package/src/Utils.ts +1 -1
- package/src/UtilsGMCookie.ts +24 -7
- package/src/types/UtilsGMCookie.d.ts +2 -2
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.
|
|
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.
|
|
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.
|
|
351
|
+
let cookies = this.getCookiesList();
|
|
343
352
|
cookies.forEach((item) => {
|
|
344
353
|
item = item.trim();
|
|
345
354
|
let itemSplit = item.split("=");
|
|
@@ -378,7 +387,7 @@ class UtilsGMCookie {
|
|
|
378
387
|
url: this.windowApi.window.location.href,
|
|
379
388
|
name: "",
|
|
380
389
|
value: "",
|
|
381
|
-
domain:
|
|
390
|
+
domain: "",
|
|
382
391
|
path: "/",
|
|
383
392
|
secure: true,
|
|
384
393
|
httpOnly: false,
|
|
@@ -397,6 +406,9 @@ class UtilsGMCookie {
|
|
|
397
406
|
";expires=" +
|
|
398
407
|
new Date(life).toGMTString() +
|
|
399
408
|
"; path=/";
|
|
409
|
+
if (utils.isNotNull(defaultOption.domain)) {
|
|
410
|
+
cookieStr += "; domain=" + defaultOption.domain;
|
|
411
|
+
}
|
|
400
412
|
this.windowApi.document.cookie = cookieStr;
|
|
401
413
|
}
|
|
402
414
|
catch (error) {
|
|
@@ -420,10 +432,13 @@ class UtilsGMCookie {
|
|
|
420
432
|
url: this.windowApi.window.location.href,
|
|
421
433
|
name: "",
|
|
422
434
|
path: "/",
|
|
423
|
-
firstPartyDomain:
|
|
435
|
+
firstPartyDomain: "",
|
|
424
436
|
};
|
|
425
437
|
defaultOption = utils.assign(defaultOption, option);
|
|
426
|
-
let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}
|
|
438
|
+
let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}`;
|
|
439
|
+
if (utils.isNotNull(defaultOption.firstPartyDomain)) {
|
|
440
|
+
cookieStr += `; domain=${defaultOption.firstPartyDomain};`;
|
|
441
|
+
}
|
|
427
442
|
this.windowApi.document.cookie = cookieStr;
|
|
428
443
|
}
|
|
429
444
|
catch (error) {
|
|
@@ -441,6 +456,9 @@ class UtilsGMCookie {
|
|
|
441
456
|
* @param cookieStr
|
|
442
457
|
*/
|
|
443
458
|
parseCookie(cookieStr) {
|
|
459
|
+
if (cookieStr.trim() === "") {
|
|
460
|
+
return [];
|
|
461
|
+
}
|
|
444
462
|
let cookies = cookieStr.split(";");
|
|
445
463
|
let result = [];
|
|
446
464
|
for (const cookieItem of cookies) {
|
|
@@ -5035,7 +5053,7 @@ class Utils {
|
|
|
5035
5053
|
this.windowApi = new WindowApi(option);
|
|
5036
5054
|
}
|
|
5037
5055
|
/** 版本号 */
|
|
5038
|
-
version = "2025.3.
|
|
5056
|
+
version = "2025.3.25";
|
|
5039
5057
|
addStyle(cssText) {
|
|
5040
5058
|
if (typeof cssText !== "string") {
|
|
5041
5059
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|