feat(lib/utils)!: remove non-working index-required-file util, add generators util
This commit is contained in:
parent
d92898ccc8
commit
c84da5a617
3 changed files with 32 additions and 6 deletions
|
|
@ -9,8 +9,8 @@
|
|||
"./functions": {
|
||||
"default": "./src/functions.ts"
|
||||
},
|
||||
"./index-required-file": {
|
||||
"default": "./src/index-required-file.ts"
|
||||
"./generators": {
|
||||
"default": "./src/generators.ts"
|
||||
},
|
||||
"./logger": {
|
||||
"default": "./src/logger.ts"
|
||||
|
|
@ -22,4 +22,4 @@
|
|||
"default": "./src/proxy.ts"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
29
lib/utils/src/generators.ts
Normal file
29
lib/utils/src/generators.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Get the next value from a generator, optionally skipping a number of values.
|
||||
*
|
||||
* @param generator The generator to get the value from.
|
||||
* @param skip The number of values to skip before getting the next value. Think of it as the generator being turned into an array, what index of the array do you want to return?
|
||||
* @returns The next value from the generator.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const generator = function* () {
|
||||
* yield 1
|
||||
* yield 2
|
||||
* yield 3
|
||||
* }
|
||||
*
|
||||
* const arr = [...generator()] // [1, 2, 3]
|
||||
*
|
||||
* yielded(generator()) === arr[0]
|
||||
* yielded(generator(), 1) === arr[1]
|
||||
* yielded(generator(), 2) === arr[2]
|
||||
*/
|
||||
export function yielded<T>(generator: Generator<T>, skip = 0): T {
|
||||
if (skip)
|
||||
for (let i = 0; i < skip; i++)
|
||||
if (generator.next().done)
|
||||
throw new Error(`Generator has no more values to drop (dropped ${i + 1} out of ${skip})`)
|
||||
|
||||
return generator.next().value
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
import { _mUninited } from '@revenge-mod/modules/_/metro'
|
||||
|
||||
if (_mUninited.has(0)) throw new Error('Cannot import this file before index (module 0) is required')
|
||||
Loading…
Add table
Reference in a new issue