パッケージの詳細

extra-generator

BlackGlory8kMIT0.5.9

sh npm install --save extra-generator # or yarn add extra-generator

Iterable, AsyncIterable, of, countdown

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>

更新履歴

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

0.5.9 (2024-08-16)

Features

0.5.8 (2024-06-13)

Features

  • add positiveFactors, positiveCommonDivisors (5e1a6a1)

0.5.7 (2024-05-16)

0.5.6 (2024-05-13)

Features

  • add allIndexCombinations (544eddb)

0.5.5 (2024-04-26)

Features

0.5.4 (2024-01-31)

Features

  • range: add the new param inclusive (b7355e4)

0.5.3 (2023-08-11)

0.5.2 (2023-08-11)

Features

0.5.1 (2023-06-10)

Bug Fixes

0.5.0 (2023-05-04)

⚠ BREAKING CHANGES

0.4.0 (2023-03-18)

⚠ BREAKING CHANGES

  • The minimal version of Node.js 16

  • upgrade dependencies (9ca977a)

0.3.3 (2023-01-28)

Bug Fixes

0.3.2 (2023-01-27)

0.3.1 (2023-01-22)

0.3.0 (2023-01-21)

⚠ BREAKING CHANGES

  • CommonJS => ESM

  • commonjs => esm (d97f9f8)

0.2.23 (2022-12-26)

Bug Fixes

  • export ngrams, allNgrams (388e13b)

0.2.22 (2022-12-24)

Features

0.2.21 (2022-11-20)

Bug Fixes

0.2.20 (2022-11-20)

0.2.19 (2022-11-20)

Bug Fixes

0.2.18 (2022-11-20)

Features

  • add handleYieldedValues, handleYieldedValuesAsync (46e4627)

0.2.17 (2022-08-01)

0.2.16 (2022-03-20)

0.2.15 (2021-12-12)

0.2.14 (2021-11-19)

0.2.13 (2021-11-17)

Features

0.2.12 (2021-10-14)

0.2.11 (2021-09-25)

0.2.10 (2021-07-14)

Features

  • expose done from ReusableIterable, ResuableAsyncIterable (685dc93)

0.2.9 (2021-07-14)

Features

  • add ReusableIterable, ReusableAsyncIterable (3e04991)

0.2.8 (2021-07-13)

Bug Fixes

  • close unexhausted iterators (9a3c09a)
  • close unexhausted iterators (d571d95)

0.2.7 (2021-07-09)

0.2.6 (2021-05-16)

0.2.5 (2021-05-13)

Features

  • throw the error before producing the first value (06c9fd9)

0.2.4 (2021-04-30)

Features

0.2.3 (2021-04-30)

Features

0.2.2 (2021-04-30)

Features

0.2.1 (2021-03-17)

0.2.0 (2021-03-13)

⚠ BREAKING CHANGES

  • rewrite sse

  • rewrite sse (ec5075a)

0.1.6 (2021-03-07)

0.1.5 (2021-02-07)

Bug Fixes

0.1.4 (2021-02-03)

0.1.3 (2021-01-29)

Bug Fixes

0.1.2 (2021-01-29)

Features

0.1.1 (2021-01-29)

Features

  • add json/ndjson stream functions (2a9c34e)

0.1.0 (2021-01-29)

Features