File tree Expand file tree Collapse file tree 4 files changed +28
-7
lines changed
Expand file tree Collapse file tree 4 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -63,13 +63,8 @@ extractLatLngFromGoogleMapsUrl("https://googlemaps.com"); // null
6363Extract a YouTube video ID from different kinds of YouTube URLs
6464
6565``` typescript
66- console .log (
67- extractYouTubeVideoID (" https://www.youtube.com/watch?v=JWJz_MS1-I8&t=1815s" )
68- );
69- // Output: "JWJz_MS1-I8"
70-
71- console .log (extractYouTubeVideoID (" https://youtu.be/JWJz_MS1-I8" ));
72- // Output: "JWJz_MS1-I8"
66+ extractYouTubeVideoID (" https://www.youtube.com/watch?v=JWJz_MS1-I8&t=1815s" ); // JWJz_MS1-I8
67+ extractYouTubeVideoID (" https://youtu.be/JWJz_MS1-I8" ); // JWJz_MS1-I8
7368```
7469
7570### ` generatePrefixedId `
@@ -85,6 +80,18 @@ generatePrefixedId("usr"); // usr_<uuid>
8580generatePrefixedId (" kyl" ); // kyl_<uuid>
8681```
8782
83+ ### ` getYoutubeThumbnail `
84+
85+ Returns a youtube thumbnail for a given youtube video
86+
87+ ** Usage:**
88+
89+ ``` typescript
90+ import { getYoutubeThumbnail } from " largs-utils" ;
91+
92+ getYoutubeThumbnail (" dQw4w9WgXcQ" ); // `https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg`
93+ ```
94+
8895### ` isValidEmail `
8996
9097Validates if a given email address is in a proper format.
Original file line number Diff line number Diff line change 1+ import { getYoutubeThumbnail } from "../getYoutubeThumbnail" ;
2+
3+ describe ( "getYoutubeThumbnail" , ( ) => {
4+ it ( "should return the correct YouTube thumbnail URL" , ( ) => {
5+ const videoId = "dQw4w9WgXcQ" ;
6+ const expectedUrl = `https://i.ytimg.com/vi/${ videoId } /maxresdefault.jpg` ;
7+
8+ expect ( getYoutubeThumbnail ( videoId ) ) . toBe ( expectedUrl ) ;
9+ } ) ;
10+ } ) ;
Original file line number Diff line number Diff line change 1+ export const getYoutubeThumbnail = ( youtubeVideoId : string ) => {
2+ return `https://i.ytimg.com/vi/${ youtubeVideoId } /maxresdefault.jpg` ;
3+ } ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ export { extractLatLngFromGoogleMapsUrl } from "./extractLatLngFromGoogleMapsUrl
44export { extractYouTubeVideoID } from "./extractYoutubeVideoId" ;
55export { generatePrefixedId } from "./generatePrefixedId" ;
66export { generateSlug } from "./generateSlug" ;
7+ export { getYoutubeThumbnail } from "./getYoutubeThumbnail" ;
78export { isValidEmail } from "./isValidEmail" ;
89export { isValidGoogleMapsUrl } from "./isValidGoogleMapsUrl" ;
910export { isValidHttpUrl } from "./isValidHttpUrl" ;
You can’t perform that action at this time.
0 commit comments