Skip to content

Commit

Permalink
docs: add more tsdoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphschuler committed Nov 26, 2023
1 parent a1f0c16 commit a40e8d5
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/assert/src/asserts/arrayContains.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that an array contains an item.
* @param array - The array to check.
* @param item - The item to check for.
* @param message - Optional message to display on failure.
*/
export function arrayContains<T>(
array: T[],
item: T,
Expand Down
5 changes: 5 additions & 0 deletions packages/assert/src/asserts/arrayNotEmpty.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that an array is not empty.
* @param array - The array to check.
* @param message - Optional message to display on failure.
*/

Check notice on line 7 in packages/assert/src/asserts/arrayNotEmpty.assert.ts

View workflow job for this annotation

GitHub Actions / Chat GPT Code Peer Review

Improve arrayNotEmpty assert

The `arrayNotEmpty` assert can be improved by checking if the `array` parameter is actually an array and also by providing a more descriptive failure message.
export function arrayNotEmpty<T>(
array: T[],
message: string = "Array is empty",
Expand Down
6 changes: 6 additions & 0 deletions packages/assert/src/asserts/equals.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that two values are equal.
* @param actual - The actual value.
* @param expected - The expected value.
* @param message - Optional message to display on failure.
*/
export function equals<T>(
actual: T,
expected: T,
Expand Down
6 changes: 6 additions & 0 deletions packages/assert/src/asserts/greaterThan.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that a number is greater than another number.
* @param actual - The actual number.
* @param expected - The expected number.
* @param message - Optional message to display on failure.
*/
export function greaterThan(
actual: number,
expected: number,
Expand Down
6 changes: 6 additions & 0 deletions packages/assert/src/asserts/instanceOf.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that an object is an instance of the specified class.

Check notice on line 4 in packages/assert/src/asserts/instanceOf.assert.ts

View workflow job for this annotation

GitHub Actions / Chat GPT Code Peer Review

Improve Readability

Consider using the term 'type' instead of 'class' in the comments for the 'instanceOf' function.
* @param object - The object to check.
* @param constructor - The class to check for.
* @param message - Optional message to display on failure.
*/
export function instanceOf<T>(
object: unknown,
constructor: { new (...args: unknown[]): T },
Expand Down
5 changes: 5 additions & 0 deletions packages/assert/src/asserts/isBoolean.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that a value is a boolean.
* @param value - The value to check.
* @param message - Optional message to display on failure.
*/
export function isBoolean(
value: unknown,
message: string = "Value is not a boolean",
Expand Down
5 changes: 5 additions & 0 deletions packages/assert/src/asserts/isDefined.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that a value is defined.
* @param value - The value to check.
* @param message - Optional message to display on failure.
*/
export function isDefined<T>(
value: T | undefined,
message: string = "Value should be defined",
Expand Down
5 changes: 5 additions & 0 deletions packages/assert/src/asserts/isNotNull.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that a value is not null.
* @param value - The value to check.
* @param message - Optional message to display on failure.
*/
export function isNotNull<T>(
value: T | null,
message: string = "Value should not be null",
Expand Down
5 changes: 5 additions & 0 deletions packages/assert/src/asserts/isNumber.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that a value is a number.
* @param value - The value to check.
* @param message - Optional message to display on failure.
*/
export function isNumber(
value: unknown,
message: string = "Value is not a number",
Expand Down
5 changes: 5 additions & 0 deletions packages/assert/src/asserts/isString.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that a value is a string.
* @param value - The value to check.
* @param message - Optional message to display on failure.
*/
export function isString(
value: unknown,
message: string = "Value is not a string",
Expand Down
6 changes: 6 additions & 0 deletions packages/assert/src/asserts/lessThan.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that a number is less than another number.
* @param actual - The actual number.
* @param expected - The expected number.
* @param message - Optional message to display on failure.
*/
export function lessThan(
actual: number,
expected: number,
Expand Down
6 changes: 6 additions & 0 deletions packages/assert/src/asserts/notEquals.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that two values are not equal.
* @param actual - The actual value.
* @param expected - The expected value.
* @param message - Optional message to display on failure.
*/
export function notEquals<T>(
actual: T,
expected: T,
Expand Down
5 changes: 5 additions & 0 deletions packages/assert/src/asserts/throws.assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { assert } from "../utils/assert.util.js";

/**
* Asserts that a function throws an error.
* @param block - The function to execute.
* @param message - Optional message to display on failure.
*/
export function throws(
block: () => void,
message: string = "Expected function to throw an error",
Expand Down
8 changes: 8 additions & 0 deletions packages/assert/src/errors/AssertionError.error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
/**
* AssertionError
* @param {string} message
* @returns {AssertionError}

Check notice on line 4 in packages/assert/src/errors/AssertionError.error.ts

View workflow job for this annotation

GitHub Actions / Chat GPT Code Peer Review

Update AssertionError.error.ts

The return type should be specified with a colon instead of an arrow. The correct syntax is: ```typescript /** * @param {string} message * @returns {AssertionError} */ ```
*/
export class AssertionError extends Error {
/**
* @param {string} message
*/
constructor(message: string) {
super(message);
this.name = "AssertionError";
Expand Down
5 changes: 5 additions & 0 deletions packages/assert/src/utils/assert.util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { AssertionError } from "../errors/AssertionError.error.js";

/**
* Asserts that a condition is true.
* @param condition - The condition to check.
* @param message - Optional message to display on failure.
*/
export function assert(
condition: boolean,
message: string = "Assertion failed",
Expand Down
24 changes: 24 additions & 0 deletions packages/better-map/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@

/**

Check failure on line 2 in packages/better-map/src/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/better-map/src/index.ts#L1-L2

[prettier/prettier] Delete `⏎`
* A better Map class that has some more useful methods.
*
* @template k The type of the keys.
* @template v The type of the values.
*/
export class BetterMap<k, v> extends Map<k, v> {

Check failure on line 9 in packages/better-map/src/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/better-map/src/index.ts#L8-L9

[prettier/prettier] Delete `⏎··`
/**
* Updates a value in the map if it exists, otherwise sets it to the default value.
* @param key - The key of the value to update.
* @param updater - The function to update the value with.
* @param notset - The default value to set if the key does not exist.
*/

Check notice on line 15 in packages/better-map/src/index.ts

View workflow job for this annotation

GitHub Actions / Chat GPT Code Peer Review

Improve comment clarity

The comment for the `update` method could be improved for clarity. Instead of using `notset` as the parameter name for the default value, it would be better to use `defaultValue` or `defaultVal` to make it more descriptive. Also, the comment could include an example of how the `updater` function should be defined.
update(key: k, updater: (v: v, k: k) => v, notset?: v) {
if (this.has(key)) this.set(key, updater(this.get(key)!, key));
else this.set(key, notset ?? updater(this.get(key)!, key));
}

/**
* Filters the map by a predicate.
* @param predicate - The predicate to filter by.
* @returns A new map with the filtered values.
*/
filter(predicate: (v: v, k: k) => boolean) {
const newMap = new BetterMap<k, v>();
const entries = Array.from(this.entries());
Expand All @@ -13,6 +32,11 @@ export class BetterMap<k, v> extends Map<k, v> {
return newMap;
}

/**
* Maps the map by a predicate.
* @param predicate - The predicate to map by.
* @returns A new map with the mapped values.
*/

Check notice on line 39 in packages/better-map/src/index.ts

View workflow job for this annotation

GitHub Actions / Chat GPT Code Peer Review

Missing Implementation Details

The implementation details of the `map` method are missing. It would be helpful to provide more information about how the map operation is performed on the map.
merge(map: Map<k, v>, resolve: (k: k, a: v, b: v) => v = (k, a, b) => b) {
const entries = Array.from(map.entries());
for (const [key, value] of entries) {
Expand Down
29 changes: 29 additions & 0 deletions packages/better-set/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

/**

Check failure on line 2 in packages/better-set/src/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/better-set/src/index.ts#L1-L2

[prettier/prettier] Delete `⏎`
* A better Set class with more methods.
* @template v The type of the values.
*/
export class BetterSet<v> extends Set<v> {

Check failure on line 7 in packages/better-set/src/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/better-set/src/index.ts#L6-L7

[prettier/prettier] Delete `⏎··`
/**
* Filters the set by a predicate.
* @param predicate - The predicate to filter by.
* @returns A new set with the filtered values.
*/
filter(predicate: (v: v) => boolean) {
const newSet = new BetterSet<v>();
const entries = Array.from(this.entries());
Expand All @@ -8,13 +19,25 @@ export class BetterSet<v> extends Set<v> {
return newSet;
}

/**
* Maps the set by a predicate.
* @param predicate - The predicate to map by.
* @returns A new set with the mapped values.
* @template v2 The type of the mapped values.
*/
merge(set: Set<v>) {
const entries = Array.from(set.entries());
for (const kv of entries) {
this.add(kv[0]);
}
}

/**
* Maps the set by a predicate.
* @param predicate - The predicate to map by.
* @returns A new set with the mapped values.
* @template v2 The type of the mapped values.
*/

Check notice on line 40 in packages/better-set/src/index.ts

View workflow job for this annotation

GitHub Actions / Chat GPT Code Peer Review

Review for `packages/better-set/src/index.ts`

Consider updating the `map` method. - Consider providing more descriptive name for the `map` method. - Consider updating the description of the `map` method to provide more context on what it does. - Consider updating the parameter name `predicate` to reflect the purpose of the function. - Consider updating the return type description to provide more details on the actual type of the values in the new set. - Consider updating the template parameter name `v2` to a more descriptive name that reflects the purpose of the mapped values.
except(set: Set<v>) {
const newSet = new Set<v>();
const entries = Array.from(set.entries());
Expand All @@ -24,6 +47,12 @@ export class BetterSet<v> extends Set<v> {
return newSet;
}

/**
* Maps the set by a predicate.
* @param predicate - The predicate to map by.
* @returns A new set with the mapped values.
* @template v2 The type of the mapped values.
*/
both(set: Set<v>) {
const newSet = new Set<v>();
const entries = Array.from(set.entries());
Expand Down

0 comments on commit a40e8d5

Please sign in to comment.