@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.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.
|
|
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.
|
|
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.
|
|
357
|
+
let cookies = this.getCookiesList();
|
|
349
358
|
cookies.forEach((item) => {
|
|
350
359
|
item = item.trim();
|
|
351
360
|
let itemSplit = item.split("=");
|
|
@@ -384,7 +393,7 @@
|
|
|
384
393
|
url: this.windowApi.window.location.href,
|
|
385
394
|
name: "",
|
|
386
395
|
value: "",
|
|
387
|
-
domain:
|
|
396
|
+
domain: "",
|
|
388
397
|
path: "/",
|
|
389
398
|
secure: true,
|
|
390
399
|
httpOnly: false,
|
|
@@ -403,6 +412,9 @@
|
|
|
403
412
|
";expires=" +
|
|
404
413
|
new Date(life).toGMTString() +
|
|
405
414
|
"; path=/";
|
|
415
|
+
if (utils.isNotNull(defaultOption.domain)) {
|
|
416
|
+
cookieStr += "; domain=" + defaultOption.domain;
|
|
417
|
+
}
|
|
406
418
|
this.windowApi.document.cookie = cookieStr;
|
|
407
419
|
}
|
|
408
420
|
catch (error) {
|
|
@@ -426,10 +438,13 @@
|
|
|
426
438
|
url: this.windowApi.window.location.href,
|
|
427
439
|
name: "",
|
|
428
440
|
path: "/",
|
|
429
|
-
firstPartyDomain:
|
|
441
|
+
firstPartyDomain: "",
|
|
430
442
|
};
|
|
431
443
|
defaultOption = utils.assign(defaultOption, option);
|
|
432
|
-
let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}
|
|
444
|
+
let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}`;
|
|
445
|
+
if (utils.isNotNull(defaultOption.firstPartyDomain)) {
|
|
446
|
+
cookieStr += `; domain=${defaultOption.firstPartyDomain};`;
|
|
447
|
+
}
|
|
433
448
|
this.windowApi.document.cookie = cookieStr;
|
|
434
449
|
}
|
|
435
450
|
catch (error) {
|
|
@@ -447,6 +462,9 @@
|
|
|
447
462
|
* @param cookieStr
|
|
448
463
|
*/
|
|
449
464
|
parseCookie(cookieStr) {
|
|
465
|
+
if (cookieStr.trim() === "") {
|
|
466
|
+
return [];
|
|
467
|
+
}
|
|
450
468
|
let cookies = cookieStr.split(";");
|
|
451
469
|
let result = [];
|
|
452
470
|
for (const cookieItem of cookies) {
|
|
@@ -5041,7 +5059,7 @@
|
|
|
5041
5059
|
this.windowApi = new WindowApi(option);
|
|
5042
5060
|
}
|
|
5043
5061
|
/** 版本号 */
|
|
5044
|
-
version = "2025.3.
|
|
5062
|
+
version = "2025.3.25";
|
|
5045
5063
|
addStyle(cssText) {
|
|
5046
5064
|
if (typeof cssText !== "string") {
|
|
5047
5065
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|