11import type { Predicate } from "./type.ts" ;
22
3+ /**
4+ * A factory function that generates assertion error messages.
5+ */
36export type AssertMessageFactory = (
47 x : unknown ,
58 pred : Predicate < unknown > ,
69 name ?: string ,
710) => string ;
811
12+ /**
13+ * The default factory function used to generate assertion error messages.
14+ */
915export const defaultAssertMessageFactory : AssertMessageFactory = (
1016 x ,
1117 pred ,
@@ -26,7 +32,7 @@ let assertMessageFactory = defaultAssertMessageFactory;
2632 */
2733export class AssertError extends Error {
2834 /**
29- * Constructs a new `AssertError` instance.
35+ * Constructs a new instance.
3036 * @param message The error message.
3137 */
3238 constructor ( message ?: string ) {
@@ -42,8 +48,7 @@ export class AssertError extends Error {
4248
4349/**
4450 * Sets the factory function used to generate assertion error messages.
45- * @param factory The factory function.
46- * @example
51+ *
4752 * ```ts
4853 * import { is, setAssertMessageFactory } from "@core/unknownutil";
4954 *
@@ -59,6 +64,8 @@ export class AssertError extends Error {
5964 * }
6065 * });
6166 * ```
67+ *
68+ * @param factory The factory function.
6269 */
6370export function setAssertMessageFactory ( factory : AssertMessageFactory ) : void {
6471 assertMessageFactory = factory ;
@@ -67,6 +74,8 @@ export function setAssertMessageFactory(factory: AssertMessageFactory): void {
6774/**
6875 * Asserts that the given value satisfies the provided predicate.
6976 *
77+ * It throws {@linkcode AssertError} if the value does not satisfy the predicate.
78+ *
7079 * ```ts
7180 * import { assert, is } from "@core/unknownutil";
7281 *
@@ -78,8 +87,7 @@ export function setAssertMessageFactory(factory: AssertMessageFactory): void {
7887 * @param x The value to be asserted.
7988 * @param pred The predicate function to test the value against.
8089 * @param options Optional configuration for the assertion.
81- * @returns Nothing. The function has a return type of `asserts x is T` to help TypeScript narrow down the type of `x` after the assertion.
82- * @throws {AssertError } If the value does not satisfy the predicate.
90+ * @returns The function has a return type of `asserts x is T` to help TypeScript narrow down the type of `x` after the assertion.
8391 */
8492export function assert < T > (
8593 x : unknown ,
0 commit comments