@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.
@@ -2,6 +2,10 @@ import type { UtilsGMCookieDeleteOptions, UtilsGMCookieListOptions, UtilsGMCooki
2
2
  export declare class UtilsGMCookie {
3
3
  private windowApi;
4
4
  constructor(windowApiOption?: WindowApiOption);
5
+ /**
6
+ * 获取Cookie分组
7
+ */
8
+ private getCookiesList;
5
9
  /**
6
10
  * 获取单个cookie
7
11
  * @param cookieName cookie名
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.6.3",
3
+ "version": "2.6.4",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -17,6 +17,15 @@ export class UtilsGMCookie {
17
17
  this.windowApi = Object.assign({}, windowApiOption);
18
18
  }
19
19
  }
20
+ /**
21
+ * 获取Cookie分组
22
+ */
23
+ private getCookiesList() {
24
+ if (this.windowApi.document.cookie.trim() === "") {
25
+ return [];
26
+ }
27
+ return this.windowApi.document.cookie.split(";");
28
+ }
20
29
  /**
21
30
  * 获取单个cookie
22
31
  * @param cookieName cookie名
@@ -25,8 +34,7 @@ export class UtilsGMCookie {
25
34
  if (typeof cookieName !== "string") {
26
35
  throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
27
36
  }
28
-
29
- let cookies = this.windowApi.document.cookie.split(";");
37
+ let cookies = this.getCookiesList();
30
38
  let findValue: UtilsGMCookieResult | undefined = void 0;
31
39
  for (const cookieItem of cookies) {
32
40
  let item = cookieItem.trim();
@@ -75,7 +83,7 @@ export class UtilsGMCookie {
75
83
  path: "/",
76
84
  };
77
85
  defaultOption = Utils.assign(defaultOption, option);
78
- let cookies = this.windowApi.document.cookie.split(";");
86
+ let cookies = this.getCookiesList();
79
87
  cookies.forEach((item) => {
80
88
  item = item.trim();
81
89
  let itemSplit = item.split("=");
@@ -126,7 +134,7 @@ export class UtilsGMCookie {
126
134
  path: "/",
127
135
  };
128
136
  defaultOption = Utils.assign(defaultOption, option);
129
- let cookies = this.windowApi.document.cookie.split(";");
137
+ let cookies = this.getCookiesList();
130
138
  cookies.forEach((item) => {
131
139
  item = item.trim();
132
140
  let itemSplit = item.split("=");
@@ -235,6 +243,9 @@ export class UtilsGMCookie {
235
243
  * @param cookieStr
236
244
  */
237
245
  parseCookie(cookieStr: string) {
246
+ if (cookieStr.trim() === "") {
247
+ return [];
248
+ }
238
249
  let cookies = cookieStr.split(";");
239
250
  let result: { key: string; value: string }[] = [];
240
251
  for (const cookieItem of cookies) {