Skip to content

Commit 284d51f

Browse files
📝 Add docstrings to docs
Docstrings generation was requested by @brianrodri. * #57 (comment) The following files were modified: * `src/model/collection/periodic-notes.ts` * `src/model/collection/util.ts` * `src/model/task/util.ts` * `src/util/luxon-utils.ts`
1 parent 766d953 commit 284d51f

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

src/model/collection/periodic-notes.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,21 @@ export type PeriodicNotesConfig<IsValidConfiguration extends boolean> =
102102
};
103103

104104
/**
105-
* @param config - the config to validate.
106-
* @throws if any of the config's properties are invalid.
107-
* @returns a new valid config with narrower types.
105+
* Validates a PeriodicNotes configuration object.
106+
*
107+
* This function ensures that:
108+
* - The folder path, after removing any trailing slash, is non-empty.
109+
* - The date format is valid with the provided date options.
110+
* - The interval duration is a valid, non-zero duration.
111+
* - The interval offset is a valid duration.
112+
*
113+
* If any of these validations fail, an {@link AggregateError} is thrown detailing all issues.
114+
* Otherwise, it returns a new configuration object with more specific types.
115+
*
116+
* @param config - The configuration object to validate.
117+
* @returns A validated configuration with strictly defined properties.
118+
*
119+
* @throws {AggregateError} If one or more properties of the configuration are invalid.
108120
*/
109121
function validated(config: PeriodicNotesConfig<false>): PeriodicNotesConfig<true> {
110122
const folder = stripTrailingSlash(config.folder);

src/model/collection/util.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/**
2-
* @param folder - the folder to sanitize.
3-
* @returns sanitized value with trailing slashes removed, if applicable.
2+
* Returns a sanitized folder path by removing a trailing slash unless the path is the root ("/").
3+
*
4+
* The function trims whitespace from the input folder string. If the trimmed string equals "/", it is returned unchanged. Otherwise, any trailing slash is removed.
5+
*
6+
* @param folder - The folder path to sanitize.
7+
* @returns The folder path without a trailing slash, except for the root path.
48
*/
59
export function stripTrailingSlash(folder: string): string {
610
folder = folder.trim();

src/model/task/util.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { DeepPartial } from "utility-types";
55
import { DEFAULT_PRIORITY_VALUE, DEFAULT_TYPE_VALUE, Task, TASK_WITH_DEFAULT_VALUES } from "@/model/task/schema";
66

77
/**
8-
* @param parts - the task parts to merge.
8+
* Merges multiple partial Task objects into a complete Task using a custom merge strategy.
9+
*
10+
* The function begins with default Task values and sequentially merges each provided partial Task. For each property, the front-most non-default value is retained. Special handling is applied for properties such as task type, priority, strings, DateTime objects, and Set collections.
11+
*
12+
* @param parts - The partial Task objects to merge.
913
* @returns new {@link Task} with the front-most non-default values taken from the parts.
1014
*/
1115
export function mergeTaskParts(...parts: DeepPartial<Task>[]): Task {

src/util/luxon-utils.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ export type LuxonValue<IsValid extends boolean> = DateTime<IsValid> | Duration<I
99
export type LuxonFormat = Brand<string, "LuxonFormat">;
1010

1111
/**
12-
* @param value - the {@link LuxonValue} to check.
13-
* @param message - the message to use in the error.
14-
* @throws error if value is invalid.
12+
* Asserts that the provided Luxon value is valid.
13+
*
14+
* This function checks whether a Luxon date, duration, or interval is valid. If the value is invalid,
15+
* it throws an error with a message combining a custom header (or default constructor name) with the
16+
* value's invalid reason and, if available, its invalid explanation.
17+
*
18+
* @param value - The Luxon object to validate.
19+
* @param message - Optional custom header for the error message.
20+
*
21+
* @throws {Error} If the provided value is invalid.
1522
*/
1623
export function assertValid(
1724
value: LuxonValue<true> | LuxonValue<false>,

0 commit comments

Comments
 (0)