Skip to content

Commit

Permalink
docs(lib): add JSDoc for YouTube library
Browse files Browse the repository at this point in the history
working on #65
  • Loading branch information
Aeonoi committed Oct 20, 2024
1 parent 5b40161 commit 191029e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const TYPE: string = "video"; // channel, video
const YOUTUBE_VIDEO_URL = "https://www.youtube.com/watch?v=";
const MAX_RESULTS = 20;

// defines type for returned json
/**
* The object returned by YouTube search API
*/
interface YoutubeAPITypes {
kind: "youtube#searchResult";
etag: string;
Expand Down Expand Up @@ -41,10 +43,14 @@ interface YoutubeAPITypes {
}

/**
* DOCS: https://developers.google.com/youtube/v3/docs/search/list#go
* @return: array of youtube url
*
* Returns the video urls of the query
*
* YouTube Search API: https://developers.google.com/youtube/v3/docs/search/list#go
*
* @returns {string[]} array of youtube url
*/
export async function fetchVideos(query: string) {
export async function fetchVideos(query: string): Promise<string[]> {
QUERY = query;
const url = `${URL_API}?key=${KEY}&q=${QUERY}&type=${TYPE}&${PART}&maxResults=${MAX_RESULTS}`;
const data = await fetch(url, {
Expand All @@ -69,5 +75,5 @@ export async function fetchVideos(query: string) {
.catch((error) => {
console.error(`Error: ${error}`);
});
return data;
return data ? data : [];
}

0 comments on commit 191029e

Please sign in to comment.