diff --git a/__tests__/loom.test.js b/__tests__/loom.test.js new file mode 100644 index 0000000..ad66960 --- /dev/null +++ b/__tests__/loom.test.js @@ -0,0 +1,28 @@ +/* eslint max-len: 0 */ +import fn from '../src/index.js'; + +/** + * Loom should be able to find these patterns: + * + * Urls: + * https://www.loom.com/share/7c7ced4911904070a5627374ccd84e8c + * https://www.loom.com/share/5bbdeb480ba84e65b1b3de8c190e2003?source=embed&t=20 + * https://www.loom.com/embed/7c7ced4911904070a5627374ccd84e8c + */ +describe('Loom', () => { + test('Loom basic link', () => { + expect(fn('https://www.loom.com/share/7c7ced4911904070a5627374ccd84e8c').id).toBe('7c7ced4911904070a5627374ccd84e8c'); + expect(fn('https://www.loom.com/share/5bbdeb480ba84e65b1b3de8c190e2003?source=embed&t=20').id).toBe('5bbdeb480ba84e65b1b3de8c190e2003'); + }); + + test('Loom embed', () => { + expect(fn('
').id).toBe('7c7ced4911904070a5627374ccd84e8c'); + }); + + test('returns undefined for unknown video ids', () => { + const actual = fn('https://www.loom.com'); + expect(actual.id).toBe(undefined); + expect(actual.service).toBe('loom'); + }); +}); + diff --git a/readme.md b/readme.md index 084340f..9392684 100644 --- a/readme.md +++ b/readme.md @@ -274,6 +274,20 @@ http://dai.ly/* **:warning: Unsupported Dailymotion urls** * Channel id urls: `http://www.dailymotion.com/hub/*_title` + ### Loom + +**Loom urls** +``` +https://www.loom.com/share/7c7ced4911904070a5627374ccd84e8c +https://www.loom.com/share/5bbdeb480ba84e65b1b3de8c190e2003?source=embed&t=20 +``` + +**Loom iframe** +``` +
+``` + + ## Contributing If you discover a url pattern that is not covered by this module, please [open an issue](https://github.com/radiovisual/get-video-id/issues) to report it, or [submit a Pull Request](https://github.com/radiovisual/get-video-id/pull/new/master). For any submitted pull requests, please ensure that you include unit test(s) to fully cover your code contribution(s). diff --git a/src/index.js b/src/index.js index d521096..fc8d0c2 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ import videopress from './videopress.js'; import microsoftStream from './microsoftstream.js'; import tiktok from './tiktok.js'; import dailymotion from './dailymotion.js'; +import loom from './loom.js'; import getSrc from './utils/get-src.js'; /** @@ -84,6 +85,11 @@ function getVideoId(urlString) { id: dailymotion(string_), service: 'dailymotion', }; + } else if (/loom\.com/.test(string_)) { + metadata = { + id: loom(string_), + service: 'loom', + }; } return metadata; diff --git a/src/loom.js b/src/loom.js new file mode 100644 index 0000000..4e4d5f1 --- /dev/null +++ b/src/loom.js @@ -0,0 +1,16 @@ +/** + * Get the loom id. + * @param {string} urlString - the url from which you want to extract the id + * @returns {string|undefined} + */ +export default function loom(urlString) { + // Parse basic url and embeds + const basicReg + = /(https?:\/\/)?(www\.)?loom\.com\/?(.*\/)?([\d)([a-z]{32})\??.*/; + const basicParsed = urlString.match(basicReg); + if (basicParsed && basicParsed.length === 5) { + return basicParsed[4]; + } + + return undefined; +}