Skip to content

Commit

Permalink
refactor: format
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed May 23, 2024
1 parent 8427dca commit 9247a07
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 40 deletions.
39 changes: 20 additions & 19 deletions src/local.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
import SpotifyUri from "./spotify-uri";
import { SpotifyTypes } from "./types-enum";
import { encode } from "./util";
import SpotifyUri from './spotify-uri'
import { SpotifyTypes } from './types-enum'
import { encode } from './util'

export default class Local extends SpotifyUri {
public artist: string;
public album: string;
public track: string;
public seconds: number;
public artist: string
public album: string
public track: string
public seconds: number

constructor(
constructor (
uri: string,
artist: string,
album: string,
track: string,
seconds: number
) {
super(uri, "", SpotifyTypes.Local);
this.artist = artist;
this.album = album;
this.track = track;
this.seconds = seconds;
super(uri, '', SpotifyTypes.Local)
this.artist = artist
this.album = album
this.track = track
this.seconds = seconds
}

public static is(v: any): v is Local {
return typeof v === "object" && v.type === "local";
public static is (v: any): v is Local {
return typeof v === 'object' && v.type === 'local'
}

public toURI(): string {
public toURI (): string {
return `spotify:${this.type}:${encode(this.artist)}:${encode(
this.album
)}:${encode(this.track)}:${this.seconds}`;
)}:${encode(this.track)}:${this.seconds}`
}

public toURL(): string {
public toURL (): string {
return `/${this.type}/${encode(this.artist)}/${encode(this.album)}/${encode(
this.track
)}/${this.seconds}`;
)}/${this.seconds}`
}
}
4 changes: 3 additions & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export default function parse (input: string | SpotifyUri): ParsedSpotifyUri {
if (hostname === 'embed.spotify.com') {
const parsedQs = Object.fromEntries(searchParams)
if (typeof parsedQs.uri !== 'string') {
throw new Error('Parsed query string was not valid: ' + searchParams.toString())
throw new Error(
'Parsed query string was not valid: ' + searchParams.toString()
)
}
return parse(parsedQs.uri)
}
Expand Down
1 change: 1 addition & 0 deletions src/playlist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import SpotifyUri from './spotify-uri'
import { SpotifyTypes } from './types-enum'
import { encode } from './util'

export default class Playlist extends SpotifyUri {
public user?: string

Expand Down
18 changes: 9 additions & 9 deletions src/spotify-uri.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { SpotifyTypes } from './types-enum';
import { SpotifyTypes } from './types-enum'
import { encode } from './util'

export default abstract class SpotifyUri {
public type: SpotifyTypes;
public id: string;
public uri: string;

constructor (uri: string, id : string, type: SpotifyTypes) {
this.uri = uri;
this.id = id;
this.type = type;
public type: SpotifyTypes
public id: string
public uri: string

constructor (uri: string, id: string, type: SpotifyTypes) {
this.uri = uri
this.id = id
this.type = type
}

public static is (v: any): v is SpotifyUri {
Expand Down
22 changes: 11 additions & 11 deletions src/types-enum.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export enum SpotifyTypes {
Album = 'album',
Artist = 'artist',
Episode = 'episode',
Local = 'local',
Playlist = 'playlist',
Search = 'search',
Show = 'show',
Track = 'track',
User = 'user',
Embed = 'embed'
}
Album = 'album',
Artist = 'artist',
Episode = 'episode',
Local = 'local',
Playlist = 'playlist',
Search = 'search',
Show = 'show',
Track = 'track',
User = 'user',
Embed = 'embed'
}

0 comments on commit 9247a07

Please sign in to comment.