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