Skip to content
On this page

kagurajs - v0.2.7 / Exports / utils

Namespace: utils

Table of contents

Functions

Functions

range

range(n): Generator<number, void, unknown>

Returns n numbers from 0 to (n-1) in order.

Parameters

NameTypeDescription
nnumberNumber to stop before that number

Returns

Generator<number, void, unknown>

A sequential number generator

Remarks

A generator that returns n numbers from 0 to (n-1) in order.

what does it exist for?

Because doing that would require writing long code. Old:

ts
for(let i = 0; i < 10; i++){
  console.log(`Count is ${i}.`)
}

Using this:

ts
for(const i of range(10)){
  console.log(`Count is ${i}.`)
}

Example

ts
for(const i of range(1000)){
  console.log(i)
}

Defined in

src/utils/range.ts:28


sleep

sleep(time): Promise<unknown>

Sleep for ms.

Parameters

NameType
timenumber

Returns

Promise<unknown>

Defined in

src/utils/sleep.ts:4