mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-18 20:12:12 +00:00
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:
31
src/parser/classes/AccountItem.ts
Normal file
31
src/parser/classes/AccountItem.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { YTNode } from '../helpers.js';
|
||||
import { type RawNode } from '../index.js';
|
||||
import NavigationEndpoint from './NavigationEndpoint.js';
|
||||
import Text from './misc/Text.js';
|
||||
import Thumbnail from './misc/Thumbnail.js';
|
||||
|
||||
/**
|
||||
* Not a real renderer but we treat it as one to keep things organized.
|
||||
*/
|
||||
export default class AccountItem extends YTNode {
|
||||
static type = 'AccountItem';
|
||||
|
||||
account_name: Text;
|
||||
account_photo: Thumbnail[];
|
||||
is_selected: boolean;
|
||||
is_disabled: boolean;
|
||||
has_channel: boolean;
|
||||
endpoint: NavigationEndpoint;
|
||||
account_byline: Text;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.account_name = new Text(data.accountName);
|
||||
this.account_photo = Thumbnail.fromResponse(data.accountPhoto);
|
||||
this.is_selected = !!data.isSelected;
|
||||
this.is_disabled = !!data.isDisabled;
|
||||
this.has_channel = !!data.hasChannel;
|
||||
this.endpoint = new NavigationEndpoint(data.serviceEndpoint);
|
||||
this.account_byline = new Text(data.accountByline);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,9 @@
|
||||
import { Parser } from '../index.js';
|
||||
import AccountItem from './AccountItem.js';
|
||||
import AccountItemSectionHeader from './AccountItemSectionHeader.js';
|
||||
import NavigationEndpoint from './NavigationEndpoint.js';
|
||||
import Text from './misc/Text.js';
|
||||
import Thumbnail from './misc/Thumbnail.js';
|
||||
|
||||
import { YTNode, observe, type ObservedArray } from '../helpers.js';
|
||||
import type { RawNode } from '../index.js';
|
||||
|
||||
/**
|
||||
* Not a real renderer but we treat it as one to keep things organized.
|
||||
*/
|
||||
export class AccountItem extends YTNode {
|
||||
static type = 'AccountItem';
|
||||
|
||||
account_name: Text;
|
||||
account_photo: Thumbnail[];
|
||||
is_selected: boolean;
|
||||
is_disabled: boolean;
|
||||
has_channel: boolean;
|
||||
endpoint: NavigationEndpoint;
|
||||
account_byline: Text;
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.account_name = new Text(data.accountName);
|
||||
this.account_photo = Thumbnail.fromResponse(data.accountPhoto);
|
||||
this.is_selected = !!data.isSelected;
|
||||
this.is_disabled = !!data.isDisabled;
|
||||
this.has_channel = !!data.hasChannel;
|
||||
this.endpoint = new NavigationEndpoint(data.serviceEndpoint);
|
||||
this.account_byline = new Text(data.accountByline);
|
||||
}
|
||||
}
|
||||
|
||||
export default class AccountItemSection extends YTNode {
|
||||
static type = 'AccountItemSection';
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ export default class ChannelAboutFullMetadata extends YTNode {
|
||||
/**
|
||||
* @deprecated
|
||||
* This will be removed in a future release.
|
||||
* Please use {@link Channel.view_count} instead.
|
||||
* Please use {@link ChannelAboutFullMetadata.view_count} instead.
|
||||
*/
|
||||
get views() {
|
||||
Log.warnOnce(ChannelAboutFullMetadata.type, 'ChannelAboutFullMetadata#views is deprecated. Please use ChannelAboutFullMetadata#view_count instead.');
|
||||
@@ -63,7 +63,7 @@ export default class ChannelAboutFullMetadata extends YTNode {
|
||||
/**
|
||||
* @deprecated
|
||||
* This will be removed in a future release.
|
||||
* Please use {@link Channel.joined_date} instead.
|
||||
* Please use {@link ChannelAboutFullMetadata.joined_date} instead.
|
||||
*/
|
||||
get joined(): Text {
|
||||
Log.warnOnce(ChannelAboutFullMetadata.type, 'ChannelAboutFullMetadata#joined is deprecated. Please use ChannelAboutFullMetadata#joined_date instead.');
|
||||
|
||||
@@ -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;
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
export { default as AboutChannel } from './classes/AboutChannel.js';
|
||||
export { default as AboutChannelView } from './classes/AboutChannelView.js';
|
||||
export { default as AccountChannel } from './classes/AccountChannel.js';
|
||||
export { default as AccountItem } from './classes/AccountItem.js';
|
||||
export { default as AccountItemSection } from './classes/AccountItemSection.js';
|
||||
export { default as AccountItemSectionHeader } from './classes/AccountItemSectionHeader.js';
|
||||
export { default as AccountSectionList } from './classes/AccountSectionList.js';
|
||||
|
||||
@@ -46,7 +46,6 @@ export default class VideoInfo extends MediaInfo {
|
||||
/**
|
||||
* @param data - API response.
|
||||
* @param actions - Actions instance.
|
||||
* @param player - Player instance.
|
||||
* @param cpn - Client Playback Nonce.
|
||||
*/
|
||||
constructor(data: [ApiResponse, ApiResponse?], actions: Actions, cpn: string) {
|
||||
|
||||
Reference in New Issue
Block a user