Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-youtube-id

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-youtube-id - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

2

component.json
{
"name": "get-youtube-id",
"version": "0.1.2",
"version": "0.1.3",
"main": "./index.js",

@@ -5,0 +5,0 @@ "dependencies": {},

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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc