-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e82d9d
commit bab29c3
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export function getEmbedSrc(id: string, platform: string, params: Record<string, string> = {}): string | undefined { | ||
if (platform === 'vimeo') return getVimeoEmbedSrc(id, params) | ||
if (platform === 'youtube') return getYouTubeEmbedSrc(id, params) | ||
if (platform === 'deezer') return getDeezerEmbedSrc(id, params) | ||
if (platform === 'spotify') return getSpotifyEmbedSrc(id, params) | ||
if (platform === 'soundcloud') return getSoundcloudEmbedSrc(id, params) | ||
} | ||
|
||
export function getVimeoEmbedSrc(id: string, params: Record<string, string> = {}): string { | ||
return getEmbedUrl(`https://player.vimeo.com/video/${id}`, params) | ||
} | ||
|
||
export function getYouTubeEmbedSrc(id: string, params: Record<string, string> = {}): string { | ||
return getEmbedUrl(`https://www.youtube-nocookie.com/embed/${id}`, params) | ||
} | ||
|
||
export function getDeezerEmbedSrc(id: string, params: Record<string, string> = {}): string { | ||
return getEmbedUrl(`https://widget.deezer.com/widget/light/${id}`, params) | ||
} | ||
|
||
export function getSpotifyEmbedSrc(id: string, params: Record<string, string> = {}): string { | ||
return getEmbedUrl(`https://open.spotify.com/embed/${id}`, params) | ||
} | ||
|
||
export function getSoundcloudEmbedSrc(id: string, params: Record<string, string> = {}): string { | ||
return getEmbedUrl(`https://w.soundcloud.com/player/?url=${id}`, params) | ||
} | ||
|
||
export function getEmbedUrl(url: string, params: Record<string, string> = {}) { | ||
const encodedParams = encodeUrlParams(params) | ||
|
||
if (encodedParams.length) url += '?' + encodedParams | ||
|
||
return url | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function toBoolean(value: unknown): boolean { | ||
return typeof value === 'string' | ||
? (value as string).toLowerCase() === 'true' || | ||
(value as string).toLowerCase() === 'yes' || | ||
(value as string).toLowerCase() === 'on' || | ||
(value as string).toLowerCase() === '1' | ||
: !!value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function encodeUrlParams(params: object): string { | ||
return Object.entries(params) | ||
.map((kv) => kv.map(encodeURIComponent).join('=')) | ||
.join('&') | ||
} |