update
This commit is contained in:
+11
-3
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* @name protocols
|
||||
* @function
|
||||
* @param {String} input The input url.
|
||||
* @param {String|URL} input The input url (string or `URL` instance)
|
||||
* @param {Boolean|Number} first If `true`, the first protocol will be returned. If number, it will represent the zero-based index of the protocols array.
|
||||
* @return {Array|String} The array of protocols or the specified protocol.
|
||||
*/
|
||||
@@ -16,8 +16,16 @@ module.exports = function protocols(input, first) {
|
||||
first = 0;
|
||||
}
|
||||
|
||||
var index = input.indexOf("://"),
|
||||
splits = input.substring(0, index).split("+").filter(Boolean);
|
||||
var prots = "";
|
||||
if (typeof input === "string") {
|
||||
try {
|
||||
prots = new URL(input).protocol;
|
||||
} catch (e) {}
|
||||
} else if (input && input.constructor === URL) {
|
||||
prots = input.protocol;
|
||||
}
|
||||
|
||||
var splits = prots.split(/\:|\+/).filter(Boolean);
|
||||
|
||||
if (typeof first === "number") {
|
||||
return splits[first];
|
||||
|
||||
Reference in New Issue
Block a user