Skip to content

Commit 8e7720c

Browse files
committed
📝 Update document comments
1 parent 3108af2 commit 8e7720c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+55
-79
lines changed

as/mod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { asOptional, asUnoptional } from "./optional.ts";
22
import { asReadonly, asUnreadonly } from "./readonly.ts";
33

4+
/**
5+
* Annotation collection for object predicate properties.
6+
*/
47
export const as = {
58
Optional: asOptional,
69
Readonly: asReadonly,

as/optional.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
* });
2121
* const a: unknown = {};
2222
* if (isMyType(a)) {
23-
* // a is narrowed to {foo?: string}
2423
* const _: {foo?: string} = a;
2524
* }
2625
* ```
@@ -64,7 +63,6 @@ export function asOptional<P extends Predicate<unknown>>(
6463
* });
6564
* const a: unknown = {foo: "a"};
6665
* if (isMyType(a)) {
67-
* // a is narrowed to {foo: string}
6866
* const _: {foo: string} = a;
6967
* }
7068
* ```

as/readonly.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { rewriteName } from "../_funcutil.ts";
2-
import type { Predicate, PredicateType } from "../type.ts";
2+
import type { Predicate } from "../type.ts";
33
import {
44
annotate,
55
hasAnnotation,
@@ -20,7 +20,6 @@ import {
2020
* });
2121
* const a: unknown = {};
2222
* if (isMyType(a)) {
23-
* // a is narrowed to {readonly foo: string}
2423
* const _: {readonly foo: string} = a;
2524
* }
2625
* ```
@@ -55,7 +54,6 @@ export function asReadonly<P extends Predicate<unknown>>(
5554
* });
5655
* const a: unknown = {foo: "a"};
5756
* if (isMyType(a)) {
58-
* // a is narrowed to {foo: string}
5957
* const _: {foo: string} = a;
6058
* }
6159
* ```

assert.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import type { Predicate } from "./type.ts";
22

3+
/**
4+
* A factory function that generates assertion error messages.
5+
*/
36
export 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+
*/
915
export const defaultAssertMessageFactory: AssertMessageFactory = (
1016
x,
1117
pred,
@@ -26,7 +32,7 @@ let assertMessageFactory = defaultAssertMessageFactory;
2632
*/
2733
export 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
*/
6370
export 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
*/
8492
export function assert<T>(
8593
x: unknown,

ensure.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { assert } from "./assert.ts";
44
/**
55
* Ensures that the given value satisfies the provided predicate.
66
*
7+
* It throws {@linkcode AssertError} if the value does not satisfy the predicate.
8+
*
79
* ```ts
810
* import { ensure, is } from "@core/unknownutil";
911
*
@@ -15,7 +17,6 @@ import { assert } from "./assert.ts";
1517
* @param pred The predicate function to test the value against.
1618
* @param options Optional configuration for the assertion.
1719
* @returns The input value `x`.
18-
* @throws {AssertError} If the value does not satisfy the predicate.
1920
*/
2021
export function ensure<T>(
2122
x: unknown,

is/any.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*
77
* const a = "a";
88
* if (is.Any(a)) {
9-
* // a is narrowed to any
109
* const _: any = a;
1110
* }
1211
* ```

is/array.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*
77
* const a: unknown = [0, 1, 2];
88
* if (is.Array(a)) {
9-
* // a is narrowed to unknown[]
109
* const _: unknown[] = a;
1110
* }
1211
* ```

is/array_of.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { isArray } from "./array.ts";
1313
* const isMyType = is.ArrayOf(is.String);
1414
* const a: unknown = ["a", "b", "c"];
1515
* if (isMyType(a)) {
16-
* // a is narrowed to string[]
1716
* const _: string[] = a;
1817
* }
1918
* ```

is/async_function.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const objectToString = Object.prototype.toString;
88
*
99
* const a: unknown = async () => {};
1010
* if (is.AsyncFunction(a)) {
11-
* // a is narrowed to (...args: unknown[]) => Promise<unknown>
1211
* const _: ((...args: unknown[]) => Promise<unknown>) = a;
1312
* }
1413
* ```

is/bigint.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*
77
* const a: unknown = 0n;
88
* if (is.Bigint(a)) {
9-
* // a is narrowed to bigint
109
* const _: bigint = a;
1110
* }
1211
* ```

0 commit comments

Comments
 (0)