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