ts-data-forge
Version:
[](https://www.npmjs.com/package/ts-data-forge) [](https://www.npmjs.com/package/ts-data-forge) [;
*
* const threeZeros = Arr.zeros(3);
*
* assert.deepStrictEqual(emptyZeros, []);
*
* assert.deepStrictEqual(threeZeros, [0, 0, 0]);
* ```
*/
export declare const zeros: <N extends SizeType.ArgArr>(len: N) => N extends SmallUint ? ArrayOfLength<N, 0> : N extends SizeType.ArgArrPositive ? NonEmptyArray<0> : readonly 0[];
/**
* Creates a sequence of consecutive integers from 0 to `len-1`.
*
* @example
*
* ```ts
* const emptySeq = Arr.seq(0);
*
* const firstFive = Arr.seq(5);
*
* assert.deepStrictEqual(emptySeq, []);
*
* assert.deepStrictEqual(firstFive, [0, 1, 2, 3, 4]);
* ```
*/
export declare const seq: <N extends SizeType.ArgArr>(len: N) => N extends SmallUint ? Seq<N> : N extends SizeType.ArgArrPositive ? NonEmptyArray<SizeType.Arr> : readonly SizeType.Arr[];
/**
* Creates a new array of the specified length, filled with the initial value.
*
* @example
*
* ```ts
* const threeOnes = Arr.create(3, 1);
*
* const emptyStrings = Arr.create(0, 'Ada');
*
* assert.deepStrictEqual(threeOnes, [1, 1, 1]);
*
* assert.deepStrictEqual(emptyStrings, []);
* ```
*/
export declare const create: <const V, N extends SizeType.ArgArr>(len: N, init: V) => N extends SmallUint ? ArrayOfLength<N, V> : N extends SizeType.ArgArrPositive ? NonEmptyArray<V> : readonly V[];
/**
* Alias for `create`.
*
* @see {@link create}
*/
export declare const newArray: <const V, N extends SizeType.ArgArr>(len: N, init: V) => N extends SmallUint ? ArrayOfLength<N, V> : N extends SizeType.ArgArrPositive ? NonEmptyArray<V> : readonly V[];
/**
* Generates an array from a generator function.
*
* @example
*
* ```ts
* const numbers = Arr.generate(function* () {
* yield 1;
*
* yield 2;
*
* yield 3;
* });
*
* assert.deepStrictEqual(numbers, [1, 2, 3]);
* ```
*/
export declare const generate: <T>(generatorFn: () => Generator<T, void, unknown>) => readonly T[];
/**
* Generates an array from an async generator function.
*
* @example
*
* ```ts
* const values = await Arr.generateAsync(async function* () {
* yield 'Ada';
*
* await Promise.resolve();
*
* yield 'Lovelace';
* });
*
* assert.deepStrictEqual(values, ['Ada', 'Lovelace']);
* ```
*/
export declare const generateAsync: <T>(generatorFn: () => AsyncGenerator<T, void, unknown>) => Promise<readonly T[]>;
/**
* Creates a shallow copy of an array.
*
* @example
*
* ```ts
* const original = [{ id: 1 }, { id: 2 }] as const;
*
* const cloned = Arr.copy(original);
*
* assert.deepStrictEqual(cloned, original);
*
* assert.notStrictEqual(cloned, original);
* ```
*/
export declare const copy: <const Ar extends readonly unknown[]>(array: Ar) => Ar;
type LT = Readonly<{
[N in SmallUint]: Index<N>;
}>;
type RangeList<S extends SmallUint, E extends SmallUint> = BoolOr<IsUnion<S>, IsUnion<E>> extends true ? readonly RelaxedExclude<LT[E], LT[Min<S>]>[] : List.Skip<S, Seq<E>>;
/**
* Creates an array of numbers within a specified range with optional step.
*
* @example
*
* ```ts
* const ascending = Arr.range(asUint32(1), asUint32(5));
*
* const empty = Arr.range(asUint32(2), asUint32(2));
*
* assert.deepStrictEqual(ascending, [1, 2, 3, 4]);
*
* assert.deepStrictEqual(empty, []);
* ```
*/
export declare function range<S extends SmallUint, E extends SmallUint>(start: S, end: E, step?: 1): RangeList<S, E>;
export declare function range(start: SafeUintWithSmallInt, end: SafeUintWithSmallInt, step?: PositiveSafeIntWithSmallInt): readonly SafeUint[];
export declare function range(start: SafeIntWithSmallInt, end: SafeIntWithSmallInt, step?: NonZeroSafeIntWithSmallInt): readonly SafeInt[];
export {};
//# sourceMappingURL=array-utils-creation.d.mts.map