@develia/commons 0.4.23 → 0.4.25
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/dist/array.d.ts.map +1 -0
- package/dist/array.js.map +1 -0
- package/dist/async-pool-executor.d.ts.map +1 -0
- package/dist/async-pool-executor.js.map +1 -0
- package/dist/browser/form-utilities.d.ts.map +1 -0
- package/dist/browser/form-utilities.js.map +1 -0
- package/dist/browser/geo-location.d.ts.map +1 -0
- package/dist/browser/geo-location.js.map +1 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/native-bridge.d.ts.map +1 -0
- package/dist/browser/native-bridge.js.map +1 -0
- package/dist/cancellable-promise.d.ts.map +1 -0
- package/dist/cancellable-promise.js.map +1 -0
- package/dist/clean-url-search-params.d.ts.map +1 -0
- package/dist/clean-url-search-params.js.map +1 -0
- package/dist/collections/cache-dictionary.d.ts.map +1 -0
- package/dist/collections/cache-dictionary.js.map +1 -0
- package/dist/collections/default-map.d.ts.map +1 -0
- package/dist/collections/default-map.js.map +1 -0
- package/dist/collections/default-weak-map.d.ts.map +1 -0
- package/dist/collections/default-weak-map.js.map +1 -0
- package/dist/collections/from.d.ts.map +1 -0
- package/dist/collections/from.js.map +1 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/collections/index.js.map +1 -0
- package/dist/debouncer.d.ts +60 -0
- package/dist/debouncer.d.ts.map +1 -0
- package/dist/debouncer.js +118 -0
- package/dist/debouncer.js.map +1 -0
- package/dist/draft.d.ts.map +1 -0
- package/dist/draft.js.map +1 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js.map +1 -0
- package/dist/{types/functions.d.ts → functions.d.ts} +5 -35
- package/dist/functions.d.ts.map +1 -0
- package/dist/{esm/functions.js → functions.js} +0 -85
- package/dist/functions.js.map +1 -0
- package/dist/{types/index.d.ts → index.d.ts} +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{web/index.js → index.js} +2 -0
- package/dist/index.js.map +1 -0
- package/dist/key-value-pair.d.ts.map +1 -0
- package/dist/key-value-pair.js.map +1 -0
- package/dist/keyed-debouncer.d.ts +56 -0
- package/dist/keyed-debouncer.d.ts.map +1 -0
- package/dist/keyed-debouncer.js +109 -0
- package/dist/keyed-debouncer.js.map +1 -0
- package/dist/lazy.d.ts.map +1 -0
- package/dist/lazy.js.map +1 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js.map +1 -0
- package/dist/order.d.ts.map +1 -0
- package/dist/order.js.map +1 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js.map +1 -0
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js.map +1 -0
- package/dist/range.d.ts.map +1 -0
- package/dist/range.js.map +1 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js.map +1 -0
- package/dist/stopwatch.d.ts.map +1 -0
- package/dist/stopwatch.js.map +1 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js.map +1 -0
- package/dist/timer.d.ts.map +1 -0
- package/dist/timer.js.map +1 -0
- package/dist/timespan.d.ts.map +1 -0
- package/dist/timespan.js.map +1 -0
- package/dist/triggers.d.ts.map +1 -0
- package/dist/triggers.js.map +1 -0
- package/dist/type-code.d.ts.map +1 -0
- package/dist/type-code.js.map +1 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js.map +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js.map +1 -0
- package/dist/{types/utilities.d.ts → utilities.d.ts} +8 -3
- package/dist/utilities.d.ts.map +1 -0
- package/dist/{web/utilities.js → utilities.js} +27 -4
- package/dist/utilities.js.map +1 -0
- package/package.json +13 -62
- package/src/debouncer.ts +135 -0
- package/src/functions.ts +5 -114
- package/src/index.ts +4 -0
- package/src/keyed-debouncer.ts +121 -0
- package/src/utilities.ts +30 -4
- package/dist/cjs/array.js +0 -106
- package/dist/cjs/array.js.map +0 -1
- package/dist/cjs/async-pool-executor.js +0 -79
- package/dist/cjs/async-pool-executor.js.map +0 -1
- package/dist/cjs/browser/form-utilities.js +0 -162
- package/dist/cjs/browser/form-utilities.js.map +0 -1
- package/dist/cjs/browser/geo-location.js +0 -78
- package/dist/cjs/browser/geo-location.js.map +0 -1
- package/dist/cjs/browser/index.js +0 -99
- package/dist/cjs/browser/index.js.map +0 -1
- package/dist/cjs/browser/native-bridge.js +0 -81
- package/dist/cjs/browser/native-bridge.js.map +0 -1
- package/dist/cjs/cancellable-promise.js +0 -81
- package/dist/cjs/cancellable-promise.js.map +0 -1
- package/dist/cjs/clean-url-search-params.js +0 -34
- package/dist/cjs/clean-url-search-params.js.map +0 -1
- package/dist/cjs/collections/cache-dictionary.js +0 -102
- package/dist/cjs/collections/cache-dictionary.js.map +0 -1
- package/dist/cjs/collections/default-map.js +0 -45
- package/dist/cjs/collections/default-map.js.map +0 -1
- package/dist/cjs/collections/default-weak-map.js +0 -46
- package/dist/cjs/collections/default-weak-map.js.map +0 -1
- package/dist/cjs/collections/from.js +0 -778
- package/dist/cjs/collections/from.js.map +0 -1
- package/dist/cjs/collections/index.js +0 -15
- package/dist/cjs/collections/index.js.map +0 -1
- package/dist/cjs/draft.js +0 -225
- package/dist/cjs/draft.js.map +0 -1
- package/dist/cjs/event-bus.js +0 -71
- package/dist/cjs/event-bus.js.map +0 -1
- package/dist/cjs/functions.js +0 -348
- package/dist/cjs/functions.js.map +0 -1
- package/dist/cjs/index.js +0 -80
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/key-value-pair.js +0 -22
- package/dist/cjs/key-value-pair.js.map +0 -1
- package/dist/cjs/lazy.js +0 -29
- package/dist/cjs/lazy.js.map +0 -1
- package/dist/cjs/math.js +0 -37
- package/dist/cjs/math.js.map +0 -1
- package/dist/cjs/order.js +0 -9
- package/dist/cjs/order.js.map +0 -1
- package/dist/cjs/parse.js +0 -174
- package/dist/cjs/parse.js.map +0 -1
- package/dist/cjs/patch.js +0 -52
- package/dist/cjs/patch.js.map +0 -1
- package/dist/cjs/range.js +0 -154
- package/dist/cjs/range.js.map +0 -1
- package/dist/cjs/result.js +0 -3
- package/dist/cjs/result.js.map +0 -1
- package/dist/cjs/stopwatch.js +0 -46
- package/dist/cjs/stopwatch.js.map +0 -1
- package/dist/cjs/string.js +0 -154
- package/dist/cjs/string.js.map +0 -1
- package/dist/cjs/timer.js +0 -57
- package/dist/cjs/timer.js.map +0 -1
- package/dist/cjs/timespan.js +0 -367
- package/dist/cjs/timespan.js.map +0 -1
- package/dist/cjs/triggers.js +0 -103
- package/dist/cjs/triggers.js.map +0 -1
- package/dist/cjs/type-code.js +0 -18
- package/dist/cjs/type-code.js.map +0 -1
- package/dist/cjs/type.js +0 -296
- package/dist/cjs/type.js.map +0 -1
- package/dist/cjs/types.js +0 -3
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/utilities.js +0 -598
- package/dist/cjs/utilities.js.map +0 -1
- package/dist/esm/array.js.map +0 -1
- package/dist/esm/async-pool-executor.js.map +0 -1
- package/dist/esm/browser/form-utilities.js.map +0 -1
- package/dist/esm/browser/geo-location.js.map +0 -1
- package/dist/esm/browser/index.js.map +0 -1
- package/dist/esm/browser/native-bridge.js.map +0 -1
- package/dist/esm/cancellable-promise.js.map +0 -1
- package/dist/esm/clean-url-search-params.js.map +0 -1
- package/dist/esm/collections/cache-dictionary.js.map +0 -1
- package/dist/esm/collections/default-map.js.map +0 -1
- package/dist/esm/collections/default-weak-map.js.map +0 -1
- package/dist/esm/collections/from.js.map +0 -1
- package/dist/esm/collections/index.js.map +0 -1
- package/dist/esm/draft.js.map +0 -1
- package/dist/esm/event-bus.js.map +0 -1
- package/dist/esm/functions.js.map +0 -1
- package/dist/esm/index.js +0 -38
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/key-value-pair.js.map +0 -1
- package/dist/esm/lazy.js.map +0 -1
- package/dist/esm/math.js.map +0 -1
- package/dist/esm/order.js.map +0 -1
- package/dist/esm/parse.js.map +0 -1
- package/dist/esm/patch.js.map +0 -1
- package/dist/esm/range.js.map +0 -1
- package/dist/esm/result.js.map +0 -1
- package/dist/esm/stopwatch.js.map +0 -1
- package/dist/esm/string.js.map +0 -1
- package/dist/esm/timer.js.map +0 -1
- package/dist/esm/timespan.js.map +0 -1
- package/dist/esm/triggers.js.map +0 -1
- package/dist/esm/type-code.js.map +0 -1
- package/dist/esm/type.js.map +0 -1
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utilities.js +0 -567
- package/dist/esm/utilities.js.map +0 -1
- package/dist/types/array.d.ts.map +0 -1
- package/dist/types/async-pool-executor.d.ts.map +0 -1
- package/dist/types/browser/form-utilities.d.ts.map +0 -1
- package/dist/types/browser/geo-location.d.ts.map +0 -1
- package/dist/types/browser/index.d.ts.map +0 -1
- package/dist/types/browser/native-bridge.d.ts.map +0 -1
- package/dist/types/cancellable-promise.d.ts.map +0 -1
- package/dist/types/clean-url-search-params.d.ts.map +0 -1
- package/dist/types/collections/cache-dictionary.d.ts.map +0 -1
- package/dist/types/collections/default-map.d.ts.map +0 -1
- package/dist/types/collections/default-weak-map.d.ts.map +0 -1
- package/dist/types/collections/from.d.ts.map +0 -1
- package/dist/types/collections/index.d.ts.map +0 -1
- package/dist/types/draft.d.ts.map +0 -1
- package/dist/types/event-bus.d.ts.map +0 -1
- package/dist/types/functions.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/key-value-pair.d.ts.map +0 -1
- package/dist/types/lazy.d.ts.map +0 -1
- package/dist/types/math.d.ts.map +0 -1
- package/dist/types/order.d.ts.map +0 -1
- package/dist/types/parse.d.ts.map +0 -1
- package/dist/types/patch.d.ts.map +0 -1
- package/dist/types/range.d.ts.map +0 -1
- package/dist/types/result.d.ts.map +0 -1
- package/dist/types/stopwatch.d.ts.map +0 -1
- package/dist/types/string.d.ts.map +0 -1
- package/dist/types/timer.d.ts.map +0 -1
- package/dist/types/timespan.d.ts.map +0 -1
- package/dist/types/triggers.d.ts.map +0 -1
- package/dist/types/type-code.d.ts.map +0 -1
- package/dist/types/type.d.ts.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/utilities.d.ts.map +0 -1
- package/dist/web/array.js +0 -98
- package/dist/web/array.js.map +0 -1
- package/dist/web/async-pool-executor.js +0 -76
- package/dist/web/async-pool-executor.js.map +0 -1
- package/dist/web/browser/form-utilities.js +0 -155
- package/dist/web/browser/form-utilities.js.map +0 -1
- package/dist/web/browser/geo-location.js +0 -75
- package/dist/web/browser/geo-location.js.map +0 -1
- package/dist/web/browser/index.js +0 -75
- package/dist/web/browser/index.js.map +0 -1
- package/dist/web/browser/native-bridge.js +0 -78
- package/dist/web/browser/native-bridge.js.map +0 -1
- package/dist/web/cancellable-promise.js +0 -78
- package/dist/web/cancellable-promise.js.map +0 -1
- package/dist/web/clean-url-search-params.js +0 -31
- package/dist/web/clean-url-search-params.js.map +0 -1
- package/dist/web/collections/cache-dictionary.js +0 -99
- package/dist/web/collections/cache-dictionary.js.map +0 -1
- package/dist/web/collections/default-map.js +0 -42
- package/dist/web/collections/default-map.js.map +0 -1
- package/dist/web/collections/default-weak-map.js +0 -43
- package/dist/web/collections/default-weak-map.js.map +0 -1
- package/dist/web/collections/from.js +0 -770
- package/dist/web/collections/from.js.map +0 -1
- package/dist/web/collections/index.js +0 -5
- package/dist/web/collections/index.js.map +0 -1
- package/dist/web/draft.js +0 -222
- package/dist/web/draft.js.map +0 -1
- package/dist/web/event-bus.js +0 -66
- package/dist/web/event-bus.js.map +0 -1
- package/dist/web/functions.js +0 -336
- package/dist/web/functions.js.map +0 -1
- package/dist/web/index.js.map +0 -1
- package/dist/web/key-value-pair.js +0 -19
- package/dist/web/key-value-pair.js.map +0 -1
- package/dist/web/lazy.js +0 -26
- package/dist/web/lazy.js.map +0 -1
- package/dist/web/math.js +0 -33
- package/dist/web/math.js.map +0 -1
- package/dist/web/order.js +0 -7
- package/dist/web/order.js.map +0 -1
- package/dist/web/parse.js +0 -169
- package/dist/web/parse.js.map +0 -1
- package/dist/web/patch.js +0 -48
- package/dist/web/patch.js.map +0 -1
- package/dist/web/range.js +0 -151
- package/dist/web/range.js.map +0 -1
- package/dist/web/result.js +0 -2
- package/dist/web/result.js.map +0 -1
- package/dist/web/stopwatch.js +0 -40
- package/dist/web/stopwatch.js.map +0 -1
- package/dist/web/string.js +0 -142
- package/dist/web/string.js.map +0 -1
- package/dist/web/timer.js +0 -54
- package/dist/web/timer.js.map +0 -1
- package/dist/web/timespan.js +0 -365
- package/dist/web/timespan.js.map +0 -1
- package/dist/web/triggers.js +0 -99
- package/dist/web/triggers.js.map +0 -1
- package/dist/web/type-code.js +0 -16
- package/dist/web/type-code.js.map +0 -1
- package/dist/web/type.js +0 -292
- package/dist/web/type.js.map +0 -1
- package/dist/web/types.js +0 -2
- package/dist/web/types.js.map +0 -1
- package/dist/web/utilities.js.map +0 -1
- /package/dist/{types/array.d.ts → array.d.ts} +0 -0
- /package/dist/{esm/array.js → array.js} +0 -0
- /package/dist/{types/async-pool-executor.d.ts → async-pool-executor.d.ts} +0 -0
- /package/dist/{esm/async-pool-executor.js → async-pool-executor.js} +0 -0
- /package/dist/{types/browser → browser}/form-utilities.d.ts +0 -0
- /package/dist/{esm/browser → browser}/form-utilities.js +0 -0
- /package/dist/{types/browser → browser}/geo-location.d.ts +0 -0
- /package/dist/{esm/browser → browser}/geo-location.js +0 -0
- /package/dist/{types/browser → browser}/index.d.ts +0 -0
- /package/dist/{esm/browser → browser}/index.js +0 -0
- /package/dist/{types/browser → browser}/native-bridge.d.ts +0 -0
- /package/dist/{esm/browser → browser}/native-bridge.js +0 -0
- /package/dist/{types/cancellable-promise.d.ts → cancellable-promise.d.ts} +0 -0
- /package/dist/{esm/cancellable-promise.js → cancellable-promise.js} +0 -0
- /package/dist/{types/clean-url-search-params.d.ts → clean-url-search-params.d.ts} +0 -0
- /package/dist/{esm/clean-url-search-params.js → clean-url-search-params.js} +0 -0
- /package/dist/{types/collections → collections}/cache-dictionary.d.ts +0 -0
- /package/dist/{esm/collections → collections}/cache-dictionary.js +0 -0
- /package/dist/{types/collections → collections}/default-map.d.ts +0 -0
- /package/dist/{esm/collections → collections}/default-map.js +0 -0
- /package/dist/{types/collections → collections}/default-weak-map.d.ts +0 -0
- /package/dist/{esm/collections → collections}/default-weak-map.js +0 -0
- /package/dist/{types/collections → collections}/from.d.ts +0 -0
- /package/dist/{esm/collections → collections}/from.js +0 -0
- /package/dist/{types/collections → collections}/index.d.ts +0 -0
- /package/dist/{esm/collections → collections}/index.js +0 -0
- /package/dist/{types/draft.d.ts → draft.d.ts} +0 -0
- /package/dist/{esm/draft.js → draft.js} +0 -0
- /package/dist/{types/event-bus.d.ts → event-bus.d.ts} +0 -0
- /package/dist/{esm/event-bus.js → event-bus.js} +0 -0
- /package/dist/{types/key-value-pair.d.ts → key-value-pair.d.ts} +0 -0
- /package/dist/{esm/key-value-pair.js → key-value-pair.js} +0 -0
- /package/dist/{types/lazy.d.ts → lazy.d.ts} +0 -0
- /package/dist/{esm/lazy.js → lazy.js} +0 -0
- /package/dist/{types/math.d.ts → math.d.ts} +0 -0
- /package/dist/{esm/math.js → math.js} +0 -0
- /package/dist/{types/order.d.ts → order.d.ts} +0 -0
- /package/dist/{esm/order.js → order.js} +0 -0
- /package/dist/{types/parse.d.ts → parse.d.ts} +0 -0
- /package/dist/{esm/parse.js → parse.js} +0 -0
- /package/dist/{types/patch.d.ts → patch.d.ts} +0 -0
- /package/dist/{esm/patch.js → patch.js} +0 -0
- /package/dist/{types/range.d.ts → range.d.ts} +0 -0
- /package/dist/{esm/range.js → range.js} +0 -0
- /package/dist/{types/result.d.ts → result.d.ts} +0 -0
- /package/dist/{esm/result.js → result.js} +0 -0
- /package/dist/{types/stopwatch.d.ts → stopwatch.d.ts} +0 -0
- /package/dist/{esm/stopwatch.js → stopwatch.js} +0 -0
- /package/dist/{types/string.d.ts → string.d.ts} +0 -0
- /package/dist/{esm/string.js → string.js} +0 -0
- /package/dist/{types/timer.d.ts → timer.d.ts} +0 -0
- /package/dist/{esm/timer.js → timer.js} +0 -0
- /package/dist/{types/timespan.d.ts → timespan.d.ts} +0 -0
- /package/dist/{esm/timespan.js → timespan.js} +0 -0
- /package/dist/{types/triggers.d.ts → triggers.d.ts} +0 -0
- /package/dist/{esm/triggers.js → triggers.js} +0 -0
- /package/dist/{types/type-code.d.ts → type-code.d.ts} +0 -0
- /package/dist/{esm/type-code.js → type-code.js} +0 -0
- /package/dist/{types/type.d.ts → type.d.ts} +0 -0
- /package/dist/{esm/type.js → type.js} +0 -0
- /package/dist/{types/types.d.ts → types.d.ts} +0 -0
- /package/dist/{esm/types.js → types.js} +0 -0
package/dist/web/timespan.js
DELETED
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a duration of time in milliseconds.
|
|
3
|
-
*/
|
|
4
|
-
class TimeSpan {
|
|
5
|
-
constructor(milliseconds) {
|
|
6
|
-
this.milliseconds = milliseconds;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Gets the time interval in seconds.
|
|
10
|
-
* @returns {number} The duration in seconds.
|
|
11
|
-
*/
|
|
12
|
-
seconds() {
|
|
13
|
-
return this.milliseconds / 1000;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Gets the time interval in minutes.
|
|
17
|
-
* @returns {number} The duration in minutes.
|
|
18
|
-
*/
|
|
19
|
-
minutes() {
|
|
20
|
-
return this.milliseconds / (1000 * 60);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Gets the time interval in hours.
|
|
24
|
-
* @returns {number} The duration in hours.
|
|
25
|
-
*/
|
|
26
|
-
hours() {
|
|
27
|
-
return this.milliseconds / (1000 * 60 * 60);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Gets the time interval in days.
|
|
31
|
-
* @returns {number} The duration in days.
|
|
32
|
-
*/
|
|
33
|
-
days() {
|
|
34
|
-
return this.milliseconds / (1000 * 60 * 60 * 24);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Gets the time interval in weeks.
|
|
38
|
-
* @returns {number} The duration in weeks.
|
|
39
|
-
*/
|
|
40
|
-
weeks() {
|
|
41
|
-
return this.milliseconds / (1000 * 60 * 60 * 24 * 7);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Creates a TimeSpan from a specified number of milliseconds.
|
|
45
|
-
* @param {number} milliseconds - The number of milliseconds.
|
|
46
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
47
|
-
*/
|
|
48
|
-
static fromMilliseconds(milliseconds) {
|
|
49
|
-
return new TimeSpan(milliseconds);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Creates a TimeSpan from a specified number of seconds.
|
|
53
|
-
* @param {number} seconds - The number of seconds.
|
|
54
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
55
|
-
*/
|
|
56
|
-
static fromSeconds(seconds) {
|
|
57
|
-
return new TimeSpan(seconds * 1000);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Creates a TimeSpan from a specified number of minutes.
|
|
61
|
-
* @param {number} minutes - The number of minutes.
|
|
62
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
63
|
-
*/
|
|
64
|
-
static fromMinutes(minutes) {
|
|
65
|
-
return new TimeSpan(minutes * 1000 * 60);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Creates a TimeSpan from a specified number of hours.
|
|
69
|
-
* @param {number} hours - The number of hours.
|
|
70
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
71
|
-
*/
|
|
72
|
-
static fromHours(hours) {
|
|
73
|
-
return new TimeSpan(hours * 1000 * 60 * 60);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Creates a TimeSpan from a specified number of days.
|
|
77
|
-
* @param {number} days - The number of days.
|
|
78
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
79
|
-
*/
|
|
80
|
-
static fromDays(days) {
|
|
81
|
-
return new TimeSpan(days * 1000 * 60 * 60 * 24);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Creates a TimeSpan from a specified number of weeks.
|
|
85
|
-
* @param {number} weeks - The number of weeks.
|
|
86
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
87
|
-
*/
|
|
88
|
-
static fromWeeks(weeks) {
|
|
89
|
-
return new TimeSpan(weeks * 1000 * 60 * 60 * 24 * 7);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Returns a new TimeSpan that adds the specified number of milliseconds to this instance.
|
|
93
|
-
* @param {number} milliseconds - The milliseconds to add.
|
|
94
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
95
|
-
*/
|
|
96
|
-
addMilliseconds(milliseconds) {
|
|
97
|
-
return new TimeSpan(this.milliseconds + milliseconds);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Returns a new TimeSpan that adds the specified number of seconds to this instance.
|
|
101
|
-
* @param {number} seconds - The seconds to add.
|
|
102
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
103
|
-
*/
|
|
104
|
-
addSeconds(seconds) {
|
|
105
|
-
return this.addMilliseconds(seconds * 1000);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Returns a new TimeSpan that adds the specified number of minutes to this instance.
|
|
109
|
-
* @param {number} minutes - The minutes to add.
|
|
110
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
111
|
-
*/
|
|
112
|
-
addMinutes(minutes) {
|
|
113
|
-
return this.addMilliseconds(minutes * 1000 * 60);
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Returns a new TimeSpan that adds the specified number of hours to this instance.
|
|
117
|
-
* @param {number} hours - The hours to add.
|
|
118
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
119
|
-
*/
|
|
120
|
-
addHours(hours) {
|
|
121
|
-
return this.addMilliseconds(hours * 1000 * 60 * 60);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Returns a new TimeSpan that adds the specified number of days to this instance.
|
|
125
|
-
* @param {number} days - The days to add.
|
|
126
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
127
|
-
*/
|
|
128
|
-
addDays(days) {
|
|
129
|
-
return this.addMilliseconds(days * 1000 * 60 * 60 * 24);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Returns a new TimeSpan that adds the specified number of weeks to this instance.
|
|
133
|
-
* @param {number} weeks - The weeks to add.
|
|
134
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
135
|
-
*/
|
|
136
|
-
addWeeks(weeks) {
|
|
137
|
-
return this.addMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Returns a new TimeSpan that subtracts the specified number of milliseconds from this instance.
|
|
141
|
-
* @param {number} milliseconds - The milliseconds to subtract.
|
|
142
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
143
|
-
*/
|
|
144
|
-
subtractMilliseconds(milliseconds) {
|
|
145
|
-
return new TimeSpan(this.milliseconds - milliseconds);
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Returns a new TimeSpan that subtracts the specified number of seconds from this instance.
|
|
149
|
-
* @param {number} seconds - The seconds to subtract.
|
|
150
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
151
|
-
*/
|
|
152
|
-
subtractSeconds(seconds) {
|
|
153
|
-
return this.subtractMilliseconds(seconds * 1000);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Returns a new TimeSpan that subtracts the specified number of minutes from this instance.
|
|
157
|
-
* @param {number} minutes - The minutes to subtract.
|
|
158
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
159
|
-
*/
|
|
160
|
-
subtractMinutes(minutes) {
|
|
161
|
-
return this.subtractMilliseconds(minutes * 1000 * 60);
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Returns a new TimeSpan that subtracts the specified number of hours from this instance.
|
|
165
|
-
* @param {number} hours - The hours to subtract.
|
|
166
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
167
|
-
*/
|
|
168
|
-
subtractHours(hours) {
|
|
169
|
-
return this.subtractMilliseconds(hours * 1000 * 60 * 60);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Returns a new TimeSpan that subtracts the specified number of days from this instance.
|
|
173
|
-
* @param {number} days - The days to subtract.
|
|
174
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
175
|
-
*/
|
|
176
|
-
subtractDays(days) {
|
|
177
|
-
return this.subtractMilliseconds(days * 1000 * 60 * 60 * 24);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Returns a new TimeSpan that subtracts the specified number of weeks from this instance.
|
|
181
|
-
* @param {number} weeks - The weeks to subtract.
|
|
182
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
183
|
-
*/
|
|
184
|
-
subtractWeeks(weeks) {
|
|
185
|
-
return this.subtractMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Returns a new TimeSpan that adds the specified TimeSpan to this instance.
|
|
189
|
-
* @param {TimeSpan} other - The TimeSpan to add.
|
|
190
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
191
|
-
*/
|
|
192
|
-
add(other) {
|
|
193
|
-
return new TimeSpan(this.milliseconds + other.milliseconds);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Returns a new TimeSpan that subtracts the specified TimeSpan from this instance.
|
|
197
|
-
* @param {TimeSpan} other - The TimeSpan to subtract.
|
|
198
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
199
|
-
*/
|
|
200
|
-
subtract(other) {
|
|
201
|
-
return new TimeSpan(this.milliseconds - other.milliseconds);
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Adds this TimeSpan to a specified Date.
|
|
205
|
-
* @param {Date} date - The date to add to.
|
|
206
|
-
* @returns {Date} A new Date instance.
|
|
207
|
-
*/
|
|
208
|
-
addTo(date) {
|
|
209
|
-
return new Date(date.getTime() + this.milliseconds);
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Subtracts this TimeSpan from a specified Date.
|
|
213
|
-
* @param {Date} date - The date to subtract from.
|
|
214
|
-
* @returns {Date} A new Date instance.
|
|
215
|
-
*/
|
|
216
|
-
subtractFrom(date) {
|
|
217
|
-
return new Date(date.getTime() - this.milliseconds);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Creates a TimeSpan from the difference between two dates.
|
|
221
|
-
* @param {Date} earlierDate - The earlier date.
|
|
222
|
-
* @param {Date} laterDate - The later date.
|
|
223
|
-
* @returns {TimeSpan} A new TimeSpan instance representing the difference.
|
|
224
|
-
*/
|
|
225
|
-
static fromDifference(earlierDate, laterDate) {
|
|
226
|
-
return new TimeSpan(laterDate.getTime() - earlierDate.getTime());
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Formats the TimeSpan as a string.
|
|
230
|
-
* Supported tokens: hh, h, mm, m, ss, s.
|
|
231
|
-
* @param {string} format - The format string (default: 'hh:mm:ss').
|
|
232
|
-
* @returns {string} The formatted string.
|
|
233
|
-
*/
|
|
234
|
-
format(format = 'hh:mm:ss') {
|
|
235
|
-
const formatLower = format.toLowerCase();
|
|
236
|
-
const hasHours = formatLower.includes("h");
|
|
237
|
-
const hasMinutes = formatLower.includes("m");
|
|
238
|
-
const sign = this.milliseconds < 0 ? "-" : "";
|
|
239
|
-
let hours = 0, minutes = 0, seconds = Math.floor(Math.abs(this.milliseconds) / 1000);
|
|
240
|
-
if (hasHours) {
|
|
241
|
-
hours = Math.floor(seconds / 3600);
|
|
242
|
-
seconds -= hours * 3600;
|
|
243
|
-
}
|
|
244
|
-
if (hasMinutes) {
|
|
245
|
-
minutes = Math.floor(seconds / 60);
|
|
246
|
-
seconds -= minutes * 60;
|
|
247
|
-
}
|
|
248
|
-
const hoursPadded = String(hours).padStart(2, '0');
|
|
249
|
-
const minutesPadded = String(minutes).padStart(2, '0');
|
|
250
|
-
const secondsPadded = String(seconds).padStart(2, '0');
|
|
251
|
-
const formatted = formatLower.replace(/hh|h|mm|m|ss|s/g, token => {
|
|
252
|
-
switch (token) {
|
|
253
|
-
case 'hh':
|
|
254
|
-
return hoursPadded;
|
|
255
|
-
case 'h':
|
|
256
|
-
return hours.toString();
|
|
257
|
-
case 'mm':
|
|
258
|
-
return minutesPadded;
|
|
259
|
-
case 'm':
|
|
260
|
-
return minutes.toString();
|
|
261
|
-
case 'ss':
|
|
262
|
-
return secondsPadded;
|
|
263
|
-
case 's':
|
|
264
|
-
return seconds.toString();
|
|
265
|
-
default:
|
|
266
|
-
return token;
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
return sign + formatted;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Checks if this TimeSpan is equal to another.
|
|
273
|
-
* @param {TimeSpan} other - The other TimeSpan.
|
|
274
|
-
* @returns {boolean} True if equal.
|
|
275
|
-
*/
|
|
276
|
-
eq(other) {
|
|
277
|
-
return this.milliseconds === other.milliseconds;
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Checks if this TimeSpan is less than or equal to another.
|
|
281
|
-
* @param {TimeSpan} other - The other TimeSpan.
|
|
282
|
-
* @returns {boolean} True if less than or equal.
|
|
283
|
-
*/
|
|
284
|
-
le(other) {
|
|
285
|
-
return this.milliseconds <= other.milliseconds;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Checks if this TimeSpan is less than another.
|
|
289
|
-
* @param {TimeSpan} other - The other TimeSpan.
|
|
290
|
-
* @returns {boolean} True if less than.
|
|
291
|
-
*/
|
|
292
|
-
lt(other) {
|
|
293
|
-
return this.milliseconds < other.milliseconds;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Checks if this TimeSpan is greater than or equal to another.
|
|
297
|
-
* @param {TimeSpan} other - The other TimeSpan.
|
|
298
|
-
* @returns {boolean} True if greater than or equal.
|
|
299
|
-
*/
|
|
300
|
-
ge(other) {
|
|
301
|
-
return this.milliseconds >= other.milliseconds;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Checks if this TimeSpan is greater than another.
|
|
305
|
-
* @param {TimeSpan} other - The other TimeSpan.
|
|
306
|
-
* @returns {boolean} True if greater than.
|
|
307
|
-
*/
|
|
308
|
-
gt(other) {
|
|
309
|
-
return this.milliseconds > other.milliseconds;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Multiplies the TimeSpan by a number.
|
|
313
|
-
* @param {number} number - The multiplier.
|
|
314
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
315
|
-
*/
|
|
316
|
-
multiply(number) {
|
|
317
|
-
return new TimeSpan(this.milliseconds * number);
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Divides the TimeSpan by a number.
|
|
321
|
-
* @param {number} number - The divisor.
|
|
322
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
323
|
-
*/
|
|
324
|
-
divide(number) {
|
|
325
|
-
return new TimeSpan(this.milliseconds / number);
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Returns the absolute value of the TimeSpan.
|
|
329
|
-
* @returns {TimeSpan} A new TimeSpan instance.
|
|
330
|
-
*/
|
|
331
|
-
abs() {
|
|
332
|
-
return new TimeSpan(Math.abs(this.milliseconds));
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Checks if the TimeSpan is infinite.
|
|
336
|
-
* @returns {boolean} True if infinite.
|
|
337
|
-
*/
|
|
338
|
-
isInfinite() {
|
|
339
|
-
return this.milliseconds === Number.POSITIVE_INFINITY || this.milliseconds === Number.NEGATIVE_INFINITY;
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Checks if the TimeSpan is positive infinite.
|
|
343
|
-
* @returns {boolean} True if positive infinite.
|
|
344
|
-
*/
|
|
345
|
-
isPositiveInfinite() {
|
|
346
|
-
return this.milliseconds === Number.POSITIVE_INFINITY;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Checks if the TimeSpan is negative infinite.
|
|
350
|
-
* @returns {boolean} True if negative infinite.
|
|
351
|
-
*/
|
|
352
|
-
isNegativeInfinite() {
|
|
353
|
-
return this.milliseconds === Number.NEGATIVE_INFINITY;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Infinite duration.
|
|
358
|
-
*/
|
|
359
|
-
TimeSpan.INFINITE = new TimeSpan(Number.POSITIVE_INFINITY);
|
|
360
|
-
/**
|
|
361
|
-
* Negative infinite duration.
|
|
362
|
-
*/
|
|
363
|
-
TimeSpan.NEGATIVE_INFINITE = new TimeSpan(Number.NEGATIVE_INFINITY);
|
|
364
|
-
export default TimeSpan;
|
|
365
|
-
//# sourceMappingURL=timespan.js.map
|
package/dist/web/timespan.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timespan.js","sourceRoot":"","sources":["../../src/timespan.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAqB,QAAQ;IAGzB,YAAoB,YAAoB;QACpC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAGD;;;OAGG;IACH,OAAO;QACH,OAAO,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,OAAO;QACH,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACH,KAAK;QACD,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;;OAGG;IACH,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AAC,iBAAiB,IAAI,IAAI,CAAC,YAAY,KAAK,MAAM,CAAC,iBAAiB,CAAA;IAC3G,CAAC;IAED;;;OAGG;IACH,kBAAkB;QACd,OAAO,IAAI,CAAC,YAAY,KAAK,MAAM,CAAC,iBAAiB,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,kBAAkB;QACd,OAAO,IAAI,CAAC,YAAY,KAAK,MAAM,CAAC,iBAAiB,CAAC;IAC1D,CAAC;;AAhCD;;GAEG;AACa,iBAAQ,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAElE;;GAEG;AACa,0BAAiB,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;eAhY1D,QAAQ","sourcesContent":["/**\n * Represents a duration of time in milliseconds.\n */\nexport default class TimeSpan {\n public milliseconds: number;\n\n private constructor(milliseconds: number) {\n this.milliseconds = milliseconds;\n }\n\n\n /**\n * Gets the time interval in seconds.\n * @returns {number} The duration in seconds.\n */\n seconds(): number {\n return this.milliseconds / 1000;\n }\n\n /**\n * Gets the time interval in minutes.\n * @returns {number} The duration in minutes.\n */\n minutes(): number {\n return this.milliseconds / (1000 * 60);\n }\n\n /**\n * Gets the time interval in hours.\n * @returns {number} The duration in hours.\n */\n hours(): number {\n return this.milliseconds / (1000 * 60 * 60);\n }\n\n /**\n * Gets the time interval in days.\n * @returns {number} The duration in days.\n */\n days(): number {\n return this.milliseconds / (1000 * 60 * 60 * 24);\n }\n\n /**\n * Gets the time interval in weeks.\n * @returns {number} The duration in weeks.\n */\n weeks(): number {\n return this.milliseconds / (1000 * 60 * 60 * 24 * 7);\n }\n\n /**\n * Creates a TimeSpan from a specified number of milliseconds.\n * @param {number} milliseconds - The number of milliseconds.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n static fromMilliseconds(milliseconds: number): TimeSpan {\n return new TimeSpan(milliseconds);\n }\n\n /**\n * Creates a TimeSpan from a specified number of seconds.\n * @param {number} seconds - The number of seconds.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n static fromSeconds(seconds: number): TimeSpan {\n return new TimeSpan(seconds * 1000);\n }\n\n /**\n * Creates a TimeSpan from a specified number of minutes.\n * @param {number} minutes - The number of minutes.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n static fromMinutes(minutes: number): TimeSpan {\n return new TimeSpan(minutes * 1000 * 60);\n }\n\n /**\n * Creates a TimeSpan from a specified number of hours.\n * @param {number} hours - The number of hours.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n static fromHours(hours: number): TimeSpan {\n return new TimeSpan(hours * 1000 * 60 * 60);\n }\n\n /**\n * Creates a TimeSpan from a specified number of days.\n * @param {number} days - The number of days.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n static fromDays(days: number): TimeSpan {\n return new TimeSpan(days * 1000 * 60 * 60 * 24);\n }\n\n /**\n * Creates a TimeSpan from a specified number of weeks.\n * @param {number} weeks - The number of weeks.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n static fromWeeks(weeks: number): TimeSpan {\n return new TimeSpan(weeks * 1000 * 60 * 60 * 24 * 7);\n }\n\n /**\n * Returns a new TimeSpan that adds the specified number of milliseconds to this instance.\n * @param {number} milliseconds - The milliseconds to add.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n addMilliseconds(milliseconds: number): TimeSpan {\n return new TimeSpan(this.milliseconds + milliseconds);\n }\n\n /**\n * Returns a new TimeSpan that adds the specified number of seconds to this instance.\n * @param {number} seconds - The seconds to add.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n addSeconds(seconds: number): TimeSpan {\n return this.addMilliseconds(seconds * 1000);\n }\n\n /**\n * Returns a new TimeSpan that adds the specified number of minutes to this instance.\n * @param {number} minutes - The minutes to add.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n addMinutes(minutes: number): TimeSpan {\n return this.addMilliseconds(minutes * 1000 * 60);\n }\n\n /**\n * Returns a new TimeSpan that adds the specified number of hours to this instance.\n * @param {number} hours - The hours to add.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n addHours(hours: number): TimeSpan {\n return this.addMilliseconds(hours * 1000 * 60 * 60);\n }\n\n /**\n * Returns a new TimeSpan that adds the specified number of days to this instance.\n * @param {number} days - The days to add.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n addDays(days: number): TimeSpan {\n return this.addMilliseconds(days * 1000 * 60 * 60 * 24);\n }\n\n /**\n * Returns a new TimeSpan that adds the specified number of weeks to this instance.\n * @param {number} weeks - The weeks to add.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n addWeeks(weeks: number): TimeSpan {\n return this.addMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);\n }\n\n /**\n * Returns a new TimeSpan that subtracts the specified number of milliseconds from this instance.\n * @param {number} milliseconds - The milliseconds to subtract.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n subtractMilliseconds(milliseconds: number): TimeSpan {\n return new TimeSpan(this.milliseconds - milliseconds);\n }\n\n /**\n * Returns a new TimeSpan that subtracts the specified number of seconds from this instance.\n * @param {number} seconds - The seconds to subtract.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n subtractSeconds(seconds: number): TimeSpan {\n return this.subtractMilliseconds(seconds * 1000);\n }\n\n /**\n * Returns a new TimeSpan that subtracts the specified number of minutes from this instance.\n * @param {number} minutes - The minutes to subtract.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n subtractMinutes(minutes: number): TimeSpan {\n return this.subtractMilliseconds(minutes * 1000 * 60);\n }\n\n /**\n * Returns a new TimeSpan that subtracts the specified number of hours from this instance.\n * @param {number} hours - The hours to subtract.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n subtractHours(hours: number): TimeSpan {\n return this.subtractMilliseconds(hours * 1000 * 60 * 60);\n }\n\n /**\n * Returns a new TimeSpan that subtracts the specified number of days from this instance.\n * @param {number} days - The days to subtract.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n subtractDays(days: number): TimeSpan {\n return this.subtractMilliseconds(days * 1000 * 60 * 60 * 24);\n }\n\n /**\n * Returns a new TimeSpan that subtracts the specified number of weeks from this instance.\n * @param {number} weeks - The weeks to subtract.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n subtractWeeks(weeks: number): TimeSpan {\n return this.subtractMilliseconds(weeks * 1000 * 60 * 60 * 24 * 7);\n }\n\n /**\n * Returns a new TimeSpan that adds the specified TimeSpan to this instance.\n * @param {TimeSpan} other - The TimeSpan to add.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n add(other: TimeSpan): TimeSpan {\n return new TimeSpan(this.milliseconds + other.milliseconds);\n }\n\n /**\n * Returns a new TimeSpan that subtracts the specified TimeSpan from this instance.\n * @param {TimeSpan} other - The TimeSpan to subtract.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n subtract(other: TimeSpan): TimeSpan {\n return new TimeSpan(this.milliseconds - other.milliseconds);\n }\n\n /**\n * Adds this TimeSpan to a specified Date.\n * @param {Date} date - The date to add to.\n * @returns {Date} A new Date instance.\n */\n addTo(date: Date): Date {\n return new Date(date.getTime() + this.milliseconds);\n }\n\n /**\n * Subtracts this TimeSpan from a specified Date.\n * @param {Date} date - The date to subtract from.\n * @returns {Date} A new Date instance.\n */\n subtractFrom(date: Date): Date {\n return new Date(date.getTime() - this.milliseconds);\n }\n\n /**\n * Creates a TimeSpan from the difference between two dates.\n * @param {Date} earlierDate - The earlier date.\n * @param {Date} laterDate - The later date.\n * @returns {TimeSpan} A new TimeSpan instance representing the difference.\n */\n static fromDifference(earlierDate: Date, laterDate: Date): TimeSpan {\n return new TimeSpan(laterDate.getTime() - earlierDate.getTime());\n }\n\n /**\n * Formats the TimeSpan as a string.\n * Supported tokens: hh, h, mm, m, ss, s.\n * @param {string} format - The format string (default: 'hh:mm:ss').\n * @returns {string} The formatted string.\n */\n format(format: string = 'hh:mm:ss'): string {\n const formatLower = format.toLowerCase();\n const hasHours = formatLower.includes(\"h\");\n const hasMinutes = formatLower.includes(\"m\");\n\n const sign = this.milliseconds < 0 ? \"-\" : \"\";\n let hours = 0, minutes = 0, seconds = Math.floor(Math.abs(this.milliseconds) / 1000);\n\n if (hasHours) {\n hours = Math.floor(seconds / 3600);\n seconds -= hours * 3600;\n }\n if (hasMinutes) {\n minutes = Math.floor(seconds / 60);\n seconds -= minutes * 60;\n }\n\n const hoursPadded = String(hours).padStart(2, '0');\n const minutesPadded = String(minutes).padStart(2, '0');\n const secondsPadded = String(seconds).padStart(2, '0');\n\n const formatted = formatLower.replace(/hh|h|mm|m|ss|s/g, token => {\n switch (token) {\n case 'hh':\n return hoursPadded;\n case 'h':\n return hours.toString();\n case 'mm':\n return minutesPadded;\n case 'm':\n return minutes.toString();\n case 'ss':\n return secondsPadded;\n case 's':\n return seconds.toString();\n default:\n return token;\n }\n });\n\n return sign + formatted;\n }\n\n /**\n * Checks if this TimeSpan is equal to another.\n * @param {TimeSpan} other - The other TimeSpan.\n * @returns {boolean} True if equal.\n */\n eq(other: TimeSpan): boolean {\n return this.milliseconds === other.milliseconds;\n }\n\n /**\n * Checks if this TimeSpan is less than or equal to another.\n * @param {TimeSpan} other - The other TimeSpan.\n * @returns {boolean} True if less than or equal.\n */\n le(other: TimeSpan): boolean {\n return this.milliseconds <= other.milliseconds;\n }\n\n /**\n * Checks if this TimeSpan is less than another.\n * @param {TimeSpan} other - The other TimeSpan.\n * @returns {boolean} True if less than.\n */\n lt(other: TimeSpan): boolean {\n return this.milliseconds < other.milliseconds;\n }\n\n /**\n * Checks if this TimeSpan is greater than or equal to another.\n * @param {TimeSpan} other - The other TimeSpan.\n * @returns {boolean} True if greater than or equal.\n */\n ge(other: TimeSpan): boolean {\n return this.milliseconds >= other.milliseconds;\n }\n\n /**\n * Checks if this TimeSpan is greater than another.\n * @param {TimeSpan} other - The other TimeSpan.\n * @returns {boolean} True if greater than.\n */\n gt(other: TimeSpan): boolean {\n return this.milliseconds > other.milliseconds;\n }\n\n /**\n * Multiplies the TimeSpan by a number.\n * @param {number} number - The multiplier.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n multiply(number: number): TimeSpan {\n return new TimeSpan(this.milliseconds * number);\n }\n\n /**\n * Divides the TimeSpan by a number.\n * @param {number} number - The divisor.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n divide(number: number): TimeSpan {\n return new TimeSpan(this.milliseconds / number);\n }\n\n /**\n * Returns the absolute value of the TimeSpan.\n * @returns {TimeSpan} A new TimeSpan instance.\n */\n abs(): TimeSpan {\n return new TimeSpan(Math.abs(this.milliseconds));\n }\n\n /**\n * Infinite duration.\n */\n static readonly INFINITE = new TimeSpan(Number.POSITIVE_INFINITY);\n\n /**\n * Negative infinite duration.\n */\n static readonly NEGATIVE_INFINITE = new TimeSpan(Number.NEGATIVE_INFINITY);\n\n /**\n * Checks if the TimeSpan is infinite.\n * @returns {boolean} True if infinite.\n */\n isInfinite() {\n return this.milliseconds === Number.POSITIVE_INFINITY || this.milliseconds === Number.NEGATIVE_INFINITY\n }\n\n /**\n * Checks if the TimeSpan is positive infinite.\n * @returns {boolean} True if positive infinite.\n */\n isPositiveInfinite(): boolean {\n return this.milliseconds === Number.POSITIVE_INFINITY;\n }\n\n /**\n * Checks if the TimeSpan is negative infinite.\n * @returns {boolean} True if negative infinite.\n */\n isNegativeInfinite(): boolean {\n return this.milliseconds === Number.NEGATIVE_INFINITY;\n }\n}"]}
|
package/dist/web/triggers.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import TimeSpan from './timespan.js';
|
|
2
|
-
/**
|
|
3
|
-
* Runs a callback at most once during a configured time interval.
|
|
4
|
-
*/
|
|
5
|
-
export class TimeTrigger {
|
|
6
|
-
constructor(callback, interval) {
|
|
7
|
-
this.callback = callback;
|
|
8
|
-
this.interval = interval;
|
|
9
|
-
this.lastRunTime = null;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Executes the callback when the configured interval has elapsed.
|
|
13
|
-
*/
|
|
14
|
-
async check() {
|
|
15
|
-
const currentTime = performance.now();
|
|
16
|
-
if (this.lastRunTime === null
|
|
17
|
-
|| currentTime - this.lastRunTime >= this.interval.milliseconds) {
|
|
18
|
-
return { success: true, output: await this.trigger() };
|
|
19
|
-
}
|
|
20
|
-
return { success: false };
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Executes the callback regardless of the configured interval.
|
|
24
|
-
*/
|
|
25
|
-
async trigger() {
|
|
26
|
-
this.lastRunTime = performance.now();
|
|
27
|
-
return this.callback();
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Replaces the callback executed by this trigger.
|
|
31
|
-
*/
|
|
32
|
-
setCallback(callback) {
|
|
33
|
-
this.callback = callback;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Gets the configured time interval.
|
|
37
|
-
*/
|
|
38
|
-
getInterval() {
|
|
39
|
-
return this.interval;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Replaces the configured time interval.
|
|
43
|
-
*/
|
|
44
|
-
setInterval(interval) {
|
|
45
|
-
this.interval = interval;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Runs a callback after a configured number of checks.
|
|
50
|
-
*/
|
|
51
|
-
export class CountTrigger {
|
|
52
|
-
constructor(callback, interval) {
|
|
53
|
-
this.interval = 1;
|
|
54
|
-
this.checkCount = 0;
|
|
55
|
-
this.callback = callback;
|
|
56
|
-
this.setInterval(interval);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Executes the callback when the configured number of checks is reached.
|
|
60
|
-
*/
|
|
61
|
-
async check() {
|
|
62
|
-
this.checkCount++;
|
|
63
|
-
if (this.checkCount >= this.interval) {
|
|
64
|
-
return { success: true, output: await this.trigger() };
|
|
65
|
-
}
|
|
66
|
-
return { success: false };
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Executes the callback regardless of the configured check count.
|
|
70
|
-
*/
|
|
71
|
-
async trigger() {
|
|
72
|
-
this.checkCount = 0;
|
|
73
|
-
return this.callback();
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Replaces the callback executed by this trigger.
|
|
77
|
-
*/
|
|
78
|
-
setCallback(callback) {
|
|
79
|
-
this.callback = callback;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Gets the configured check interval.
|
|
83
|
-
*/
|
|
84
|
-
getInterval() {
|
|
85
|
-
return this.interval;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Replaces the configured check interval.
|
|
89
|
-
*
|
|
90
|
-
* @throws {RangeError} When the interval is less than one.
|
|
91
|
-
*/
|
|
92
|
-
setInterval(interval) {
|
|
93
|
-
if (interval < 1) {
|
|
94
|
-
throw new RangeError('Interval must be greater than zero.');
|
|
95
|
-
}
|
|
96
|
-
this.interval = interval;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
//# sourceMappingURL=triggers.js.map
|
package/dist/web/triggers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"triggers.js","sourceRoot":"","sources":["../../src/triggers.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,eAAe,CAAC;AAGrC;;GAEG;AACH,MAAM,OAAO,WAAW;IAKpB,YAAmB,QAAkC,EAAE,QAAkB;QACrE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QACd,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAEtC,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI;eACtB,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EACjE,CAAC;YACC,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,MAA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IACI,WAAW,CAAC,QAAkC;QACjD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED;;OAEG;IACI,WAAW;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,QAAgB;QAC/B,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;YACf,MAAM,IAAI,UAAU,CAAC,qCAAqC,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ","sourcesContent":["import type {Result} from './result.js';\nimport TimeSpan from './timespan.js';\nimport type {Nullable, Supplier} from './types.js';\n\n/**\n * Runs a callback at most once during a configured time interval.\n */\nexport class TimeTrigger<T> {\n private callback: Supplier<T | Promise<T>>;\n private interval: TimeSpan;\n private lastRunTime: Nullable<number>;\n\n public constructor(callback: Supplier<T | Promise<T>>, interval: TimeSpan) {\n this.callback = callback;\n this.interval = interval;\n this.lastRunTime = null;\n }\n\n /**\n * Executes the callback when the configured interval has elapsed.\n */\n public async check(): Promise<Result<T>> {\n const currentTime = performance.now();\n\n if (this.lastRunTime === null\n || currentTime - this.lastRunTime >= this.interval.milliseconds\n ) {\n return {success: true, output: await this.trigger()};\n }\n\n return {success: false};\n }\n\n /**\n * Executes the callback regardless of the configured interval.\n */\n public async trigger(): Promise<T> {\n this.lastRunTime = performance.now();\n return this.callback();\n }\n\n /**\n * Replaces the callback executed by this trigger.\n */\n public setCallback(callback: Supplier<T | Promise<T>>): void {\n this.callback = callback;\n }\n\n /**\n * Gets the configured time interval.\n */\n public getInterval(): TimeSpan {\n return this.interval;\n }\n\n /**\n * Replaces the configured time interval.\n */\n public setInterval(interval: TimeSpan): void {\n this.interval = interval;\n }\n\n\n}\n\n/**\n * Runs a callback after a configured number of checks.\n */\nexport class CountTrigger<T> {\n private callback: Supplier<T | Promise<T>>;\n private interval: number = 1;\n private checkCount: number = 0;\n\n public constructor(callback: Supplier<T | Promise<T>>, interval: number) {\n this.callback = callback;\n this.setInterval(interval);\n }\n\n /**\n * Executes the callback when the configured number of checks is reached.\n */\n public async check(): Promise<Result<T>> {\n this.checkCount++;\n\n if (this.checkCount >= this.interval) {\n return {success: true, output: await this.trigger()};\n }\n\n return {success: false};\n }\n\n /**\n * Executes the callback regardless of the configured check count.\n */\n public async trigger(): Promise<T> {\n this.checkCount = 0;\n return this.callback();\n }\n\n /**\n * Replaces the callback executed by this trigger.\n */\n public setCallback(callback: Supplier<T | Promise<T>>): void {\n this.callback = callback;\n }\n\n /**\n * Gets the configured check interval.\n */\n public getInterval(): number {\n return this.interval;\n }\n\n /**\n * Replaces the configured check interval.\n *\n * @throws {RangeError} When the interval is less than one.\n */\n public setInterval(interval: number): void {\n if (interval < 1) {\n throw new RangeError('Interval must be greater than zero.');\n }\n\n this.interval = interval;\n }\n}\n"]}
|
package/dist/web/type-code.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
var TypeCode;
|
|
2
|
-
(function (TypeCode) {
|
|
3
|
-
TypeCode["String"] = "string";
|
|
4
|
-
TypeCode["Number"] = "number";
|
|
5
|
-
TypeCode["Boolean"] = "boolean";
|
|
6
|
-
TypeCode["Symbol"] = "symbol";
|
|
7
|
-
TypeCode["BigInt"] = "bigint";
|
|
8
|
-
TypeCode["Null"] = "null";
|
|
9
|
-
TypeCode["Undefined"] = "undefined";
|
|
10
|
-
TypeCode["Object"] = "object";
|
|
11
|
-
TypeCode["Function"] = "function";
|
|
12
|
-
TypeCode["Array"] = "array";
|
|
13
|
-
TypeCode["Unknown"] = "unknown";
|
|
14
|
-
})(TypeCode || (TypeCode = {}));
|
|
15
|
-
export default TypeCode;
|
|
16
|
-
//# sourceMappingURL=type-code.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type-code.js","sourceRoot":"","sources":["../../src/type-code.ts"],"names":[],"mappings":"AAAA,IAAK,QAYJ;AAZD,WAAK,QAAQ;IACT,6BAAoB,CAAA;IACpB,6BAAoB,CAAA;IACpB,+BAAqB,CAAA;IACrB,6BAAoB,CAAA;IACpB,6BAAoB,CAAA;IACpB,yBAAkB,CAAA;IAClB,mCAAuB,CAAA;IACvB,6BAAoB,CAAA;IACpB,iCAAsB,CAAA;IACtB,2BAAmB,CAAA;IACnB,+BAAqB,CAAA;AACzB,CAAC,EAZI,QAAQ,KAAR,QAAQ,QAYZ;AAGD,eAAe,QAAQ,CAAC","sourcesContent":["enum TypeCode {\n String = 'string',\n Number = 'number',\n Boolean = 'boolean',\n Symbol = 'symbol',\n BigInt = 'bigint',\n Null = 'null',\n Undefined = 'undefined',\n Object = 'object',\n Function = 'function',\n Array = 'array',\n Unknown = 'unknown',\n}\n\n\nexport default TypeCode;"]}
|