lenix 1.8.5 → 1.8.6

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/nui/fetch.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { NuiFetchGeneric, Request } from '../shared/types.ts'
2
- import { palette } from '../shared/palette.ts'
3
2
 
4
3
  declare function GetParentResourceName(): string
5
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lenix",
3
- "version": "1.8.5",
3
+ "version": "1.8.6",
4
4
  "description": "Typed FiveM utilities for client, server, shared, and NUI scripts",
5
5
  "author": "Lenix",
6
6
  "license": "MIT",
package/shared/repeat.ts CHANGED
@@ -1,32 +1,34 @@
1
1
  /* */
2
- export function repeat<T>(
3
- until: () => T,
4
- ): Promise<T>
5
- export function repeat<T, const C extends T>(
6
- until: () => T,
7
- equal: C,
2
+ export function repeat<T>(check: () => T): Promise<T>
3
+ export function repeat<T, C extends T>(
4
+ check: () => T,
5
+ untilOrEqual: C | ((checked: T) => checked is C),
8
6
  each?: number,
9
7
  ): Promise<C>
10
- export function repeat <T>(
11
- until: () => T,
12
- equal?: T,
13
- each?: number
8
+ export function repeat<T>(
9
+ check: () => T,
10
+ untilOrEqual?: T | ((checked: T) => boolean),
11
+ each?: number,
14
12
  ): Promise<T> {
13
+ const hasCondition = arguments.length > 1
14
+ const predicate = typeof untilOrEqual === 'function'
15
+ ? untilOrEqual as (checked: T) => boolean
16
+ : undefined
17
+
15
18
  return new Promise(resolve => {
16
19
  const interval = setInterval(() => {
17
- const result = until()
18
-
19
- if (equal === undefined) {
20
- if (result === undefined || result === null) return
21
- resolve(result)
22
- clearInterval(interval)
23
- return
24
- }
20
+ const checked = check()
25
21
 
26
- if (result !== equal) return
22
+ const met = predicate
23
+ ? predicate(checked)
24
+ : hasCondition
25
+ ? checked === untilOrEqual
26
+ : checked !== undefined && checked !== null
27
27
 
28
- resolve(equal ?? result)
28
+ if (!met) return
29
+
29
30
  clearInterval(interval)
31
+ resolve(checked)
30
32
  }, each)
31
33
  })
32
- }
34
+ }