Skip to content

Commit 8f97f13

Browse files
authored
Merge pull request #140 from theluckystrike/feat/types
feat(types): add TypeScript type definitions
2 parents 3018817 + ab83c03 commit 8f97f13

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"homepage": "https://github.com/microlinkhq/spotify-url-info",
55
"version": "3.2.18",
66
"main": "src/index.js",
7+
"types": "src/index.d.ts",
78
"author": {
89
"email": "kall@kall.ws",
910
"name": "Karl Sander"

src/index.d.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
export type SpotifyType = 'album' | 'artist' | 'episode' | 'playlist' | 'track'
2+
3+
export interface ImageSource {
4+
url: string
5+
width?: number
6+
height?: number
7+
}
8+
9+
export interface Track {
10+
artist: string
11+
duration?: number
12+
name: string
13+
previewUrl?: string
14+
uri: string
15+
}
16+
17+
export interface Preview {
18+
date: string | null
19+
title: string
20+
type: SpotifyType
21+
track: string
22+
description?: string
23+
artist: string
24+
image?: string
25+
audio?: string
26+
link: string
27+
embed: string
28+
}
29+
30+
export interface Details {
31+
preview: Preview
32+
tracks: Track[]
33+
}
34+
35+
export interface SpotifyUrlInfo {
36+
getLink: (data: unknown) => string
37+
getData: (url: string, opts?: RequestInit) => Promise<unknown>
38+
getPreview: (url: string, opts?: RequestInit) => Promise<Preview>
39+
getTracks: (url: string, opts?: RequestInit) => Promise<Track[]>
40+
getDetails: (url: string, opts?: RequestInit) => Promise<Details>
41+
}
42+
43+
export interface SpotifyUrlInfoModule {
44+
(fetch: typeof fetch): SpotifyUrlInfo
45+
parseData: (html: string) => unknown
46+
throwError: (message: string, html: string) => never
47+
}
48+
49+
export default SpotifyUrlInfoModule

0 commit comments

Comments
 (0)