@byloth/core 2.1.7 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/core.cjs +2 -2
- package/dist/core.cjs.map +1 -1
- package/dist/core.esm.js +1243 -1306
- package/dist/core.esm.js.map +1 -1
- package/dist/core.global.js +2 -2
- package/dist/core.global.js.map +1 -1
- package/dist/core.umd.cjs +2 -2
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +1 -2
- package/src/models/aggregators/aggregated-async-iterator.ts +12 -9
- package/src/models/callbacks/callable-object.ts +2 -2
- package/src/models/callbacks/publisher.ts +99 -37
- package/src/models/callbacks/switchable-callback.ts +0 -1
- package/src/models/callbacks/types.ts +3 -3
- package/src/models/collections/map-view.ts +7 -5
- package/src/models/collections/set-view.ts +4 -3
- package/src/models/collections/types.ts +6 -4
- package/src/models/iterators/smart-async-iterator.ts +0 -3
- package/src/models/json/json-storage.ts +1 -2
- package/src/models/promises/promise-queue.ts +8 -7
- package/src/models/promises/smart-promise.ts +7 -5
- package/src/models/timers/clock.ts +3 -2
- package/src/models/timers/countdown.ts +5 -4
- package/src/models/timers/game-loop.ts +5 -4
- package/src/utils/async.ts +11 -9
- package/src/utils/date.ts +14 -2
- package/src/utils/dom.ts +5 -3
package/src/utils/async.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SmartPromise } from "../models/index.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Returns a promise that resolves after a certain number of milliseconds.
|
|
3
5
|
* It can be used to pause or delay the execution of an asynchronous function.
|
|
@@ -15,11 +17,11 @@
|
|
|
15
17
|
*
|
|
16
18
|
* @param milliseconds The number of milliseconds to wait before resolving the promise.
|
|
17
19
|
*
|
|
18
|
-
* @returns A {@link
|
|
20
|
+
* @returns A {@link SmartPromise} that resolves after the specified number of milliseconds.
|
|
19
21
|
*/
|
|
20
|
-
export function delay(milliseconds: number):
|
|
22
|
+
export function delay(milliseconds: number): SmartPromise<void>
|
|
21
23
|
{
|
|
22
|
-
return new
|
|
24
|
+
return new SmartPromise((resolve) => setTimeout(resolve, milliseconds));
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
/**
|
|
@@ -39,11 +41,11 @@ export function delay(milliseconds: number): Promise<void>
|
|
|
39
41
|
*
|
|
40
42
|
* ---
|
|
41
43
|
*
|
|
42
|
-
* @returns A {@link
|
|
44
|
+
* @returns A {@link SmartPromise} that resolves on the next animation frame.
|
|
43
45
|
*/
|
|
44
|
-
export function nextAnimationFrame():
|
|
46
|
+
export function nextAnimationFrame(): SmartPromise<void>
|
|
45
47
|
{
|
|
46
|
-
return new
|
|
48
|
+
return new SmartPromise((resolve) => requestAnimationFrame(() => resolve()));
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/**
|
|
@@ -64,9 +66,9 @@ export function nextAnimationFrame(): Promise<void>
|
|
|
64
66
|
*
|
|
65
67
|
* ---
|
|
66
68
|
*
|
|
67
|
-
* @returns A {@link
|
|
69
|
+
* @returns A {@link SmartPromise} that resolves on the next microtask.
|
|
68
70
|
*/
|
|
69
|
-
export function yieldToEventLoop():
|
|
71
|
+
export function yieldToEventLoop(): SmartPromise<void>
|
|
70
72
|
{
|
|
71
|
-
return new
|
|
73
|
+
return new SmartPromise((resolve) => setTimeout(resolve));
|
|
72
74
|
}
|
package/src/utils/date.ts
CHANGED
|
@@ -174,8 +174,9 @@ export function dateDifference(start: number | string | Date, end: number | stri
|
|
|
174
174
|
*
|
|
175
175
|
* @returns A {@link SmartIterator} object that generates the dates in the range.
|
|
176
176
|
*/
|
|
177
|
-
export function dateRange(
|
|
178
|
-
:
|
|
177
|
+
export function dateRange(
|
|
178
|
+
start: number | string | Date, end: number | string | Date, step = TimeUnit.Day
|
|
179
|
+
): SmartIterator<Date>
|
|
179
180
|
{
|
|
180
181
|
start = new Date(start);
|
|
181
182
|
end = new Date(end);
|
|
@@ -271,3 +272,14 @@ export function getWeek(date: number | string | Date, firstDay = WeekDay.Sunday)
|
|
|
271
272
|
|
|
272
273
|
return dateRound(new Date(firstDayTime));
|
|
273
274
|
}
|
|
275
|
+
|
|
276
|
+
export function getMonth(date: number | string | Date): Date
|
|
277
|
+
{
|
|
278
|
+
date = new Date(date);
|
|
279
|
+
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth()));
|
|
280
|
+
}
|
|
281
|
+
export function getYear(date: number | string | Date): Date
|
|
282
|
+
{
|
|
283
|
+
date = new Date(date);
|
|
284
|
+
return new Date(Date.UTC(date.getUTCFullYear()));
|
|
285
|
+
}
|
package/src/utils/dom.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SmartPromise } from "../models/index.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Appends a script element to the document body.
|
|
3
5
|
* It can be used to load external scripts dynamically.
|
|
@@ -15,11 +17,11 @@
|
|
|
15
17
|
* @param scriptType The type of the script to load. Default is `"text/javascript"`.
|
|
16
18
|
*
|
|
17
19
|
* @returns
|
|
18
|
-
* A {@link
|
|
20
|
+
* A {@link SmartPromise} that resolves when the script has been loaded successfully or rejects if an error occurs.
|
|
19
21
|
*/
|
|
20
|
-
export function loadScript(scriptUrl: string, scriptType = "text/javascript"):
|
|
22
|
+
export function loadScript(scriptUrl: string, scriptType = "text/javascript"): SmartPromise<void>
|
|
21
23
|
{
|
|
22
|
-
return new
|
|
24
|
+
return new SmartPromise<void>((resolve, reject) =>
|
|
23
25
|
{
|
|
24
26
|
const script = document.createElement("script");
|
|
25
27
|
|