@etsoo/shared 1.2.51 → 1.2.54

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.
Files changed (94) hide show
  1. package/.github/workflows/main.yml +6 -5
  2. package/README.md +1 -1
  3. package/lib/cjs/ActionResult.d.ts +1 -1
  4. package/lib/cjs/ActionResult.js +3 -3
  5. package/lib/cjs/ArrayUtils.d.ts +1 -1
  6. package/lib/cjs/ArrayUtils.js +4 -4
  7. package/lib/cjs/ColorUtils.d.ts +1 -1
  8. package/lib/cjs/ColorUtils.js +2 -2
  9. package/lib/cjs/DataTypes.d.ts +6 -6
  10. package/lib/cjs/DataTypes.js +50 -51
  11. package/lib/cjs/DateUtils.d.ts +1 -1
  12. package/lib/cjs/DateUtils.js +27 -28
  13. package/lib/cjs/DomUtils.d.ts +3 -3
  14. package/lib/cjs/DomUtils.js +64 -73
  15. package/lib/cjs/ExtendUtils.d.ts +1 -1
  16. package/lib/cjs/ExtendUtils.js +6 -6
  17. package/lib/cjs/IActionResult.d.ts +15 -2
  18. package/lib/cjs/NumberUtils.d.ts +1 -1
  19. package/lib/cjs/NumberUtils.js +9 -9
  20. package/lib/cjs/StorageUtils.js +2 -2
  21. package/lib/cjs/Utils.d.ts +4 -4
  22. package/lib/cjs/Utils.js +58 -62
  23. package/lib/cjs/index.d.ts +22 -22
  24. package/lib/cjs/storage/WindowStorage.d.ts +1 -1
  25. package/lib/cjs/types/ContentDisposition.d.ts +2 -2
  26. package/lib/cjs/types/ContentDisposition.js +11 -13
  27. package/lib/cjs/types/EColor.js +5 -7
  28. package/lib/cjs/types/EHistory.d.ts +3 -3
  29. package/lib/cjs/types/EHistory.js +4 -4
  30. package/lib/cjs/types/ErrorData.d.ts +1 -1
  31. package/lib/cjs/types/EventClass.js +1 -1
  32. package/lib/mjs/ActionResult.d.ts +1 -1
  33. package/lib/mjs/ActionResult.js +3 -3
  34. package/lib/mjs/ArrayUtils.d.ts +1 -1
  35. package/lib/mjs/ArrayUtils.js +5 -5
  36. package/lib/mjs/ColorUtils.d.ts +1 -1
  37. package/lib/mjs/ColorUtils.js +3 -3
  38. package/lib/mjs/DataTypes.d.ts +6 -6
  39. package/lib/mjs/DataTypes.js +50 -51
  40. package/lib/mjs/DateUtils.d.ts +1 -1
  41. package/lib/mjs/DateUtils.js +27 -28
  42. package/lib/mjs/DomUtils.d.ts +3 -3
  43. package/lib/mjs/DomUtils.js +67 -76
  44. package/lib/mjs/ExtendUtils.d.ts +1 -1
  45. package/lib/mjs/ExtendUtils.js +6 -6
  46. package/lib/mjs/IActionResult.d.ts +15 -2
  47. package/lib/mjs/NumberUtils.d.ts +1 -1
  48. package/lib/mjs/NumberUtils.js +9 -9
  49. package/lib/mjs/StorageUtils.js +4 -4
  50. package/lib/mjs/Utils.d.ts +4 -4
  51. package/lib/mjs/Utils.js +61 -65
  52. package/lib/mjs/index.d.ts +22 -22
  53. package/lib/mjs/index.js +22 -22
  54. package/lib/mjs/storage/WindowStorage.d.ts +1 -1
  55. package/lib/mjs/storage/WindowStorage.js +2 -2
  56. package/lib/mjs/types/ContentDisposition.d.ts +2 -2
  57. package/lib/mjs/types/ContentDisposition.js +12 -14
  58. package/lib/mjs/types/EColor.js +5 -7
  59. package/lib/mjs/types/EHistory.d.ts +3 -3
  60. package/lib/mjs/types/EHistory.js +5 -5
  61. package/lib/mjs/types/ErrorData.d.ts +1 -1
  62. package/lib/mjs/types/EventClass.js +1 -1
  63. package/package.json +61 -63
  64. package/src/ActionResult.ts +23 -23
  65. package/src/ArrayUtils.ts +164 -172
  66. package/src/ColorUtils.ts +80 -82
  67. package/src/DataTypes.ts +745 -754
  68. package/src/DateUtils.ts +266 -268
  69. package/src/DomUtils.ts +806 -831
  70. package/src/ExtendUtils.ts +191 -191
  71. package/src/IActionResult.ts +55 -40
  72. package/src/Keyboard.ts +258 -258
  73. package/src/NumberUtils.ts +135 -135
  74. package/src/StorageUtils.ts +117 -117
  75. package/src/Utils.ts +908 -930
  76. package/src/index.ts +22 -22
  77. package/src/node/Storage.ts +53 -53
  78. package/src/storage/IStorage.ts +62 -62
  79. package/src/storage/WindowStorage.ts +140 -140
  80. package/src/types/ContentDisposition.ts +59 -63
  81. package/src/types/DataError.ts +15 -15
  82. package/src/types/DelayedExecutorType.ts +15 -15
  83. package/src/types/EColor.ts +241 -248
  84. package/src/types/EHistory.ts +151 -151
  85. package/src/types/ErrorData.ts +11 -11
  86. package/src/types/EventClass.ts +220 -220
  87. package/src/types/FormData.ts +25 -25
  88. package/src/types/ParsedPath.ts +5 -5
  89. package/tsconfig.cjs.json +16 -16
  90. package/tsconfig.json +16 -16
  91. package/.eslintignore +0 -3
  92. package/.eslintrc.json +0 -29
  93. package/.prettierignore +0 -5
  94. package/.prettierrc +0 -6
