@whitesev/utils 1.1.3 → 1.1.5
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 +93 -9
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +93 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +93 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +93 -9
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +93 -9
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +93 -9
- package/dist/index.umd.js.map +1 -1
- package/dist/src/UtilsGMCookie.d.ts +23 -3
- package/package.json +1 -1
- package/src/UtilsGMCookie.ts +104 -16
package/dist/index.iife.js
CHANGED
|
@@ -260,17 +260,53 @@ var Utils = (function () {
|
|
|
260
260
|
|
|
261
261
|
class UtilsGMCookie {
|
|
262
262
|
/**
|
|
263
|
-
*
|
|
263
|
+
* 获取单个cookie
|
|
264
|
+
* @param cookieName cookie名
|
|
265
|
+
*/
|
|
266
|
+
get(cookieName) {
|
|
267
|
+
if (typeof cookieName !== "string") {
|
|
268
|
+
throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
|
|
269
|
+
}
|
|
270
|
+
let cookies = document.cookie.split(";");
|
|
271
|
+
let findValue = void 0;
|
|
272
|
+
for (const cookieItem of cookies) {
|
|
273
|
+
let item = cookieItem.trim();
|
|
274
|
+
let itemSplit = item.split("=");
|
|
275
|
+
let itemName = itemSplit[0];
|
|
276
|
+
itemSplit.splice(0, 1);
|
|
277
|
+
let itemValue = itemSplit.join("");
|
|
278
|
+
if (itemName === cookieName) {
|
|
279
|
+
findValue = {
|
|
280
|
+
domain: globalThis.location.hostname,
|
|
281
|
+
expirationDate: null,
|
|
282
|
+
hostOnly: true,
|
|
283
|
+
httpOnly: false,
|
|
284
|
+
name: cookieName,
|
|
285
|
+
path: "/",
|
|
286
|
+
sameSite: "unspecified",
|
|
287
|
+
secure: true,
|
|
288
|
+
session: false,
|
|
289
|
+
value: itemValue,
|
|
290
|
+
};
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return findValue;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* 获取多组Cookie
|
|
264
298
|
* @param paramDetails
|
|
265
299
|
* @param callback
|
|
266
300
|
* + cookies object[]
|
|
267
301
|
* + error string|undefined
|
|
268
302
|
**/
|
|
269
|
-
list(paramDetails
|
|
303
|
+
list(paramDetails, callback) {
|
|
304
|
+
if (paramDetails == null) {
|
|
305
|
+
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
306
|
+
}
|
|
270
307
|
let resultData = [];
|
|
271
308
|
try {
|
|
272
309
|
let details = {
|
|
273
|
-
// @ts-ignore
|
|
274
310
|
url: globalThis.location.href,
|
|
275
311
|
domain: globalThis.location.hostname,
|
|
276
312
|
name: "",
|
|
@@ -279,9 +315,11 @@ var Utils = (function () {
|
|
|
279
315
|
details = utils.assign(details, paramDetails);
|
|
280
316
|
let cookies = document.cookie.split(";");
|
|
281
317
|
cookies.forEach((item) => {
|
|
282
|
-
item = item.
|
|
283
|
-
let
|
|
284
|
-
let
|
|
318
|
+
item = item.trim();
|
|
319
|
+
let itemSplit = item.split("=");
|
|
320
|
+
let itemName = itemSplit[0];
|
|
321
|
+
itemSplit.splice(0, 1);
|
|
322
|
+
let itemValue = itemSplit.join("");
|
|
285
323
|
let nameRegexp = details.name instanceof RegExp
|
|
286
324
|
? details.name
|
|
287
325
|
: new RegExp("^" + details.name, "g");
|
|
@@ -298,14 +336,60 @@ var Utils = (function () {
|
|
|
298
336
|
session: false,
|
|
299
337
|
value: itemValue,
|
|
300
338
|
});
|
|
301
|
-
return;
|
|
302
339
|
}
|
|
303
340
|
});
|
|
304
|
-
callback
|
|
341
|
+
if (typeof callback === "function") {
|
|
342
|
+
callback(resultData);
|
|
343
|
+
}
|
|
305
344
|
}
|
|
306
345
|
catch (error) {
|
|
307
|
-
|
|
346
|
+
if (typeof callback === "function") {
|
|
347
|
+
callback(resultData, error);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* 获取多组Cookie
|
|
353
|
+
* @param paramDetails
|
|
354
|
+
**/
|
|
355
|
+
getList(paramDetails) {
|
|
356
|
+
if (paramDetails == null) {
|
|
357
|
+
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
308
358
|
}
|
|
359
|
+
let resultData = [];
|
|
360
|
+
let details = {
|
|
361
|
+
url: globalThis.location.href,
|
|
362
|
+
domain: globalThis.location.hostname,
|
|
363
|
+
name: "",
|
|
364
|
+
path: "/",
|
|
365
|
+
};
|
|
366
|
+
details = utils.assign(details, paramDetails);
|
|
367
|
+
let cookies = document.cookie.split(";");
|
|
368
|
+
cookies.forEach((item) => {
|
|
369
|
+
item = item.trim();
|
|
370
|
+
let itemSplit = item.split("=");
|
|
371
|
+
let itemName = itemSplit[0];
|
|
372
|
+
itemSplit.splice(0, 1);
|
|
373
|
+
let itemValue = itemSplit.join("");
|
|
374
|
+
let nameRegexp = details.name instanceof RegExp
|
|
375
|
+
? details.name
|
|
376
|
+
: new RegExp("^" + details.name, "g");
|
|
377
|
+
if (itemName.match(nameRegexp)) {
|
|
378
|
+
resultData.push({
|
|
379
|
+
domain: globalThis.location.hostname,
|
|
380
|
+
expirationDate: null,
|
|
381
|
+
hostOnly: true,
|
|
382
|
+
httpOnly: false,
|
|
383
|
+
name: itemName,
|
|
384
|
+
path: "/",
|
|
385
|
+
sameSite: "unspecified",
|
|
386
|
+
secure: true,
|
|
387
|
+
session: false,
|
|
388
|
+
value: itemValue,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
return resultData;
|
|
309
393
|
}
|
|
310
394
|
/**
|
|
311
395
|
* 设置Cookie
|