diff --git a/global.d.ts b/global.d.ts new file mode 100644 index 0000000..f0ae398 --- /dev/null +++ b/global.d.ts @@ -0,0 +1,87 @@ +declare module "@meting/core" { + export {}; + export type Platform = "netease" | "tencent" | "kugou" | "baidu" | "kuwo"; + + export default class Meting { + constructor(server?: Platform); + + readonly VERSION: string; + /** + * raw response + */ + readonly raw: string; + /** + * response information + */ + readonly info: Readonly<{ statusCode: number; headers: Readonly> }>; + /** + * error code + */ + readonly error: string; + /** + * error message + */ + readonly status: string; + /** + * request headers + */ + readonly header: Readonly>; + readonly server: Platform; + readonly provider: unknown; + readonly isFormat: boolean; + + site(server: Platform): this; + cookie(cookie: string): this; + format(enable: boolean): this; + + search(keyword: string, option?: SearchOption): Promise; + song(id: string): Promise; + album(id: string): Promise; + artist(id: string, limit?: number): Promise; + playlist(id: string): Promise; + url(id: string, bitrate?: number): Promise; + lyric(id: string): Promise; + pic(id: string, size?: number): Promise; + + static getSupportedPlatforms(): Platform[]; + static isSupported(server: string): boolean; + } + + interface SearchOption { + page?: number; + limit?: number; + type?: number; + } + + export interface FormattedSong { + id: string; + name: string; + artist: string[]; + album: string; + pic_id: string; + url_id: string; + lyric_id: string; + source: Platform; + } + + export interface FormattedLyric { + lyric: string; + tlyric: string; + } + + export type FormattedUrl = + & { size?: number } + & ( + { + url: ""; + br: -1; + } | { + url: string; + br: number; + } + ); + + export interface FormattedPic { + url: string; + } +} diff --git a/package.json b/package.json index c54bb1a..d322af6 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,12 @@ "type": "module", "exports": { "import": "./lib/meting.esm.js", + "types": "./global.d.ts", "require": "./lib/meting.js" }, "files": [ "lib/", + "global.d.ts", "LICENSE" ], "scripts": {