@@ -1,11 +1,11 @@
1
1
  /// <reference lib="dom" />
2
- import { DataTypes } from './DataTypes';
3
- import { DateUtils } from './DateUtils';
4
- import { Utils } from './Utils';
5
- if (typeof navigator === 'undefined') {
2
+ import { DataTypes } from "./DataTypes";
3
+ import { DateUtils } from "./DateUtils";
4
+ import { Utils } from "./Utils";
5
+ if (typeof navigator === "undefined") {
6
6
  // Test mock only
7
- globalThis.navigator = { language: 'en-US' };
8
- globalThis.location = { href: 'http://localhost/' };
7
+ globalThis.navigator = { language: "en-US" };
8
+ globalThis.location = { href: "http://localhost/" };
9
9
  }
10
10
  /**
11
11
  * Dom Utilities
@@ -16,11 +16,11 @@ export var DomUtils;
16
16
  /**
17
17
  * Language cache parameter name
18
18
  */
19
- DomUtils.CultureField = 'culture';
19
+ DomUtils.CultureField = "culture";
20
20
  /**
21
21
  * Country cache parameter name
22
22
  */
23
- DomUtils.CountryField = 'country';
23
+ DomUtils.CountryField = "country";
24
24
  /**
25
25
  * Clear form data
26
26
  * @param data Form data
@@ -37,7 +37,7 @@ export var DomUtils;
37
37
  return;
38
38
  // Get all values
39
39
  const formValues = data.getAll(key);
40
- if (formValues.length == 1 && formValues[0] === '') {
40
+ if (formValues.length == 1 && formValues[0] === "") {
41
41
  // Remove empty field
42
42
  data.delete(key);
43
43
  }
@@ -62,7 +62,7 @@ export var DomUtils;
62
62
  const sourceValue = Reflect.get(source, key);
63
63
  if (Array.isArray(sourceValue)) {
64
64
  // Array, types may differ
65
- if (formValues.join('`') === sourceValue.join('`')) {
65
+ if (formValues.join("`") === sourceValue.join("`")) {
66
66
  // Equal value, remove the key
67
67
  data.delete(key);
68
68
  }
@@ -96,8 +96,7 @@ export var DomUtils;
96
96
  const entries = Object.entries(isFormData(source) ? formDataToObject(source) : source);
97
97
  for (const [key, value] of entries) {
98
98
  // Is included or keepSource
99
- const property = properties.find((p) => p.localeCompare(key, 'en', { sensitivity: 'base' }) ===
100
- 0) ?? (keepSource ? key : undefined);
99
+ const property = properties.find((p) => p.localeCompare(key, "en", { sensitivity: "base" }) === 0) ?? (keepSource ? key : undefined);
101
100
  if (property == null)
102
101
  continue;
103
102
  // Template value
@@ -135,7 +134,7 @@ export var DomUtils;
135
134
  // New data
136
135
  // Object.create(...)
137
136
  const data = {};
138
- if (source != null && typeof source === 'object') {
137
+ if (source != null && typeof source === "object") {
139
138
  // Travel all properties
140
139
  dataAsTraveller(source, data, template, keepSource, false);
141
140
  }
@@ -196,8 +195,7 @@ export var DomUtils;
196
195
  // Browser detected
197
196
  if (culture == null) {
198
197
  culture =
199
- (navigator.languages && navigator.languages[0]) ||
200
- navigator.language;
198
+ (navigator.languages && navigator.languages[0]) || navigator.language;
201
199
  }
202
200
  // Return
203
201
  return culture;
@@ -231,7 +229,7 @@ export var DomUtils;
231
229
  */
232
230
  async function downloadFile(data, suggestedName, autoDetect = true) {
233
231
  try {
234
- if (autoDetect && 'showSaveFilePicker' in globalThis) {
232
+ if (autoDetect && "showSaveFilePicker" in globalThis) {
235
233
  // AbortError - Use dismisses the window
236
234
  const handle = await globalThis.showSaveFilePicker({
237
235
  suggestedName
@@ -248,11 +246,9 @@ export var DomUtils;
248
246
  return true;
249
247
  }
250
248
  else {
251
- const url = window.URL.createObjectURL(data instanceof Blob
252
- ? data
253
- : await new Response(data).blob());
254
- const a = document.createElement('a');
255
- a.style.display = 'none';
249
+ const url = window.URL.createObjectURL(data instanceof Blob ? data : await new Response(data).blob());
250
+ const a = document.createElement("a");
251
+ a.style.display = "none";
256
252
  a.href = url;
257
253
  if (suggestedName)
258
254
  a.download = suggestedName;
@@ -264,7 +260,7 @@ export var DomUtils;
264
260
  }
265
261
  }
266
262
  catch (e) {
267
- console.error('DomUtils.downloadFile with error', e);
263
+ console.error("DomUtils.downloadFile with error", e);
268
264
  }
269
265
  return false;
270
266
  }
@@ -313,7 +309,7 @@ export var DomUtils;
313
309
  data ?? (data = parseUserAgent());
314
310
  if (!data)
315
311
  return false;
316
- return data.brands.some((item) => item.brand.toLowerCase() === 'micromessenger');
312
+ return data.brands.some((item) => item.brand.toLowerCase() === "micromessenger");
317
313
  }
318
314
  DomUtils.isWechatClient = isWechatClient;
319
315
  /**
@@ -332,8 +328,8 @@ export var DomUtils;
332
328
  * @returns Result
333
329
  */
334
330
  DomUtils.en = (resources) => ({
335
- name: 'en',
336
- label: 'English',
331
+ name: "en",
332
+ label: "English",
337
333
  resources
338
334
  });
339
335
  /**
@@ -342,10 +338,10 @@ export var DomUtils;
342
338
  * @returns Result
343
339
  */
344
340
  DomUtils.zhHans = (resources) => ({
345
- name: 'zh-Hans',
346
- label: '简体中文',
341
+ name: "zh-Hans",
342
+ label: "简体中文",
347
343
  resources,
348
- compatibleNames: ['zh-CN', 'zh-SG']
344
+ compatibleNames: ["zh-CN", "zh-SG"]
349
345
  });
350
346
  /**
351
347
  * Get traditional Chinese resources definition
@@ -353,10 +349,10 @@ export var DomUtils;
353
349
  * @returns Result
354
350
  */
355
351
  DomUtils.zhHant = (resources) => ({
356
- name: 'zh-Hant',
357
- label: '繁體中文',
352
+ name: "zh-Hant",
353
+ label: "繁體中文",
358
354
  resources,
359
- compatibleNames: ['zh-HK', 'zh-TW', 'zh-MO']
355
+ compatibleNames: ["zh-HK", "zh-TW", "zh-MO"]
360
356
  });
361
357
  /**
362
358
  * Get the available culture definition
@@ -373,11 +369,11 @@ export var DomUtils;
373
369
  return [exactMatch, CultureMatch.Exact];
374
370
  // Compatible match
375
371
  const compatibleMatch = items.find((item) => item.compatibleNames?.includes(culture) ||
376
- culture.startsWith(item + '-'));
372
+ culture.startsWith(item + "-"));
377
373
  if (compatibleMatch)
378
374
  return [compatibleMatch, CultureMatch.Compatible];
379
375
  // Same part, like zh-CN and zh-HK
380
- const samePart = culture.split('-')[0];
376
+ const samePart = culture.split("-")[0];
381
377
  const samePartMatch = items.find((item) => item.name.startsWith(samePart));
382
378
  if (samePartMatch)
383
379
  return [samePartMatch, CultureMatch.SamePart];
@@ -391,13 +387,13 @@ export var DomUtils;
391
387
  */
392
388
  function getInputValue(input) {
393
389
  const type = input.type;
394
- if (type === 'number' || type === 'range') {
390
+ if (type === "number" || type === "range") {
395
391
  const num = input.valueAsNumber;
396
392
  if (isNaN(num))
397
393
  return null;
398
394
  return num;
399
395
  }
400
- else if (type === 'date' || type === 'datetime-local')
396
+ else if (type === "date" || type === "datetime-local")
401
397
  return input.valueAsDate ?? DateUtils.parse(input.value);
402
398
  return input.value;
403
399
  }
@@ -418,7 +414,7 @@ export var DomUtils;
418
414
  if (Array.isArray(headers)) {
419
415
  return Object.fromEntries(headers);
420
416
  }
421
- if (typeof Headers === 'undefined') {
417
+ if (typeof Headers === "undefined") {
422
418
  return Object.fromEntries(Object.entries(headers));
423
419
  }
424
420
  if (headers instanceof Headers) {
@@ -436,11 +432,11 @@ export var DomUtils;
436
432
  * @returns result
437
433
  */
438
434
  function isFormData(input) {
439
- if (typeof input === 'object' &&
435
+ if (typeof input === "object" &&
440
436
  input != null &&
441
- 'entries' in input &&
442
- 'getAll' in input &&
443
- 'keys' in input) {
437
+ "entries" in input &&
438
+ "getAll" in input &&
439
+ "keys" in input) {
444
440
  return true;
445
441
  }
446
442
  return false;
@@ -454,8 +450,8 @@ export var DomUtils;
454
450
  if (contentType &&
455
451
  // application/problem+json
456
452
  // application/json
457
- (contentType.includes('json') ||
458
- contentType.startsWith('application/javascript')))
453
+ (contentType.includes("json") ||
454
+ contentType.startsWith("application/javascript")))
459
455
  return true;
460
456
  return false;
461
457
  }
@@ -470,9 +466,7 @@ export var DomUtils;
470
466
  for (const newForm of forms) {
471
467
  for (const key of new Set(newForm.keys())) {
472
468
  form.delete(key);
473
- newForm
474
- .getAll(key)
475
- .forEach((value) => form.append(key, value));
469
+ newForm.getAll(key).forEach((value) => form.append(key, value));
476
470
  }
477
471
  }
478
472
  return form;
@@ -506,16 +500,16 @@ export var DomUtils;
506
500
  }
507
501
  const parts = ua.split(/(?!\(.*)\s+(?!\()(?![^(]*?\))/g);
508
502
  let mobile = false;
509
- let platform = '';
503
+ let platform = "";
510
504
  let platformVersion;
511
- let device = 'Desktop';
505
+ let device = "Desktop";
512
506
  const brands = [];
513
507
  // with the 'g' will causing failures for multiple calls
514
508
  const platformVersionReg = /^[a-zA-Z0-9-\s]+\s+(0|\d+)(\.(0|\d+)){0,3}(\(|$)/;
515
509
  const versionReg = /^[a-zA-Z0-9]+\/(0|\d+)(\.(0|\d+)){0,3}(\(|$)/;
516
510
  parts.forEach((part) => {
517
511
  const pl = part.toLowerCase();
518
- if (pl.startsWith('mozilla/')) {
512
+ if (pl.startsWith("mozilla/")) {
519
513
  const data = /\((.*)\)$/.exec(part);
520
514
  if (data && data.length > 1) {
521
515
  const pfItems = data[1].split(/;\s*/);
@@ -524,7 +518,7 @@ export var DomUtils;
524
518
  if (pfIndex !== -1) {
525
519
  const pfParts = pfItems[pfIndex].split(/\s+/);
526
520
  platformVersion = pfParts.pop();
527
- platform = pfParts.join(' ');
521
+ platform = pfParts.join(" ");
528
522
  }
529
523
  else {
530
524
  const appleVersionReg = /((iPhone|Mac)\s+OS(\s+\w+)?)\s+((0|\d+)(_(0|\d+)){0,3})/i;
@@ -532,46 +526,46 @@ export var DomUtils;
532
526
  const match = appleVersionReg.exec(pfItems[i]);
533
527
  if (match && match.length > 4) {
534
528
  platform = match[1];
535
- platformVersion = match[4].replace(/_/g, '.');
529
+ platformVersion = match[4].replace(/_/g, ".");
536
530
  pfItems.splice(i, 1);
537
531
  break;
538
532
  }
539
533
  }
540
534
  }
541
535
  // Device
542
- const deviceIndex = pfItems.findIndex((item) => item.includes(' Build/'));
536
+ const deviceIndex = pfItems.findIndex((item) => item.includes(" Build/"));
543
537
  if (deviceIndex === -1) {
544
538
  const firstItem = pfItems[0];
545
- if (firstItem.toLowerCase() !== 'linux' &&
539
+ if (firstItem.toLowerCase() !== "linux" &&
546
540
  !firstItem.startsWith(platform)) {
547
541
  device = firstItem;
548
542
  pfItems.shift();
549
543
  }
550
544
  }
551
545
  else {
552
- device = pfItems[deviceIndex].split(' Build/')[0];
546
+ device = pfItems[deviceIndex].split(" Build/")[0];
553
547
  pfItems.splice(deviceIndex, 1);
554
548
  }
555
549
  }
556
550
  return;
557
551
  }
558
- if (pl === 'mobile' || pl.startsWith('mobile/')) {
552
+ if (pl === "mobile" || pl.startsWith("mobile/")) {
559
553
  mobile = true;
560
554
  return;
561
555
  }
562
- if (pl === 'version' || pl.startsWith('version/')) {
556
+ if (pl === "version" || pl.startsWith("version/")) {
563
557
  // No process
564
558
  return;
565
559
  }
566
560
  if (versionReg.test(part)) {
567
- let [brand, version] = part.split('/');
568
- const pindex = version.indexOf('(');
561
+ let [brand, version] = part.split("/");
562
+ const pindex = version.indexOf("(");
569
563
  if (pindex > 0) {
570
564
  version = version.substring(0, pindex);
571
565
  }
572
566
  brands.push({
573
567
  brand,
574
- version: Utils.trimEnd(version, '.0')
568
+ version: Utils.trimEnd(version, ".0")
575
569
  });
576
570
  return;
577
571
  }
@@ -585,7 +579,7 @@ export var DomUtils;
585
579
  * @param container Container, limits the element range
586
580
  */
587
581
  function setFocus(name, container) {
588
- const elementName = typeof name === 'string' ? name : Object.keys(name)[0];
582
+ const elementName = typeof name === "string" ? name : Object.keys(name)[0];
589
583
  container ?? (container = document.body);
590
584
  const element = container.querySelector(`[name="${elementName}"]`);
591
585
  if (element != null)
@@ -602,13 +596,13 @@ export var DomUtils;
602
596
  // Avoid multiple setup, if there is already a handler, please set "window.onunhandledrejection = null" first
603
597
  if (window.onunhandledrejection)
604
598
  return;
605
- const errorType = 'error';
599
+ const errorType = "error";
606
600
  const errorPD = Utils.getResult(preventDefault, errorType) ?? true;
607
601
  window.onerror = (message, source, lineNo, colNo, error) => {
608
602
  // Default source
609
603
  source || (source = window.location.href);
610
604
  let data;
611
- if (typeof message === 'string') {
605
+ if (typeof message === "string") {
612
606
  data = {
613
607
  type: errorType,
614
608
  message, // Share the same message with error
@@ -622,8 +616,7 @@ export var DomUtils;
622
616
  data = {
623
617
  type: errorType,
624
618
  subType: message.type,
625
- message: error?.message ??
626
- `${message.currentTarget} event error`,
619
+ message: error?.message ?? `${message.currentTarget} event error`,
627
620
  source,
628
621
  lineNo,
629
622
  colNo,
@@ -634,7 +627,7 @@ export var DomUtils;
634
627
  // Return true to suppress error alert
635
628
  return errorPD;
636
629
  };
637
- const rejectionType = 'unhandledrejection';
630
+ const rejectionType = "unhandledrejection";
638
631
  const rejectionPD = Utils.getResult(preventDefault, rejectionType) ?? true;
639
632
  window.onunhandledrejection = (event) => {
640
633
  if (rejectionPD)
@@ -655,9 +648,7 @@ export var DomUtils;
655
648
  else {
656
649
  data = {
657
650
  type: rejectionType,
658
- message: typeof reason === 'string'
659
- ? reason
660
- : JSON.stringify(reason),
651
+ message: typeof reason === "string" ? reason : JSON.stringify(reason),
661
652
  source
662
653
  };
663
654
  }
@@ -671,14 +662,14 @@ export var DomUtils;
671
662
  orgin(...args);
672
663
  const [first, ...rest] = args;
673
664
  let message;
674
- if (typeof first === 'string') {
665
+ if (typeof first === "string") {
675
666
  message = first;
676
667
  }
677
668
  else {
678
669
  message = JSON.stringify(first);
679
670
  }
680
671
  const stack = rest.length > 0
681
- ? rest.map((item) => JSON.stringify(item)).join(', ')
672
+ ? rest.map((item) => JSON.stringify(item)).join(", ")
682
673
  : undefined;
683
674
  const data = {
684
675
  type,
@@ -689,8 +680,8 @@ export var DomUtils;
689
680
  action(data);
690
681
  };
691
682
  };
692
- window.console.warn = localConsole('consoleWarn', window.console.warn);
693
- window.console.error = localConsole('consoleError', window.console.error);
683
+ window.console.warn = localConsole("consoleWarn", window.console.warn);
684
+ window.console.error = localConsole("consoleError", window.console.error);
694
685
  }
695
686
  DomUtils.setupLogging = setupLogging;
696
687
  /**
@@ -701,17 +692,17 @@ export var DomUtils;
701
692
  * @returns Result
702
693
  */
703
694
  async function verifyPermission(fileHandle, withWrite = false) {
704
- if (!('queryPermission' in fileHandle) ||
705
- !('requestPermission' in fileHandle))
695
+ if (!("queryPermission" in fileHandle) ||
696
+ !("requestPermission" in fileHandle))
706
697
  return false;
707
698
  // FileSystemHandlePermissionDescriptor
708
- const opts = { mode: withWrite ? 'readwrite' : 'read' };
699
+ const opts = { mode: withWrite ? "readwrite" : "read" };
709
700
  // Check if we already have permission, if so, return true.
710
- if ((await fileHandle.queryPermission(opts)) === 'granted') {
701
+ if ((await fileHandle.queryPermission(opts)) === "granted") {
711
702
  return true;
712
703
  }
713
704
  // Request permission to the file, if the user grants permission, return true.
714
- if ((await fileHandle.requestPermission(opts)) === 'granted') {
705
+ if ((await fileHandle.requestPermission(opts)) === "granted") {
715
706
  return true;
716
707
  }
717
708
  // The user did not grant permission, return false.
@@ -1,4 +1,4 @@
1
- import { DelayedExecutorType } from './types/DelayedExecutorType';
1
+ import { DelayedExecutorType } from "./types/DelayedExecutorType";
2
2
  /**
3
3
  * Extend utilities
4
4
  */
@@ -1,4 +1,4 @@
1
- const hasRequestAnimationFrame = typeof requestAnimationFrame === 'function';
1
+ const hasRequestAnimationFrame = typeof requestAnimationFrame === "function";
2
2
  /**
3
3
  * Extend utilities
4
4
  */
@@ -13,7 +13,7 @@ export var ExtendUtils;
13
13
  function applyMixins(derivedCtor, baseCtors) {
14
14
  baseCtors.forEach((baseCtor) => {
15
15
  Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
16
- if (name !== 'constructor') {
16
+ if (name !== "constructor") {
17
17
  // eslint-disable-next-line no-param-reassign
18
18
  derivedCtor.prototype[name] = baseCtor.prototype[name];
19
19
  }
@@ -98,7 +98,7 @@ export var ExtendUtils;
98
98
  lastTime = timestamp;
99
99
  }
100
100
  const elapsed = timestamp - lastTime;
101
- const isReady = typeof checkReady === 'number'
101
+ const isReady = typeof checkReady === "number"
102
102
  ? elapsed >= checkReady
103
103
  : checkReady(elapsed);
104
104
  if (isReady) {
@@ -111,7 +111,7 @@ export var ExtendUtils;
111
111
  }
112
112
  requestID = requestAnimationFrame(loop);
113
113
  }
114
- else if (typeof checkReady === 'number') {
114
+ else if (typeof checkReady === "number") {
115
115
  requestID = setTimeout(callback, checkReady);
116
116
  }
117
117
  else {
@@ -136,7 +136,7 @@ export var ExtendUtils;
136
136
  }
137
137
  return () => {
138
138
  if (requestID) {
139
- if (hasRequestAnimationFrame && typeof requestID === 'number') {
139
+ if (hasRequestAnimationFrame && typeof requestID === "number") {
140
140
  cancelAnimationFrame(requestID);
141
141
  }
142
142
  else {
@@ -181,7 +181,7 @@ export var ExtendUtils;
181
181
  }
182
182
  return () => {
183
183
  if (requestID) {
184
- if (hasRequestAnimationFrame && typeof requestID === 'number') {
184
+ if (hasRequestAnimationFrame && typeof requestID === "number") {
185
185
  cancelAnimationFrame(requestID);
186
186
  }
187
187
  else {
@@ -1,4 +1,4 @@
1
- import { IdType } from './DataTypes';
1
+ import { IdType } from "./DataTypes";
2
2
  /**
3
3
  * Result errors
4
4
  * Indexable type
@@ -48,11 +48,24 @@ export interface IActionResult<D extends object = {}> {
48
48
  readonly ok: boolean;
49
49
  }
50
50
  /**
51
- * Action result with id data
51
+ * Action result with id
52
52
  */
53
53
  export type IdActionResult<T extends IdType = number> = IActionResult<{
54
54
  id: T;
55
55
  }>;
56
+ /**
57
+ * Action result with message data
58
+ */
59
+ export type MsgActionResult = IActionResult<{
60
+ msg: string;
61
+ }>;
62
+ /**
63
+ * Action result with id, message data
64
+ */
65
+ export type IdMsgActionResult = IActionResult<{
66
+ id: number;
67
+ msg: string;
68
+ }>;
56
69
  /**
57
70
  * Action result with dynamic data
58
71
  */
@@ -40,7 +40,7 @@ export declare namespace NumberUtils {
40
40
  * @param locale Locale
41
41
  * @returns Result
42
42
  */
43
- function getCurrencySymbol(code: string, display?: 'symbol' | 'narrowSymbol' | 'name', locale?: string): string | undefined;
43
+ function getCurrencySymbol(code: string, display?: "symbol" | "narrowSymbol" | "name", locale?: string): string | undefined;
44
44
  /**
45
45
  * Parse number
46
46
  * @param rawData Raw data
@@ -33,9 +33,9 @@ export var NumberUtils;
33
33
  function formatMoney(input, currency, locale, isInteger = false, options = {}) {
34
34
  if (currency) {
35
35
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
36
- options.style = 'currency';
36
+ options.style = "currency";
37
37
  options.currency = currency;
38
- options.currencyDisplay ?? (options.currencyDisplay = 'narrowSymbol');
38
+ options.currencyDisplay ?? (options.currencyDisplay = "narrowSymbol");
39
39
  }
40
40
  if (isInteger) {
41
41
  options.minimumFractionDigits ?? (options.minimumFractionDigits = 0);
@@ -55,8 +55,8 @@ export var NumberUtils;
55
55
  function formatFileSize(size, fractionDigits = 2) {
56
56
  const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
57
57
  return ((size / Math.pow(1024, i)).toFixed(fractionDigits) +
58
- ' ' +
59
- ['B', 'KB', 'MB', 'GB', 'TB', 'PB'][i]);
58
+ " " +
59
+ ["B", "KB", "MB", "GB", "TB", "PB"][i]);
60
60
  }
61
61
  NumberUtils.formatFileSize = formatFileSize;
62
62
  /**
@@ -66,22 +66,22 @@ export var NumberUtils;
66
66
  * @param locale Locale
67
67
  * @returns Result
68
68
  */
69
- function getCurrencySymbol(code, display = 'narrowSymbol', locale) {
69
+ function getCurrencySymbol(code, display = "narrowSymbol", locale) {
70
70
  const formatter = new Intl.NumberFormat(locale, {
71
- style: 'currency',
71
+ style: "currency",
72
72
  currency: code,
73
73
  currencyDisplay: display
74
74
  });
75
75
  const parts = formatter.formatToParts();
76
- const symbol = parts.find((part) => part.type === 'currency')?.value;
76
+ const symbol = parts.find((part) => part.type === "currency")?.value;
77
77
  return symbol;
78
78
  }
79
79
  NumberUtils.getCurrencySymbol = getCurrencySymbol;
80
80
  function parse(rawData, defaultValue) {
81
- if (rawData == null || rawData === '') {
81
+ if (rawData == null || rawData === "") {
82
82
  return defaultValue;
83
83
  }
84
- if (typeof rawData === 'number') {
84
+ if (typeof rawData === "number") {
85
85
  if (isNaN(rawData))
86
86
  return defaultValue;
87
87
  return rawData;
@@ -1,5 +1,5 @@
1
- import { NodeStorage } from './node/Storage';
2
- import { Utils } from './Utils';
1
+ import { NodeStorage } from "./node/Storage";
2
+ import { Utils } from "./Utils";
3
3
  // Mock node
4
4
  globalThis.localStorage ?? (globalThis.localStorage = new NodeStorage());
5
5
  globalThis.sessionStorage ?? (globalThis.sessionStorage = new NodeStorage());
@@ -19,7 +19,7 @@ export var StorageUtils;
19
19
  localStorage.removeItem(key);
20
20
  return;
21
21
  }
22
- localStorage.setItem(key, typeof data === 'string' ? data : JSON.stringify(data));
22
+ localStorage.setItem(key, typeof data === "string" ? data : JSON.stringify(data));
23
23
  }
24
24
  StorageUtils.setLocalData = setLocalData;
25
25
  /**
@@ -32,7 +32,7 @@ export var StorageUtils;
32
32
  sessionStorage.removeItem(key);
33
33
  return;
34
34
  }
35
- sessionStorage.setItem(key, typeof data === 'string' ? data : JSON.stringify(data));
35
+ sessionStorage.setItem(key, typeof data === "string" ? data : JSON.stringify(data));
36
36
  }
37
37
  StorageUtils.setSessionData = setSessionData;
38
38
  /**
@@ -1,5 +1,5 @@
1
- import { DataTypes, IdType } from './DataTypes';
2
- import { ParsedPath } from './types/ParsedPath';
1
+ import { DataTypes, IdType } from "./DataTypes";
2
+ import { ParsedPath } from "./types/ParsedPath";
3
3
  declare global {
4
4
  interface String {
5
5
  /**
@@ -127,7 +127,7 @@ export declare namespace Utils {
127
127
  */
128
128
  function exclude<T extends {
129
129
  [P in D]: IdType;
130
- }, D extends string = 'id'>(items: T[], field: D, ...excludedValues: T[D][]): T[];
130
+ }, D extends string = "id">(items: T[], field: D, ...excludedValues: T[D][]): T[];
131
131
  /**
132
132
  * Async exclude specific items
133
133
  * @param items Items
@@ -137,7 +137,7 @@ export declare namespace Utils {
137
137
  */
138
138
  function excludeAsync<T extends {
139
139
  [P in D]: IdType;
140
- }, D extends string = 'id'>(items: Promise<T[] | undefined>, field: D, ...excludedValues: T[D][]): Promise<T[] | undefined>;
140
+ }, D extends string = "id">(items: Promise<T[] | undefined>, field: D, ...excludedValues: T[D][]): Promise<T[] | undefined>;
141
141
  /**
142
142
  * Format inital character to lower case or upper case
143
143
  * @param input Input string