@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,412 @@
|
|
|
1
|
+
import { ITimeElapsedFormatOptions, TTimeElapsedFormats, IFormatConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a duration of time with formatting and calculation capabilities.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ElapsedTime {
|
|
6
|
+
/** Whether the elapsed time represents a negative duration */
|
|
7
|
+
private _IsNegative;
|
|
8
|
+
/** The total duration in milliseconds (always positive, sign stored in isNegative) */
|
|
9
|
+
private _TotalMilliseconds;
|
|
10
|
+
/** Cached total seconds value */
|
|
11
|
+
private _TotalSeconds;
|
|
12
|
+
/** Cached total minutes value */
|
|
13
|
+
private _TotalMinutes;
|
|
14
|
+
/** Cached total hours value */
|
|
15
|
+
private _TotalHours;
|
|
16
|
+
/** Cached total days value */
|
|
17
|
+
private _TotalDays;
|
|
18
|
+
/** Cached seconds component (excluding complete minutes) */
|
|
19
|
+
private _Seconds;
|
|
20
|
+
/** Cached minutes component (excluding complete hours) */
|
|
21
|
+
private _Minutes;
|
|
22
|
+
/** Cached hours component (excluding complete days) */
|
|
23
|
+
private _Hours;
|
|
24
|
+
/** Cached days component (excluding complete weeks) */
|
|
25
|
+
private _Days;
|
|
26
|
+
/** Cached weeks component */
|
|
27
|
+
private _Weeks;
|
|
28
|
+
/** Cached milliseconds component (excluding complete seconds) */
|
|
29
|
+
private _Milliseconds;
|
|
30
|
+
/** Flag to track whether cached values have been calculated */
|
|
31
|
+
private _ValuesCalculated;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new ElapsedTime instance.
|
|
34
|
+
* @param milliseconds The total number of milliseconds.
|
|
35
|
+
*/
|
|
36
|
+
constructor(milliseconds: number);
|
|
37
|
+
/**
|
|
38
|
+
* Calculate all time unit values for efficient access.
|
|
39
|
+
* This method performs the core time decomposition calculations and caches
|
|
40
|
+
* the results to avoid redundant computation on subsequent property access.
|
|
41
|
+
*
|
|
42
|
+
* The calculation process:
|
|
43
|
+
* 1. Converts total milliseconds to larger units (seconds, minutes, hours, days)
|
|
44
|
+
* 2. Calculates component values using modulo operations
|
|
45
|
+
* 3. Caches all results with the _valuesCalculated flag
|
|
46
|
+
*
|
|
47
|
+
* @private
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // Internal usage - called automatically when accessing time properties
|
|
52
|
+
* const elapsed = new ElapsedTime(93784000); // 26h 3m 4s
|
|
53
|
+
* // First access triggers calculation
|
|
54
|
+
* console.log(elapsed.Hours); // 2 (26 % 24)
|
|
55
|
+
* console.log(elapsed.TotalHours); // 26
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
private _CalculateTimeValues;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the number of weeks in the elapsed time.
|
|
61
|
+
*/
|
|
62
|
+
get Weeks(): number;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the number of days in the elapsed time (excluding complete weeks).
|
|
65
|
+
*/
|
|
66
|
+
get Days(): number;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the total number of days in the elapsed time.
|
|
69
|
+
*/
|
|
70
|
+
get TotalDays(): number;
|
|
71
|
+
/**
|
|
72
|
+
* Gets the number of hours in the elapsed time (excluding complete days).
|
|
73
|
+
*/
|
|
74
|
+
get Hours(): number;
|
|
75
|
+
/**
|
|
76
|
+
* Gets the hours component as a padded string.
|
|
77
|
+
* @param length The minimum length to pad to (default: 2).
|
|
78
|
+
* @returns The zero-padded string.
|
|
79
|
+
*/
|
|
80
|
+
HoursPadded(length?: number): string;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the total number of hours in the elapsed time.
|
|
83
|
+
*/
|
|
84
|
+
get TotalHours(): number;
|
|
85
|
+
/**
|
|
86
|
+
* Gets the total hours as a padded string.
|
|
87
|
+
* @param length The minimum length to pad to (default: 2).
|
|
88
|
+
* @returns The zero-padded string.
|
|
89
|
+
*/
|
|
90
|
+
TotalHoursPadded(length?: number): string;
|
|
91
|
+
/**
|
|
92
|
+
* Gets the number of minutes in the elapsed time (excluding complete hours).
|
|
93
|
+
*/
|
|
94
|
+
get Minutes(): number;
|
|
95
|
+
/**
|
|
96
|
+
* Gets the minutes component as a padded string.
|
|
97
|
+
* @param length The minimum length to pad to (default: 2).
|
|
98
|
+
* @returns The zero-padded string.
|
|
99
|
+
*/
|
|
100
|
+
MinutesPadded(length?: number): string;
|
|
101
|
+
/**
|
|
102
|
+
* Gets the total number of minutes in the elapsed time.
|
|
103
|
+
*/
|
|
104
|
+
get TotalMinutes(): number;
|
|
105
|
+
/**
|
|
106
|
+
* Gets the total minutes as a padded string.
|
|
107
|
+
* @param length The minimum length to pad to (default: 2).
|
|
108
|
+
* @returns The zero-padded string.
|
|
109
|
+
*/
|
|
110
|
+
TotalMinutesPadded(length?: number): string;
|
|
111
|
+
/**
|
|
112
|
+
* Gets the number of seconds in the elapsed time (excluding complete minutes).
|
|
113
|
+
*/
|
|
114
|
+
get Seconds(): number;
|
|
115
|
+
/**
|
|
116
|
+
* Gets the seconds component as a padded string.
|
|
117
|
+
* @param length The minimum length to pad to (default: 2).
|
|
118
|
+
* @returns The zero-padded string.
|
|
119
|
+
*/
|
|
120
|
+
SecondsPadded(length?: number): string;
|
|
121
|
+
/**
|
|
122
|
+
* Gets the total number of seconds in the elapsed time.
|
|
123
|
+
*/
|
|
124
|
+
get TotalSeconds(): number;
|
|
125
|
+
/**
|
|
126
|
+
* Gets the total seconds as a padded string.
|
|
127
|
+
* @param length The minimum length to pad to (default: 2).
|
|
128
|
+
* @returns The zero-padded string.
|
|
129
|
+
*/
|
|
130
|
+
TotalSecondsPadded(length?: number): string;
|
|
131
|
+
/**
|
|
132
|
+
* Gets the number of milliseconds in the elapsed time (excluding complete seconds).
|
|
133
|
+
*/
|
|
134
|
+
get Milliseconds(): number;
|
|
135
|
+
/**
|
|
136
|
+
* Gets the milliseconds component as a padded string.
|
|
137
|
+
* @param length The minimum length to pad to (default: 3).
|
|
138
|
+
* @returns The zero-padded string.
|
|
139
|
+
*/
|
|
140
|
+
MillisecondsPadded(length?: number): string;
|
|
141
|
+
/**
|
|
142
|
+
* Checks if the elapsed time represents a negative duration.
|
|
143
|
+
*/
|
|
144
|
+
get IsNegative(): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Gets the total number of milliseconds in the elapsed time.
|
|
147
|
+
*/
|
|
148
|
+
get TotalMilliseconds(): number;
|
|
149
|
+
/**
|
|
150
|
+
* Sets the total number of milliseconds in the elapsed time.
|
|
151
|
+
*/
|
|
152
|
+
set TotalMilliseconds(value: number);
|
|
153
|
+
/**
|
|
154
|
+
* Get the total milliseconds as a padded string.
|
|
155
|
+
*
|
|
156
|
+
* @param length - The minimum length to pad to (default: 3)
|
|
157
|
+
* @returns The total milliseconds as a zero-padded string
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const elapsed = new ElapsedTime(5750);
|
|
162
|
+
* console.log(elapsed.TotalMillisecondsPadded()); // "5750"
|
|
163
|
+
* console.log(elapsed.TotalMillisecondsPadded(6)); // "005750"
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
TotalMillisecondsPadded(length?: number): string;
|
|
167
|
+
/**
|
|
168
|
+
* Create a new ElapsedTime instance from start and stop timestamps.
|
|
169
|
+
* Convenience method for calculating elapsed time between two points in time.
|
|
170
|
+
*
|
|
171
|
+
* @param start - The start time in milliseconds (typically from Date.now() or performance.now())
|
|
172
|
+
* @param stop - The stop time in milliseconds
|
|
173
|
+
* @returns A new ElapsedTime instance representing the duration between start and stop
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const start = Date.now();
|
|
178
|
+
* // ... some operation that takes time ...
|
|
179
|
+
* const end = Date.now();
|
|
180
|
+
* const duration = ElapsedTime.From(start, end);
|
|
181
|
+
* console.log(duration.Format('CONCISE')); // "1s 250ms"
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* // Using with performance.now() for high precision
|
|
187
|
+
* const start = performance.now();
|
|
188
|
+
* await someAsyncOperation();
|
|
189
|
+
* const end = performance.now();
|
|
190
|
+
* const duration = ElapsedTime.From(start, end);
|
|
191
|
+
* console.log(duration.Format('MEDIUM')); // "1 sec 250 ms"
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
static From(start: number, stop: number): ElapsedTime;
|
|
195
|
+
/**
|
|
196
|
+
* Format a duration of time using static method convenience.
|
|
197
|
+
* Creates a temporary ElapsedTime instance and formats it in one operation.
|
|
198
|
+
*
|
|
199
|
+
* @param milliseconds - The total number of milliseconds to format
|
|
200
|
+
* @param format - The format string or predefined format name (default: 'CONCISE')
|
|
201
|
+
* @param options - Formatting options of type ITimeElapsedFormatOptions for customization
|
|
202
|
+
* @returns The formatted time string
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* // Quick formatting without creating an instance
|
|
207
|
+
* console.log(ElapsedTime.Format(3661000)); // "1h 1m 1s"
|
|
208
|
+
* console.log(ElapsedTime.Format(3661000, 'LONG')); // "1 hour 1 minute 1 second"
|
|
209
|
+
*
|
|
210
|
+
* // With custom options
|
|
211
|
+
* const options = { maxUnits: 2, showZeroValues: false };
|
|
212
|
+
* console.log(ElapsedTime.Format(3661000, 'MEDIUM', options)); // "1 hour 1 min"
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
static Format(milliseconds: number, format?: TTimeElapsedFormats, options?: Partial<ITimeElapsedFormatOptions>): string;
|
|
216
|
+
/**
|
|
217
|
+
* Format the elapsed time according to the specified format and options.
|
|
218
|
+
* This is the primary formatting method that handles all predefined formats
|
|
219
|
+
* and custom formatting configurations.
|
|
220
|
+
*
|
|
221
|
+
* Available predefined formats:
|
|
222
|
+
* - **CONCISE**: "1h 30m 45s" - Ultra-compact with single-letter units
|
|
223
|
+
* - **SHORT**: "1hr 30min 45sec" - Abbreviated but readable units
|
|
224
|
+
* - **MEDIUM**: "1 hour 30 min 45 sec" - Balanced readability and length
|
|
225
|
+
* - **LONG**: "1 hour 30 minutes 45 seconds" - Full words with proper pluralization
|
|
226
|
+
* - **MOST_SIGNIFICANT**: Shows only the 2 most significant units
|
|
227
|
+
* - **TIME**: "1:30" - Clock-style hours:minutes format
|
|
228
|
+
* - **TIME_WITH_SECONDS**: "1:30:45" - Extended clock format with seconds
|
|
229
|
+
*
|
|
230
|
+
* @param format - The format string or predefined format name (default: 'CONCISE')
|
|
231
|
+
* @param options - Formatting options of type ITimeElapsedFormatOptions for fine-tuned control
|
|
232
|
+
* @returns The formatted time string
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* const elapsed = new ElapsedTime(5425000); // 1h 30m 25s
|
|
237
|
+
*
|
|
238
|
+
* // Predefined formats
|
|
239
|
+
* elapsed.Format('CONCISE'); // "1h 30m 25s"
|
|
240
|
+
* elapsed.Format('SHORT'); // "1hr 30min 25sec"
|
|
241
|
+
* elapsed.Format('MEDIUM'); // "1 hour 30 min 25 sec"
|
|
242
|
+
* elapsed.Format('LONG'); // "1 hour 30 minutes 25 seconds"
|
|
243
|
+
* elapsed.Format('TIME'); // "1:30"
|
|
244
|
+
* elapsed.Format('TIME_WITH_SECONDS'); // "1:30:25"
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* // Custom formatting with options
|
|
250
|
+
* const elapsed = new ElapsedTime(-5425000); // Negative duration
|
|
251
|
+
*
|
|
252
|
+
* const options = {
|
|
253
|
+
* negativeValueFormat: 'Parenthesis',
|
|
254
|
+
* maxUnits: 2,
|
|
255
|
+
* showZeroValues: false
|
|
256
|
+
* };
|
|
257
|
+
*
|
|
258
|
+
* elapsed.Format('MEDIUM', options); // "(1 hour 30 min)"
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* // Custom labels
|
|
264
|
+
* const elapsed = new ElapsedTime(5425000);
|
|
265
|
+
*
|
|
266
|
+
* const customOptions = {
|
|
267
|
+
* unitLabels: {
|
|
268
|
+
* hour: 'hrs',
|
|
269
|
+
* minute: 'mins',
|
|
270
|
+
* second: 'secs'
|
|
271
|
+
* }
|
|
272
|
+
* };
|
|
273
|
+
*
|
|
274
|
+
* elapsed.Format('CUSTOM', customOptions); // "1 hrs 30 mins 25 secs"
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
Format(format?: TTimeElapsedFormats, options?: Partial<ITimeElapsedFormatOptions>): string;
|
|
278
|
+
/**
|
|
279
|
+
* Special formatter for LONG format with proper pluralization.
|
|
280
|
+
* Handles the unique requirements of the LONG format which uses
|
|
281
|
+
* full English words with grammatically correct singular/plural forms.
|
|
282
|
+
*
|
|
283
|
+
* @param options - Formatting options with LONG-specific settings
|
|
284
|
+
* @returns Formatted string with proper pluralization (e.g., "1 hour 30 minutes")
|
|
285
|
+
* @private
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* // Internal usage - called automatically for LONG format
|
|
290
|
+
* const elapsed = new ElapsedTime(3661000); // 1 hour, 1 minute, 1 second
|
|
291
|
+
* elapsed.Format('LONG'); // "1 hour 1 minute 1 second" (all singular)
|
|
292
|
+
*
|
|
293
|
+
* const elapsed2 = new ElapsedTime(7322000); // 2 hours, 2 minutes, 2 seconds
|
|
294
|
+
* elapsed2.Format('LONG'); // "2 hours 2 minutes 2 seconds" (all plural)
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
private _FormatLong;
|
|
298
|
+
/**
|
|
299
|
+
* Format the elapsed time using the token-based formatting system.
|
|
300
|
+
* This is the main formatting engine that handles all predefined formats
|
|
301
|
+
* except LONG (which has special pluralization requirements).
|
|
302
|
+
*
|
|
303
|
+
* The method:
|
|
304
|
+
* 1. Creates an array of time units with their values
|
|
305
|
+
* 2. Filters and limits units based on options
|
|
306
|
+
* 3. Determines formatting approach (TIME vs standard formats)
|
|
307
|
+
* 4. Applies appropriate formatting and returns the result
|
|
308
|
+
*
|
|
309
|
+
* @param options - Complete formatting options with defaults applied
|
|
310
|
+
* @returns Formatted time string according to the specified format
|
|
311
|
+
* @private
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* // Internal usage - handles formats like CONCISE, SHORT, MEDIUM, TIME, etc.
|
|
316
|
+
* // Called automatically by Format() method for most format types
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
private _FormatUsingTokens;
|
|
320
|
+
/**
|
|
321
|
+
* Format time units for TIME and TIME_WITH_SECONDS formats
|
|
322
|
+
* These formats use special formatting with colons for displaying time (e.g., "1:30:45")
|
|
323
|
+
* @param units - Array of time units with their values
|
|
324
|
+
* @param unitLabels - Object containing label definitions for each time unit
|
|
325
|
+
* @returns Formatted time string with colons (e.g., "1:30:45")
|
|
326
|
+
* @private
|
|
327
|
+
*/
|
|
328
|
+
private static _FormatTimeUnits;
|
|
329
|
+
/**
|
|
330
|
+
* Format units for standard (non-time) formats
|
|
331
|
+
* Handles different formatting styles including CONCISE, SHORT, MEDIUM, LONG, and custom formats
|
|
332
|
+
* @param units - Array of time units with their values
|
|
333
|
+
* @param unitLabels - Object containing label definitions for each time unit
|
|
334
|
+
* @returns Formatted time string according to the specified format style
|
|
335
|
+
* @private
|
|
336
|
+
*/
|
|
337
|
+
private static _FormatStandardUnits;
|
|
338
|
+
/**
|
|
339
|
+
* Determine if the unit labels represent a time format with colons.
|
|
340
|
+
* Analyzes the unit label configuration to detect TIME and TIME_WITH_SECONDS
|
|
341
|
+
* formats which require special colon-separated formatting.
|
|
342
|
+
*
|
|
343
|
+
* @param unitLabels - The unit labels to analyze
|
|
344
|
+
* @returns True if this is a colon-based time format, false for standard formats
|
|
345
|
+
* @private
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```typescript
|
|
349
|
+
* // Internal usage - distinguishes between:
|
|
350
|
+
* // TIME format: "1:30" (colon-separated)
|
|
351
|
+
* // CONCISE format: "1h 30m" (space-separated with labels)
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
private static _ValidateTimeFormat;
|
|
355
|
+
/**
|
|
356
|
+
* Filter and limit time units based on formatting options.
|
|
357
|
+
* Applies showZeroValues and maxUnits options to determine which
|
|
358
|
+
* time components should be included in the final formatted output.
|
|
359
|
+
*
|
|
360
|
+
* @param units - All available time units with their calculated values
|
|
361
|
+
* @param options - Formatting options containing filtering rules
|
|
362
|
+
* @returns Filtered and limited array of time units for formatting
|
|
363
|
+
* @private
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```typescript
|
|
367
|
+
* // Internal usage - handles cases like:
|
|
368
|
+
* // showZeroValues: false -> filters out units with value 0
|
|
369
|
+
* // maxUnits: 2 -> keeps only the first 2 significant units
|
|
370
|
+
* // All zero values -> ensures at least "0 seconds" is shown
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
private static _FilterAndLimitUnits;
|
|
374
|
+
/**
|
|
375
|
+
* Apply negative value formatting based on user preferences.
|
|
376
|
+
* Wraps or modifies the formatted time string to indicate negative durations
|
|
377
|
+
* according to the specified negativeValueFormat option.
|
|
378
|
+
*
|
|
379
|
+
* @param output - The pre-formatted time string (positive representation)
|
|
380
|
+
* @param options - Formatting options containing negative value format preference
|
|
381
|
+
* @returns The formatted string with negative formatting applied if needed
|
|
382
|
+
* @private
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* // Internal usage - transforms positive format to negative representation:
|
|
387
|
+
* // NegativeSign: "1h 30m" -> "-1h 30m"
|
|
388
|
+
* // Parenthesis: "1h 30m" -> "(1h 30m)"
|
|
389
|
+
* // Brackets: "1h 30m" -> "[1h 30m]"
|
|
390
|
+
* // Empty: "1h 30m" -> "1h 30m" (no change)
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
private static _ApplyNegativeFormatting;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Formats elapsed time using the specified configuration.
|
|
397
|
+
* This is a simplified formatting function that uses IFormatConfig for basic formatting options.
|
|
398
|
+
*
|
|
399
|
+
* @param milliseconds - The total number of milliseconds to format
|
|
400
|
+
* @param options - Formatting configuration options
|
|
401
|
+
* @returns The formatted time string
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```typescript
|
|
405
|
+
* import { FormatElapsedTime } from './elapsed-time';
|
|
406
|
+
*
|
|
407
|
+
* console.log(FormatElapsedTime(3661000)); // "1h 1m 1s"
|
|
408
|
+
* console.log(FormatElapsedTime(3661000, { maxUnits: 1 })); // "1h"
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
export declare function FormatElapsedTime(milliseconds: number, options?: IFormatConfig): string;
|
|
412
|
+
//# sourceMappingURL=elapsed-time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elapsed-time.d.ts","sourceRoot":"","sources":["../../../src/time/elapsed-time/elapsed-time.ts"],"names":[],"mappings":"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"}
|