chore: add proper documentation (#763)

* chore: generate API ref using `typedoc`

* chore: declutter readme and add links to ytjs.dev

* chore: clean up
This commit is contained in:
Luan
2024-09-23 17:32:50 -03:00
committed by GitHub
parent dd7f5cf778
commit 74659fd03f
853 changed files with 139814 additions and 1929 deletions

View File

@@ -165,8 +165,8 @@ export class Maybe {
/**
* Get the value as an array.
* @returns the value as any[]
* @throws If the value is not an array
* @returns the value as any[].
* @throws If the value is not an array.
*/
array(): any[] {
if (!Array.isArray(this.#value)) {
@@ -177,7 +177,7 @@ export class Maybe {
/**
* More typesafe variant of {@link Maybe#array}.
* @returns a proxied array which returns all the values as {@link Maybe}
* @returns a proxied array which returns all the values as {@link Maybe}.
* @throws If the value is not an array
*/
arrayOfMaybe(): Maybe[] {
@@ -194,16 +194,16 @@ export class Maybe {
/**
* Check whether the value is an array.
* @returns whether the value is an array
* @returns whether the value is an array.
*/
isArray() {
return Array.isArray(this.#value);
}
/**
* Get the value as a YTNode
* @returns the value as a YTNode
* @throws If the value is not a YTNode
* Get the value as a YTNode.
* @returns the value as a YTNode.
* @throws If the value is not a YTNode.
*/
node() {
if (!(this.#value instanceof YTNode)) {
@@ -213,8 +213,8 @@ export class Maybe {
}
/**
* Check if the value is a YTNode
* @returns Whether the value is a YTNode
* Check if the value is a YTNode.
* @returns Whether the value is a YTNode.
*/
isNode() {
return this.#value instanceof YTNode;
@@ -222,9 +222,9 @@ export class Maybe {
/**
* Get the value as a YTNode of the given type.
* @param type - The type to cast to
* @returns The node casted to the given type
* @throws If the node is not of the given type
* @param types - The type(s) to cast to.
* @returns The node casted to the given type.
* @throws If the node is not of the given type.
*/
nodeOfType<T extends YTNode, K extends YTNodeConstructor<T>[]>(...types: K) {
return this.node().as(...types);
@@ -232,8 +232,8 @@ export class Maybe {
/**
* Check if the value is a YTNode of the given type.
* @param type - the type to check
* @returns Whether the value is a YTNode of the given type
* @param types - the type(s) to check.
* @returns Whether the value is a YTNode of the given type.
*/
isNodeOfType<T extends YTNode, K extends YTNodeConstructor<T>[]>(...types: K) {
return this.isNode() && this.node().is(...types);
@@ -241,7 +241,7 @@ export class Maybe {
/**
* Get the value as an ObservedArray.
* @returns the value of the Maybe as a ObservedArray
* @returns the value of the Maybe as a ObservedArray.
*/
observed(): ObservedArray<YTNode> {
if (!this.isObserved()) {
@@ -259,8 +259,8 @@ export class Maybe {
/**
* Get the value of the Maybe as a SuperParsedResult.
* @returns the value as a SuperParsedResult
* @throws If the value is not a SuperParsedResult
* @returns the value as a SuperParsedResult.
* @throws If the value is not a SuperParsedResult.
*/
parsed(): SuperParsedResult {
if (!(this.#value instanceof SuperParsedResult)) {
@@ -287,9 +287,9 @@ export class Maybe {
/**
* Get the node as an instance of the given class.
* @param type - The type to check
* @returns the value as the given type
* @throws If the node is not of the given type
* @param type - The type to check.
* @returns the value as the given type.
* @throws If the node is not of the given type.
*/
instanceof<T extends object>(type: Constructor<T>): T {
if (!this.isInstanceof(type)) {
@@ -300,8 +300,8 @@ export class Maybe {
/**
* Check if the node is an instance of the given class.
* @param type - The type to check
* @returns Whether the node is an instance of the given type
* @param type - The type to check.
* @returns Whether the node is an instance of the given type.
*/
isInstanceof<T extends object>(type: Constructor<T>): this is this & T {
return this.#value instanceof type;
@@ -370,15 +370,15 @@ export type ObservedArray<T extends YTNode = YTNode> = Array<T> & {
*/
remove: (index: number) => T[];
/**
* Get all items of a specific type
* Get all items of a specific type.
*/
filterType<R extends YTNode, K extends YTNodeConstructor<R>[]>(...types: K): ObservedArray<InstanceType<K[number]>>;
/**
* Get the first of a specific type
* Get the first of a specific type.
*/
firstOfType<R extends YTNode, K extends YTNodeConstructor<R>[]>(...types: K): InstanceType<K[number]> | undefined;
/**
* Get the first item
* Get the first item.
*/
first: () => T;
/**