@cloudtower/eagle 0.35.6 → 0.35.8

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 (34) hide show
  1. package/dist/cjs/core/Duration/index.js +78 -0
  2. package/dist/cjs/core/index.js +15 -12
  3. package/dist/cjs/hooks/useFormatDuration.js +35 -0
  4. package/dist/cjs/index.js +247 -245
  5. package/dist/cjs/stats1.html +1 -1
  6. package/dist/cjs/utils/formatDuration.js +67 -0
  7. package/dist/components.css +1506 -1506
  8. package/dist/esm/core/Duration/index.js +72 -0
  9. package/dist/esm/core/index.js +4 -2
  10. package/dist/esm/hooks/useFormatDuration.js +33 -0
  11. package/dist/esm/index.js +1 -0
  12. package/dist/esm/stats1.html +1 -1
  13. package/dist/esm/utils/formatDuration.js +65 -0
  14. package/dist/linaria.merged.scss +1897 -1897
  15. package/dist/src/core/Duration/duration.type.d.ts +42 -0
  16. package/dist/src/core/Duration/index.d.ts +4 -0
  17. package/dist/src/core/index.d.ts +4 -0
  18. package/dist/src/coreX/Copy/CopyButton.d.ts +5 -0
  19. package/dist/src/coreX/Copy/CopyButton.type.d.ts +8 -0
  20. package/dist/src/coreX/Copy/CopyTooltip.d.ts +5 -0
  21. package/dist/src/coreX/Copy/CopyTooltip.typs.d.ts +16 -0
  22. package/dist/src/coreX/Copy/index.d.ts +2 -0
  23. package/dist/src/coreX/index.d.ts +1 -0
  24. package/dist/src/hooks/__tests__/useFormatDuration.test.d.ts +1 -0
  25. package/dist/src/hooks/index.d.ts +1 -0
  26. package/dist/src/hooks/useFormatDuration.d.ts +31 -0
  27. package/dist/src/utils/__test__/formatDuration.spec.d.ts +1 -0
  28. package/dist/src/utils/formatDuration.d.ts +28 -0
  29. package/dist/src/utils/index.d.ts +1 -0
  30. package/dist/stories/docs/core/Duration.stories.d.ts +88 -0
  31. package/dist/stories/docs/coreX/Copy/CopyButton.stories.d.ts +66 -0
  32. package/dist/stories/docs/coreX/Copy/CopyTooltip.stories.d.ts +66 -0
  33. package/dist/style.css +1506 -1506
  34. package/package.json +6 -4
@@ -0,0 +1,65 @@
1
+ function formatDuration(milliseconds, options = {}) {
2
+ const { maxDisplayUnits = 2, minUnit = "second" } = options;
3
+ const effectiveMaxDisplayUnits = Math.max(1, maxDisplayUnits);
4
+ if (milliseconds < 0 || milliseconds === 0) {
5
+ const minUnitValue2 = minUnit || "second";
6
+ return [{ value: 0, unit: minUnitValue2 }];
7
+ }
8
+ const units = [
9
+ { value: 365 * 24 * 60 * 60 * 1e3, unit: "year" },
10
+ { value: 30 * 24 * 60 * 60 * 1e3, unit: "month" },
11
+ { value: 7 * 24 * 60 * 60 * 1e3, unit: "week" },
12
+ { value: 24 * 60 * 60 * 1e3, unit: "day" },
13
+ { value: 60 * 60 * 1e3, unit: "hour" },
14
+ { value: 60 * 1e3, unit: "minute" },
15
+ { value: 1e3, unit: "second" },
16
+ { value: 1, unit: "millisecond" }
17
+ ];
18
+ const minUnitValue = minUnit || "second";
19
+ const minUnitIndex = units.findIndex((u) => u.unit === minUnitValue);
20
+ if (minUnitIndex === -1) {
21
+ const defaultMinUnitIndex = units.findIndex((u) => u.unit === "second");
22
+ const filteredUnits2 = units.slice(0, defaultMinUnitIndex + 1);
23
+ const parts2 = [];
24
+ let remaining2 = milliseconds;
25
+ for (const unitDef of filteredUnits2) {
26
+ if (remaining2 >= unitDef.value) {
27
+ const count = Math.floor(remaining2 / unitDef.value);
28
+ remaining2 = remaining2 % unitDef.value;
29
+ parts2.push({
30
+ value: count,
31
+ unit: unitDef.unit
32
+ });
33
+ if (parts2.length >= effectiveMaxDisplayUnits) {
34
+ break;
35
+ }
36
+ }
37
+ }
38
+ if (parts2.length === 0) {
39
+ return [{ value: 0, unit: "second" }];
40
+ }
41
+ return parts2;
42
+ }
43
+ const filteredUnits = units.slice(0, minUnitIndex + 1);
44
+ const parts = [];
45
+ let remaining = milliseconds;
46
+ for (const unitDef of filteredUnits) {
47
+ if (remaining >= unitDef.value) {
48
+ const count = Math.floor(remaining / unitDef.value);
49
+ remaining = remaining % unitDef.value;
50
+ parts.push({
51
+ value: count,
52
+ unit: unitDef.unit
53
+ });
54
+ if (parts.length >= effectiveMaxDisplayUnits) {
55
+ break;
56
+ }
57
+ }
58
+ }
59
+ if (parts.length === 0) {
60
+ return [{ value: 0, unit: minUnitValue || "second" }];
61
+ }
62
+ return parts;
63
+ }
64
+
65
+ export { formatDuration };