@pawells/typescript-common 1.0.0
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/LICENSE +21 -0
- package/README.md +148 -0
- package/build/array/array-chunk.d.ts +10 -0
- package/build/array/array-chunk.d.ts.map +1 -0
- package/build/array/array-chunk.js +19 -0
- package/build/array/array-chunk.js.map +1 -0
- package/build/array/array-compact.d.ts +18 -0
- package/build/array/array-compact.d.ts.map +1 -0
- package/build/array/array-compact.js +22 -0
- package/build/array/array-compact.js.map +1 -0
- package/build/array/array-contains.d.ts +9 -0
- package/build/array/array-contains.d.ts.map +1 -0
- package/build/array/array-contains.js +13 -0
- package/build/array/array-contains.js.map +1 -0
- package/build/array/array-count-by.d.ts +21 -0
- package/build/array/array-count-by.d.ts.map +1 -0
- package/build/array/array-count-by.js +29 -0
- package/build/array/array-count-by.js.map +1 -0
- package/build/array/array-difference.d.ts +25 -0
- package/build/array/array-difference.d.ts.map +1 -0
- package/build/array/array-difference.js +34 -0
- package/build/array/array-difference.js.map +1 -0
- package/build/array/array-element.d.ts +7 -0
- package/build/array/array-element.d.ts.map +1 -0
- package/build/array/array-element.js +2 -0
- package/build/array/array-element.js.map +1 -0
- package/build/array/array-filter.d.ts +37 -0
- package/build/array/array-filter.d.ts.map +1 -0
- package/build/array/array-filter.js +78 -0
- package/build/array/array-filter.js.map +1 -0
- package/build/array/array-flatten.d.ts +16 -0
- package/build/array/array-flatten.d.ts.map +1 -0
- package/build/array/array-flatten.js +20 -0
- package/build/array/array-flatten.js.map +1 -0
- package/build/array/array-group-by.d.ts +13 -0
- package/build/array/array-group-by.d.ts.map +1 -0
- package/build/array/array-group-by.js +24 -0
- package/build/array/array-group-by.js.map +1 -0
- package/build/array/array-intersection.d.ts +25 -0
- package/build/array/array-intersection.d.ts.map +1 -0
- package/build/array/array-intersection.js +39 -0
- package/build/array/array-intersection.js.map +1 -0
- package/build/array/array-partition.d.ts +19 -0
- package/build/array/array-partition.d.ts.map +1 -0
- package/build/array/array-partition.js +32 -0
- package/build/array/array-partition.js.map +1 -0
- package/build/array/array-range.d.ts +18 -0
- package/build/array/array-range.d.ts.map +1 -0
- package/build/array/array-range.js +30 -0
- package/build/array/array-range.js.map +1 -0
- package/build/array/array-sample.d.ts +29 -0
- package/build/array/array-sample.d.ts.map +1 -0
- package/build/array/array-sample.js +19 -0
- package/build/array/array-sample.js.map +1 -0
- package/build/array/array-shuffle.d.ts +8 -0
- package/build/array/array-shuffle.d.ts.map +1 -0
- package/build/array/array-shuffle.js +19 -0
- package/build/array/array-shuffle.js.map +1 -0
- package/build/array/array-sort-by.d.ts +20 -0
- package/build/array/array-sort-by.d.ts.map +1 -0
- package/build/array/array-sort-by.js +31 -0
- package/build/array/array-sort-by.js.map +1 -0
- package/build/array/array-zip.d.ts +22 -0
- package/build/array/array-zip.d.ts.map +1 -0
- package/build/array/array-zip.js +25 -0
- package/build/array/array-zip.js.map +1 -0
- package/build/array/array.test.d.ts +2 -0
- package/build/array/array.test.d.ts.map +1 -0
- package/build/array/array.test.js +347 -0
- package/build/array/array.test.js.map +1 -0
- package/build/array/index.d.ts +27 -0
- package/build/array/index.d.ts.map +1 -0
- package/build/array/index.js +25 -0
- package/build/array/index.js.map +1 -0
- package/build/array/types.d.ts +32 -0
- package/build/array/types.d.ts.map +1 -0
- package/build/array/types.js +2 -0
- package/build/array/types.js.map +1 -0
- package/build/array/unique.d.ts +8 -0
- package/build/array/unique.d.ts.map +1 -0
- package/build/array/unique.js +13 -0
- package/build/array/unique.js.map +1 -0
- package/build/enum/enum-entries.d.ts +11 -0
- package/build/enum/enum-entries.d.ts.map +1 -0
- package/build/enum/enum-entries.js +14 -0
- package/build/enum/enum-entries.js.map +1 -0
- package/build/enum/enum-key-by-value.d.ts +13 -0
- package/build/enum/enum-key-by-value.d.ts.map +1 -0
- package/build/enum/enum-key-by-value.js +21 -0
- package/build/enum/enum-key-by-value.js.map +1 -0
- package/build/enum/enum-keys.d.ts +10 -0
- package/build/enum/enum-keys.d.ts.map +1 -0
- package/build/enum/enum-keys.js +14 -0
- package/build/enum/enum-keys.js.map +1 -0
- package/build/enum/enum-safe-value.d.ts +14 -0
- package/build/enum/enum-safe-value.d.ts.map +1 -0
- package/build/enum/enum-safe-value.js +16 -0
- package/build/enum/enum-safe-value.js.map +1 -0
- package/build/enum/enum-values.d.ts +19 -0
- package/build/enum/enum-values.d.ts.map +1 -0
- package/build/enum/enum-values.js +25 -0
- package/build/enum/enum-values.js.map +1 -0
- package/build/enum/enum.test.d.ts +2 -0
- package/build/enum/enum.test.d.ts.map +1 -0
- package/build/enum/enum.test.js +122 -0
- package/build/enum/enum.test.js.map +1 -0
- package/build/enum/index.d.ts +17 -0
- package/build/enum/index.d.ts.map +1 -0
- package/build/enum/index.js +17 -0
- package/build/enum/index.js.map +1 -0
- package/build/enum/types.d.ts +9 -0
- package/build/enum/types.d.ts.map +1 -0
- package/build/enum/types.js +2 -0
- package/build/enum/types.js.map +1 -0
- package/build/enum/validate-enum-value.d.ts +13 -0
- package/build/enum/validate-enum-value.d.ts.map +1 -0
- package/build/enum/validate-enum-value.js +18 -0
- package/build/enum/validate-enum-value.js.map +1 -0
- package/build/function/compose.d.ts +37 -0
- package/build/function/compose.d.ts.map +1 -0
- package/build/function/compose.js +7 -0
- package/build/function/compose.js.map +1 -0
- package/build/function/debounce.d.ts +25 -0
- package/build/function/debounce.d.ts.map +1 -0
- package/build/function/debounce.js +37 -0
- package/build/function/debounce.js.map +1 -0
- package/build/function/function.test.d.ts +2 -0
- package/build/function/function.test.d.ts.map +1 -0
- package/build/function/function.test.js +158 -0
- package/build/function/function.test.js.map +1 -0
- package/build/function/index.d.ts +17 -0
- package/build/function/index.d.ts.map +1 -0
- package/build/function/index.js +16 -0
- package/build/function/index.js.map +1 -0
- package/build/function/memoize.d.ts +23 -0
- package/build/function/memoize.d.ts.map +1 -0
- package/build/function/memoize.js +34 -0
- package/build/function/memoize.js.map +1 -0
- package/build/function/once.d.ts +17 -0
- package/build/function/once.d.ts.map +1 -0
- package/build/function/once.js +27 -0
- package/build/function/once.js.map +1 -0
- package/build/function/sleep.d.ts +20 -0
- package/build/function/sleep.d.ts.map +1 -0
- package/build/function/sleep.js +22 -0
- package/build/function/sleep.js.map +1 -0
- package/build/function/throttle.d.ts +17 -0
- package/build/function/throttle.d.ts.map +1 -0
- package/build/function/throttle.js +37 -0
- package/build/function/throttle.js.map +1 -0
- package/build/function/types.d.ts +5 -0
- package/build/function/types.d.ts.map +1 -0
- package/build/function/types.js +2 -0
- package/build/function/types.js.map +1 -0
- package/build/index.d.ts +32 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +51 -0
- package/build/index.js.map +1 -0
- package/build/object/assert-object.d.ts +8 -0
- package/build/object/assert-object.d.ts.map +1 -0
- package/build/object/assert-object.js +10 -0
- package/build/object/assert-object.js.map +1 -0
- package/build/object/clone.d.ts +39 -0
- package/build/object/clone.d.ts.map +1 -0
- package/build/object/clone.js +85 -0
- package/build/object/clone.js.map +1 -0
- package/build/object/equals.d.ts +44 -0
- package/build/object/equals.d.ts.map +1 -0
- package/build/object/equals.js +104 -0
- package/build/object/equals.js.map +1 -0
- package/build/object/filter-cached.d.ts +9 -0
- package/build/object/filter-cached.d.ts.map +1 -0
- package/build/object/filter-cached.js +108 -0
- package/build/object/filter-cached.js.map +1 -0
- package/build/object/filter.d.ts +85 -0
- package/build/object/filter.d.ts.map +1 -0
- package/build/object/filter.js +248 -0
- package/build/object/filter.js.map +1 -0
- package/build/object/has-circular-reference.d.ts +8 -0
- package/build/object/has-circular-reference.d.ts.map +1 -0
- package/build/object/has-circular-reference.js +40 -0
- package/build/object/has-circular-reference.js.map +1 -0
- package/build/object/hash.d.ts +20 -0
- package/build/object/hash.d.ts.map +1 -0
- package/build/object/hash.js +39 -0
- package/build/object/hash.js.map +1 -0
- package/build/object/index.d.ts +32 -0
- package/build/object/index.d.ts.map +1 -0
- package/build/object/index.js +30 -0
- package/build/object/index.js.map +1 -0
- package/build/object/key-value-pairs.d.ts +21 -0
- package/build/object/key-value-pairs.d.ts.map +1 -0
- package/build/object/key-value-pairs.js +28 -0
- package/build/object/key-value-pairs.js.map +1 -0
- package/build/object/map-cached.d.ts +9 -0
- package/build/object/map-cached.d.ts.map +1 -0
- package/build/object/map-cached.js +97 -0
- package/build/object/map-cached.js.map +1 -0
- package/build/object/map.d.ts +29 -0
- package/build/object/map.d.ts.map +1 -0
- package/build/object/map.js +40 -0
- package/build/object/map.js.map +1 -0
- package/build/object/merge.d.ts +14 -0
- package/build/object/merge.d.ts.map +1 -0
- package/build/object/merge.js +41 -0
- package/build/object/merge.js.map +1 -0
- package/build/object/object-diff.d.ts +40 -0
- package/build/object/object-diff.d.ts.map +1 -0
- package/build/object/object-diff.js +45 -0
- package/build/object/object-diff.js.map +1 -0
- package/build/object/object-flatten.d.ts +22 -0
- package/build/object/object-flatten.d.ts.map +1 -0
- package/build/object/object-flatten.js +38 -0
- package/build/object/object-flatten.js.map +1 -0
- package/build/object/object-invert.d.ts +20 -0
- package/build/object/object-invert.d.ts.map +1 -0
- package/build/object/object-invert.js +26 -0
- package/build/object/object-invert.js.map +1 -0
- package/build/object/object.test.d.ts +2 -0
- package/build/object/object.test.d.ts.map +1 -0
- package/build/object/object.test.js +432 -0
- package/build/object/object.test.js.map +1 -0
- package/build/object/omit.d.ts +8 -0
- package/build/object/omit.d.ts.map +1 -0
- package/build/object/omit.js +17 -0
- package/build/object/omit.js.map +1 -0
- package/build/object/pick.d.ts +50 -0
- package/build/object/pick.d.ts.map +1 -0
- package/build/object/pick.js +60 -0
- package/build/object/pick.js.map +1 -0
- package/build/object/property-paths.d.ts +115 -0
- package/build/object/property-paths.d.ts.map +1 -0
- package/build/object/property-paths.js +170 -0
- package/build/object/property-paths.js.map +1 -0
- package/build/object/security-utils.d.ts +59 -0
- package/build/object/security-utils.d.ts.map +1 -0
- package/build/object/security-utils.js +165 -0
- package/build/object/security-utils.js.map +1 -0
- package/build/object/sort-keys.d.ts +26 -0
- package/build/object/sort-keys.d.ts.map +1 -0
- package/build/object/sort-keys.js +52 -0
- package/build/object/sort-keys.js.map +1 -0
- package/build/object/types.d.ts +152 -0
- package/build/object/types.d.ts.map +1 -0
- package/build/object/types.js +6 -0
- package/build/object/types.js.map +1 -0
- package/build/string/case-conversion.d.ts +50 -0
- package/build/string/case-conversion.d.ts.map +1 -0
- package/build/string/case-conversion.js +94 -0
- package/build/string/case-conversion.js.map +1 -0
- package/build/string/formatting.d.ts +108 -0
- package/build/string/formatting.d.ts.map +1 -0
- package/build/string/formatting.js +171 -0
- package/build/string/formatting.js.map +1 -0
- package/build/string/index.d.ts +15 -0
- package/build/string/index.d.ts.map +1 -0
- package/build/string/index.js +14 -0
- package/build/string/index.js.map +1 -0
- package/build/string/string.test.d.ts +2 -0
- package/build/string/string.test.d.ts.map +1 -0
- package/build/string/string.test.js +321 -0
- package/build/string/string.test.js.map +1 -0
- package/build/string/transformation.d.ts +18 -0
- package/build/string/transformation.d.ts.map +1 -0
- package/build/string/transformation.js +32 -0
- package/build/string/transformation.js.map +1 -0
- package/build/string/types.d.ts +44 -0
- package/build/string/types.d.ts.map +1 -0
- package/build/string/types.js +2 -0
- package/build/string/types.js.map +1 -0
- package/build/string/validation.d.ts +18 -0
- package/build/string/validation.d.ts.map +1 -0
- package/build/string/validation.js +26 -0
- package/build/string/validation.js.map +1 -0
- package/build/time/elapsed-time/constants.d.ts +10 -0
- package/build/time/elapsed-time/constants.d.ts.map +1 -0
- package/build/time/elapsed-time/constants.js +96 -0
- package/build/time/elapsed-time/constants.js.map +1 -0
- package/build/time/elapsed-time/elapsed-time.d.ts +412 -0
- package/build/time/elapsed-time/elapsed-time.d.ts.map +1 -0
- package/build/time/elapsed-time/elapsed-time.js +652 -0
- package/build/time/elapsed-time/elapsed-time.js.map +1 -0
- package/build/time/elapsed-time/types.d.ts +150 -0
- package/build/time/elapsed-time/types.d.ts.map +1 -0
- package/build/time/elapsed-time/types.js +2 -0
- package/build/time/elapsed-time/types.js.map +1 -0
- package/build/time/elapsed-time/utils.d.ts +18 -0
- package/build/time/elapsed-time/utils.d.ts.map +1 -0
- package/build/time/elapsed-time/utils.js +24 -0
- package/build/time/elapsed-time/utils.js.map +1 -0
- package/build/time/index.d.ts +18 -0
- package/build/time/index.d.ts.map +1 -0
- package/build/time/index.js +17 -0
- package/build/time/index.js.map +1 -0
- package/build/time/stopwatch/entry-types.d.ts +13 -0
- package/build/time/stopwatch/entry-types.d.ts.map +1 -0
- package/build/time/stopwatch/entry-types.js +2 -0
- package/build/time/stopwatch/entry-types.js.map +1 -0
- package/build/time/stopwatch/entry.d.ts +80 -0
- package/build/time/stopwatch/entry.d.ts.map +1 -0
- package/build/time/stopwatch/entry.js +105 -0
- package/build/time/stopwatch/entry.js.map +1 -0
- package/build/time/stopwatch/stopwatch.d.ts +232 -0
- package/build/time/stopwatch/stopwatch.d.ts.map +1 -0
- package/build/time/stopwatch/stopwatch.js +315 -0
- package/build/time/stopwatch/stopwatch.js.map +1 -0
- package/build/time/time.test.d.ts +2 -0
- package/build/time/time.test.d.ts.map +1 -0
- package/build/time/time.test.js +211 -0
- package/build/time/time.test.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a time unit and its corresponding value.
|
|
3
|
+
*/
|
|
4
|
+
export interface ITimeUnitValue {
|
|
5
|
+
/** The time unit type (week, day, hour, minute, second, millisecond) */
|
|
6
|
+
unit: TTimeUnit;
|
|
7
|
+
/** The numeric value for this time unit */
|
|
8
|
+
value: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Configuration options for formatting elapsed time values.
|
|
12
|
+
*/
|
|
13
|
+
export interface ITimeElapsedFormatOptions {
|
|
14
|
+
/** How to format negative values: 'Empty' (no indicator), 'NegativeSign' (prefix with -), 'Parenthesis' (wrap in parentheses), or 'Brackets' (wrap in brackets) */
|
|
15
|
+
negativeValueFormat?: 'Empty' | 'NegativeSign' | 'Parenthesis' | 'Brackets' | undefined;
|
|
16
|
+
/** Show zero value units in formatter output (default: false) */
|
|
17
|
+
showZeroValues?: boolean | undefined;
|
|
18
|
+
/** Maximum number of units to include in formatter output (default: unlimited) */
|
|
19
|
+
maxUnits?: number | undefined;
|
|
20
|
+
/** Custom unit labels for formatter */
|
|
21
|
+
unitLabels?: {
|
|
22
|
+
week?: string | ((_value: number) => string) | undefined;
|
|
23
|
+
day?: string | ((_value: number) => string) | undefined;
|
|
24
|
+
hour?: string | ((_value: number) => string) | undefined;
|
|
25
|
+
minute?: string | ((_value: number) => string) | undefined;
|
|
26
|
+
second?: string | ((_value: number) => string) | undefined;
|
|
27
|
+
millisecond?: string | ((_value: number) => string) | undefined;
|
|
28
|
+
} | undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Predefined time elapsed format styles.
|
|
32
|
+
*/
|
|
33
|
+
export type TTimeElapsedFormats = 'concise' | 'short' | 'medium' | 'long' | 'mostSignificant' | 'time' | 'timeWithSeconds';
|
|
34
|
+
/**
|
|
35
|
+
* Available time unit types for formatting elapsed time values.
|
|
36
|
+
*/
|
|
37
|
+
export type TTimeUnit = 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
|
|
38
|
+
/**
|
|
39
|
+
* Unit label as a string
|
|
40
|
+
*/
|
|
41
|
+
export type TUnitLabelString = string;
|
|
42
|
+
/**
|
|
43
|
+
* Unit label as a function that handles pluralization
|
|
44
|
+
* @param value - The numeric value to determine singular/plural
|
|
45
|
+
* @returns The appropriate label string
|
|
46
|
+
*/
|
|
47
|
+
export type TUnitLabelFunction = (value: number) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Unit label can be either a string or a function
|
|
50
|
+
*/
|
|
51
|
+
export type TUnitLabel = TUnitLabelString | TUnitLabelFunction;
|
|
52
|
+
/**
|
|
53
|
+
* Map of time units to their labels
|
|
54
|
+
*/
|
|
55
|
+
export interface IUnitLabelMap {
|
|
56
|
+
/** Label for milliseconds */
|
|
57
|
+
millisecond: TUnitLabel;
|
|
58
|
+
/** Label for seconds */
|
|
59
|
+
second: TUnitLabel;
|
|
60
|
+
/** Label for minutes */
|
|
61
|
+
minute: TUnitLabel;
|
|
62
|
+
/** Label for hours */
|
|
63
|
+
hour: TUnitLabel;
|
|
64
|
+
/** Label for days */
|
|
65
|
+
day: TUnitLabel;
|
|
66
|
+
/** Label for weeks */
|
|
67
|
+
week: TUnitLabel;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Concise format style with single-character labels
|
|
71
|
+
*/
|
|
72
|
+
export interface IConciseUnitLabels extends IUnitLabelMap {
|
|
73
|
+
millisecond: 'ms';
|
|
74
|
+
second: 's';
|
|
75
|
+
minute: 'm';
|
|
76
|
+
hour: 'h';
|
|
77
|
+
day: 'd';
|
|
78
|
+
week: 'w';
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Long format style with full words and pluralization
|
|
82
|
+
*/
|
|
83
|
+
export interface ILongUnitLabels extends IUnitLabelMap {
|
|
84
|
+
millisecond: TUnitLabelFunction;
|
|
85
|
+
second: TUnitLabelFunction;
|
|
86
|
+
minute: TUnitLabelFunction;
|
|
87
|
+
hour: TUnitLabelFunction;
|
|
88
|
+
day: TUnitLabelFunction;
|
|
89
|
+
week: TUnitLabelFunction;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Medium format style with abbreviated words
|
|
93
|
+
*/
|
|
94
|
+
export interface IMediumUnitLabels extends IUnitLabelMap {
|
|
95
|
+
millisecond: 'ms';
|
|
96
|
+
second: 'sec';
|
|
97
|
+
minute: 'min';
|
|
98
|
+
hour: 'hour';
|
|
99
|
+
day: 'day';
|
|
100
|
+
week: 'week';
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Short format style with short abbreviations
|
|
104
|
+
*/
|
|
105
|
+
export interface IShortUnitLabels extends IUnitLabelMap {
|
|
106
|
+
millisecond: 'ms';
|
|
107
|
+
second: 'sec';
|
|
108
|
+
minute: 'min';
|
|
109
|
+
hour: 'hr';
|
|
110
|
+
day: 'd';
|
|
111
|
+
week: 'wk';
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Complete set of default unit labels for all formatting styles
|
|
115
|
+
*/
|
|
116
|
+
export interface IDefaultUnitLabels {
|
|
117
|
+
concise: IConciseUnitLabels;
|
|
118
|
+
long: ILongUnitLabels;
|
|
119
|
+
medium: IMediumUnitLabels;
|
|
120
|
+
short: IShortUnitLabels;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Configuration options for elapsed time formatting
|
|
124
|
+
*/
|
|
125
|
+
export interface IFormatConfig {
|
|
126
|
+
/** Maximum number of units to display */
|
|
127
|
+
maxUnits?: number;
|
|
128
|
+
/** Unit labels to use for formatting */
|
|
129
|
+
unitLabels: Partial<IUnitLabelMap>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Predefined formatter styles
|
|
133
|
+
*/
|
|
134
|
+
export interface IFormats {
|
|
135
|
+
/** Format like "1h 30m 45s" */
|
|
136
|
+
concise: IFormatConfig;
|
|
137
|
+
/** Format like "1 hour 30 minutes 45 seconds" with proper pluralization */
|
|
138
|
+
long: IFormatConfig;
|
|
139
|
+
/** Format like "1 hour 30 min 45 sec" */
|
|
140
|
+
medium: IFormatConfig;
|
|
141
|
+
/** Format showing only the most significant 2 units */
|
|
142
|
+
mostSignificant: IFormatConfig;
|
|
143
|
+
/** Format like "1hr 30min 45sec" */
|
|
144
|
+
short: IFormatConfig;
|
|
145
|
+
/** Format showing only hours and minutes like "1:30" */
|
|
146
|
+
time: IFormatConfig;
|
|
147
|
+
/** Format showing hours, minutes and seconds like "1:30:45" */
|
|
148
|
+
timeWithSeconds: IFormatConfig;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/time/elapsed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AAM,EAAE,KAAK,CAAC;IACd,MAAM,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,KAAK,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACtD,WAAW,EAAE,IAAI,CAAC;IAClB,MAAM,EAAE,KAAK,CAAC;IACd,MAAM,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;CACX;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,kBAAkB,CAAC;IAC5B,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,EAAE,gBAAgB,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,+BAA+B;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,2EAA2E;IAC3E,IAAI,EAAE,aAAa,CAAC;IACpB,yCAAyC;IACzC,MAAM,EAAE,aAAa,CAAC;IACtB,uDAAuD;IACvD,eAAe,EAAE,aAAa,CAAC;IAC/B,oCAAoC;IACpC,KAAK,EAAE,aAAa,CAAC;IACrB,wDAAwD;IACxD,IAAI,EAAE,aAAa,CAAC;IACpB,+DAA+D;IAC/D,eAAe,EAAE,aAAa,CAAC;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/time/elapsed-time/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ITimeElapsedFormatOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Apply default options to format options object.
|
|
4
|
+
* Merges user-provided options with sensible defaults for time formatting.
|
|
5
|
+
*
|
|
6
|
+
* @param options - Partial formatting options of type ITimeElapsedFormatOptions provided by the user
|
|
7
|
+
* @returns Complete formatting options with defaults applied
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const userOptions = { showZeroValues: true };
|
|
12
|
+
* const complete = ApplyDefaultOptions(userOptions);
|
|
13
|
+
* // Result: { negativeValueFormat: 'NegativeSign', showZeroValues: true, maxUnits: undefined, unitLabels: undefined }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function ApplyDefaultOptions(options: Partial<ITimeElapsedFormatOptions>): ITimeElapsedFormatOptions;
|
|
17
|
+
export { ApplyDefaultOptions };
|
|
18
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/time/elapsed-time/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACH,iBAAS,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAAG,yBAAyB,CAOnG;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apply default options to format options object.
|
|
3
|
+
* Merges user-provided options with sensible defaults for time formatting.
|
|
4
|
+
*
|
|
5
|
+
* @param options - Partial formatting options of type ITimeElapsedFormatOptions provided by the user
|
|
6
|
+
* @returns Complete formatting options with defaults applied
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const userOptions = { showZeroValues: true };
|
|
11
|
+
* const complete = ApplyDefaultOptions(userOptions);
|
|
12
|
+
* // Result: { negativeValueFormat: 'NegativeSign', showZeroValues: true, maxUnits: undefined, unitLabels: undefined }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
function ApplyDefaultOptions(options) {
|
|
16
|
+
return {
|
|
17
|
+
maxUnits: options.maxUnits,
|
|
18
|
+
negativeValueFormat: options.negativeValueFormat ?? 'NegativeSign',
|
|
19
|
+
showZeroValues: options.showZeroValues ?? false,
|
|
20
|
+
unitLabels: options.unitLabels,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export { ApplyDefaultOptions };
|
|
24
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/time/elapsed-time/utils.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,SAAS,mBAAmB,CAAC,OAA2C;IACvE,OAAO;QACN,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,mBAAmB,EAAE,OAAO,CAAC,mBAAmB,IAAI,cAAc;QAClE,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,KAAK;QAC/C,UAAU,EAAE,OAAO,CAAC,UAAU;KAC9B,CAAC;AACH,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time measurement utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides the {@link ElapsedTime} value-object for representing and formatting
|
|
5
|
+
* durations, and the {@link Stopwatch} class for recording timestamped events
|
|
6
|
+
* such as starts, stops, pauses, resumes, and laps.
|
|
7
|
+
*
|
|
8
|
+
* @module time
|
|
9
|
+
*/
|
|
10
|
+
export * from './elapsed-time/elapsed-time.js';
|
|
11
|
+
export * from './elapsed-time/types.js';
|
|
12
|
+
export * from './elapsed-time/constants.js';
|
|
13
|
+
export * from './elapsed-time/utils.js';
|
|
14
|
+
export * from './stopwatch/stopwatch.js';
|
|
15
|
+
export * from './stopwatch/entry.js';
|
|
16
|
+
export * from './stopwatch/entry-types.js';
|
|
17
|
+
export type { TUnitLabel, TUnitLabelString, TUnitLabelFunction, IUnitLabelMap, IConciseUnitLabels, ILongUnitLabels, IMediumUnitLabels, IShortUnitLabels, IDefaultUnitLabels, IFormatConfig, IFormats, } from './elapsed-time/types.js';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/time/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAE3C,YAAY,EACX,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,QAAQ,GACR,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time measurement utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides the {@link ElapsedTime} value-object for representing and formatting
|
|
5
|
+
* durations, and the {@link Stopwatch} class for recording timestamped events
|
|
6
|
+
* such as starts, stops, pauses, resumes, and laps.
|
|
7
|
+
*
|
|
8
|
+
* @module time
|
|
9
|
+
*/
|
|
10
|
+
export * from './elapsed-time/elapsed-time.js';
|
|
11
|
+
export * from './elapsed-time/types.js';
|
|
12
|
+
export * from './elapsed-time/constants.js';
|
|
13
|
+
export * from './elapsed-time/utils.js';
|
|
14
|
+
export * from './stopwatch/stopwatch.js';
|
|
15
|
+
export * from './stopwatch/entry.js';
|
|
16
|
+
export * from './stopwatch/entry-types.js';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/time/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ElapsedTime } from '../elapsed-time/elapsed-time.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a single timestamp entry recorded by the stopwatch.
|
|
4
|
+
*/
|
|
5
|
+
export interface IStopwatchEntryData {
|
|
6
|
+
/** The timestamp when this entry was recorded (milliseconds since epoch) */
|
|
7
|
+
timestamp: number;
|
|
8
|
+
/** The elapsed time since the previous entry */
|
|
9
|
+
elapsed: ElapsedTime;
|
|
10
|
+
/** The total elapsed time since the stopwatch was first started */
|
|
11
|
+
elapsedTotal: ElapsedTime;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=entry-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-types.d.ts","sourceRoot":"","sources":["../../../src/time/stopwatch/entry-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,OAAO,EAAE,WAAW,CAAC;IACrB,mEAAmE;IACnE,YAAY,EAAE,WAAW,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-types.js","sourceRoot":"","sources":["../../../src/time/stopwatch/entry-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ElapsedTime } from '../elapsed-time/elapsed-time.js';
|
|
2
|
+
import { Stopwatch } from './stopwatch.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a single timestamped entry recorded by a {@link Stopwatch}.
|
|
5
|
+
*
|
|
6
|
+
* Each entry captures the exact moment in time (milliseconds since epoch) at
|
|
7
|
+
* which a stopwatch event occurred — such as a start, stop, pause, resume, or
|
|
8
|
+
* lap click. It exposes both the interval elapsed since the previous entry and
|
|
9
|
+
* the total elapsed time since the stopwatch was first started.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const sw = new Stopwatch(true);
|
|
14
|
+
* // ... some work ...
|
|
15
|
+
* const entry = sw.Stop();
|
|
16
|
+
* console.log(entry?.timestamp); // e.g. 1708512000000
|
|
17
|
+
* console.log(entry?.Elapsed.Format()); // e.g. "250ms"
|
|
18
|
+
* console.log(entry?.ElapsedTotal.Format()); // e.g. "1s 250ms"
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class StopwatchEntry {
|
|
22
|
+
private readonly _timestamp;
|
|
23
|
+
private readonly _stopwatch;
|
|
24
|
+
private readonly _index;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new stopwatch entry.
|
|
27
|
+
*
|
|
28
|
+
* @param _timestamp - The Unix timestamp in milliseconds when this entry was recorded.
|
|
29
|
+
* @param stopwatch - The parent {@link Stopwatch} instance, used to compute
|
|
30
|
+
* relative elapsed times. If omitted the entry is standalone, and `Elapsed`
|
|
31
|
+
* and `ElapsedTotal` will always return zero.
|
|
32
|
+
* @param index - Zero-based position of this entry within the stopwatch's
|
|
33
|
+
* internal times array. Used to locate the preceding entry for lap calculations.
|
|
34
|
+
*/
|
|
35
|
+
constructor(_timestamp: number, stopwatch?: Stopwatch, index?: number);
|
|
36
|
+
/**
|
|
37
|
+
* The Unix timestamp (milliseconds since epoch) when this entry was recorded.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const sw = new Stopwatch(true);
|
|
42
|
+
* const entry = sw.Stop()!;
|
|
43
|
+
* console.log(new Date(entry.timestamp).toISOString());
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
get timestamp(): number;
|
|
47
|
+
/**
|
|
48
|
+
* The elapsed time between this entry and the immediately preceding entry.
|
|
49
|
+
*
|
|
50
|
+
* Returns {@link ElapsedTime} with a value of `0` if:
|
|
51
|
+
* - This is the first entry in the stopwatch (no previous entry exists), or
|
|
52
|
+
* - The entry was created without an associated stopwatch.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const sw = new Stopwatch(true);
|
|
57
|
+
* // ... 300 ms of work ...
|
|
58
|
+
* const lap1 = sw.Lap();
|
|
59
|
+
* console.log(lap1.Format()); // "300ms"
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
get Elapsed(): ElapsedTime;
|
|
63
|
+
/**
|
|
64
|
+
* The total elapsed time from the very first entry of the parent stopwatch
|
|
65
|
+
* up to and including this entry.
|
|
66
|
+
*
|
|
67
|
+
* Returns {@link ElapsedTime} with a value of `0` if this entry was created
|
|
68
|
+
* without an associated stopwatch or if the stopwatch has no recorded entries.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const sw = new Stopwatch(true);
|
|
73
|
+
* // ... 1200 ms of work ...
|
|
74
|
+
* const stopEntry = sw.Stop()!;
|
|
75
|
+
* console.log(stopEntry.ElapsedTotal.Format('LONG')); // "1 second 200 milliseconds"
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
get ElapsedTotal(): ElapsedTime;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../../src/time/stopwatch/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAc;IAed,OAAO,CAAC,QAAQ,CAAC,UAAU;IAdvC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0B;IAErD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IAErC;;;;;;;;;OASG;gBAC0B,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,MAAM;IAOtF;;;;;;;;;OASG;IACH,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED;;;;;;;;;;;;;;OAcG;IACH,IAAW,OAAO,IAAI,WAAW,CAUhC;IAED;;;;;;;;;;;;;;OAcG;IACH,IAAW,YAAY,IAAI,WAAW,CAUrC;CACD"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ElapsedTime } from '../elapsed-time/elapsed-time.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a single timestamped entry recorded by a {@link Stopwatch}.
|
|
4
|
+
*
|
|
5
|
+
* Each entry captures the exact moment in time (milliseconds since epoch) at
|
|
6
|
+
* which a stopwatch event occurred — such as a start, stop, pause, resume, or
|
|
7
|
+
* lap click. It exposes both the interval elapsed since the previous entry and
|
|
8
|
+
* the total elapsed time since the stopwatch was first started.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const sw = new Stopwatch(true);
|
|
13
|
+
* // ... some work ...
|
|
14
|
+
* const entry = sw.Stop();
|
|
15
|
+
* console.log(entry?.timestamp); // e.g. 1708512000000
|
|
16
|
+
* console.log(entry?.Elapsed.Format()); // e.g. "250ms"
|
|
17
|
+
* console.log(entry?.ElapsedTotal.Format()); // e.g. "1s 250ms"
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export class StopwatchEntry {
|
|
21
|
+
_timestamp;
|
|
22
|
+
_stopwatch = null;
|
|
23
|
+
_index = -1;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new stopwatch entry.
|
|
26
|
+
*
|
|
27
|
+
* @param _timestamp - The Unix timestamp in milliseconds when this entry was recorded.
|
|
28
|
+
* @param stopwatch - The parent {@link Stopwatch} instance, used to compute
|
|
29
|
+
* relative elapsed times. If omitted the entry is standalone, and `Elapsed`
|
|
30
|
+
* and `ElapsedTotal` will always return zero.
|
|
31
|
+
* @param index - Zero-based position of this entry within the stopwatch's
|
|
32
|
+
* internal times array. Used to locate the preceding entry for lap calculations.
|
|
33
|
+
*/
|
|
34
|
+
constructor(_timestamp, stopwatch, index) {
|
|
35
|
+
this._timestamp = _timestamp;
|
|
36
|
+
if (stopwatch) {
|
|
37
|
+
this._stopwatch = stopwatch;
|
|
38
|
+
this._index = index ?? 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The Unix timestamp (milliseconds since epoch) when this entry was recorded.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const sw = new Stopwatch(true);
|
|
47
|
+
* const entry = sw.Stop()!;
|
|
48
|
+
* console.log(new Date(entry.timestamp).toISOString());
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
get timestamp() {
|
|
52
|
+
return this._timestamp;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The elapsed time between this entry and the immediately preceding entry.
|
|
56
|
+
*
|
|
57
|
+
* Returns {@link ElapsedTime} with a value of `0` if:
|
|
58
|
+
* - This is the first entry in the stopwatch (no previous entry exists), or
|
|
59
|
+
* - The entry was created without an associated stopwatch.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const sw = new Stopwatch(true);
|
|
64
|
+
* // ... 300 ms of work ...
|
|
65
|
+
* const lap1 = sw.Lap();
|
|
66
|
+
* console.log(lap1.Format()); // "300ms"
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
get Elapsed() {
|
|
70
|
+
if (!this._stopwatch || this._index <= 0) {
|
|
71
|
+
return new ElapsedTime(0);
|
|
72
|
+
}
|
|
73
|
+
const previousEntry = this._stopwatch.Times[this._index - 1];
|
|
74
|
+
if (!previousEntry) {
|
|
75
|
+
return new ElapsedTime(0);
|
|
76
|
+
}
|
|
77
|
+
return new ElapsedTime(this._timestamp - previousEntry.timestamp);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The total elapsed time from the very first entry of the parent stopwatch
|
|
81
|
+
* up to and including this entry.
|
|
82
|
+
*
|
|
83
|
+
* Returns {@link ElapsedTime} with a value of `0` if this entry was created
|
|
84
|
+
* without an associated stopwatch or if the stopwatch has no recorded entries.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const sw = new Stopwatch(true);
|
|
89
|
+
* // ... 1200 ms of work ...
|
|
90
|
+
* const stopEntry = sw.Stop()!;
|
|
91
|
+
* console.log(stopEntry.ElapsedTotal.Format('LONG')); // "1 second 200 milliseconds"
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
get ElapsedTotal() {
|
|
95
|
+
if (!this._stopwatch) {
|
|
96
|
+
return new ElapsedTime(0);
|
|
97
|
+
}
|
|
98
|
+
const firstEntry = this._stopwatch.First;
|
|
99
|
+
if (!firstEntry) {
|
|
100
|
+
return new ElapsedTime(0);
|
|
101
|
+
}
|
|
102
|
+
return new ElapsedTime(this._timestamp - firstEntry.timestamp);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../src/time/stopwatch/entry.ts"],"names":[],"mappings":"AAAA,OAA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