@whitesev/utils 1.1.4 → 1.1.6
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 +31 -25
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +31 -25
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +31 -25
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +31 -25
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +31 -25
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +31 -25
- package/dist/index.umd.js.map +1 -1
- package/dist/src/UtilsGMCookie.d.ts +4 -15
- package/package.json +1 -1
- package/src/UtilsGMCookie.ts +36 -30
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare interface
|
|
1
|
+
declare interface UtilsGMCookieResult {
|
|
2
2
|
/** 为 window.location.hostname */
|
|
3
3
|
domain: string;
|
|
4
4
|
expirationDate: null;
|
|
@@ -26,18 +26,7 @@ declare class UtilsGMCookie {
|
|
|
26
26
|
* 获取单个cookie
|
|
27
27
|
* @param cookieName cookie名
|
|
28
28
|
*/
|
|
29
|
-
get(cookieName: string):
|
|
30
|
-
domain: string;
|
|
31
|
-
expirationDate: null;
|
|
32
|
-
hostOnly: boolean;
|
|
33
|
-
httpOnly: boolean;
|
|
34
|
-
name: string;
|
|
35
|
-
path: string;
|
|
36
|
-
sameSite: string;
|
|
37
|
-
secure: boolean;
|
|
38
|
-
session: boolean;
|
|
39
|
-
value: string;
|
|
40
|
-
} | undefined;
|
|
29
|
+
get(cookieName: string): UtilsGMCookieResult | undefined;
|
|
41
30
|
/**
|
|
42
31
|
* 获取多组Cookie
|
|
43
32
|
* @param paramDetails
|
|
@@ -45,12 +34,12 @@ declare class UtilsGMCookie {
|
|
|
45
34
|
* + cookies object[]
|
|
46
35
|
* + error string|undefined
|
|
47
36
|
**/
|
|
48
|
-
list(paramDetails: Partial<UtilsGMCookieListOptions>, callback?: (data:
|
|
37
|
+
list(paramDetails: Partial<UtilsGMCookieListOptions>, callback?: (data: UtilsGMCookieResult[], error?: Error) => void): void;
|
|
49
38
|
/**
|
|
50
39
|
* 获取多组Cookie
|
|
51
40
|
* @param paramDetails
|
|
52
41
|
**/
|
|
53
|
-
getList(paramDetails: Partial<UtilsGMCookieListOptions>):
|
|
42
|
+
getList(paramDetails: Partial<UtilsGMCookieListOptions>): UtilsGMCookieResult[];
|
|
54
43
|
/**
|
|
55
44
|
* 设置Cookie
|
|
56
45
|
* @param paramDetails
|
package/package.json
CHANGED
package/src/UtilsGMCookie.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Utils } from "./Utils";
|
|
2
2
|
|
|
3
|
-
declare interface
|
|
3
|
+
declare interface UtilsGMCookieResult {
|
|
4
4
|
/** 为 window.location.hostname */
|
|
5
5
|
domain: string;
|
|
6
6
|
expirationDate: null;
|
|
@@ -62,28 +62,30 @@ class UtilsGMCookie {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
let cookies = document.cookie.split(";");
|
|
65
|
-
let
|
|
66
|
-
|
|
67
|
-
let
|
|
68
|
-
let
|
|
65
|
+
let findValue: UtilsGMCookieResult | undefined = void 0;
|
|
66
|
+
for (const cookieItem of cookies) {
|
|
67
|
+
let item = cookieItem.trim();
|
|
68
|
+
let itemSplit = item.split("=");
|
|
69
|
+
let itemName = itemSplit[0];
|
|
70
|
+
itemSplit.splice(0, 1);
|
|
71
|
+
let itemValue = decodeURIComponent(itemSplit.join(""));
|
|
69
72
|
if (itemName === cookieName) {
|
|
70
|
-
|
|
73
|
+
findValue = {
|
|
74
|
+
domain: globalThis.location.hostname,
|
|
75
|
+
expirationDate: null,
|
|
76
|
+
hostOnly: true,
|
|
77
|
+
httpOnly: false,
|
|
78
|
+
name: cookieName,
|
|
79
|
+
path: "/",
|
|
80
|
+
sameSite: "unspecified",
|
|
81
|
+
secure: true,
|
|
82
|
+
session: false,
|
|
83
|
+
value: itemValue,
|
|
84
|
+
};
|
|
85
|
+
break;
|
|
71
86
|
}
|
|
72
|
-
});
|
|
73
|
-
if (findCookie) {
|
|
74
|
-
return {
|
|
75
|
-
domain: globalThis.location.hostname,
|
|
76
|
-
expirationDate: null,
|
|
77
|
-
hostOnly: true,
|
|
78
|
-
httpOnly: false,
|
|
79
|
-
name: cookieName,
|
|
80
|
-
path: "/",
|
|
81
|
-
sameSite: "unspecified",
|
|
82
|
-
secure: true,
|
|
83
|
-
session: false,
|
|
84
|
-
value: findCookie,
|
|
85
|
-
};
|
|
86
87
|
}
|
|
88
|
+
return findValue;
|
|
87
89
|
}
|
|
88
90
|
/**
|
|
89
91
|
* 获取多组Cookie
|
|
@@ -94,12 +96,12 @@ class UtilsGMCookie {
|
|
|
94
96
|
**/
|
|
95
97
|
list(
|
|
96
98
|
paramDetails: Partial<UtilsGMCookieListOptions>,
|
|
97
|
-
callback?: (data:
|
|
99
|
+
callback?: (data: UtilsGMCookieResult[], error?: Error) => void
|
|
98
100
|
) {
|
|
99
101
|
if (paramDetails == null) {
|
|
100
102
|
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
101
103
|
}
|
|
102
|
-
let resultData:
|
|
104
|
+
let resultData: UtilsGMCookieResult[] = [];
|
|
103
105
|
try {
|
|
104
106
|
let details: Partial<UtilsGMCookieListOptions> = {
|
|
105
107
|
url: globalThis.location.href,
|
|
@@ -110,9 +112,11 @@ class UtilsGMCookie {
|
|
|
110
112
|
details = Utils.assign(details, paramDetails);
|
|
111
113
|
let cookies = document.cookie.split(";");
|
|
112
114
|
cookies.forEach((item) => {
|
|
113
|
-
item = item.
|
|
114
|
-
let
|
|
115
|
-
let
|
|
115
|
+
item = item.trim();
|
|
116
|
+
let itemSplit = item.split("=");
|
|
117
|
+
let itemName = itemSplit[0];
|
|
118
|
+
itemSplit.splice(0, 1);
|
|
119
|
+
let itemValue = decodeURIComponent(itemSplit.join(""));
|
|
116
120
|
let nameRegexp =
|
|
117
121
|
(details.name as RegExp) instanceof RegExp
|
|
118
122
|
? details.name
|
|
@@ -147,11 +151,11 @@ class UtilsGMCookie {
|
|
|
147
151
|
**/
|
|
148
152
|
getList(
|
|
149
153
|
paramDetails: Partial<UtilsGMCookieListOptions>
|
|
150
|
-
):
|
|
154
|
+
): UtilsGMCookieResult[] {
|
|
151
155
|
if (paramDetails == null) {
|
|
152
156
|
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
153
157
|
}
|
|
154
|
-
let resultData:
|
|
158
|
+
let resultData: UtilsGMCookieResult[] = [];
|
|
155
159
|
let details: Partial<UtilsGMCookieListOptions> = {
|
|
156
160
|
url: globalThis.location.href,
|
|
157
161
|
domain: globalThis.location.hostname,
|
|
@@ -161,9 +165,11 @@ class UtilsGMCookie {
|
|
|
161
165
|
details = Utils.assign(details, paramDetails);
|
|
162
166
|
let cookies = document.cookie.split(";");
|
|
163
167
|
cookies.forEach((item) => {
|
|
164
|
-
item = item.
|
|
165
|
-
let
|
|
166
|
-
let
|
|
168
|
+
item = item.trim();
|
|
169
|
+
let itemSplit = item.split("=");
|
|
170
|
+
let itemName = itemSplit[0];
|
|
171
|
+
itemSplit.splice(0, 1);
|
|
172
|
+
let itemValue = decodeURIComponent(itemSplit.join(""));
|
|
167
173
|
let nameRegexp =
|
|
168
174
|
(details.name as RegExp) instanceof RegExp
|
|
169
175
|
? details.name
|