@social-embed/lib
Advanced tools
Comparing version 0.0.1-next.11 to 0.0.1-next.12
@@ -7,2 +7,7 @@ --- | ||
- Add `matcher` helper to generate regex matchers | ||
- Generic URL regular expression | ||
## 0.0.1: next.0 - next.11 | ||
- Added API Documentation: | ||
@@ -13,1 +18,3 @@ https://social-embed.git-pull.com/api/modules/lib.html | ||
- YouTube: Move back to single file | ||
- [#30](https://github.com/social-embed/social-embed/pull/30): Add loom, wistia | ||
and edpuzzle |
@@ -21,13 +21,2 @@ 'use strict'; | ||
// Credit: https://stackoverflow.com/a/50644701, (2021-03-14: Support ?playlist) | ||
var dailyMotionUrlRegex = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:\?playlist=[a-zA-Z0-9]+)?$/; | ||
var getDailyMotionIdFromUrl = function getDailyMotionIdFromUrl(url) { | ||
var _url$match$, _url$match; | ||
return (_url$match$ = (_url$match = url.match(dailyMotionUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
}; | ||
var getDailyMotionEmbedFromId = function getDailyMotionEmbedFromId(dailyMotionId) { | ||
return "https://www.dailymotion.com/embed/video/" + dailyMotionId; // ?autoplay=1 | ||
}; | ||
// regex: derived from https://gist.github.com/TrevorJTClarke/a14c37db3c11ee23a700 | ||
@@ -59,6 +48,17 @@ // Thank you @TrevorJTClarke | ||
// Credit: https://stackoverflow.com/a/50644701, (2021-03-14: Support ?playlist) | ||
var dailyMotionUrlRegex = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:\?playlist=[a-zA-Z0-9]+)?$/; | ||
var getDailyMotionIdFromUrl = function getDailyMotionIdFromUrl(url) { | ||
var _url$match$, _url$match; | ||
return (_url$match$ = (_url$match = url.match(dailyMotionUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
}; | ||
var getDailyMotionEmbedFromId = function getDailyMotionEmbedFromId(dailyMotionId) { | ||
return "https://www.dailymotion.com/embed/video/" + dailyMotionId; // ?autoplay=1 | ||
}; | ||
/** | ||
* Detection and parsing for Edpuzzle URLs | ||
* | ||
* [Edpuzzle's officie embed docs](https://support.edpuzzle.com/hc/en-us/articles/360007260632-Can-I-embed-an-assignment-into-an-LMS-blog-or-website-) | ||
* [Edpuzzle's official embed docs](https://support.edpuzzle.com/hc/en-us/articles/360007260632-Can-I-embed-an-assignment-into-an-LMS-blog-or-website-) | ||
* | ||
@@ -98,26 +98,17 @@ * @module providers/edpuzzle | ||
/** | ||
* Detecting and parsing for Wistia URLs. | ||
* Detecting and parsing for Loom URLs. | ||
* | ||
* [Wistia's Official embed documentation](https://wistia.com/support/embed-and-share/video-on-your-website) | ||
* [Wistia's Embed building documentation](https://wistia.com/support/developers/construct-an-embed-code) | ||
* [Loom's Official embed documentation](https://www.loom.com/share/e883f70b219a49f6ba7fbeac71a72604) | ||
* | ||
* @module providers/wistia | ||
* @module providers/loom | ||
*/ | ||
/* | ||
<iframe src="//fast.wistia.net/embed/iframe/26sk4lmiix" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen width="620" height="349"></iframe> | ||
<script src="//fast.wistia.net/assets/external/E-v1.js" async></script> | ||
<div style="position: relative; padding-bottom: 61.224489795918366%; height: 0;"><iframe src="https://www.loom.com/embed/e883f70b219a49f6ba7fbeac71a72604" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div> | ||
*/ | ||
/** | ||
* Matches ID from URLs matching: | ||
* - https://support.wistia.com/medias/26sk4lmiix | ||
* - https://support.wistia.com/embed/26sk4lmiix | ||
* | ||
* While these are not used, these are mentions on [Wistia's embed construction](https://wistia.com/support/developers/construct-an-embed-code) docs: | ||
* - https://support.wi.st/embed/26sk4lmiix | ||
* - https://support.wi.st/medias/26sk4lmiix | ||
* Matches ID from URLs matching: https://www.loom.com/share/e883f70b219a49f6ba7fbeac71a72604 | ||
*/ | ||
var wistiaUrlRegex = /*#__PURE__*/new RegExp('^(?:(?:https?):)?(?://)?[^/]*(?:wistia.com|wi.st).*[=/](?:medias|embed)/([-\\w]+)' // '^(?:(?:https?):)?(?://)?[^/]*wistia.com.*[=/]medias/([-\\w]+)' // v1 (handcrafted by Tony) | ||
); | ||
var loomUrlRegex = /*#__PURE__*/new RegExp('^(?:(?:https?):)?(?://)?[^/]*loom.com.*[=/]share/([-\\w]+)'); | ||
/** | ||
@@ -129,7 +120,7 @@ * Return ID from shared link. | ||
var getWistiaIdFromUrl = function getWistiaIdFromUrl(url) { | ||
var getLoomIdFromUrl = function getLoomIdFromUrl(url) { | ||
if (url) { | ||
var _url$match$, _url$match; | ||
return (_url$match$ = (_url$match = url.match(wistiaUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
return (_url$match$ = (_url$match = url.match(loomUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
} | ||
@@ -142,25 +133,34 @@ | ||
* | ||
* @param wistiaId ID of embed | ||
* @param loomId ID of embed | ||
*/ | ||
var getWistiaEmbedUrlFromId = function getWistiaEmbedUrlFromId(wistiaId) { | ||
return "https://fast.wistia.net/embed/iframe/" + wistiaId; | ||
var getLoomEmbedUrlFromId = function getLoomEmbedUrlFromId(loomId) { | ||
return "https://www.loom.com/embed/" + loomId; | ||
}; | ||
/** | ||
* Detecting and parsing for Loom URLs. | ||
* Detecting and parsing for Wistia URLs. | ||
* | ||
* [Loom's Official embed documentation](https://www.loom.com/share/e883f70b219a49f6ba7fbeac71a72604) | ||
* [Wistia's Official embed documentation](https://wistia.com/support/embed-and-share/video-on-your-website) | ||
* [Wistia's Embed building documentation](https://wistia.com/support/developers/construct-an-embed-code) | ||
* | ||
* @module providers/loom | ||
* @module providers/wistia | ||
*/ | ||
/* | ||
<div style="position: relative; padding-bottom: 61.224489795918366%; height: 0;"><iframe src="https://www.loom.com/embed/e883f70b219a49f6ba7fbeac71a72604" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div> | ||
<iframe src="//fast.wistia.net/embed/iframe/26sk4lmiix" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen width="620" height="349"></iframe> | ||
<script src="//fast.wistia.net/assets/external/E-v1.js" async></script> | ||
*/ | ||
/** | ||
* Matches ID from URLs matching: https://www.loom.com/share/e883f70b219a49f6ba7fbeac71a72604 | ||
* Matches ID from URLs matching: | ||
* - https://support.wistia.com/medias/26sk4lmiix | ||
* - https://support.wistia.com/embed/26sk4lmiix | ||
* | ||
* While these are not used, these are mentions on [Wistia's embed construction](https://wistia.com/support/developers/construct-an-embed-code) docs: | ||
* - https://support.wi.st/embed/26sk4lmiix | ||
* - https://support.wi.st/medias/26sk4lmiix | ||
*/ | ||
var loomUrlRegex = /*#__PURE__*/new RegExp('^(?:(?:https?):)?(?://)?[^/]*loom.com.*[=/]share/([-\\w]+)'); | ||
var wistiaUrlRegex = /*#__PURE__*/new RegExp('^(?:(?:https?):)?(?://)?[^/]*(?:wistia.com|wi.st).*[=/](?:medias|embed)/([-\\w]+)' // '^(?:(?:https?):)?(?://)?[^/]*wistia.com.*[=/]medias/([-\\w]+)' // v1 (handcrafted by Tony) | ||
); | ||
/** | ||
@@ -172,7 +172,7 @@ * Return ID from shared link. | ||
var getLoomIdFromUrl = function getLoomIdFromUrl(url) { | ||
var getWistiaIdFromUrl = function getWistiaIdFromUrl(url) { | ||
if (url) { | ||
var _url$match$, _url$match; | ||
return (_url$match$ = (_url$match = url.match(loomUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
return (_url$match$ = (_url$match = url.match(wistiaUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
} | ||
@@ -185,7 +185,7 @@ | ||
* | ||
* @param loomId ID of embed | ||
* @param wistiaId ID of embed | ||
*/ | ||
var getLoomEmbedUrlFromId = function getLoomEmbedUrlFromId(loomId) { | ||
return "https://www.loom.com/embed/" + loomId; | ||
var getWistiaEmbedUrlFromId = function getWistiaEmbedUrlFromId(wistiaId) { | ||
return "https://fast.wistia.net/embed/iframe/" + wistiaId; | ||
}; | ||
@@ -242,2 +242,6 @@ | ||
var ProviderIdUrlFunctionMap = (_ProviderIdUrlFunctio = {}, _ProviderIdUrlFunctio[exports.Provider.DailyMotion] = getDailyMotionEmbedFromId, _ProviderIdUrlFunctio[exports.Provider.Spotify] = getSpotifyEmbedUrlFromIdAndType, _ProviderIdUrlFunctio[exports.Provider.Vimeo] = getVimeoEmbedUrlFromId, _ProviderIdUrlFunctio[exports.Provider.YouTube] = getYouTubeEmbedUrlFromId, _ProviderIdUrlFunctio[exports.Provider.EdPuzzle] = getEdPuzzleEmbedUrlFromId, _ProviderIdUrlFunctio[exports.Provider.Loom] = getLoomEmbedUrlFromId, _ProviderIdUrlFunctio[exports.Provider.Wistia] = getWistiaEmbedUrlFromId, _ProviderIdUrlFunctio); | ||
/** | ||
* Converts URL variations from sites to their "embed-friendly" URL. | ||
*/ | ||
var convertUrlToEmbedUrl = function convertUrlToEmbedUrl(url) { | ||
@@ -262,3 +266,36 @@ var provider = getProviderFromUrl(url); | ||
}; | ||
var isString = function isString(val) { | ||
return typeof val === 'string'; | ||
}; | ||
var isRegExp = function isRegExp(val) { | ||
return val instanceof RegExp; | ||
}; | ||
/** | ||
* Factory to create regex matchers | ||
* | ||
* @param regex Regular expression or string pattern to match | ||
*/ | ||
var matcher = function matcher(regex) { | ||
return function (value) { | ||
return isString(value) && !isRegExp(regex) ? value.includes(regex) : new RegExp(regex).test(value); | ||
}; | ||
}; | ||
// See valid URLs in RFC3987 (http://tools.ietf.org/html/rfc3987) | ||
// Note: We are being more lenient, because browsers are too. | ||
// 1. Scheme | ||
// 2. Slashes | ||
// 3. Username | ||
// 4. Password | ||
// 5. Hostname | ||
// 6. Port | ||
// 7. Path | ||
// 8. Query | ||
// 9. Fragment | ||
// 1111111111111111 222 333333 44444 55555555555555555555555 666 77777777 8888888 999 | ||
var genericUrlRegex = /^[a-z][a-z\d.+-]*:\/*(?:[^:@]+(?::[^@]+)?@)?(?:[^\s:/?#]+|\[[a-f\d:]+])(?::\d+)?(?:\/[^?#]*)?(?:\?[^#]*)?(?:#.*)?$/i; | ||
var isValidUrl = /*#__PURE__*/matcher(genericUrlRegex); | ||
exports.ProviderIdFunctionMap = ProviderIdFunctionMap; | ||
@@ -269,2 +306,3 @@ exports.ProviderIdUrlFunctionMap = ProviderIdUrlFunctionMap; | ||
exports.edPuzzleUrlRegex = edPuzzleUrlRegex; | ||
exports.genericUrlRegex = genericUrlRegex; | ||
exports.getDailyMotionEmbedFromId = getDailyMotionEmbedFromId; | ||
@@ -285,2 +323,3 @@ exports.getDailyMotionIdFromUrl = getDailyMotionIdFromUrl; | ||
exports.getYouTubeIdFromUrl = getYouTubeIdFromUrl; | ||
exports.isValidUrl = isValidUrl; | ||
exports.loomUrlRegex = loomUrlRegex; | ||
@@ -287,0 +326,0 @@ exports.spotifySymbolRegex = spotifySymbolRegex; |
@@ -1,2 +0,2 @@ | ||
"use strict";var o,e,r,t="^(?:(?:https?):)?(?://)?[^/]*(?:youtube(?:-nocookie)?.com|youtu.be).*[=/]([-\\w]{11})(?:\\?|=|&|$)",i=function(o){var e,r;return o&&null!=(e=null==(r=o.match(t))?void 0:r[1])?e:""},p=function(o){return"https://www.youtube.com/embed/"+o},s=/^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:\?playlist=[a-zA-Z0-9]+)?$/,d=function(o){var e,r;return null!=(e=null==(r=o.match(s))?void 0:r[1])?e:""},m=function(o){return"https://www.dailymotion.com/embed/video/"+o},n=/(?:(?:https?):)?(?:\/\/)?(?:embed\.|open\.)(?:spotify\.com\/)(?:(album|track|playlist)\/|\?uri=spotify:track:)((\w|-){22})/,u=/spotify:(?:(album|track|playlist):|\?uri=spotify:track:)((\w|-){22})/,l=function(o){var e=o.match(n)||o.match(u)||[];return[e[2],e[1]]},a=function(o,e){return"https://open.spotify.com/embed/"+e+"/"+o},x=/(?:(?:https?):)?(?:\/\/)?(?:www\.|player\.)?vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^/]*)\/videos\/|video\/|)(\d+)(?:|\/\?)/,v=function(o){var e,r;return null!=(e=null==(r=o.match(x))?void 0:r[1])?e:""},c=function(o){return"https://player.vimeo.com/video/"+o},y=new RegExp("^(?:(?:https?):)?(?://)?[^/]*edpuzzle.com.*[=/]media/([-\\w]+)"),f=function(o){var e,r;return o&&null!=(e=null==(r=o.match(y))?void 0:r[1])?e:""},P=function(o){return"https://edpuzzle.com/embed/media/"+o},b=new RegExp("^(?:(?:https?):)?(?://)?[^/]*(?:wistia.com|wi.st).*[=/](?:medias|embed)/([-\\w]+)"),h=function(o){var e,r;return o&&null!=(e=null==(r=o.match(b))?void 0:r[1])?e:""},w=function(o){return"https://fast.wistia.net/embed/iframe/"+o},g=new RegExp("^(?:(?:https?):)?(?://)?[^/]*loom.com.*[=/]share/([-\\w]+)"),z=function(o){var e,r;return o&&null!=(e=null==(r=o.match(g))?void 0:r[1])?e:""},U=function(o){return"https://www.loom.com/embed/"+o};(r=exports.Provider||(exports.Provider={})).YouTube="YouTube",r.Spotify="Spotify",r.Vimeo="Vimeo",r.DailyMotion="DailyMotion",r.EdPuzzle="EdPuzzle",r.Loom="Loom",r.Wistia="Wistia";var E=function(o){if(o)return o.match(/dailymotion/)?exports.Provider.DailyMotion:o.match(/spotify/)?exports.Provider.Spotify:o.match(/vimeo/)?exports.Provider.Vimeo:o.match(/youtu\.?be/)?exports.Provider.YouTube:o.match(/edpuzzle.com/)?exports.Provider.EdPuzzle:h(o)?exports.Provider.Wistia:z(o)?exports.Provider.Loom:void 0},F=((o={})[exports.Provider.DailyMotion]=d,o[exports.Provider.Spotify]=l,o[exports.Provider.Vimeo]=v,o[exports.Provider.YouTube]=i,o[exports.Provider.EdPuzzle]=f,o[exports.Provider.Loom]=z,o[exports.Provider.Wistia]=h,o),I=((e={})[exports.Provider.DailyMotion]=m,e[exports.Provider.Spotify]=a,e[exports.Provider.Vimeo]=c,e[exports.Provider.YouTube]=p,e[exports.Provider.EdPuzzle]=P,e[exports.Provider.Loom]=U,e[exports.Provider.Wistia]=w,e);exports.ProviderIdFunctionMap=F,exports.ProviderIdUrlFunctionMap=I,exports.convertUrlToEmbedUrl=function(o){var e=E(o);if(!e)return"";var r=I[e],t=(0,F[e])(o);if(Array.isArray(t)){var i=t.shift();return i?r.apply(void 0,[i].concat(t)):""}return r(t)},exports.dailyMotionUrlRegex=s,exports.edPuzzleUrlRegex=y,exports.getDailyMotionEmbedFromId=m,exports.getDailyMotionIdFromUrl=d,exports.getEdPuzzleEmbedUrlFromId=P,exports.getEdPuzzleIdFromUrl=f,exports.getLoomEmbedUrlFromId=U,exports.getLoomIdFromUrl=z,exports.getProviderFromUrl=E,exports.getSpotifyEmbedUrlFromIdAndType=a,exports.getSpotifyIdAndTypeFromUrl=l,exports.getVimeoEmbedUrlFromId=c,exports.getVimeoIdFromUrl=v,exports.getWistiaEmbedUrlFromId=w,exports.getWistiaIdFromUrl=h,exports.getYouTubeEmbedUrlFromId=p,exports.getYouTubeIdFromUrl=i,exports.loomUrlRegex=g,exports.spotifySymbolRegex=u,exports.spotifyUrlRegex=n,exports.vimeoUrlRegex=x,exports.wistiaUrlRegex=b,exports.youTubeUrlRegex=t; | ||
"use strict";var o,e,r,t="^(?:(?:https?):)?(?://)?[^/]*(?:youtube(?:-nocookie)?.com|youtu.be).*[=/]([-\\w]{11})(?:\\?|=|&|$)",i=function(o){var e,r;return o&&null!=(e=null==(r=o.match(t))?void 0:r[1])?e:""},n=function(o){return"https://www.youtube.com/embed/"+o},p=/(?:(?:https?):)?(?:\/\/)?(?:embed\.|open\.)(?:spotify\.com\/)(?:(album|track|playlist)\/|\?uri=spotify:track:)((\w|-){22})/,s=/spotify:(?:(album|track|playlist):|\?uri=spotify:track:)((\w|-){22})/,d=function(o){var e=o.match(p)||o.match(s)||[];return[e[2],e[1]]},u=function(o,e){return"https://open.spotify.com/embed/"+e+"/"+o},l=/(?:(?:https?):)?(?:\/\/)?(?:www\.|player\.)?vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^/]*)\/videos\/|video\/|)(\d+)(?:|\/\?)/,m=function(o){var e,r;return null!=(e=null==(r=o.match(l))?void 0:r[1])?e:""},a=function(o){return"https://player.vimeo.com/video/"+o},x=/^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:\?playlist=[a-zA-Z0-9]+)?$/,c=function(o){var e,r;return null!=(e=null==(r=o.match(x))?void 0:r[1])?e:""},v=function(o){return"https://www.dailymotion.com/embed/video/"+o},y=new RegExp("^(?:(?:https?):)?(?://)?[^/]*edpuzzle.com.*[=/]media/([-\\w]+)"),f=function(o){var e,r;return o&&null!=(e=null==(r=o.match(y))?void 0:r[1])?e:""},P=function(o){return"https://edpuzzle.com/embed/media/"+o},b=new RegExp("^(?:(?:https?):)?(?://)?[^/]*loom.com.*[=/]share/([-\\w]+)"),g=function(o){var e,r;return o&&null!=(e=null==(r=o.match(b))?void 0:r[1])?e:""},w=function(o){return"https://www.loom.com/embed/"+o},h=new RegExp("^(?:(?:https?):)?(?://)?[^/]*(?:wistia.com|wi.st).*[=/](?:medias|embed)/([-\\w]+)"),z=function(o){var e,r;return o&&null!=(e=null==(r=o.match(h))?void 0:r[1])?e:""},U=function(o){return"https://fast.wistia.net/embed/iframe/"+o};(r=exports.Provider||(exports.Provider={})).YouTube="YouTube",r.Spotify="Spotify",r.Vimeo="Vimeo",r.DailyMotion="DailyMotion",r.EdPuzzle="EdPuzzle",r.Loom="Loom",r.Wistia="Wistia";var E=function(o){if(o)return o.match(/dailymotion/)?exports.Provider.DailyMotion:o.match(/spotify/)?exports.Provider.Spotify:o.match(/vimeo/)?exports.Provider.Vimeo:o.match(/youtu\.?be/)?exports.Provider.YouTube:o.match(/edpuzzle.com/)?exports.Provider.EdPuzzle:z(o)?exports.Provider.Wistia:g(o)?exports.Provider.Loom:void 0},F=((o={})[exports.Provider.DailyMotion]=c,o[exports.Provider.Spotify]=d,o[exports.Provider.Vimeo]=m,o[exports.Provider.YouTube]=i,o[exports.Provider.EdPuzzle]=f,o[exports.Provider.Loom]=g,o[exports.Provider.Wistia]=z,o),I=((e={})[exports.Provider.DailyMotion]=v,e[exports.Provider.Spotify]=u,e[exports.Provider.Vimeo]=a,e[exports.Provider.YouTube]=n,e[exports.Provider.EdPuzzle]=P,e[exports.Provider.Loom]=w,e[exports.Provider.Wistia]=U,e),R=/^[a-z][a-z\d.+-]*:\/*(?:[^:@]+(?::[^@]+)?@)?(?:[^\s:/?#]+|\[[a-f\d:]+])(?::\d+)?(?:\/[^?#]*)?(?:\?[^#]*)?(?:#.*)?$/i,T=function(o){return function(e){return"string"!=typeof e||function(o){return o instanceof RegExp}(o)?new RegExp(o).test(e):e.includes(o)}}(R);exports.ProviderIdFunctionMap=F,exports.ProviderIdUrlFunctionMap=I,exports.convertUrlToEmbedUrl=function(o){var e=E(o);if(!e)return"";var r=I[e],t=(0,F[e])(o);if(Array.isArray(t)){var i=t.shift();return i?r.apply(void 0,[i].concat(t)):""}return r(t)},exports.dailyMotionUrlRegex=x,exports.edPuzzleUrlRegex=y,exports.genericUrlRegex=R,exports.getDailyMotionEmbedFromId=v,exports.getDailyMotionIdFromUrl=c,exports.getEdPuzzleEmbedUrlFromId=P,exports.getEdPuzzleIdFromUrl=f,exports.getLoomEmbedUrlFromId=w,exports.getLoomIdFromUrl=g,exports.getProviderFromUrl=E,exports.getSpotifyEmbedUrlFromIdAndType=u,exports.getSpotifyIdAndTypeFromUrl=d,exports.getVimeoEmbedUrlFromId=a,exports.getVimeoIdFromUrl=m,exports.getWistiaEmbedUrlFromId=U,exports.getWistiaIdFromUrl=z,exports.getYouTubeEmbedUrlFromId=n,exports.getYouTubeIdFromUrl=i,exports.isValidUrl=T,exports.loomUrlRegex=b,exports.spotifySymbolRegex=s,exports.spotifyUrlRegex=p,exports.vimeoUrlRegex=l,exports.wistiaUrlRegex=h,exports.youTubeUrlRegex=t; | ||
//# sourceMappingURL=lib.cjs.production.min.js.map |
@@ -19,13 +19,2 @@ /** | ||
// Credit: https://stackoverflow.com/a/50644701, (2021-03-14: Support ?playlist) | ||
var dailyMotionUrlRegex = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:\?playlist=[a-zA-Z0-9]+)?$/; | ||
var getDailyMotionIdFromUrl = function getDailyMotionIdFromUrl(url) { | ||
var _url$match$, _url$match; | ||
return (_url$match$ = (_url$match = url.match(dailyMotionUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
}; | ||
var getDailyMotionEmbedFromId = function getDailyMotionEmbedFromId(dailyMotionId) { | ||
return "https://www.dailymotion.com/embed/video/" + dailyMotionId; // ?autoplay=1 | ||
}; | ||
// regex: derived from https://gist.github.com/TrevorJTClarke/a14c37db3c11ee23a700 | ||
@@ -57,6 +46,17 @@ // Thank you @TrevorJTClarke | ||
// Credit: https://stackoverflow.com/a/50644701, (2021-03-14: Support ?playlist) | ||
var dailyMotionUrlRegex = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:\?playlist=[a-zA-Z0-9]+)?$/; | ||
var getDailyMotionIdFromUrl = function getDailyMotionIdFromUrl(url) { | ||
var _url$match$, _url$match; | ||
return (_url$match$ = (_url$match = url.match(dailyMotionUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
}; | ||
var getDailyMotionEmbedFromId = function getDailyMotionEmbedFromId(dailyMotionId) { | ||
return "https://www.dailymotion.com/embed/video/" + dailyMotionId; // ?autoplay=1 | ||
}; | ||
/** | ||
* Detection and parsing for Edpuzzle URLs | ||
* | ||
* [Edpuzzle's officie embed docs](https://support.edpuzzle.com/hc/en-us/articles/360007260632-Can-I-embed-an-assignment-into-an-LMS-blog-or-website-) | ||
* [Edpuzzle's official embed docs](https://support.edpuzzle.com/hc/en-us/articles/360007260632-Can-I-embed-an-assignment-into-an-LMS-blog-or-website-) | ||
* | ||
@@ -96,26 +96,17 @@ * @module providers/edpuzzle | ||
/** | ||
* Detecting and parsing for Wistia URLs. | ||
* Detecting and parsing for Loom URLs. | ||
* | ||
* [Wistia's Official embed documentation](https://wistia.com/support/embed-and-share/video-on-your-website) | ||
* [Wistia's Embed building documentation](https://wistia.com/support/developers/construct-an-embed-code) | ||
* [Loom's Official embed documentation](https://www.loom.com/share/e883f70b219a49f6ba7fbeac71a72604) | ||
* | ||
* @module providers/wistia | ||
* @module providers/loom | ||
*/ | ||
/* | ||
<iframe src="//fast.wistia.net/embed/iframe/26sk4lmiix" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen width="620" height="349"></iframe> | ||
<script src="//fast.wistia.net/assets/external/E-v1.js" async></script> | ||
<div style="position: relative; padding-bottom: 61.224489795918366%; height: 0;"><iframe src="https://www.loom.com/embed/e883f70b219a49f6ba7fbeac71a72604" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div> | ||
*/ | ||
/** | ||
* Matches ID from URLs matching: | ||
* - https://support.wistia.com/medias/26sk4lmiix | ||
* - https://support.wistia.com/embed/26sk4lmiix | ||
* | ||
* While these are not used, these are mentions on [Wistia's embed construction](https://wistia.com/support/developers/construct-an-embed-code) docs: | ||
* - https://support.wi.st/embed/26sk4lmiix | ||
* - https://support.wi.st/medias/26sk4lmiix | ||
* Matches ID from URLs matching: https://www.loom.com/share/e883f70b219a49f6ba7fbeac71a72604 | ||
*/ | ||
var wistiaUrlRegex = /*#__PURE__*/new RegExp('^(?:(?:https?):)?(?://)?[^/]*(?:wistia.com|wi.st).*[=/](?:medias|embed)/([-\\w]+)' // '^(?:(?:https?):)?(?://)?[^/]*wistia.com.*[=/]medias/([-\\w]+)' // v1 (handcrafted by Tony) | ||
); | ||
var loomUrlRegex = /*#__PURE__*/new RegExp('^(?:(?:https?):)?(?://)?[^/]*loom.com.*[=/]share/([-\\w]+)'); | ||
/** | ||
@@ -127,7 +118,7 @@ * Return ID from shared link. | ||
var getWistiaIdFromUrl = function getWistiaIdFromUrl(url) { | ||
var getLoomIdFromUrl = function getLoomIdFromUrl(url) { | ||
if (url) { | ||
var _url$match$, _url$match; | ||
return (_url$match$ = (_url$match = url.match(wistiaUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
return (_url$match$ = (_url$match = url.match(loomUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
} | ||
@@ -140,25 +131,34 @@ | ||
* | ||
* @param wistiaId ID of embed | ||
* @param loomId ID of embed | ||
*/ | ||
var getWistiaEmbedUrlFromId = function getWistiaEmbedUrlFromId(wistiaId) { | ||
return "https://fast.wistia.net/embed/iframe/" + wistiaId; | ||
var getLoomEmbedUrlFromId = function getLoomEmbedUrlFromId(loomId) { | ||
return "https://www.loom.com/embed/" + loomId; | ||
}; | ||
/** | ||
* Detecting and parsing for Loom URLs. | ||
* Detecting and parsing for Wistia URLs. | ||
* | ||
* [Loom's Official embed documentation](https://www.loom.com/share/e883f70b219a49f6ba7fbeac71a72604) | ||
* [Wistia's Official embed documentation](https://wistia.com/support/embed-and-share/video-on-your-website) | ||
* [Wistia's Embed building documentation](https://wistia.com/support/developers/construct-an-embed-code) | ||
* | ||
* @module providers/loom | ||
* @module providers/wistia | ||
*/ | ||
/* | ||
<div style="position: relative; padding-bottom: 61.224489795918366%; height: 0;"><iframe src="https://www.loom.com/embed/e883f70b219a49f6ba7fbeac71a72604" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div> | ||
<iframe src="//fast.wistia.net/embed/iframe/26sk4lmiix" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen width="620" height="349"></iframe> | ||
<script src="//fast.wistia.net/assets/external/E-v1.js" async></script> | ||
*/ | ||
/** | ||
* Matches ID from URLs matching: https://www.loom.com/share/e883f70b219a49f6ba7fbeac71a72604 | ||
* Matches ID from URLs matching: | ||
* - https://support.wistia.com/medias/26sk4lmiix | ||
* - https://support.wistia.com/embed/26sk4lmiix | ||
* | ||
* While these are not used, these are mentions on [Wistia's embed construction](https://wistia.com/support/developers/construct-an-embed-code) docs: | ||
* - https://support.wi.st/embed/26sk4lmiix | ||
* - https://support.wi.st/medias/26sk4lmiix | ||
*/ | ||
var loomUrlRegex = /*#__PURE__*/new RegExp('^(?:(?:https?):)?(?://)?[^/]*loom.com.*[=/]share/([-\\w]+)'); | ||
var wistiaUrlRegex = /*#__PURE__*/new RegExp('^(?:(?:https?):)?(?://)?[^/]*(?:wistia.com|wi.st).*[=/](?:medias|embed)/([-\\w]+)' // '^(?:(?:https?):)?(?://)?[^/]*wistia.com.*[=/]medias/([-\\w]+)' // v1 (handcrafted by Tony) | ||
); | ||
/** | ||
@@ -170,7 +170,7 @@ * Return ID from shared link. | ||
var getLoomIdFromUrl = function getLoomIdFromUrl(url) { | ||
var getWistiaIdFromUrl = function getWistiaIdFromUrl(url) { | ||
if (url) { | ||
var _url$match$, _url$match; | ||
return (_url$match$ = (_url$match = url.match(loomUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
return (_url$match$ = (_url$match = url.match(wistiaUrlRegex)) == null ? void 0 : _url$match[1]) != null ? _url$match$ : ''; | ||
} | ||
@@ -183,7 +183,7 @@ | ||
* | ||
* @param loomId ID of embed | ||
* @param wistiaId ID of embed | ||
*/ | ||
var getLoomEmbedUrlFromId = function getLoomEmbedUrlFromId(loomId) { | ||
return "https://www.loom.com/embed/" + loomId; | ||
var getWistiaEmbedUrlFromId = function getWistiaEmbedUrlFromId(wistiaId) { | ||
return "https://fast.wistia.net/embed/iframe/" + wistiaId; | ||
}; | ||
@@ -241,2 +241,6 @@ | ||
var ProviderIdUrlFunctionMap = (_ProviderIdUrlFunctio = {}, _ProviderIdUrlFunctio[Provider.DailyMotion] = getDailyMotionEmbedFromId, _ProviderIdUrlFunctio[Provider.Spotify] = getSpotifyEmbedUrlFromIdAndType, _ProviderIdUrlFunctio[Provider.Vimeo] = getVimeoEmbedUrlFromId, _ProviderIdUrlFunctio[Provider.YouTube] = getYouTubeEmbedUrlFromId, _ProviderIdUrlFunctio[Provider.EdPuzzle] = getEdPuzzleEmbedUrlFromId, _ProviderIdUrlFunctio[Provider.Loom] = getLoomEmbedUrlFromId, _ProviderIdUrlFunctio[Provider.Wistia] = getWistiaEmbedUrlFromId, _ProviderIdUrlFunctio); | ||
/** | ||
* Converts URL variations from sites to their "embed-friendly" URL. | ||
*/ | ||
var convertUrlToEmbedUrl = function convertUrlToEmbedUrl(url) { | ||
@@ -261,4 +265,37 @@ var provider = getProviderFromUrl(url); | ||
}; | ||
var isString = function isString(val) { | ||
return typeof val === 'string'; | ||
}; | ||
var isRegExp = function isRegExp(val) { | ||
return val instanceof RegExp; | ||
}; | ||
/** | ||
* Factory to create regex matchers | ||
* | ||
* @param regex Regular expression or string pattern to match | ||
*/ | ||
export { Provider, ProviderIdFunctionMap, ProviderIdUrlFunctionMap, convertUrlToEmbedUrl, dailyMotionUrlRegex, edPuzzleUrlRegex, getDailyMotionEmbedFromId, getDailyMotionIdFromUrl, getEdPuzzleEmbedUrlFromId, getEdPuzzleIdFromUrl, getLoomEmbedUrlFromId, getLoomIdFromUrl, getProviderFromUrl, getSpotifyEmbedUrlFromIdAndType, getSpotifyIdAndTypeFromUrl, getVimeoEmbedUrlFromId, getVimeoIdFromUrl, getWistiaEmbedUrlFromId, getWistiaIdFromUrl, getYouTubeEmbedUrlFromId, getYouTubeIdFromUrl, loomUrlRegex, spotifySymbolRegex, spotifyUrlRegex, vimeoUrlRegex, wistiaUrlRegex, youTubeUrlRegex }; | ||
var matcher = function matcher(regex) { | ||
return function (value) { | ||
return isString(value) && !isRegExp(regex) ? value.includes(regex) : new RegExp(regex).test(value); | ||
}; | ||
}; | ||
// See valid URLs in RFC3987 (http://tools.ietf.org/html/rfc3987) | ||
// Note: We are being more lenient, because browsers are too. | ||
// 1. Scheme | ||
// 2. Slashes | ||
// 3. Username | ||
// 4. Password | ||
// 5. Hostname | ||
// 6. Port | ||
// 7. Path | ||
// 8. Query | ||
// 9. Fragment | ||
// 1111111111111111 222 333333 44444 55555555555555555555555 666 77777777 8888888 999 | ||
var genericUrlRegex = /^[a-z][a-z\d.+-]*:\/*(?:[^:@]+(?::[^@]+)?@)?(?:[^\s:/?#]+|\[[a-f\d:]+])(?::\d+)?(?:\/[^?#]*)?(?:\?[^#]*)?(?:#.*)?$/i; | ||
var isValidUrl = /*#__PURE__*/matcher(genericUrlRegex); | ||
export { Provider, ProviderIdFunctionMap, ProviderIdUrlFunctionMap, convertUrlToEmbedUrl, dailyMotionUrlRegex, edPuzzleUrlRegex, genericUrlRegex, getDailyMotionEmbedFromId, getDailyMotionIdFromUrl, getEdPuzzleEmbedUrlFromId, getEdPuzzleIdFromUrl, getLoomEmbedUrlFromId, getLoomIdFromUrl, getProviderFromUrl, getSpotifyEmbedUrlFromIdAndType, getSpotifyIdAndTypeFromUrl, getVimeoEmbedUrlFromId, getVimeoIdFromUrl, getWistiaEmbedUrlFromId, getWistiaIdFromUrl, getYouTubeEmbedUrlFromId, getYouTubeIdFromUrl, isValidUrl, loomUrlRegex, spotifySymbolRegex, spotifyUrlRegex, vimeoUrlRegex, wistiaUrlRegex, youTubeUrlRegex }; | ||
//# sourceMappingURL=lib.esm.js.map |
/** | ||
* Detection and parsing for Edpuzzle URLs | ||
* | ||
* [Edpuzzle's officie embed docs](https://support.edpuzzle.com/hc/en-us/articles/360007260632-Can-I-embed-an-assignment-into-an-LMS-blog-or-website-) | ||
* [Edpuzzle's official embed docs](https://support.edpuzzle.com/hc/en-us/articles/360007260632-Can-I-embed-an-assignment-into-an-LMS-blog-or-website-) | ||
* | ||
@@ -6,0 +6,0 @@ * @module providers/edpuzzle |
@@ -0,1 +1,2 @@ | ||
export * from './generic'; | ||
export * from './youtube'; | ||
@@ -2,0 +3,0 @@ export * from './dailymotion'; |
@@ -20,4 +20,15 @@ export declare enum Provider { | ||
}; | ||
/** | ||
* Converts URL variations from sites to their "embed-friendly" URL. | ||
*/ | ||
export declare const convertUrlToEmbedUrl: (url: string) => string; | ||
export declare const isString: (val: unknown) => val is string; | ||
export declare const isRegExp: (val: unknown) => val is RegExp; | ||
/** | ||
* Factory to create regex matchers | ||
* | ||
* @param regex Regular expression or string pattern to match | ||
*/ | ||
export declare const matcher: (regex: RegExp | string) => (value: string) => boolean; | ||
export {}; | ||
//# sourceMappingURL=utils.d.ts.map |
{ | ||
"name": "@social-embed/lib", | ||
"description": "Regexes, ID extraction, for embed providers (YouTube, other OEmbed compatible providers),", | ||
"version": "0.0.1-next.11", | ||
"version": "0.0.1-next.12", | ||
"main": "dist/index.js", | ||
@@ -39,6 +39,6 @@ "module": "dist/lib.esm.js", | ||
"devDependencies": { | ||
"@types/jest": "^26.0.22", | ||
"prettier": "^2.2.1", | ||
"@types/jest": "^26.0.23", | ||
"prettier": "^2.3.0", | ||
"tsdx": "^0.14.1" | ||
} | ||
} |
// Credit: https://stackoverflow.com/a/50644701, (2021-03-14: Support ?playlist) | ||
export const dailyMotionUrlRegex = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:\?playlist=[a-zA-Z0-9]+)?$/; | ||
export const dailyMotionUrlRegex = | ||
/^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:\?playlist=[a-zA-Z0-9]+)?$/; | ||
export const getDailyMotionIdFromUrl = (url: string): string => { | ||
@@ -4,0 +5,0 @@ return url.match(dailyMotionUrlRegex)?.[1] ?? ''; |
/** | ||
* Detection and parsing for Edpuzzle URLs | ||
* | ||
* [Edpuzzle's officie embed docs](https://support.edpuzzle.com/hc/en-us/articles/360007260632-Can-I-embed-an-assignment-into-an-LMS-blog-or-website-) | ||
* [Edpuzzle's official embed docs](https://support.edpuzzle.com/hc/en-us/articles/360007260632-Can-I-embed-an-assignment-into-an-LMS-blog-or-website-) | ||
* | ||
@@ -6,0 +6,0 @@ * @module providers/edpuzzle |
@@ -0,1 +1,2 @@ | ||
export * from './generic'; | ||
export * from './youtube'; | ||
@@ -2,0 +3,0 @@ export * from './dailymotion'; |
// regex: derived from https://gist.github.com/TrevorJTClarke/a14c37db3c11ee23a700 | ||
// Thank you @TrevorJTClarke | ||
export const spotifyUrlRegex = /(?:(?:https?):)?(?:\/\/)?(?:embed\.|open\.)(?:spotify\.com\/)(?:(album|track|playlist)\/|\?uri=spotify:track:)((\w|-){22})/; | ||
export const spotifyUrlRegex = | ||
/(?:(?:https?):)?(?:\/\/)?(?:embed\.|open\.)(?:spotify\.com\/)(?:(album|track|playlist)\/|\?uri=spotify:track:)((\w|-){22})/; | ||
export const spotifySymbolRegex = /spotify:(?:(album|track|playlist):|\?uri=spotify:track:)((\w|-){22})/; | ||
export const spotifySymbolRegex = | ||
/spotify:(?:(album|track|playlist):|\?uri=spotify:track:)((\w|-){22})/; | ||
@@ -7,0 +9,0 @@ export const getSpotifyIdAndTypeFromUrl = (url: string): [string, string] => { |
// Credit: https://stackoverflow.com/a/50777192 (2021-03-14: modified / fixed to ignore unused groups) | ||
export const vimeoUrlRegex = /(?:(?:https?):)?(?:\/\/)?(?:www\.|player\.)?vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^/]*)\/videos\/|video\/|)(\d+)(?:|\/\?)/; | ||
export const vimeoUrlRegex = | ||
/(?:(?:https?):)?(?:\/\/)?(?:www\.|player\.)?vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^/]*)\/videos\/|video\/|)(\d+)(?:|\/\?)/; | ||
@@ -4,0 +5,0 @@ export const getVimeoIdFromUrl = (url: string): string => |
@@ -75,2 +75,5 @@ import * as YouTube from './providers/youtube'; | ||
/** | ||
* Converts URL variations from sites to their "embed-friendly" URL. | ||
*/ | ||
export const convertUrlToEmbedUrl = (url: string): string => { | ||
@@ -95,1 +98,22 @@ const provider = getProviderFromUrl(url); | ||
}; | ||
export const isString = (val: unknown): val is string => { | ||
return typeof val === 'string'; | ||
}; | ||
export const isRegExp = (val: unknown): val is RegExp => { | ||
return val instanceof RegExp; | ||
}; | ||
/** | ||
* Factory to create regex matchers | ||
* | ||
* @param regex Regular expression or string pattern to match | ||
*/ | ||
export const matcher = | ||
(regex: RegExp | string): ((value: string) => boolean) => | ||
(value: string) => { | ||
return isString(value) && !isRegExp(regex) | ||
? value.includes(regex) | ||
: new RegExp(regex).test(value); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
97799
44
1007