@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.
@@ -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 Promise} that resolves after the specified number of milliseconds.
20
+ * @returns A {@link SmartPromise} that resolves after the specified number of milliseconds.
19
21
  */
20
- export function delay(milliseconds: number): Promise<void>
22
+ export function delay(milliseconds: number): SmartPromise<void>
21
23
  {
22
- return new Promise((resolve) => setTimeout(resolve, milliseconds));
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 Promise} that resolves on the next animation frame.
44
+ * @returns A {@link SmartPromise} that resolves on the next animation frame.
43
45
  */
44
- export function nextAnimationFrame(): Promise<void>
46
+ export function nextAnimationFrame(): SmartPromise<void>
45
47
  {
46
- return new Promise((resolve) => requestAnimationFrame(() => resolve()));
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 Promise} that resolves on the next microtask.
69
+ * @returns A {@link SmartPromise} that resolves on the next microtask.
68
70
  */
69
- export function yieldToEventLoop(): Promise<void>
71
+ export function yieldToEventLoop(): SmartPromise<void>
70
72
  {
71
- return new Promise((resolve) => setTimeout(resolve));
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(start: number | string | Date, end: number | string | Date, step = TimeUnit.Day)
178
- : SmartIterator<Date>
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 Promise} that resolves when the script has been loaded successfully or rejects if an error occurs.
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"): Promise<void>
22
+ export function loadScript(scriptUrl: string, scriptType = "text/javascript"): SmartPromise<void>
21
23
  {
22
- return new Promise<void>((resolve, reject) =>
24
+ return new SmartPromise<void>((resolve, reject) =>
23
25
  {
24
26
  const script = document.createElement("script");
25
27