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