Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
feat: add jsdoc to user.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
vaaski committed Feb 12, 2021
1 parent 6d71bff commit 2c25d6b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ky from "ky-universal"
import { APIv2, getClientIDv2, scrapeData, ScrapeIDs, urlify } from "./util"

/**
* Get a playlist using the APIv2 with a playlist ID
* Get a playlist by ID using the APIv2.
* @param id A playlist ID
* @param client_id client_id for APIv2
*/
Expand All @@ -18,7 +18,7 @@ const byID = async (id: number, client_id: ClientIDv2) => {
}

/**
* Get a playlist using the APIv2 with a playlist URL
* Get a playlist by URL using the APIv2.
* @param url A playlist URL
*/
const byURL = async (url: string) => {
Expand All @@ -31,13 +31,12 @@ const byURL = async (url: string) => {
}

/**
* Get a playlist using the APIv2 with either a playlist URL or its ID.
*
* If you use a playlist ID, you can provide a v2 client_id (recommended).
* Get a playlist by either URL or ID using the APIv2.
*
* If you use a playlist ID, you can provide a v2 client_id to speed up the process (recommended).
* Uses `util.getClientIDv2` to find a client_id if none is provided.
* @param identifier A playlist URL or ID
* @param client_id Optional.
* @param client_id Optional client_id for APIv2.
*/
const playlist = async (identifier: URLorID, client_id?: ClientIDv2): Promise<Playlistv2> => {
if (typeof identifier === "string") return await byURL(identifier)
Expand Down
29 changes: 27 additions & 2 deletions src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import {
} from "./util"
import resolve from "./resolve"

// TODO JSDoc

/**
* Get a user by ID using the APIv2
* @param id A user ID
* @param client_id client_id for APIv2
*/
const getByID = async (id: number, client_id: ClientIDv2) => {
const url = urlify(`users/${id}`, APIv2)
const searchParams = { client_id }
Expand All @@ -23,6 +26,10 @@ const getByID = async (id: number, client_id: ClientIDv2) => {
return data as Userv2
}

/**
* Get a user by URL using the APIv2
* @param url A user URL
*/
const getByURL = async (url: string) => {
const scraped = await scrapeData(urlify(url))
const userData = scraped.find(({ id }) => id === ScrapeIDs.user)
Expand All @@ -32,6 +39,14 @@ const getByURL = async (url: string) => {
return data as Userv2
}

/**
* Get a user by either URL or ID using the APIv2.
*
* You can provide a v2 client_id to speed up the process (recommended).
* Uses `util.getClientIDv2` to find a client_id if none is provided.
* @param identifier A user URL or ID
* @param client_id Optional client_id for APIv2.
*/
const user = async (identifier: URLorID, client_id?: ClientIDv2): Promise<Userv2> => {
if (typeof identifier === "string") return await getByURL(identifier)

Expand All @@ -47,6 +62,16 @@ export interface LikesOptions {
limit?: number
client_id?: ClientIDv2
}
/**
* Get a user's likes by either URL or ID using the APIv2.
*
* You can provide a v2 client_id to speed up the process (recommended).
* Uses `util.getClientIDv2` to find a client_id if none is provided.
* @param identifier A user URL or ID
* @param options Optional options object.
* @param options.limit Limit the amount of tracks returned. Defaults to 50.
* @param options.client_id client_id for APIv2.
*/
user.likes = async (
identifier: URLorID,
{ limit = 50, client_id }: LikesOptions = {}
Expand Down

0 comments on commit 2c25d6b

Please sign in to comment.