@whitesev/utils 2.5.2 → 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 +48 -40
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +48 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +48 -40
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +48 -40
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +48 -40
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +48 -40
- 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 +4 -4
- 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.esm.js
CHANGED
|
@@ -270,24 +270,24 @@ class UtilsGMCookie {
|
|
|
270
270
|
}
|
|
271
271
|
/**
|
|
272
272
|
* 获取多组Cookie
|
|
273
|
-
* @param
|
|
273
|
+
* @param option 配置
|
|
274
274
|
* @param callback 获取操作后的回调
|
|
275
275
|
* + cookies object[]
|
|
276
276
|
* + error string|undefined
|
|
277
277
|
**/
|
|
278
|
-
list(
|
|
279
|
-
if (
|
|
278
|
+
list(option, callback) {
|
|
279
|
+
if (option == null) {
|
|
280
280
|
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
281
281
|
}
|
|
282
282
|
let resultData = [];
|
|
283
283
|
try {
|
|
284
|
-
let
|
|
284
|
+
let defaultOption = {
|
|
285
285
|
url: this.windowApi.window.location.href,
|
|
286
286
|
domain: this.windowApi.window.location.hostname,
|
|
287
287
|
name: "",
|
|
288
288
|
path: "/",
|
|
289
289
|
};
|
|
290
|
-
|
|
290
|
+
defaultOption = utils.assign(defaultOption, option);
|
|
291
291
|
let cookies = this.windowApi.document.cookie.split(";");
|
|
292
292
|
cookies.forEach((item) => {
|
|
293
293
|
item = item.trim();
|
|
@@ -295,9 +295,9 @@ class UtilsGMCookie {
|
|
|
295
295
|
let itemName = itemSplit[0];
|
|
296
296
|
itemSplit.splice(0, 1);
|
|
297
297
|
let itemValue = decodeURIComponent(itemSplit.join(""));
|
|
298
|
-
let nameRegexp =
|
|
299
|
-
?
|
|
300
|
-
: new RegExp("^" +
|
|
298
|
+
let nameRegexp = defaultOption.name instanceof RegExp
|
|
299
|
+
? defaultOption.name
|
|
300
|
+
: new RegExp("^" + defaultOption.name, "g");
|
|
301
301
|
if (itemName.match(nameRegexp)) {
|
|
302
302
|
resultData.push({
|
|
303
303
|
domain: this.windowApi.window.location.hostname,
|
|
@@ -325,20 +325,20 @@ class UtilsGMCookie {
|
|
|
325
325
|
}
|
|
326
326
|
/**
|
|
327
327
|
* 获取多组Cookie
|
|
328
|
-
* @param
|
|
328
|
+
* @param option 配置
|
|
329
329
|
**/
|
|
330
|
-
getList(
|
|
331
|
-
if (
|
|
330
|
+
getList(option) {
|
|
331
|
+
if (option == null) {
|
|
332
332
|
throw new Error("Utils.GMCookie.list 参数不能为空");
|
|
333
333
|
}
|
|
334
334
|
let resultData = [];
|
|
335
|
-
let
|
|
335
|
+
let defaultOption = {
|
|
336
336
|
url: this.windowApi.window.location.href,
|
|
337
337
|
domain: this.windowApi.window.location.hostname,
|
|
338
338
|
name: "",
|
|
339
339
|
path: "/",
|
|
340
340
|
};
|
|
341
|
-
|
|
341
|
+
defaultOption = utils.assign(defaultOption, option);
|
|
342
342
|
let cookies = this.windowApi.document.cookie.split(";");
|
|
343
343
|
cookies.forEach((item) => {
|
|
344
344
|
item = item.trim();
|
|
@@ -346,9 +346,9 @@ class UtilsGMCookie {
|
|
|
346
346
|
let itemName = itemSplit[0];
|
|
347
347
|
itemSplit.splice(0, 1);
|
|
348
348
|
let itemValue = decodeURIComponent(itemSplit.join(""));
|
|
349
|
-
let nameRegexp =
|
|
350
|
-
?
|
|
351
|
-
: new RegExp("^" +
|
|
349
|
+
let nameRegexp = defaultOption.name instanceof RegExp
|
|
350
|
+
? defaultOption.name
|
|
351
|
+
: new RegExp("^" + defaultOption.name, "g");
|
|
352
352
|
if (itemName.match(nameRegexp)) {
|
|
353
353
|
resultData.push({
|
|
354
354
|
domain: this.windowApi.window.location.hostname,
|
|
@@ -368,12 +368,13 @@ class UtilsGMCookie {
|
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
370
|
* 设置Cookie
|
|
371
|
-
* @param
|
|
371
|
+
* @param option 配置
|
|
372
372
|
* @param callback 设置操作后的回调(成功/失败)
|
|
373
373
|
*/
|
|
374
|
-
set(
|
|
374
|
+
set(option, callback) {
|
|
375
|
+
let errorInfo;
|
|
375
376
|
try {
|
|
376
|
-
let
|
|
377
|
+
let defaultOption = {
|
|
377
378
|
url: this.windowApi.window.location.href,
|
|
378
379
|
name: "",
|
|
379
380
|
value: "",
|
|
@@ -386,43 +387,52 @@ class UtilsGMCookie {
|
|
|
386
387
|
*/
|
|
387
388
|
expirationDate: Math.floor(Date.now()) + 60 * 60 * 24 * 30,
|
|
388
389
|
};
|
|
389
|
-
|
|
390
|
-
let life =
|
|
391
|
-
?
|
|
390
|
+
defaultOption = utils.assign(defaultOption, option);
|
|
391
|
+
let life = defaultOption.expirationDate
|
|
392
|
+
? defaultOption.expirationDate
|
|
392
393
|
: Math.floor(Date.now()) + 60 * 60 * 24 * 30;
|
|
393
|
-
let cookieStr =
|
|
394
|
+
let cookieStr = defaultOption.name +
|
|
394
395
|
"=" +
|
|
395
|
-
decodeURIComponent(
|
|
396
|
+
decodeURIComponent(defaultOption.value) +
|
|
396
397
|
";expires=" +
|
|
397
398
|
new Date(life).toGMTString() +
|
|
398
399
|
"; path=/";
|
|
399
400
|
this.windowApi.document.cookie = cookieStr;
|
|
400
|
-
callback();
|
|
401
401
|
}
|
|
402
402
|
catch (error) {
|
|
403
|
-
|
|
403
|
+
errorInfo = error;
|
|
404
|
+
}
|
|
405
|
+
finally {
|
|
406
|
+
if (typeof callback === "function") {
|
|
407
|
+
callback(errorInfo);
|
|
408
|
+
}
|
|
404
409
|
}
|
|
405
410
|
}
|
|
406
411
|
/**
|
|
407
412
|
* 删除Cookie
|
|
408
|
-
* @param
|
|
413
|
+
* @param option 配置
|
|
409
414
|
* @param callback 删除操作后的回调(成功/失败)
|
|
410
415
|
*/
|
|
411
|
-
delete(
|
|
416
|
+
delete(option, callback) {
|
|
417
|
+
let errorInfo;
|
|
412
418
|
try {
|
|
413
|
-
let
|
|
419
|
+
let defaultOption = {
|
|
414
420
|
url: this.windowApi.window.location.href,
|
|
415
421
|
name: "",
|
|
416
|
-
|
|
417
|
-
firstPartyDomain:
|
|
422
|
+
path: "/",
|
|
423
|
+
firstPartyDomain: this.windowApi.window.location.hostname,
|
|
418
424
|
};
|
|
419
|
-
|
|
420
|
-
let cookieStr =
|
|
425
|
+
defaultOption = utils.assign(defaultOption, option);
|
|
426
|
+
let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}; domain=${defaultOption.firstPartyDomain};`;
|
|
421
427
|
this.windowApi.document.cookie = cookieStr;
|
|
422
|
-
callback();
|
|
423
428
|
}
|
|
424
429
|
catch (error) {
|
|
425
|
-
|
|
430
|
+
errorInfo = error;
|
|
431
|
+
}
|
|
432
|
+
finally {
|
|
433
|
+
if (typeof callback === "function") {
|
|
434
|
+
callback(errorInfo);
|
|
435
|
+
}
|
|
426
436
|
}
|
|
427
437
|
}
|
|
428
438
|
}
|
|
@@ -4108,7 +4118,7 @@ class Utils {
|
|
|
4108
4118
|
this.windowApi = new WindowApi(option);
|
|
4109
4119
|
}
|
|
4110
4120
|
/** 版本号 */
|
|
4111
|
-
version = "2024.
|
|
4121
|
+
version = "2024.12.3";
|
|
4112
4122
|
addStyle(cssText) {
|
|
4113
4123
|
if (typeof cssText !== "string") {
|
|
4114
4124
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -4826,9 +4836,7 @@ class Utils {
|
|
|
4826
4836
|
getMaxZIndexNodeInfo(deviation = 1, target = this.windowApi.document, ignoreCallBack) {
|
|
4827
4837
|
deviation = Number.isNaN(deviation) ? 1 : deviation;
|
|
4828
4838
|
const UtilsContext = this;
|
|
4829
|
-
//
|
|
4830
|
-
const maxZIndex = Math.pow(2, 31) - 1;
|
|
4831
|
-
// 比较值2000000000
|
|
4839
|
+
// 比较值 2000000000
|
|
4832
4840
|
const maxZIndexCompare = 2 * Math.pow(10, 9);
|
|
4833
4841
|
// 当前页面最大的z-index
|
|
4834
4842
|
let zIndex = 0;
|
|
@@ -4880,7 +4888,7 @@ class Utils {
|
|
|
4880
4888
|
zIndex += deviation;
|
|
4881
4889
|
if (zIndex >= maxZIndexCompare) {
|
|
4882
4890
|
// 最好不要超过最大值
|
|
4883
|
-
zIndex =
|
|
4891
|
+
zIndex = maxZIndexCompare;
|
|
4884
4892
|
}
|
|
4885
4893
|
return {
|
|
4886
4894
|
node: maxZIndexNode,
|