@whitesev/utils 2.5.3 → 2.5.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 +46 -36
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +46 -36
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +46 -36
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +46 -36
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +46 -36
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +46 -36
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/UtilsGMCookie.d.ts +8 -8
- package/dist/types/src/types/UtilsGMCookie.d.ts +54 -16
- package/dist/types/src/types/global.d.ts +3 -0
- package/package.json +3 -2
- package/src/Utils.ts +1 -1
- package/src/UtilsGMCookie.ts +44 -42
- package/src/types/UtilsGMCookie.d.ts +54 -16
- package/src/types/global.d.ts +3 -0
package/dist/index.iife.js
CHANGED
|
@@ -273,24 +273,24 @@ var Utils = (function () {
|
|
|
273
273
|
}
|
|
274
274
|
/**
|
|
275
275
|
* 获取多组Cookie
|
|
276
|
-
* @param
|
|
276
|
+
* @param option 配置
|
|
277
277
|
* @param callback 获取操作后的回调
|
|
278
278
|
* + cookies object[]
|
|
279
279
|
* + error string|undefined
|
|
280
280
|
**/
|
|
281
|
-
list(
|
|
282
|
-
if (
|
|
281
|
+
list(option, callback) {
|
|
282
|
+
if (option == null) {
|
|
283
283
|
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
284
284
|
}
|
|
285
285
|
let resultData = [];
|
|
286
286
|
try {
|
|
287
|
-
let
|
|
287
|
+
let defaultOption = {
|
|
288
288
|
url: this.windowApi.window.location.href,
|
|
289
289
|
domain: this.windowApi.window.location.hostname,
|
|
290
290
|
name: "",
|
|
291
291
|
path: "/",
|
|
292
292
|
};
|
|
293
|
-
|
|
293
|
+
defaultOption = utils.assign(defaultOption, option);
|
|
294
294
|
let cookies = this.windowApi.document.cookie.split(";");
|
|
295
295
|
cookies.forEach((item) => {
|
|
296
296
|
item = item.trim();
|
|
@@ -298,9 +298,9 @@ var Utils = (function () {
|
|
|
298
298
|
let itemName = itemSplit[0];
|
|
299
299
|
itemSplit.splice(0, 1);
|
|
300
300
|
let itemValue = decodeURIComponent(itemSplit.join(""));
|
|
301
|
-
let nameRegexp =
|
|
302
|
-
?
|
|
303
|
-
: new RegExp("^" +
|
|
301
|
+
let nameRegexp = defaultOption.name instanceof RegExp
|
|
302
|
+
? defaultOption.name
|
|
303
|
+
: new RegExp("^" + defaultOption.name, "g");
|
|
304
304
|
if (itemName.match(nameRegexp)) {
|
|
305
305
|
resultData.push({
|
|
306
306
|
domain: this.windowApi.window.location.hostname,
|
|
@@ -328,20 +328,20 @@ var Utils = (function () {
|
|
|
328
328
|
}
|
|
329
329
|
/**
|
|
330
330
|
* 获取多组Cookie
|
|
331
|
-
* @param
|
|
331
|
+
* @param option 配置
|
|
332
332
|
**/
|
|
333
|
-
getList(
|
|
334
|
-
if (
|
|
333
|
+
getList(option) {
|
|
334
|
+
if (option == null) {
|
|
335
335
|
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
336
336
|
}
|
|
337
337
|
let resultData = [];
|
|
338
|
-
let
|
|
338
|
+
let defaultOption = {
|
|
339
339
|
url: this.windowApi.window.location.href,
|
|
340
340
|
domain: this.windowApi.window.location.hostname,
|
|
341
341
|
name: "",
|
|
342
342
|
path: "/",
|
|
343
343
|
};
|
|
344
|
-
|
|
344
|
+
defaultOption = utils.assign(defaultOption, option);
|
|
345
345
|
let cookies = this.windowApi.document.cookie.split(";");
|
|
346
346
|
cookies.forEach((item) => {
|
|
347
347
|
item = item.trim();
|
|
@@ -349,9 +349,9 @@ var Utils = (function () {
|
|
|
349
349
|
let itemName = itemSplit[0];
|
|
350
350
|
itemSplit.splice(0, 1);
|
|
351
351
|
let itemValue = decodeURIComponent(itemSplit.join(""));
|
|
352
|
-
let nameRegexp =
|
|
353
|
-
?
|
|
354
|
-
: new RegExp("^" +
|
|
352
|
+
let nameRegexp = defaultOption.name instanceof RegExp
|
|
353
|
+
? defaultOption.name
|
|
354
|
+
: new RegExp("^" + defaultOption.name, "g");
|
|
355
355
|
if (itemName.match(nameRegexp)) {
|
|
356
356
|
resultData.push({
|
|
357
357
|
domain: this.windowApi.window.location.hostname,
|
|
@@ -371,12 +371,13 @@ var Utils = (function () {
|
|
|
371
371
|
}
|
|
372
372
|
/**
|
|
373
373
|
* 设置Cookie
|
|
374
|
-
* @param
|
|
374
|
+
* @param option 配置
|
|
375
375
|
* @param callback 设置操作后的回调(成功/失败)
|
|
376
376
|
*/
|
|
377
|
-
set(
|
|
377
|
+
set(option, callback) {
|
|
378
|
+
let errorInfo;
|
|
378
379
|
try {
|
|
379
|
-
let
|
|
380
|
+
let defaultOption = {
|
|
380
381
|
url: this.windowApi.window.location.href,
|
|
381
382
|
name: "",
|
|
382
383
|
value: "",
|
|
@@ -389,43 +390,52 @@ var Utils = (function () {
|
|
|
389
390
|
*/
|
|
390
391
|
expirationDate: Math.floor(Date.now()) + 60 * 60 * 24 * 30,
|
|
391
392
|
};
|
|
392
|
-
|
|
393
|
-
let life =
|
|
394
|
-
?
|
|
393
|
+
defaultOption = utils.assign(defaultOption, option);
|
|
394
|
+
let life = defaultOption.expirationDate
|
|
395
|
+
? defaultOption.expirationDate
|
|
395
396
|
: Math.floor(Date.now()) + 60 * 60 * 24 * 30;
|
|
396
|
-
let cookieStr =
|
|
397
|
+
let cookieStr = defaultOption.name +
|
|
397
398
|
"=" +
|
|
398
|
-
decodeURIComponent(
|
|
399
|
+
decodeURIComponent(defaultOption.value) +
|
|
399
400
|
";expires=" +
|
|
400
401
|
new Date(life).toGMTString() +
|
|
401
402
|
"; path=/";
|
|
402
403
|
this.windowApi.document.cookie = cookieStr;
|
|
403
|
-
callback();
|
|
404
404
|
}
|
|
405
405
|
catch (error) {
|
|
406
|
-
|
|
406
|
+
errorInfo = error;
|
|
407
|
+
}
|
|
408
|
+
finally {
|
|
409
|
+
if (typeof callback === "function") {
|
|
410
|
+
callback(errorInfo);
|
|
411
|
+
}
|
|
407
412
|
}
|
|
408
413
|
}
|
|
409
414
|
/**
|
|
410
415
|
* 删除Cookie
|
|
411
|
-
* @param
|
|
416
|
+
* @param option 配置
|
|
412
417
|
* @param callback 删除操作后的回调(成功/失败)
|
|
413
418
|
*/
|
|
414
|
-
delete(
|
|
419
|
+
delete(option, callback) {
|
|
420
|
+
let errorInfo;
|
|
415
421
|
try {
|
|
416
|
-
let
|
|
422
|
+
let defaultOption = {
|
|
417
423
|
url: this.windowApi.window.location.href,
|
|
418
424
|
name: "",
|
|
419
|
-
|
|
420
|
-
firstPartyDomain:
|
|
425
|
+
path: "/",
|
|
426
|
+
firstPartyDomain: this.windowApi.window.location.hostname,
|
|
421
427
|
};
|
|
422
|
-
|
|
423
|
-
let cookieStr =
|
|
428
|
+
defaultOption = utils.assign(defaultOption, option);
|
|
429
|
+
let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}; domain=${defaultOption.firstPartyDomain};`;
|
|
424
430
|
this.windowApi.document.cookie = cookieStr;
|
|
425
|
-
callback();
|
|
426
431
|
}
|
|
427
432
|
catch (error) {
|
|
428
|
-
|
|
433
|
+
errorInfo = error;
|
|
434
|
+
}
|
|
435
|
+
finally {
|
|
436
|
+
if (typeof callback === "function") {
|
|
437
|
+
callback(errorInfo);
|
|
438
|
+
}
|
|
429
439
|
}
|
|
430
440
|
}
|
|
431
441
|
}
|
|
@@ -4111,7 +4121,7 @@ var Utils = (function () {
|
|
|
4111
4121
|
this.windowApi = new WindowApi(option);
|
|
4112
4122
|
}
|
|
4113
4123
|
/** 版本号 */
|
|
4114
|
-
version = "2024.
|
|
4124
|
+
version = "2024.12.3";
|
|
4115
4125
|
addStyle(cssText) {
|
|
4116
4126
|
if (typeof cssText !== "string") {
|
|
4117
4127
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|