extra-generator
v0.5.9
Published
```sh npm install --save extra-generator # or yarn add extra-generator ```
Downloads
28,261
Maintainers
Readme
extra-generator
Install
npm install --save extra-generator
# or
yarn add extra-generator
API
handleYieldedValues
function handleYieldedValues<T, Return, Next>(
generator: Generator<T, Return, Next>
, fn: (value: T, index: number) => Next
): Return
handleYieldedValuesAsync
function handleYieldedValuesAsync<T, Return, Next>(
generator: Generator<T, Return, Next>
, fn: (value: T, index: number) => PromiseLike<Next>
): Promise<Return>
function handleYieldedValuesAsync<T, Return, Next>(
generator: AsyncGenerator<T, Return, Next>
, fn: (value: T, index: number) => Awaitable<Next>
): Promise<Return>
of
function of<T>(val: T): IterableIterator<T>
of(1) // [1]
repeat
function repeat<T>(val: T, times: number = Infinity): IterableIterator<T>
repeat(1) // [1, 1, 1, ...]
repeat(1, 3) // [1, 1, 1]
repeat(1, 0) // []
spawn
function spawn<T>(create: (num: number) => T, times: number = Infinity): IterableIterator<T>
spawn(x => x * 2) // [2, 4, 6, ...]
spawn(x => x * 2, 3) // [2, 4, 6]
spawn(x => x * 2, 0) // []
countdown
function countdown(begin: number, end: number): IterableIterator<number>
countdown(2, -2) // [2, 1, 0, -1, -2]
countdown(1, 1) // [1]
countdown(0, 1) // []
countup
function countup(begin: number, end: number): IterableIterator<number>
countup(-2, 2) // [-2, -1, 0, 1, 2]
countup(1, 1) // [1]
countup(1, 0) // []
range
function range(
start: number
, end: number
, step: number = 1 // step > 0
, inclusive: boolean = false
): IterableIterator<number>
range(1, 1) // []
range(-2, 2) // [-2, -1, 0, 1]
range(2, -2) // [2, 1, 0, -1]
range(1, -1, 0.5) // [1, 0.5, 0, -0.5]
range(2, -2, 0) // throw Error
range(2, -2, -0.5) // throw Error
stringifyJSONStream
function stringifyJSONStream<T>(iterable: Iterable<T>): Iterable<string>
stringifyJSONStreamAsync
function stringifyNDJSONStreamAsync<T>(iterable: AsyncIterable<T>): AsyncIterable<string>
stringifyNDJSONStream
function stringifyNDJSONStream<T>(iterable: Iterable<T>): Iterable<string>
stringifyNDJSONStreamAsync
function stringifyNDJSONStreamAsync<T>(iterable: AsyncIterable<T>): AsyncIterable<string>
timestampBasedId
function timestampBasedId(): Iterator<[timestamp: number, num: number]>
ReusableIterable
interface IReusableIterable<T> extends Iterable<T> {
close(): void
}
class ReusableIterable<T> implements IReusableIterable<T> {
get done(): boolean | undefined
constructor(iterable: Iterable<T>)
close(): void
}
ReusableAsyncIterable
interface IReusableAsyncIterable<T> extends AsyncIterable<T> {
close(): Promise<void>
}
class ReusableAsyncIterable<T> implements IReusableAsyncIterable<T> {
get done(): boolean | undefined
constructor(iterable: AsyncIterable<T>)
close(): Promise<void>
}
ngrams
function ngrams(text: string, n: number): IterableIterator<string>
allNgrams
function allNgrams(text: string): IterableIterator<string>
allCombinations
function allCombinations<T>(arr: T[], k: number): IterableIterator<T[]>
allIndexCombinations
function allIndexCombinations(
arr: unknown[]
, k: number
): IterableIterator<number[]>
positiveFactors
function positiveFactors(value: number): IterableIterator<number>
positiveFactors(0) // []
positiveFactors(10) // [10, 5, 2, 1]
positiveFactors(-10) // [10, 5, 2, 1]
positiveCommonDivisors
function positiveCommonDivisors(a: number, b: number): IterableIterator<number>
positiveCommonDivisors(0, 0) // []
positiveCommonDivisors(12, 8) // [4, 2, 1]
positiveCommonDivisors(-12, 8) // [4, 2, 1]
reverse
function reverse<T>(arr: ArrayLike<T>): IterableIterator<T>