@transcommerce/cwm-shared 1.1.88 → 1.1.90
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/fesm2022/transcommerce-cwm-shared.mjs +814 -143
- package/fesm2022/transcommerce-cwm-shared.mjs.map +1 -1
- package/lib/components/external-navigation/external-navigation.component.d.ts +1 -1
- package/lib/components/navigate-to-route/navigate-to-route.component.d.ts +1 -1
- package/lib/components/page-not-found/page-not-found.component.d.ts +1 -1
- package/lib/cwm-shared-standalone.d.ts +19 -0
- package/lib/helpers/async-utils.d.ts +31 -3
- package/lib/helpers/jwt.d.ts +35 -0
- package/lib/helpers/time-span.d.ts +344 -0
- package/lib/helpers/utilities.d.ts +301 -0
- package/lib/modules/cwm-shared.module.d.ts +25 -10
- package/lib/pipes/safe-html.pipe.d.ts +1 -1
- package/lib/services/local-storage.service.d.ts +2 -0
- package/package.json +1 -1
- package/public-api.d.ts +9 -9
- package/lib/helpers/db-keys.d.ts +0 -18
- package/lib/helpers/time-span-overflow-error.d.ts +0 -2
|
@@ -13,5 +13,5 @@ export declare class ExternalNavigationComponent implements AfterViewInit {
|
|
|
13
13
|
navigateToExternalHref(): void;
|
|
14
14
|
onKeyPress($event: KeyboardEvent): void;
|
|
15
15
|
static ɵfac: i0.ɵɵFactoryDeclaration<ExternalNavigationComponent, never>;
|
|
16
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<ExternalNavigationComponent, "cwm-external-navigation", never, {}, {}, never, never,
|
|
16
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<ExternalNavigationComponent, "cwm-external-navigation", never, {}, {}, never, never, true, never>;
|
|
17
17
|
}
|
|
@@ -9,5 +9,5 @@ export declare class NavigateToRouteComponent implements AfterViewInit {
|
|
|
9
9
|
navigateToRoute(): void;
|
|
10
10
|
onKeyPress($event: KeyboardEvent): void;
|
|
11
11
|
static ɵfac: i0.ɵɵFactoryDeclaration<NavigateToRouteComponent, never>;
|
|
12
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<NavigateToRouteComponent, "cwm-navigate-to-route", never, {}, {}, never, never,
|
|
12
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<NavigateToRouteComponent, "cwm-navigate-to-route", never, {}, {}, never, never, true, never>;
|
|
13
13
|
}
|
|
@@ -12,5 +12,5 @@ export declare class PageNotFoundComponent implements OnInit, OnDestroy {
|
|
|
12
12
|
ngOnDestroy(): void;
|
|
13
13
|
private startRedirectTimer;
|
|
14
14
|
static ɵfac: i0.ɵɵFactoryDeclaration<PageNotFoundComponent, never>;
|
|
15
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<PageNotFoundComponent, "cwm-page-not-found", never, {}, {}, never, never,
|
|
15
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<PageNotFoundComponent, "cwm-page-not-found", never, {}, {}, never, never, true, never>;
|
|
16
16
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone Angular architecture for cwm-shared library
|
|
3
|
+
* Export all standalone components, pipes, directives, and injectable services
|
|
4
|
+
*/
|
|
5
|
+
export { ExternalNavigationComponent } from './components/external-navigation/external-navigation.component';
|
|
6
|
+
export { NavigateToRouteComponent } from './components/navigate-to-route/navigate-to-route.component';
|
|
7
|
+
export { PageNotFoundComponent } from './components/page-not-found/page-not-found.component';
|
|
8
|
+
export { SafeHtmlPipe } from './pipes/safe-html.pipe';
|
|
9
|
+
export { BaseApiService } from './services/base-api.service';
|
|
10
|
+
export type { IBaseApiService } from './services/ibase-api.service';
|
|
11
|
+
export { ClassLoggerService } from './services/class-logger.service';
|
|
12
|
+
export { ConfigService } from './services/config.service';
|
|
13
|
+
export { InventoryApiService } from './services/inventory-api.service';
|
|
14
|
+
export { LocalStorageService } from './services/local-storage.service';
|
|
15
|
+
export { LogService } from './services/log.service';
|
|
16
|
+
export { SubscriptionApiService } from './services/subscription-api.service';
|
|
17
|
+
export { msalInstanceFactory } from './factories/msal.instance.factory';
|
|
18
|
+
export { msalGuardConfigFactory } from './factories/msal.guard.config.factory';
|
|
19
|
+
export { msalInterceptorConfigFactory } from './factories/msal-interceptor-config.factory';
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module async-utils
|
|
3
|
+
* @description Utility functions for working with asynchronous code and managing concurrent task execution.
|
|
4
|
+
* Provides utilities for delays, promise management, and synchronization primitives for controlling
|
|
5
|
+
* the execution of async tasks to ensure only one task executes at a time for a given lock name.
|
|
6
|
+
*/
|
|
1
7
|
/**
|
|
2
8
|
* A wrapper around setTimeout which returns a promise. Useful for waiting for an amount of
|
|
3
9
|
* time from an async function. e.g. await waitFor(1000);
|
|
4
10
|
*
|
|
5
11
|
* @param milliseconds The amount of time to wait.
|
|
6
12
|
* @returns A promise that resolves once the given number of milliseconds has ellapsed.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Wait for 2 seconds before continuing
|
|
16
|
+
* await waitFor(2000);
|
|
17
|
+
* console.log('2 seconds have passed');
|
|
7
18
|
*/
|
|
8
19
|
export declare function waitFor(milliseconds: number): Promise<void>;
|
|
9
20
|
/**
|
|
@@ -14,8 +25,25 @@ export declare function waitFor(milliseconds: number): Promise<void>;
|
|
|
14
25
|
* lock name for a group of tasks you can ensure the only one task will ever be in progress
|
|
15
26
|
* at a given time.
|
|
16
27
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
28
|
+
* Uses a queue-based locking mechanism where tasks are executed in FIFO order. Each task must
|
|
29
|
+
* complete (or throw an error) before the next task in the queue begins execution.
|
|
30
|
+
*
|
|
31
|
+
* @param lockName The name of the lock to be obtained. Tasks with the same lock name will be serialized.
|
|
32
|
+
* @param task The task to execute. Should return a Promise.
|
|
33
|
+
* @returns The value returned by the task. Rejects if the task throws an error.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // Execute multiple API calls sequentially to prevent race conditions
|
|
37
|
+
* const result1 = await doWithLock('api-calls', async () => {
|
|
38
|
+
* return await fetchUser(userId);
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Multiple locks can run in parallel, but tasks with the same lock name are serialized
|
|
43
|
+
* await Promise.all([
|
|
44
|
+
* doWithLock('lock-a', () => slowTask1()),
|
|
45
|
+
* doWithLock('lock-a', () => slowTask2()), // Waits for slowTask1 to complete
|
|
46
|
+
* doWithLock('lock-b', () => otherTask()) // Runs in parallel with the lock-a tasks
|
|
47
|
+
* ]);
|
|
20
48
|
*/
|
|
21
49
|
export declare function doWithLock<T>(lockName: string, task: () => Promise<T>): Promise<T>;
|
package/lib/helpers/jwt.d.ts
CHANGED
|
@@ -1,2 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a JWT (JSON Web Token) and returns the decoded claims as an object.
|
|
3
|
+
*
|
|
4
|
+
* JWT tokens consist of three Base64-encoded parts separated by dots: header.payload.signature.
|
|
5
|
+
* This function decodes all parts and merges them into a single object, returning the combined result.
|
|
6
|
+
*
|
|
7
|
+
* @param token The JWT token string to decode. Can be a complete token or any of its parts.
|
|
8
|
+
* @returns An object containing the decoded claims from the token parts, or undefined if the token is empty or invalid.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
|
|
12
|
+
* const decoded = decodeToken(token);
|
|
13
|
+
* // Returns: { alg: 'HS256', typ: 'JWT', sub: '1234567890', name: 'John Doe', iat: 1516239022 }
|
|
14
|
+
*/
|
|
1
15
|
export declare function decodeToken(token: string): any;
|
|
16
|
+
/**
|
|
17
|
+
* Validates whether a JWT token is still valid based on its expiration time.
|
|
18
|
+
*
|
|
19
|
+
* This function checks the 'exp' (expiration) claim of a JWT token. The expiration time is
|
|
20
|
+
* expected to be a Unix timestamp (seconds since epoch). If the current time is less than the
|
|
21
|
+
* expiration time, the token is considered valid.
|
|
22
|
+
*
|
|
23
|
+
* @param input Either a JWT token string (from which the expiration will be extracted) or
|
|
24
|
+
* a Unix timestamp (expiration time in seconds). If invalid or undefined, returns false.
|
|
25
|
+
* @returns true if the token/timestamp has not yet expired, false otherwise.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Check if a token string is valid
|
|
29
|
+
* const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjk5OTk5OTk5OTl9.xxx';
|
|
30
|
+
* const isValid = isTokenValid(token); // true if not expired
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Check if an expiration timestamp is valid
|
|
34
|
+
* const futureTimestamp = Math.floor(Date.now() / 1000) + 3600; // 1 hour from now
|
|
35
|
+
* const isValid = isTokenValid(futureTimestamp); // true
|
|
36
|
+
*/
|
|
2
37
|
export declare function isTokenValid(input: string | number): boolean;
|
|
@@ -1,32 +1,376 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an error that occurs when a TimeSpan operation would result in a value
|
|
3
|
+
* that exceeds the safe bounds of a number in JavaScript.
|
|
4
|
+
*
|
|
5
|
+
* This error is thrown when:
|
|
6
|
+
* - Creating a TimeSpan from a value that, when multiplied by a time scale (e.g., days, hours),
|
|
7
|
+
* would exceed {@link TimeSpan.maxValue} or fall below {@link TimeSpan.minValue}
|
|
8
|
+
* - Adding or subtracting TimeSpan instances would result in overflow
|
|
9
|
+
* - Converting time components that would exceed safe integer bounds
|
|
10
|
+
*
|
|
11
|
+
* The safe bounds are defined by JavaScript's {@link Number.MAX_SAFE_INTEGER} and
|
|
12
|
+
* {@link Number.MIN_SAFE_INTEGER}.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* try {
|
|
16
|
+
* // This will throw TimeSpanOverflowError
|
|
17
|
+
* const hugeSpan = TimeSpan.fromDays(Number.MAX_SAFE_INTEGER);
|
|
18
|
+
* } catch (error) {
|
|
19
|
+
* if (error instanceof TimeSpanOverflowError) {
|
|
20
|
+
* console.log('TimeSpan duration exceeded safe bounds');
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
export declare class TimeSpanOverflowError extends Error {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Represents a time interval with support for days, hours, minutes, seconds, and milliseconds.
|
|
28
|
+
*
|
|
29
|
+
* The TimeSpan class provides a way to represent and work with time durations, similar to
|
|
30
|
+
* .NET's TimeSpan class. It stores time internally as milliseconds and provides various
|
|
31
|
+
* static factory methods to create instances from different time units.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Create a TimeSpan of 5 days
|
|
35
|
+
* const fiveDays = TimeSpan.fromDays(5);
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Create a TimeSpan from specific time components
|
|
39
|
+
* const timespan = TimeSpan.fromTime(2, 30, 45); // 2 hours, 30 minutes, 45 seconds
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Create a TimeSpan from a string representation
|
|
43
|
+
* const parsed = TimeSpan.fromString("5:30:45"); // 5 hours, 30 minutes, 45 seconds
|
|
44
|
+
*/
|
|
1
45
|
export declare class TimeSpan {
|
|
46
|
+
/** @private The number of milliseconds represented by this TimeSpan */
|
|
2
47
|
private _millis;
|
|
48
|
+
/**
|
|
49
|
+
* @private
|
|
50
|
+
* Creates a TimeSpan from a value and time scale.
|
|
51
|
+
* Converts the value using the provided scale factor and rounds the result.
|
|
52
|
+
*
|
|
53
|
+
* @param value - The numeric value to convert
|
|
54
|
+
* @param scale - The scale factor (e.g., MILLIS_PER_DAY) to multiply by
|
|
55
|
+
* @returns A new TimeSpan instance
|
|
56
|
+
* @throws {Error} If value is NaN
|
|
57
|
+
* @throws {TimeSpanOverflowError} If the resulting milliseconds exceed safe integer bounds
|
|
58
|
+
*/
|
|
3
59
|
private static interval;
|
|
60
|
+
/**
|
|
61
|
+
* @private
|
|
62
|
+
* Rounds a number towards zero (floor for positive, ceil for negative).
|
|
63
|
+
*
|
|
64
|
+
* @param n - The number to round
|
|
65
|
+
* @returns The rounded number
|
|
66
|
+
*/
|
|
4
67
|
private static round;
|
|
68
|
+
/**
|
|
69
|
+
* @private
|
|
70
|
+
* Converts time components (hours, minutes, seconds) to milliseconds.
|
|
71
|
+
* Validates that the total does not exceed TimeSpan bounds.
|
|
72
|
+
*
|
|
73
|
+
* @param hour - The number of hours (0-23 for typical usage)
|
|
74
|
+
* @param minute - The number of minutes (0-59)
|
|
75
|
+
* @param second - The number of seconds (0-59)
|
|
76
|
+
* @returns The total milliseconds
|
|
77
|
+
* @throws {TimeSpanOverflowError} If the total seconds exceed safe bounds
|
|
78
|
+
*/
|
|
5
79
|
private static timeToMilliseconds;
|
|
80
|
+
/**
|
|
81
|
+
* Gets a TimeSpan instance representing zero duration.
|
|
82
|
+
*
|
|
83
|
+
* @returns A TimeSpan with 0 milliseconds
|
|
84
|
+
*/
|
|
6
85
|
static get zero(): TimeSpan;
|
|
86
|
+
/**
|
|
87
|
+
* Gets the maximum possible TimeSpan value.
|
|
88
|
+
* Uses JavaScript's MAX_SAFE_INTEGER as the underlying millisecond limit.
|
|
89
|
+
*
|
|
90
|
+
* @returns A TimeSpan with the maximum safe integer milliseconds
|
|
91
|
+
*/
|
|
7
92
|
static get maxValue(): TimeSpan;
|
|
93
|
+
/**
|
|
94
|
+
* Gets the minimum possible TimeSpan value.
|
|
95
|
+
* Uses JavaScript's MIN_SAFE_INTEGER as the underlying millisecond limit.
|
|
96
|
+
*
|
|
97
|
+
* @returns A TimeSpan with the minimum safe integer milliseconds
|
|
98
|
+
*/
|
|
8
99
|
static get minValue(): TimeSpan;
|
|
100
|
+
/**
|
|
101
|
+
* Creates a TimeSpan from a number of days.
|
|
102
|
+
*
|
|
103
|
+
* @param value - The number of days
|
|
104
|
+
* @returns A new TimeSpan instance representing the specified duration
|
|
105
|
+
* @throws {Error} If value is NaN
|
|
106
|
+
* @throws {TimeSpanOverflowError} If the result exceeds safe bounds
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* const span = TimeSpan.fromDays(7); // 7 days
|
|
110
|
+
*/
|
|
9
111
|
static fromDays(value: number): TimeSpan;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a TimeSpan from a number of hours.
|
|
114
|
+
*
|
|
115
|
+
* @param value - The number of hours
|
|
116
|
+
* @returns A new TimeSpan instance representing the specified duration
|
|
117
|
+
* @throws {Error} If value is NaN
|
|
118
|
+
* @throws {TimeSpanOverflowError} If the result exceeds safe bounds
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* const span = TimeSpan.fromHours(24); // 24 hours = 1 day
|
|
122
|
+
*/
|
|
10
123
|
static fromHours(value: number): TimeSpan;
|
|
124
|
+
/**
|
|
125
|
+
* Creates a TimeSpan from a number of milliseconds.
|
|
126
|
+
*
|
|
127
|
+
* @param value - The number of milliseconds
|
|
128
|
+
* @returns A new TimeSpan instance representing the specified duration
|
|
129
|
+
* @throws {Error} If value is NaN
|
|
130
|
+
* @throws {TimeSpanOverflowError} If the result exceeds safe bounds
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* const span = TimeSpan.fromMilliseconds(5000); // 5 seconds
|
|
134
|
+
*/
|
|
11
135
|
static fromMilliseconds(value: number): TimeSpan;
|
|
136
|
+
/**
|
|
137
|
+
* Creates a TimeSpan from a number of minutes.
|
|
138
|
+
*
|
|
139
|
+
* @param value - The number of minutes
|
|
140
|
+
* @returns A new TimeSpan instance representing the specified duration
|
|
141
|
+
* @throws {Error} If value is NaN
|
|
142
|
+
* @throws {TimeSpanOverflowError} If the result exceeds safe bounds
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* const span = TimeSpan.fromMinutes(60); // 60 minutes = 1 hour
|
|
146
|
+
*/
|
|
12
147
|
static fromMinutes(value: number): TimeSpan;
|
|
148
|
+
/**
|
|
149
|
+
* Creates a TimeSpan from a number of seconds.
|
|
150
|
+
*
|
|
151
|
+
* @param value - The number of seconds
|
|
152
|
+
* @returns A new TimeSpan instance representing the specified duration
|
|
153
|
+
* @throws {Error} If value is NaN
|
|
154
|
+
* @throws {TimeSpanOverflowError} If the result exceeds safe bounds
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* const span = TimeSpan.fromSeconds(300); // 300 seconds = 5 minutes
|
|
158
|
+
*/
|
|
13
159
|
static fromSeconds(value: number): TimeSpan;
|
|
160
|
+
/**
|
|
161
|
+
* Creates a TimeSpan from time components.
|
|
162
|
+
*
|
|
163
|
+
* This method has two overloads:
|
|
164
|
+
* 1. fromTime(hours, minutes, seconds) - Creates a TimeSpan with hours, minutes, and seconds
|
|
165
|
+
* 2. fromTime(days, hours, minutes, seconds, milliseconds) - Creates a TimeSpan with all components
|
|
166
|
+
*
|
|
167
|
+
* @overload
|
|
168
|
+
* @param hours - The number of hours (0-23 for typical usage)
|
|
169
|
+
* @param minutes - The number of minutes (0-59)
|
|
170
|
+
* @param seconds - The number of seconds (0-59)
|
|
171
|
+
* @returns A new TimeSpan instance representing the specified duration
|
|
172
|
+
*
|
|
173
|
+
* @overload
|
|
174
|
+
* @param days - The number of days
|
|
175
|
+
* @param hours - The number of hours (0-23 for typical usage)
|
|
176
|
+
* @param minutes - The number of minutes (0-59)
|
|
177
|
+
* @param seconds - The number of seconds (0-59)
|
|
178
|
+
* @param milliseconds - The number of milliseconds (0-999)
|
|
179
|
+
* @returns A new TimeSpan instance representing the specified duration
|
|
180
|
+
*
|
|
181
|
+
* @throws {TimeSpanOverflowError} If the total exceeds safe bounds
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* // Create 2 hours, 30 minutes, 45 seconds
|
|
185
|
+
* const span1 = TimeSpan.fromTime(2, 30, 45);
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* // Create 5 days, 2 hours, 30 minutes, 45 seconds, 500 milliseconds
|
|
189
|
+
* const span2 = TimeSpan.fromTime(5, 2, 30, 45, 500);
|
|
190
|
+
*/
|
|
14
191
|
static fromTime(hours: number, minutes: number, seconds: number): TimeSpan;
|
|
15
192
|
static fromTime(days: number, hours: number, minutes: number, seconds: number, milliseconds: number): TimeSpan;
|
|
193
|
+
/**
|
|
194
|
+
* @private
|
|
195
|
+
* Creates a TimeSpan from hours, minutes, and seconds components.
|
|
196
|
+
*
|
|
197
|
+
* @param hours - The number of hours
|
|
198
|
+
* @param minutes - The number of minutes
|
|
199
|
+
* @param seconds - The number of seconds
|
|
200
|
+
* @returns A new TimeSpan instance
|
|
201
|
+
* @throws {TimeSpanOverflowError} If the total exceeds safe bounds
|
|
202
|
+
*/
|
|
16
203
|
private static fromTimeStartingFromHours;
|
|
204
|
+
/**
|
|
205
|
+
* @private
|
|
206
|
+
* Creates a TimeSpan from all time components (days through milliseconds).
|
|
207
|
+
*
|
|
208
|
+
* @param days - The number of days
|
|
209
|
+
* @param hours - The number of hours
|
|
210
|
+
* @param minutes - The number of minutes
|
|
211
|
+
* @param seconds - The number of seconds
|
|
212
|
+
* @param milliseconds - The number of milliseconds
|
|
213
|
+
* @returns A new TimeSpan instance
|
|
214
|
+
* @throws {TimeSpanOverflowError} If the total exceeds safe bounds
|
|
215
|
+
*/
|
|
17
216
|
private static fromTimeStartingFromDays;
|
|
217
|
+
/**
|
|
218
|
+
* Creates a new TimeSpan instance with the specified number of milliseconds.
|
|
219
|
+
*
|
|
220
|
+
* @param millis - The total number of milliseconds
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* const span = new TimeSpan(5000); // 5 seconds
|
|
224
|
+
*/
|
|
18
225
|
constructor(millis: number);
|
|
226
|
+
/**
|
|
227
|
+
* Gets the day component of this TimeSpan (0-31+).
|
|
228
|
+
* This returns only the day portion, not the total days.
|
|
229
|
+
*
|
|
230
|
+
* @returns The number of whole days
|
|
231
|
+
* @example
|
|
232
|
+
* const span = TimeSpan.fromTime(1, 5, 30, 0); // 1 day, 5 hours, 30 minutes
|
|
233
|
+
* console.log(span.days); // 1
|
|
234
|
+
*/
|
|
19
235
|
get days(): number;
|
|
236
|
+
/**
|
|
237
|
+
* Gets the hours component of this TimeSpan (0-23).
|
|
238
|
+
* This returns only the hours portion within a day, not the total hours.
|
|
239
|
+
*
|
|
240
|
+
* @returns The number of hours (0-23)
|
|
241
|
+
* @example
|
|
242
|
+
* const span = TimeSpan.fromTime(25, 30, 0); // 25 hours, 30 minutes
|
|
243
|
+
* console.log(span.hours); // 1 (25 % 24)
|
|
244
|
+
*/
|
|
20
245
|
get hours(): number;
|
|
246
|
+
/**
|
|
247
|
+
* Gets the minutes component of this TimeSpan (0-59).
|
|
248
|
+
* This returns only the minutes portion within an hour, not the total minutes.
|
|
249
|
+
*
|
|
250
|
+
* @returns The number of minutes (0-59)
|
|
251
|
+
* @example
|
|
252
|
+
* const span = TimeSpan.fromTime(0, 90, 0); // 90 minutes
|
|
253
|
+
* console.log(span.minutes); // 30 (90 % 60)
|
|
254
|
+
*/
|
|
21
255
|
get minutes(): number;
|
|
256
|
+
/**
|
|
257
|
+
* Gets the seconds component of this TimeSpan (0-59).
|
|
258
|
+
* This returns only the seconds portion within a minute, not the total seconds.
|
|
259
|
+
*
|
|
260
|
+
* @returns The number of seconds (0-59)
|
|
261
|
+
* @example
|
|
262
|
+
* const span = TimeSpan.fromTime(0, 0, 90); // 90 seconds
|
|
263
|
+
* console.log(span.seconds); // 30 (90 % 60)
|
|
264
|
+
*/
|
|
22
265
|
get seconds(): number;
|
|
266
|
+
/**
|
|
267
|
+
* Gets the milliseconds component of this TimeSpan (0-999).
|
|
268
|
+
* This returns only the milliseconds portion within a second, not the total milliseconds.
|
|
269
|
+
*
|
|
270
|
+
* @returns The number of milliseconds (0-999)
|
|
271
|
+
* @example
|
|
272
|
+
* const span = TimeSpan.fromTime(0, 0, 0, 1, 500); // 1 second, 500 milliseconds
|
|
273
|
+
* console.log(span.milliseconds); // 500
|
|
274
|
+
*/
|
|
23
275
|
get milliseconds(): number;
|
|
276
|
+
/**
|
|
277
|
+
* Gets the total number of days in this TimeSpan.
|
|
278
|
+
* Unlike the {@link days} property, this returns the complete duration in days as a decimal.
|
|
279
|
+
*
|
|
280
|
+
* @returns The total duration in days
|
|
281
|
+
* @example
|
|
282
|
+
* const span = TimeSpan.fromHours(30); // 30 hours
|
|
283
|
+
* console.log(span.totalDays); // 1.25
|
|
284
|
+
*/
|
|
24
285
|
get totalDays(): number;
|
|
286
|
+
/**
|
|
287
|
+
* Gets the total number of hours in this TimeSpan.
|
|
288
|
+
* Unlike the {@link hours} property, this returns the complete duration in hours as a decimal.
|
|
289
|
+
*
|
|
290
|
+
* @returns The total duration in hours
|
|
291
|
+
* @example
|
|
292
|
+
* const span = TimeSpan.fromMinutes(90); // 90 minutes
|
|
293
|
+
* console.log(span.totalHours); // 1.5
|
|
294
|
+
*/
|
|
25
295
|
get totalHours(): number;
|
|
296
|
+
/**
|
|
297
|
+
* Gets the total number of minutes in this TimeSpan.
|
|
298
|
+
* Unlike the {@link minutes} property, this returns the complete duration in minutes as a decimal.
|
|
299
|
+
*
|
|
300
|
+
* @returns The total duration in minutes
|
|
301
|
+
* @example
|
|
302
|
+
* const span = TimeSpan.fromSeconds(150); // 150 seconds
|
|
303
|
+
* console.log(span.totalMinutes); // 2.5
|
|
304
|
+
*/
|
|
26
305
|
get totalMinutes(): number;
|
|
306
|
+
/**
|
|
307
|
+
* Gets the total number of seconds in this TimeSpan.
|
|
308
|
+
* Unlike the {@link seconds} property, this returns the complete duration in seconds as a decimal.
|
|
309
|
+
*
|
|
310
|
+
* @returns The total duration in seconds
|
|
311
|
+
* @example
|
|
312
|
+
* const span = TimeSpan.fromMilliseconds(5500); // 5500 milliseconds
|
|
313
|
+
* console.log(span.totalSeconds); // 5.5
|
|
314
|
+
*/
|
|
27
315
|
get totalSeconds(): number;
|
|
316
|
+
/**
|
|
317
|
+
* Gets the total number of milliseconds in this TimeSpan.
|
|
318
|
+
*
|
|
319
|
+
* @returns The total duration in milliseconds
|
|
320
|
+
* @example
|
|
321
|
+
* const span = TimeSpan.fromSeconds(2); // 2 seconds
|
|
322
|
+
* console.log(span.totalMilliseconds); // 2000
|
|
323
|
+
*/
|
|
28
324
|
get totalMilliseconds(): number;
|
|
325
|
+
/**
|
|
326
|
+
* Returns a new TimeSpan that represents the sum of this instance and the specified TimeSpan.
|
|
327
|
+
*
|
|
328
|
+
* @param ts - The TimeSpan to add
|
|
329
|
+
* @returns A new TimeSpan representing the sum
|
|
330
|
+
* @throws {TimeSpanOverflowError} If the result exceeds safe integer bounds
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* const span1 = TimeSpan.fromHours(2);
|
|
334
|
+
* const span2 = TimeSpan.fromHours(3);
|
|
335
|
+
* const span3 = span1.add(span2);
|
|
336
|
+
* console.log(span3.totalHours); // 5
|
|
337
|
+
*/
|
|
29
338
|
add(ts: TimeSpan): TimeSpan;
|
|
339
|
+
/**
|
|
340
|
+
* Returns a new TimeSpan that represents the difference between this instance and the specified TimeSpan.
|
|
341
|
+
*
|
|
342
|
+
* @param ts - The TimeSpan to subtract
|
|
343
|
+
* @returns A new TimeSpan representing the difference
|
|
344
|
+
* @throws {TimeSpanOverflowError} If the result exceeds safe integer bounds
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* const span1 = TimeSpan.fromHours(5);
|
|
348
|
+
* const span2 = TimeSpan.fromHours(2);
|
|
349
|
+
* const span3 = span1.subtract(span2);
|
|
350
|
+
* console.log(span3.totalHours); // 3
|
|
351
|
+
*/
|
|
30
352
|
subtract(ts: TimeSpan): TimeSpan;
|
|
353
|
+
/**
|
|
354
|
+
* Creates a TimeSpan from a string representation.
|
|
355
|
+
*
|
|
356
|
+
* Supports two string formats:
|
|
357
|
+
* 1. "HH:mm:ss" - Hours, minutes, seconds (e.g., "5:30:45")
|
|
358
|
+
* 2. "d.HH:mm:ss.fff" - Days, hours, minutes, seconds, milliseconds (e.g., "5.02:30:45.500")
|
|
359
|
+
*
|
|
360
|
+
* @param value - The string representation of a TimeSpan
|
|
361
|
+
* @returns A new TimeSpan instance parsed from the string
|
|
362
|
+
* @throws {Error} If the string format is invalid or values cannot be parsed as integers
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* // Parse hours:minutes:seconds
|
|
366
|
+
* const span1 = TimeSpan.fromString("5:30:45");
|
|
367
|
+
* console.log(span1.totalSeconds); // 19845
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* // Parse days.hours:minutes:seconds.milliseconds
|
|
371
|
+
* const span2 = TimeSpan.fromString("5.02:30:45.500");
|
|
372
|
+
* console.log(span2.days); // 5
|
|
373
|
+
* console.log(span2.milliseconds); // 500
|
|
374
|
+
*/
|
|
31
375
|
static fromString(value: string): TimeSpan;
|
|
32
376
|
}
|