mirror of
https://github.com/maciejpedzich/spotifyplaylistarchive.com.git
synced 2024-11-09 23:13:01 +01:00
16 lines
425 B
TypeScript
16 lines
425 B
TypeScript
export const useGetPlaylistId = () => (url: string) => {
|
|
const urlObject = new URL(url);
|
|
const [collectionName, playlistId] = urlObject.pathname
|
|
.split('/')
|
|
.filter(Boolean);
|
|
|
|
const isValidPlaylistUrl =
|
|
urlObject.hostname === 'open.spotify.com' &&
|
|
collectionName === 'playlist' &&
|
|
playlistId;
|
|
|
|
if (!isValidPlaylistUrl) throw new Error('This is not a valid playlist URL');
|
|
|
|
return playlistId;
|
|
};
|