-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from radiovisual/misc-updates
feat!: fix cjs export; return undefined instead of null
- Loading branch information
Showing
27 changed files
with
11,113 additions
and
10,846 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,10 @@ | ||
/* istanbul ignore file */ | ||
/* eslint-disable unicorn/prefer-module */ | ||
const getVideoId = require('../../dist/get-video-id.js'); | ||
|
||
describe('bundled CJS module', () => { | ||
test('has the expected API', () => { | ||
expect(typeof getVideoId).toBe('function'); | ||
expect(getVideoId('https://www.youtube.com/watch?v=1234').id).toBe('1234'); | ||
}); | ||
}); |
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
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
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
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,30 @@ | ||
import extractGoogleRedirectionUrl from '../../src/utils/extract-google-redirection-url.js'; | ||
|
||
describe('extractGoogleRedirectionUrl', () => { | ||
test('throws TypeError if input is not a string', () => { | ||
expect(() => extractGoogleRedirectionUrl(123)).toThrow(TypeError); | ||
expect(() => extractGoogleRedirectionUrl({})).toThrow(TypeError); | ||
expect(() => extractGoogleRedirectionUrl([])).toThrow(TypeError); | ||
}); | ||
|
||
test('returns input as is if it does not contain Google redirect URL', () => { | ||
const nonGoogleUrl = 'https://www.example.com'; | ||
expect(extractGoogleRedirectionUrl(nonGoogleUrl)).toBe(nonGoogleUrl); | ||
}); | ||
|
||
test('extracts and decodes URL from a Google redirect URL', () => { | ||
const expectedUrl = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'; | ||
const googleRedirectUrl = `https://www.google.cz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=123&url=${encodeURIComponent(expectedUrl)}`; | ||
expect(extractGoogleRedirectionUrl(googleRedirectUrl)).toBe(expectedUrl); | ||
}); | ||
|
||
test('returns trimmed input if it does not match Google redirect pattern', () => { | ||
const nonMatchingUrl = ' https://www.google.com/search?q=openai '; | ||
expect(extractGoogleRedirectionUrl(nonMatchingUrl)).toBe(nonMatchingUrl.trim()); | ||
}); | ||
|
||
test('returns input as-is if the value is not a URL', () => { | ||
const nonMatchingUrl = 'lorem ipsum'; | ||
expect(extractGoogleRedirectionUrl(nonMatchingUrl)).toBe(nonMatchingUrl); | ||
}); | ||
}); |
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,33 @@ | ||
import sanitizeUrl from '../../src/utils/sanitize-url.js'; | ||
|
||
describe('sanitize-url', () => { | ||
test('returns the URL without modification for valid URL strings', () => { | ||
const url = 'https://example.com'; | ||
expect(sanitizeUrl(url)).toBe(url); | ||
}); | ||
|
||
test('throws TypeError for non-string inputs', () => { | ||
const input = 123; | ||
expect(() => sanitizeUrl(input)).toThrow(TypeError); | ||
}); | ||
|
||
test('trims leading or trailing spaces', () => { | ||
const url = ' https://example.com '; | ||
expect(sanitizeUrl(url)).toBe('https://example.com'); | ||
}); | ||
|
||
test('removes leading "www."', () => { | ||
const url = 'https://www.example.com'; | ||
expect(sanitizeUrl(url)).toBe('https://example.com'); | ||
}); | ||
|
||
test('extracts src from an iframe input', () => { | ||
const iframeHtml = '<iframe src="https://example.com"></iframe>'; | ||
expect(sanitizeUrl(iframeHtml)).toBe('https://example.com'); | ||
}); | ||
|
||
test('returns an empty string when getSrc returns undefined for an iframe', () => { | ||
const iframeHtml = '<iframe></iframe>'; | ||
expect(sanitizeUrl(iframeHtml)).toBe(''); | ||
}); | ||
}); |
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
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
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
{ | ||
"env": { | ||
"test": { | ||
"plugins": [ | ||
"@babel/plugin-transform-modules-commonjs" | ||
] | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export default function getVideoId( | ||
url: string | ||
): { | ||
id: string | null; | ||
service: 'youtube' | 'vimeo' | 'vine' | 'videopress' | 'microsoftstream' | 'tiktok' | 'dailymotion' | null; | ||
id: string | undefined; | ||
service: 'youtube' | 'vimeo' | 'vine' | 'videopress' | 'microsoftstream' | 'tiktok' | 'dailymotion' | undefined; | ||
}; |
Oops, something went wrong.