@whitesev/utils 1.1.3 → 1.1.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 +84 -6
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +84 -6
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +84 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +84 -6
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +84 -6
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +84 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/src/UtilsGMCookie.d.ts +33 -2
- package/package.json +1 -1
- package/src/UtilsGMCookie.ts +93 -11
package/dist/index.iife.js
CHANGED
|
@@ -260,17 +260,51 @@ 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 findCookie = cookies.find((item) => {
|
|
272
|
+
item = item.trimStart();
|
|
273
|
+
let itemName = item.split("=")[0];
|
|
274
|
+
let itemValue = item.replace(new RegExp("^" + itemName + "="), "");
|
|
275
|
+
if (itemName === cookieName) {
|
|
276
|
+
return itemValue;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
if (findCookie) {
|
|
280
|
+
return {
|
|
281
|
+
domain: globalThis.location.hostname,
|
|
282
|
+
expirationDate: null,
|
|
283
|
+
hostOnly: true,
|
|
284
|
+
httpOnly: false,
|
|
285
|
+
name: cookieName,
|
|
286
|
+
path: "/",
|
|
287
|
+
sameSite: "unspecified",
|
|
288
|
+
secure: true,
|
|
289
|
+
session: false,
|
|
290
|
+
value: findCookie,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* 获取多组Cookie
|
|
264
296
|
* @param paramDetails
|
|
265
297
|
* @param callback
|
|
266
298
|
* + cookies object[]
|
|
267
299
|
* + error string|undefined
|
|
268
300
|
**/
|
|
269
|
-
list(paramDetails
|
|
301
|
+
list(paramDetails, callback) {
|
|
302
|
+
if (paramDetails == null) {
|
|
303
|
+
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
304
|
+
}
|
|
270
305
|
let resultData = [];
|
|
271
306
|
try {
|
|
272
307
|
let details = {
|
|
273
|
-
// @ts-ignore
|
|
274
308
|
url: globalThis.location.href,
|
|
275
309
|
domain: globalThis.location.hostname,
|
|
276
310
|
name: "",
|
|
@@ -298,15 +332,59 @@ var Utils = (function () {
|
|
|
298
332
|
session: false,
|
|
299
333
|
value: itemValue,
|
|
300
334
|
});
|
|
301
|
-
return;
|
|
302
335
|
}
|
|
303
336
|
});
|
|
304
|
-
callback
|
|
337
|
+
if (typeof callback === "function") {
|
|
338
|
+
callback(resultData);
|
|
339
|
+
}
|
|
305
340
|
}
|
|
306
341
|
catch (error) {
|
|
307
|
-
|
|
342
|
+
if (typeof callback === "function") {
|
|
343
|
+
callback(resultData, error);
|
|
344
|
+
}
|
|
308
345
|
}
|
|
309
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* 获取多组Cookie
|
|
349
|
+
* @param paramDetails
|
|
350
|
+
**/
|
|
351
|
+
getList(paramDetails) {
|
|
352
|
+
if (paramDetails == null) {
|
|
353
|
+
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
354
|
+
}
|
|
355
|
+
let resultData = [];
|
|
356
|
+
let details = {
|
|
357
|
+
url: globalThis.location.href,
|
|
358
|
+
domain: globalThis.location.hostname,
|
|
359
|
+
name: "",
|
|
360
|
+
path: "/",
|
|
361
|
+
};
|
|
362
|
+
details = utils.assign(details, paramDetails);
|
|
363
|
+
let cookies = document.cookie.split(";");
|
|
364
|
+
cookies.forEach((item) => {
|
|
365
|
+
item = item.trimStart();
|
|
366
|
+
let itemName = item.split("=")[0];
|
|
367
|
+
let itemValue = item.replace(new RegExp("^" + itemName + "="), "");
|
|
368
|
+
let nameRegexp = details.name instanceof RegExp
|
|
369
|
+
? details.name
|
|
370
|
+
: new RegExp("^" + details.name, "g");
|
|
371
|
+
if (itemName.match(nameRegexp)) {
|
|
372
|
+
resultData.push({
|
|
373
|
+
domain: globalThis.location.hostname,
|
|
374
|
+
expirationDate: null,
|
|
375
|
+
hostOnly: true,
|
|
376
|
+
httpOnly: false,
|
|
377
|
+
name: itemName,
|
|
378
|
+
path: "/",
|
|
379
|
+
sameSite: "unspecified",
|
|
380
|
+
secure: true,
|
|
381
|
+
session: false,
|
|
382
|
+
value: itemValue,
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
return resultData;
|
|
387
|
+
}
|
|
310
388
|
/**
|
|
311
389
|
* 设置Cookie
|
|
312
390
|
* @param paramDetails
|