get-youtube-id
Advanced tools
Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "get-youtube-id", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"main": "./index.js", | ||
@@ -5,0 +5,0 @@ "dependencies": {}, |
64
index.js
function getYouTubeID(url) { | ||
if (/youtu\.?be/.test(url)) { | ||
(function (root, factory) { | ||
if (typeof exports === 'object') { | ||
module.exports = factory(); | ||
} else if (typeof define === 'function' && define.amd) { | ||
define(factory); | ||
} else { | ||
root.getYouTubeID = factory(); | ||
} | ||
}(this, function (exports) { | ||
// Look first for known patterns | ||
var i; | ||
var patterns = [ | ||
/youtu\.be\/([^#\&\?]{11})/, // youtu.be/<id> | ||
/\?v=([^#\&\?]{11})/, // ?v=<id> | ||
/\&v=([^#\&\?]{11})/, // &v=<id> | ||
/embed\/([^#\&\?]{11})/, // embed/<id> | ||
/\/v\/([^#\&\?]{11})/ // /v/<id> | ||
]; | ||
return function (url) { | ||
if (/youtu\.?be/.test(url)) { | ||
// If any pattern matches, return the ID | ||
for (i = 0; i < patterns.length; ++i) { | ||
if (patterns[i].test(url)) { | ||
return patterns[i].exec(url)[1]; | ||
// Look first for known patterns | ||
var i; | ||
var patterns = [ | ||
/youtu\.be\/([^#\&\?]{11})/, // youtu.be/<id> | ||
/\?v=([^#\&\?]{11})/, // ?v=<id> | ||
/\&v=([^#\&\?]{11})/, // &v=<id> | ||
/embed\/([^#\&\?]{11})/, // embed/<id> | ||
/\/v\/([^#\&\?]{11})/ // /v/<id> | ||
]; | ||
// If any pattern matches, return the ID | ||
for (i = 0; i < patterns.length; ++i) { | ||
if (patterns[i].test(url)) { | ||
return patterns[i].exec(url)[1]; | ||
} | ||
} | ||
} | ||
// If that fails, break it apart by certain characters and look | ||
// for the 11 character key | ||
var tokens = url.split(/[\/\&\?=#\.\s]/g); | ||
for (i = 0; i < tokens.length; ++i) { | ||
if (/^[^#\&\?]{11}$/.test(tokens[i])) { | ||
return tokens[i]; | ||
// If that fails, break it apart by certain characters and look | ||
// for the 11 character key | ||
var tokens = url.split(/[\/\&\?=#\.\s]/g); | ||
for (i = 0; i < tokens.length; ++i) { | ||
if (/^[^#\&\?]{11}$/.test(tokens[i])) { | ||
return tokens[i]; | ||
} | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
return null; | ||
}; | ||
if(typeof exports !== 'undefined') { | ||
module.exports = getYouTubeID; | ||
} | ||
})); |
{ | ||
"name": "get-youtube-id", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Parse a youtube url returning the video ID.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6300
88