buddy

node MVC discord bot
Log | Files | Refs | README

youtube-api-v3-search.js (10211B)


      1 (function webpackUniversalModuleDefinition(root, factory) {
      2 	if(typeof exports === 'object' && typeof module === 'object')
      3 		module.exports = factory();
      4 	else if(typeof define === 'function' && define.amd)
      5 		define([], factory);
      6 	else if(typeof exports === 'object')
      7 		exports["searchYoutube"] = factory();
      8 	else
      9 		root["searchYoutube"] = factory();
     10 })(typeof self !== 'undefined' ? self : this, function() {
     11 return /******/ (function(modules) { // webpackBootstrap
     12 /******/ 	// The module cache
     13 /******/ 	var installedModules = {};
     14 /******/
     15 /******/ 	// The require function
     16 /******/ 	function __webpack_require__(moduleId) {
     17 /******/
     18 /******/ 		// Check if module is in cache
     19 /******/ 		if(installedModules[moduleId]) {
     20 /******/ 			return installedModules[moduleId].exports;
     21 /******/ 		}
     22 /******/ 		// Create a new module (and put it into the cache)
     23 /******/ 		var module = installedModules[moduleId] = {
     24 /******/ 			i: moduleId,
     25 /******/ 			l: false,
     26 /******/ 			exports: {}
     27 /******/ 		};
     28 /******/
     29 /******/ 		// Execute the module function
     30 /******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
     31 /******/
     32 /******/ 		// Flag the module as loaded
     33 /******/ 		module.l = true;
     34 /******/
     35 /******/ 		// Return the exports of the module
     36 /******/ 		return module.exports;
     37 /******/ 	}
     38 /******/
     39 /******/
     40 /******/ 	// expose the modules object (__webpack_modules__)
     41 /******/ 	__webpack_require__.m = modules;
     42 /******/
     43 /******/ 	// expose the module cache
     44 /******/ 	__webpack_require__.c = installedModules;
     45 /******/
     46 /******/ 	// define getter function for harmony exports
     47 /******/ 	__webpack_require__.d = function(exports, name, getter) {
     48 /******/ 		if(!__webpack_require__.o(exports, name)) {
     49 /******/ 			Object.defineProperty(exports, name, {
     50 /******/ 				configurable: false,
     51 /******/ 				enumerable: true,
     52 /******/ 				get: getter
     53 /******/ 			});
     54 /******/ 		}
     55 /******/ 	};
     56 /******/
     57 /******/ 	// getDefaultExport function for compatibility with non-harmony modules
     58 /******/ 	__webpack_require__.n = function(module) {
     59 /******/ 		var getter = module && module.__esModule ?
     60 /******/ 			function getDefault() { return module['default']; } :
     61 /******/ 			function getModuleExports() { return module; };
     62 /******/ 		__webpack_require__.d(getter, 'a', getter);
     63 /******/ 		return getter;
     64 /******/ 	};
     65 /******/
     66 /******/ 	// Object.prototype.hasOwnProperty.call
     67 /******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
     68 /******/
     69 /******/ 	// __webpack_public_path__
     70 /******/ 	__webpack_require__.p = "";
     71 /******/
     72 /******/ 	// Load entry module and return exports
     73 /******/ 	return __webpack_require__(__webpack_require__.s = 0);
     74 /******/ })
     75 /************************************************************************/
     76 /******/ ([
     77 /* 0 */
     78 /***/ (function(module, exports, __webpack_require__) {
     79 
     80 "use strict";
     81 
     82 
     83 var request = __webpack_require__(1);
     84 var common = __webpack_require__(2);
     85 module.exports = function (key, options, cb) {
     86   console.log('browserJS');
     87   return common(request, key, options, cb);
     88 };
     89 
     90 /***/ }),
     91 /* 1 */
     92 /***/ (function(module, exports, __webpack_require__) {
     93 
     94 "use strict";
     95 
     96 
     97 module.exports = function (url) {
     98   var req = new XMLHttpRequest();
     99   return new Promise(function (resolve, reject) {
    100     req.onreadystatechange = function () {
    101       if (this.readyState == 4) {
    102         if (this.status == 200) {
    103           var response = JSON.parse(this.response);
    104           resolve(response);
    105         } else {
    106           var err = JSON.parse(this.response);
    107           reject(err);
    108         }
    109       }
    110     };
    111     req.onerror = function (e) {
    112       reject(new Error(this.statusText));
    113     };
    114     req.open('GET', url, true);
    115     req.send(null);
    116   });
    117 };
    118 
    119 /***/ }),
    120 /* 2 */
    121 /***/ (function(module, exports, __webpack_require__) {
    122 
    123 "use strict";
    124 
    125 
    126 var config = __webpack_require__(3);
    127 var querystring = __webpack_require__(4);
    128 
    129 module.exports = function (request, key, options, cb) {
    130   if (!key && typeof cb === 'function') return cb(new Error('API Key is required'));else if (!key) throw new Error('API Key is required');
    131   fillData(key, options);
    132   var q = querystring.stringify(config.options);
    133   if (typeof cb === 'function') request(config.URL + q).then(function (res) {
    134     return cb(null, res);
    135   }).catch(function (err) {
    136     return cb(err);
    137   });else return request(config.URL + q);
    138 };
    139 
    140 function fillData(key, options) {
    141   config.options.key = key;
    142   for (var i in options) {
    143     config.options[i] = options[i];
    144   }
    145 }
    146 
    147 /***/ }),
    148 /* 3 */
    149 /***/ (function(module, exports, __webpack_require__) {
    150 
    151 "use strict";
    152 
    153 
    154 module.exports.URL = 'https://www.googleapis.com/youtube/v3/search?';
    155 module.exports.options = {
    156   q: '',
    157   part: 'snippet',
    158   type: 'video'
    159 };
    160 
    161 /***/ }),
    162 /* 4 */
    163 /***/ (function(module, exports, __webpack_require__) {
    164 
    165 "use strict";
    166 
    167 
    168 exports.decode = exports.parse = __webpack_require__(5);
    169 exports.encode = exports.stringify = __webpack_require__(6);
    170 
    171 
    172 /***/ }),
    173 /* 5 */
    174 /***/ (function(module, exports, __webpack_require__) {
    175 
    176 "use strict";
    177 // Copyright Joyent, Inc. and other Node contributors.
    178 //
    179 // Permission is hereby granted, free of charge, to any person obtaining a
    180 // copy of this software and associated documentation files (the
    181 // "Software"), to deal in the Software without restriction, including
    182 // without limitation the rights to use, copy, modify, merge, publish,
    183 // distribute, sublicense, and/or sell copies of the Software, and to permit
    184 // persons to whom the Software is furnished to do so, subject to the
    185 // following conditions:
    186 //
    187 // The above copyright notice and this permission notice shall be included
    188 // in all copies or substantial portions of the Software.
    189 //
    190 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    191 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    192 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
    193 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    194 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
    195 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
    196 // USE OR OTHER DEALINGS IN THE SOFTWARE.
    197 
    198 
    199 
    200 // If obj.hasOwnProperty has been overridden, then calling
    201 // obj.hasOwnProperty(prop) will break.
    202 // See: https://github.com/joyent/node/issues/1707
    203 function hasOwnProperty(obj, prop) {
    204   return Object.prototype.hasOwnProperty.call(obj, prop);
    205 }
    206 
    207 module.exports = function(qs, sep, eq, options) {
    208   sep = sep || '&';
    209   eq = eq || '=';
    210   var obj = {};
    211 
    212   if (typeof qs !== 'string' || qs.length === 0) {
    213     return obj;
    214   }
    215 
    216   var regexp = /\+/g;
    217   qs = qs.split(sep);
    218 
    219   var maxKeys = 1000;
    220   if (options && typeof options.maxKeys === 'number') {
    221     maxKeys = options.maxKeys;
    222   }
    223 
    224   var len = qs.length;
    225   // maxKeys <= 0 means that we should not limit keys count
    226   if (maxKeys > 0 && len > maxKeys) {
    227     len = maxKeys;
    228   }
    229 
    230   for (var i = 0; i < len; ++i) {
    231     var x = qs[i].replace(regexp, '%20'),
    232         idx = x.indexOf(eq),
    233         kstr, vstr, k, v;
    234 
    235     if (idx >= 0) {
    236       kstr = x.substr(0, idx);
    237       vstr = x.substr(idx + 1);
    238     } else {
    239       kstr = x;
    240       vstr = '';
    241     }
    242 
    243     k = decodeURIComponent(kstr);
    244     v = decodeURIComponent(vstr);
    245 
    246     if (!hasOwnProperty(obj, k)) {
    247       obj[k] = v;
    248     } else if (isArray(obj[k])) {
    249       obj[k].push(v);
    250     } else {
    251       obj[k] = [obj[k], v];
    252     }
    253   }
    254 
    255   return obj;
    256 };
    257 
    258 var isArray = Array.isArray || function (xs) {
    259   return Object.prototype.toString.call(xs) === '[object Array]';
    260 };
    261 
    262 
    263 /***/ }),
    264 /* 6 */
    265 /***/ (function(module, exports, __webpack_require__) {
    266 
    267 "use strict";
    268 // Copyright Joyent, Inc. and other Node contributors.
    269 //
    270 // Permission is hereby granted, free of charge, to any person obtaining a
    271 // copy of this software and associated documentation files (the
    272 // "Software"), to deal in the Software without restriction, including
    273 // without limitation the rights to use, copy, modify, merge, publish,
    274 // distribute, sublicense, and/or sell copies of the Software, and to permit
    275 // persons to whom the Software is furnished to do so, subject to the
    276 // following conditions:
    277 //
    278 // The above copyright notice and this permission notice shall be included
    279 // in all copies or substantial portions of the Software.
    280 //
    281 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    282 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    283 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
    284 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    285 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
    286 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
    287 // USE OR OTHER DEALINGS IN THE SOFTWARE.
    288 
    289 
    290 
    291 var stringifyPrimitive = function(v) {
    292   switch (typeof v) {
    293     case 'string':
    294       return v;
    295 
    296     case 'boolean':
    297       return v ? 'true' : 'false';
    298 
    299     case 'number':
    300       return isFinite(v) ? v : '';
    301 
    302     default:
    303       return '';
    304   }
    305 };
    306 
    307 module.exports = function(obj, sep, eq, name) {
    308   sep = sep || '&';
    309   eq = eq || '=';
    310   if (obj === null) {
    311     obj = undefined;
    312   }
    313 
    314   if (typeof obj === 'object') {
    315     return map(objectKeys(obj), function(k) {
    316       var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
    317       if (isArray(obj[k])) {
    318         return map(obj[k], function(v) {
    319           return ks + encodeURIComponent(stringifyPrimitive(v));
    320         }).join(sep);
    321       } else {
    322         return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
    323       }
    324     }).join(sep);
    325 
    326   }
    327 
    328   if (!name) return '';
    329   return encodeURIComponent(stringifyPrimitive(name)) + eq +
    330          encodeURIComponent(stringifyPrimitive(obj));
    331 };
    332 
    333 var isArray = Array.isArray || function (xs) {
    334   return Object.prototype.toString.call(xs) === '[object Array]';
    335 };
    336 
    337 function map (xs, f) {
    338   if (xs.map) return xs.map(f);
    339   var res = [];
    340   for (var i = 0; i < xs.length; i++) {
    341     res.push(f(xs[i], i));
    342   }
    343   return res;
    344 }
    345 
    346 var objectKeys = Object.keys || function (obj) {
    347   var res = [];
    348   for (var key in obj) {
    349     if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
    350   }
    351   return res;
    352 };
    353 
    354 
    355 /***/ })
    356 /******/ ]);
    357 });