This commit is contained in:
2022-07-18 02:50:52 +00:00
parent befd344ab0
commit 06181b34d6
8569 changed files with 818704 additions and 352705 deletions
+11 -3
View File
@@ -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];