ts-data-forge
Version:
[](https://www.npmjs.com/package/ts-data-forge) [](https://www.npmjs.com/package/ts-data-forge) [);
*
* assert.isFalse(Arr.isArray(maybeValue));
*
* if (Arr.isArray(maybeArray)) {
* assert.deepStrictEqual(maybeArray, [1, 2, 3]);
* }
* ```
*/
export declare const isArray: <E>(value: E) => value is FilterArray<E>;
type FilterArray<T> = T extends T ? BoolOr<TypeEq<T, unknown>, TypeEq<T, any>> extends true ? Cast<readonly unknown[], T> : T extends readonly unknown[] ? T : never : never;
type Cast<A, B> = A extends B ? A : never;
/**
* Type guard that checks if an array is empty.
*
* @example
*
* ```ts
* const emptyNumbers: readonly number[] = [] as const;
*
* const words = ['Ada', 'Lovelace'] as const;
*
* assert.isTrue(Arr.isEmpty(emptyNumbers));
*
* assert.isFalse(Arr.isEmpty(words));
*
* if (Arr.isEmpty(emptyNumbers)) {
* assert.deepStrictEqual(emptyNumbers, []);
* }
* ```
*/
export declare const isEmpty: <E>(array: readonly E[]) => array is readonly [];
/**
* Type guard that checks if an array is non-empty.
*
* @example
*
* ```ts
* const users: readonly { id: number }[] = [{ id: 1 }];
*
* const emptyUsers: readonly { id: number }[] = [];
*
* assert.isTrue(Arr.isNonEmpty(users));
*
* assert.isFalse(Arr.isNonEmpty(emptyUsers));
*
* if (Arr.isNonEmpty(users)) {
* assert.deepStrictEqual(users[0], { id: 1 });
* }
* ```
*/
export declare const isNonEmpty: <E>(array: readonly E[]) => array is NonEmptyArray<E>;
/**
* Checks if an array has a specific length.
*
* @example
*
* ```ts
* const pair: readonly number[] = [1, 2];
*
* const triple: readonly number[] = [1, 2, 3];
*
* assert.isTrue(Arr.isArrayOfLength(pair, 2));
*
* assert.isFalse(Arr.isArrayOfLength(triple, 2));
*
* if (Arr.isArrayOfLength(pair, 2)) {
* assert.deepStrictEqual(pair, [1, 2]);
* }
* ```
*/
export declare const isArrayOfLength: <E, N extends SizeType.ArgArr>(array: readonly E[], len: N) => array is ArrayOfLength<N, E>;
/**
* Checks if an array has at least a specific length.
*
* @example
*
* ```ts
* const queue: readonly string[] = ['task-1', 'task-2'];
*
* const emptyQueue: readonly string[] = [];
*
* assert.isTrue(Arr.isArrayAtLeastLength(queue, 1));
*
* assert.isFalse(Arr.isArrayAtLeastLength(emptyQueue, 1));
*
* if (Arr.isArrayAtLeastLength(queue, 1)) {
* assert.isTrue(queue[0] === 'task-1');
* }
* ```
*/
export declare const isArrayAtLeastLength: <E, N extends SizeType.ArgArr>(array: readonly E[], len: N) => array is ArrayAtLeastLen<N, E>;
/**
* Tests whether all elements in an array pass a test implemented by a predicate.
*
* @example
*
* ```ts
* const numbers = [2, 4, 6] as const;
*
* const words = ['Ada', 'Grace'] as const;
*
* const allEven = Arr.every(numbers, (value) => value % 2 === 0);
*
* const allStartWithA = Arr.every(words, (value) => value.startsWith('A'));
*
* assert.isTrue(allEven);
*
* assert.isFalse(allStartWithA);
* ```
*/
export declare function every<E, S extends E>(array: readonly E[], predicate: (a: E, index: SizeType.Arr) => a is S): array is readonly S[];
export declare function every<E, S extends E>(predicate: (a: E, index: SizeType.Arr) => a is S): (array: readonly E[]) => array is readonly S[];
export declare function every<const Ar extends readonly unknown[]>(array: Ar, predicate: (a: Ar[number], index: ArrayIndex<Ar>) => boolean): boolean;
export declare function every<E>(predicate: (a: E, index: SizeType.Arr) => boolean): (array: readonly E[]) => boolean;
/**
* Tests whether at least one element in an array passes a test implemented by a predicate.
*
* @example
*
* ```ts
* const numbers = [1, 3, 5] as const;
*
* const words = ['Ada', 'Grace'] as const;
*
* const hasEven = Arr.some(numbers, (value) => value % 2 === 0);
*
* const hasShortName = Arr.some(words, (value) => value.length <= 3);
*
* assert.isFalse(hasEven);
*
* assert.isTrue(hasShortName);
* ```
*/
export declare function some<const Ar extends readonly unknown[]>(array: Ar, predicate: (a: Ar[number], index: ArrayIndex<Ar>) => boolean): boolean;
export declare function some<E>(predicate: (a: E, index: SizeType.Arr) => boolean): (array: readonly E[]) => boolean;
/**
* Checks if an index is within the valid range of an array.
*
* @example
*
* ```ts
* const items = ['Ada', 'Grace', 'Katherine'] as const;
*
* assert.isTrue(Arr.indexIsInRange(items, 1));
*
* assert.isFalse(Arr.indexIsInRange(items, 3));
*
* if (Arr.indexIsInRange(items, 2)) {
* assert.isTrue(items[2] === 'Katherine');
* }
* ```
*/
export declare const indexIsInRange: <E>(array: readonly E[], index: SizeType.ArgArr) => boolean;
export {};
//# sourceMappingURL=array-utils-validation.d.mts.map