@naturalcycles/js-lib
Version:
Standard library for universal (browser + Node.js) javascript
35 lines (34 loc) • 1.52 kB
TypeScript
import { AsyncIterable2 } from '../iter/asyncIterable2.js';
import { Iterable2 } from '../iter/iterable2.js';
import type { Integer, Primitive } from '../types.js';
/**
* Returns an array with ranges from `from` up to (but not including) `to`.
*
* Right bound is Exclusive (not Inclusive), to comply with lodash _.range
*
* @example
* range(3) // [0, 1, 2]
* range(3, 6) // [ 3, 4, 5 ]
* range(1, 10, 2) // [ 1, 3, 5, 7, 9 ]
*/
export declare function _range(toExcl: Integer): number[];
export declare function _range(fromIncl: Integer, toExcl: Integer, step?: number): number[];
/**
* Returns an array of `length` filled with `fill` primitive value.
* Performance-optimized implementation.
* `Array.from({ length }, () => fill)` shows ~25x perf regression in benchmarks
*
* Fill is Primitive, because it's safe to shallow-copy.
* If it was an object - it'll paste the same object reference, which can create bugs.
*/
export declare function _arrayFilled<T extends Primitive>(length: Integer, fill: T): T[];
/**
* Like _range, but returns an Iterable2.
*/
export declare function _rangeIterable(toExcl: Integer): Iterable2<number>;
export declare function _rangeIterable(fromIncl: Integer, toExcl: Integer, step?: number): Iterable2<number>;
/**
* Like _range, but returns an AsyncIterable2.
*/
export declare function _rangeAsyncIterable(toExcl: Integer): AsyncIterable2<number>;
export declare function _rangeAsyncIterable(fromIncl: Integer, toExcl: Integer, step?: number): AsyncIterable2<number>;