import { Constructor, NestedKeys, NestedValue, PlainObject } from "../models.mjs"; //#region src/function/assert.d.ts /** * Asserter for a property of a value */ type AssertProperty, Asserted extends NestedPick = NestedPick> = Asserter; /** * A function that asserts a value is of a specific type, throwing an error if it is not */ type Asserter = (value: unknown) => asserts value is Value; type NestedPick = Value extends PlainObject ? Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Value ? { [Key in Head]: NestedPick } : never : Path extends keyof Value ? { [Key in Path]: Value[Key] } : never : never; /** * Asserts that a condition is true, throwing an error if it is not * * @param condition Condition to assert * @param message Error message * @param error Error constructor _(defaults to `Error`)_ */ declare function assert boolean>(condition: Condition, message: string, error?: ErrorConstructor): asserts condition; declare namespace assert { var condition: typeof assertCondition; var defined: typeof assertDefined; var instanceOf: typeof assertInstanceOf; var is: typeof assertIs; var property: typeof assertProperty; } /** * Creates an _Asserter_ that asserts a condition is true, throwing an error if it is not * * _Available as `assertCondition` and `assert.condition`_ * * @param condition Condition to assert * @param message Error message * @param error Error constructor _(defaults to `Error`)_ * @returns _Asserter_ */ declare function assertCondition(condition: (value: unknown) => boolean, message: string, error?: ErrorConstructor): Asserter; /** * Asserts that a value is defined, throwing an error if it is not * * _Available as `assertDefined` and `assert.defined`_ * * @param value Value to assert * @param message Error message * @param error Error constructor _(defaults to `Error`)_ */ declare function assertDefined(value: unknown, message?: string, error?: ErrorConstructor): asserts value is Exclude; /** * Creates an _Asserter_ that asserts a value is an instance of a constructor, throwing an error if it is not * * _Available as `assertInstanceOf` and `assert.instanceOf`_ * * @param constructor Constructor to check against * @param message Error message * @param error Error constructor _(defaults to `Error`)_ * @returns _Asserter_ */ declare function assertInstanceOf(constructor: Constructor, message: string, error?: ErrorConstructor): Asserter; /** * Creates an _Asserter_ that asserts a value is of a specific type, throwing an error if it is not * * _Available as `assertIs` and `assert.is`_ * * @param condition Type guard function to check the value * @param message Error message * @param error Error constructor _(defaults to `Error`)_ * @returns _Asserter_ */ declare function assertIs(condition: (value: unknown) => value is Value, message: string, error?: ErrorConstructor): Asserter; /** * Creates an _Asserter_ that asserts a property of a value exists and satisfies a condition, throwing an error if it does not * * _Available as `assertProperty` and `assert.property`_ * * @param path Path to the property to check, e.g., `foo.bar.baz` for a nested property * @param condition Condition to assert for the property * @param message Error message * @param error Error constructor _(defaults to `Error`)_ * @returns _Asserter_ */ declare function assertProperty, Asserted = NestedPick>(path: Path, condition: (value: NestedValue) => boolean, message: string, error?: ErrorConstructor): Asserter; //#endregion export { AssertProperty, Asserter, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty };