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