Socket
Socket
Sign inDemoInstall

url-parse

Package Overview
Dependencies
Maintainers
4
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-parse - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

dist/url-parse.min.js.map

467

dist/url-parse.js

@@ -1,57 +0,148 @@

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.URLParse=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.URLParse = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
(function (global){
'use strict';
var required = require('requires-port')
, lolcation = require('./lolcation')
, qs = require('querystringify');
, qs = require('querystringify')
, protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i
, slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//;
var keys = ',,protocol,username,password,host,hostname,port,pathname,query,hash'.split(',')
, inherit = { protocol: 1, host: 1, hostname: 1 }
, parts = keys.length;
/**
* These are the parse rules for the URL parser, it informs the parser
* about:
*
* 0. The char it Needs to parse, if it's a string it should be done using
* indexOf, RegExp using exec and NaN means set as current value.
* 1. The property we should set when parsing this value.
* 2. Indication if it's backwards or forward parsing, when set as number it's
* the value of extra chars that should be split off.
* 3. Inherit from location if non existing in the parser.
* 4. `toLowerCase` the resulting value.
*/
var rules = [
['#', 'hash'], // Extract from the back.
['?', 'query'], // Extract from the back.
['/', 'pathname'], // Extract from the back.
['@', 'auth', 1], // Extract from the front.
[NaN, 'host', undefined, 1, 1], // Set left over value.
[/:(\d+)$/, 'port', undefined, 1], // RegExp the back.
[NaN, 'hostname', undefined, 1, 1] // Set left over.
];
//
// Story time children:
//
// FireFox 34 has some problems with their Regular Expression engine and
// executing a RegExp can cause a `too much recursion` error. We initially fixed
// this by moving the Regular Expression in the URL constructor so it's created
// every single time. This fixed it for some URL's but the more complex the
// URL's get the easier it is to trigger. Complexer URL like:
//
// https://www.mozilla.org/en-US/firefox/34.0/whatsnew/?oldversion=33.1
//
// Still triggered the recursion error. After talking with Chrome and FireFox
// engineers it seemed to be caused by:
//
// https://code.google.com/p/v8/issues/detail?id=430
//
// As FireFox started using Chrome's RegExp engine. After testing various of
// workarounds I finally stumbled upon this gem, use new RegExp as it sometimes
// behaves different then a RegExp literal.
//
// Steps for compiling the new RegExp:
//
// 1. Take the regular RegExp as seen below.
// 2. Escape the RegExp using XRegExp.escape from http://xregexp.com/tests/
// 3. ??
// 4. Profit.
//
// RegExp source: /^(?:(?:(([^:\/#\?]+:)?(?:(?:\/\/)(?:(?:(?:([^:@\/#\?]+)(?:\:([^:@\/#\?]*))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((?:\/?(?:[^\/\?#]+\/+)*)(?:[^\?#]*)))?(\?[^#]+)?)(#.*)?/
//
var regexp = new RegExp('\^\(\?:\(\?:\(\(\[\^:\\/\#\\\?\]\+:\)\?\(\?:\(\?:\\/\\/\)\(\?:\(\?:\(\?:\(\[\^:@\\/\#\\\?\]\+\)\(\?:\\:\(\[\^:@\\/\#\\\?\]\*\)\)\?\)@\)\?\(\(\[\^:\\/\#\\\?\\\]\\\[\]\+\|\\\[\[\^\\/\\\]@\#\?\]\+\\\]\)\(\?:\\:\(\[0\-9\]\+\)\)\?\)\)\?\)\?\)\?\(\(\?:\\/\?\(\?:\[\^\\/\\\?\#\]\+\\/\+\)\*\)\(\?:\[\^\\\?\#\]\*\)\)\)\?\(\\\?\[\^\#\]\+\)\?\)\(\#\.\*\)\?');
/**
* These properties should not be copied or inherited from. This is only needed
* for all non blob URL's as a blob URL does not include a hash, only the
* origin.
*
* @type {Object}
* @private
*/
var ignore = { hash: 1, query: 1 };
function parse(url) {
try { return regexp.exec(url); }
catch (e) { return url.match(regexp); }
/**
* The location object differs when your code is loaded through a normal page,
* Worker or through a worker using a blob. And with the blobble begins the
* trouble as the location object will contain the URL of the blob, not the
* location of the page where our code is loaded in. The actual origin is
* encoded in the `pathname` so we can thankfully generate a good "default"
* location from it so we can generate proper relative URL's again.
*
* @param {Object|String} loc Optional default location object.
* @returns {Object} lolcation object.
* @api public
*/
function lolcation(loc) {
loc = loc || global.location || {};
var finaldestination = {}
, type = typeof loc
, key;
if ('blob:' === loc.protocol) {
finaldestination = new URL(unescape(loc.pathname), {});
} else if ('string' === type) {
finaldestination = new URL(loc, {});
for (key in ignore) delete finaldestination[key];
} else if ('object' === type) {
for (key in loc) {
if (key in ignore) continue;
finaldestination[key] = loc[key];
}
if (finaldestination.slashes === undefined) {
finaldestination.slashes = slashes.test(loc.href);
}
}
return finaldestination;
}
/**
* @typedef ProtocolExtract
* @type Object
* @property {String} protocol Protocol matched in the URL, in lowercase.
* @property {Boolean} slashes `true` if protocol is followed by "//", else `false`.
* @property {String} rest Rest of the URL that is not part of the protocol.
*/
/**
* Extract protocol information from a URL with/without double slash ("//").
*
* @param {String} address URL we want to extract from.
* @return {ProtocolExtract} Extracted information.
* @api private
*/
function extractProtocol(address) {
var match = protocolre.exec(address);
return {
protocol: match[1] ? match[1].toLowerCase() : '',
slashes: !!match[2],
rest: match[3]
};
}
/**
* Resolve a relative URL pathname against a base URL pathname.
*
* @param {String} relative Pathname of the relative URL.
* @param {String} base Pathname of the base URL.
* @return {String} Resolved pathname.
* @api private
*/
function resolve(relative, base) {
var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/'))
, i = path.length
, last = path[i - 1]
, unshift = false
, up = 0;
while (i--) {
if (path[i] === '.') {
path.splice(i, 1);
} else if (path[i] === '..') {
path.splice(i, 1);
up++;
} else if (up) {
if (i === 0) unshift = true;
path.splice(i, 1);
up--;
}
}
if (unshift) path.unshift('');
if (last === '.' || last === '..') path.push('');
return path.join('/');
}
/**
* The actual URL instance. Instead of returning an object we've opted-in to
* create an actual constructor as it's much more memory efficient and
* faster and it pleases my CDO.
* faster and it pleases my OCD.
*
* @constructor
* @param {String} address URL we want to parse.
* @param {Boolean|function} parser Parser for the query string.
* @param {Object} location Location defaults for relative paths.
* @param {Object|String} location Location defaults for relative paths.
* @param {Boolean|Function} parser Parser for the query string.
* @api public

@@ -64,7 +155,7 @@ */

var type = typeof location
, bits = parse(address)
var relative, extracted, parse, instruction, index, key
, instructions = rules.slice()
, type = typeof location
, url = this
, i = 0
, key;
, i = 0;

@@ -87,19 +178,52 @@ //

if (parser && 'function' !== typeof parser) {
parser = qs.parse;
}
if (parser && 'function' !== typeof parser) parser = qs.parse;
location = lolcation(location);
for (; i < parts; key = keys[++i]) {
if (!key) continue;
//
// Extract protocol information before running the instructions.
//
extracted = extractProtocol(address || '');
relative = !extracted.protocol && !extracted.slashes;
url.slashes = extracted.slashes || relative && location.slashes;
url.protocol = extracted.protocol || location.protocol || '';
address = extracted.rest;
url[key] = bits[i] || (key in inherit ? location[key] || '' : '');
//
// When the authority component is absent the URL starts with a path
// component.
//
if (!extracted.slashes) instructions[2] = [/(.*)/, 'pathname'];
for (; i < instructions.length; i++) {
instruction = instructions[i];
parse = instruction[0];
key = instruction[1];
if (parse !== parse) {
url[key] = address;
} else if ('string' === typeof parse) {
if (~(index = address.indexOf(parse))) {
if ('number' === typeof instruction[2]) {
url[key] = address.slice(0, index);
address = address.slice(index + instruction[2]);
} else {
url[key] = address.slice(index);
address = address.slice(0, index);
}
}
} else if ((index = parse.exec(address))) {
url[key] = index[1];
address = address.slice(0, index.index);
}
url[key] = url[key] || (
relative && instruction[3] ? location[key] || '' : ''
);
//
// The protocol, host, host name should always be lower cased even if they
// are supplied in uppercase. This way, when people generate an `origin`
// it be correct.
// Hostname, host and protocol should be lowercased so they can be used to
// create a proper `origin`.
//
if (i === 2 || i === 5 || i === 6) url[key] = url[key].toLowerCase();
if (instruction[4]) url[key] = url[key].toLowerCase();
}

@@ -115,2 +239,14 @@

//
// If the URL is relative, resolve the pathname against the base URL.
//
if (
relative
&& location.slashes
&& url.pathname.charAt(0) !== '/'
&& (url.pathname !== '' || location.pathname !== '')
) {
url.pathname = resolve(url.pathname, location.pathname);
}
//
// We should not add port numbers if they are already the default port number

@@ -126,2 +262,16 @@ // for a given protocol. As the host also contains the port number we're going

//
// Parse down the `auth` for the username and password.
//
url.username = url.password = '';
if (url.auth) {
instruction = url.auth.split(':');
url.username = instruction[0] || '';
url.password = instruction[1] || '';
}
url.origin = url.protocol && url.host && url.protocol !== 'file:'
? url.protocol +'//'+ url.host
: 'null';
//
// The href is just the compiled result.

@@ -136,42 +286,89 @@ //

*
* @param {String} prop Property we need to adjust.
* @param {Mixed} value The newly assigned value.
* @param {String} part Property we need to adjust.
* @param {Mixed} value The newly assigned value.
* @param {Boolean|Function} fn When setting the query, it will be the function
* used to parse the query.
* When setting the protocol, double slash will be
* removed from the final url if it is true.
* @returns {URL}
* @api public
*/
URL.prototype.set = function set(part, value, fn) {
function set(part, value, fn) {
var url = this;
if ('query' === part) {
if ('string' === typeof value) value = (fn || qs.parse)(value);
url[part] = value;
} else if ('port' === part) {
url[part] = value;
switch (part) {
case 'query':
if ('string' === typeof value && value.length) {
value = (fn || qs.parse)(value);
}
if (!required(value, url.protocol)) {
url.host = url.hostname;
url[part] = '';
} else if (value) {
url.host = url.hostname +':'+ value;
}
} else if ('hostname' === part) {
url[part] = value;
url[part] = value;
break;
if (url.port) value += ':'+ url.port;
url.host = value;
} else if ('host' === part) {
url[part] = value;
case 'port':
url[part] = value;
if (/\:\d+/.test(value)) {
value = value.split(':');
url.hostname = value[0];
url.port = value[1];
}
} else {
url[part] = value;
if (!required(value, url.protocol)) {
url.host = url.hostname;
url[part] = '';
} else if (value) {
url.host = url.hostname +':'+ value;
}
break;
case 'hostname':
url[part] = value;
if (url.port) value += ':'+ url.port;
url.host = value;
break;
case 'host':
url[part] = value;
if (/:\d+$/.test(value)) {
value = value.split(':');
url.port = value.pop();
url.hostname = value.join(':');
} else {
url.hostname = value;
url.port = '';
}
break;
case 'protocol':
url.protocol = value.toLowerCase();
url.slashes = !fn;
break;
case 'pathname':
case 'hash':
if (value) {
var char = part === 'pathname' ? '/' : '#';
url[part] = value.charAt(0) !== char ? char + value : value;
} else {
url[part] = value;
}
break;
default:
url[part] = value;
}
for (var i = 0; i < rules.length; i++) {
var ins = rules[i];
if (ins[4]) url[ins[1]] = url[ins[1]].toLowerCase();
}
url.origin = url.protocol && url.host && url.protocol !== 'file:'
? url.protocol +'//'+ url.host
: 'null';
url.href = url.toString();
return url;
};
}

@@ -185,3 +382,3 @@ /**

*/
URL.prototype.toString = function toString(stringify) {
function toString(stringify) {
if (!stringify || 'function' !== typeof stringify) stringify = qs.stringify;

@@ -191,17 +388,18 @@

, url = this
, result = url.protocol +'//';
, protocol = url.protocol;
if (url.username) result += url.username +':'+ url.password +'@';
if (protocol && protocol.charAt(protocol.length - 1) !== ':') protocol += ':';
result += url.hostname;
if (url.port) result += ':'+ url.port;
var result = protocol + (url.slashes ? '//' : '');
result += url.pathname;
if (url.username) {
result += url.username;
if (url.password) result += ':'+ url.password;
result += '@';
}
if (url.query) {
if ('object' === typeof url.query) query = stringify(url.query);
else query = url.query;
result += url.host + url.pathname;
result += (query.charAt(0) === '?' ? '' : '?') + query;
}
query = 'object' === typeof url.query ? stringify(url.query) : url.query;
if (query) result += '?' !== query.charAt(0) ? '?'+ query : query;

@@ -211,66 +409,33 @@ if (url.hash) result += url.hash;

return result;
};
}
URL.prototype = { set: set, toString: toString };
//
// Expose the URL parser and some additional properties that might be useful for
// others.
// others or testing.
//
URL.extractProtocol = extractProtocol;
URL.location = lolcation;
URL.qs = qs;
URL.location = lolcation;
module.exports = URL;
},{"./lolcation":2,"querystringify":3,"requires-port":4}],2:[function(require,module,exports){
(function (global){
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"querystringify":2,"requires-port":3}],2:[function(require,module,exports){
'use strict';
/**
* These properties should not be copied or inherited from. This is only needed
* for all non blob URL's as the a blob URL does not include a hash, only the
* origin.
*
* @type {Object}
* @private
*/
var ignore = { hash: 1, query: 1 }
, URL;
var has = Object.prototype.hasOwnProperty;
/**
* The location object differs when your code is loaded through a normal page,
* Worker or through a worker using a blob. And with the blobble begins the
* trouble as the location object will contain the URL of the blob, not the
* location of the page where our code is loaded in. The actual origin is
* encoded in the `pathname` so we can thankfully generate a good "default"
* location from it so we can generate proper relative URL's again.
* Decode a URI encoded string.
*
* @param {Object} loc Optional default location object.
* @returns {Object} lolcation object.
* @api public
* @param {String} input The URI encoded string.
* @returns {String} The decoded string.
* @api private
*/
module.exports = function lolcation(loc) {
loc = loc || global.location || {};
URL = URL || require('./');
function decode(input) {
return decodeURIComponent(input.replace(/\+/g, ' '));
}
var finaldestination = {}
, type = typeof loc
, key;
if ('blob:' === loc.protocol) {
finaldestination = new URL(unescape(loc.pathname), {});
} else if ('string' === type) {
finaldestination = new URL(loc, {});
for (key in ignore) delete finaldestination[key];
} else if ('object' === type) for (key in loc) {
if (key in ignore) continue;
finaldestination[key] = loc[key];
}
return finaldestination;
};
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./":1}],3:[function(require,module,exports){
'use strict';
var has = Object.prototype.hasOwnProperty;
/**

@@ -284,3 +449,3 @@ * Simple query string parser.

function querystring(query) {
var parser = /([^=?&]+)=([^&]*)/g
var parser = /([^=?&]+)=?([^&]*)/g
, result = {}

@@ -296,3 +461,3 @@ , part;

part = parser.exec(query);
result[decodeURIComponent(part[1])] = decodeURIComponent(part[2])
result[decode(part[1])] = decode(part[2])
);

@@ -327,3 +492,3 @@

return prefix + pairs.join('&');
return pairs.length ? prefix + pairs.join('&') : '';
}

@@ -337,3 +502,3 @@

},{}],4:[function(require,module,exports){
},{}],3:[function(require,module,exports){
'use strict';

@@ -366,3 +531,3 @@

case 'ftp':
return port !== 22;
return port !== 21;

@@ -380,2 +545,2 @@ case 'gopher':

},{}]},{},[1])(1)
});
});

@@ -1,1 +0,1 @@

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).URLParse=e()}}(function(){return function e(t,o,r){function n(a,i){if(!o[a]){if(!t[a]){var p="function"==typeof require&&require;if(!i&&p)return p(a,!0);if(s)return s(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var f=o[a]={exports:{}};t[a][0].call(f.exports,function(e){var o=t[a][1][e];return n(o||e)},f,f.exports,e,t,o,r)}return o[a].exports}for(var s="function"==typeof require&&require,a=0;a<r.length;a++)n(r[a]);return n}({1:[function(e,t,o){(function(o){"use strict";function r(e){var t,r={},n=typeof(e=e||o.location||{});if("blob:"===e.protocol)r=new a(unescape(e.pathname),{});else if("string"===n){r=new a(e,{});for(t in u)delete r[t]}else if("object"===n){for(t in e)t in u||(r[t]=e[t]);void 0===r.slashes&&(r.slashes=f.test(e.href))}return r}function n(e){var t=c.exec(e);return{protocol:t[1]?t[1].toLowerCase():"",slashes:!!t[2],rest:t[3]}}function s(e,t){for(var o=(t||"/").split("/").slice(0,-1).concat(e.split("/")),r=o.length,n=o[r-1],s=!1,a=0;r--;)"."===o[r]?o.splice(r,1):".."===o[r]?(o.splice(r,1),a++):a&&(0===r&&(s=!0),o.splice(r,1),a--);return s&&o.unshift(""),"."!==n&&".."!==n||o.push(""),o.join("/")}function a(e,t,o){if(!(this instanceof a))return new a(e,t,o);var c,f,u,h,d,y,m=l.slice(),g=typeof t,w=this,v=0;for("object"!==g&&"string"!==g&&(o=t,t=null),o&&"function"!=typeof o&&(o=p.parse),t=r(t),c=!(f=n(e||"")).protocol&&!f.slashes,w.slashes=f.slashes||c&&t.slashes,w.protocol=f.protocol||t.protocol||"",e=f.rest,f.slashes||(m[2]=[/(.*)/,"pathname"]);v<m.length;v++)u=(h=m[v])[0],y=h[1],u!=u?w[y]=e:"string"==typeof u?~(d=e.indexOf(u))&&("number"==typeof h[2]?(w[y]=e.slice(0,d),e=e.slice(d+h[2])):(w[y]=e.slice(d),e=e.slice(0,d))):(d=u.exec(e))&&(w[y]=d[1],e=e.slice(0,d.index)),w[y]=w[y]||(c&&h[3]?t[y]||"":""),h[4]&&(w[y]=w[y].toLowerCase());o&&(w.query=o(w.query)),c&&t.slashes&&"/"!==w.pathname.charAt(0)&&(""!==w.pathname||""!==t.pathname)&&(w.pathname=s(w.pathname,t.pathname)),i(w.port,w.protocol)||(w.host=w.hostname,w.port=""),w.username=w.password="",w.auth&&(h=w.auth.split(":"),w.username=h[0]||"",w.password=h[1]||""),w.origin=w.protocol&&w.host&&"file:"!==w.protocol?w.protocol+"//"+w.host:"null",w.href=w.toString()}var i=e("requires-port"),p=e("querystringify"),c=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,f=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,l=[["#","hash"],["?","query"],["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],u={hash:1,query:1};a.prototype={set:function(e,t,o){var r=this;switch(e){case"query":"string"==typeof t&&t.length&&(t=(o||p.parse)(t)),r[e]=t;break;case"port":r[e]=t,i(t,r.protocol)?t&&(r.host=r.hostname+":"+t):(r.host=r.hostname,r[e]="");break;case"hostname":r[e]=t,r.port&&(t+=":"+r.port),r.host=t;break;case"host":r[e]=t,/:\d+$/.test(t)?(t=t.split(":"),r.port=t.pop(),r.hostname=t.join(":")):(r.hostname=t,r.port="");break;case"protocol":r.protocol=t.toLowerCase(),r.slashes=!o;break;case"pathname":case"hash":if(t){var n="pathname"===e?"/":"#";r[e]=t.charAt(0)!==n?n+t:t}else r[e]=t;break;default:r[e]=t}for(var s=0;s<l.length;s++){var a=l[s];a[4]&&(r[a[1]]=r[a[1]].toLowerCase())}return r.origin=r.protocol&&r.host&&"file:"!==r.protocol?r.protocol+"//"+r.host:"null",r.href=r.toString(),r},toString:function(e){e&&"function"==typeof e||(e=p.stringify);var t,o=this,r=o.protocol;r&&":"!==r.charAt(r.length-1)&&(r+=":");var n=r+(o.slashes?"//":"");return o.username&&(n+=o.username,o.password&&(n+=":"+o.password),n+="@"),n+=o.host+o.pathname,(t="object"==typeof o.query?e(o.query):o.query)&&(n+="?"!==t.charAt(0)?"?"+t:t),o.hash&&(n+=o.hash),n}},a.extractProtocol=n,a.location=r,a.qs=p,t.exports=a}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{querystringify:2,"requires-port":3}],2:[function(e,t,o){"use strict";function r(e){return decodeURIComponent(e.replace(/\+/g," "))}var n=Object.prototype.hasOwnProperty;o.stringify=function(e,t){var o=[];"string"!=typeof(t=t||"")&&(t="?");for(var r in e)n.call(e,r)&&o.push(encodeURIComponent(r)+"="+encodeURIComponent(e[r]));return o.length?t+o.join("&"):""},o.parse=function(e){for(var t,o=/([^=?&]+)=?([^&]*)/g,n={};t=o.exec(e);n[r(t[1])]=r(t[2]));return n}},{}],3:[function(e,t,o){"use strict";t.exports=function(e,t){if(t=t.split(":")[0],!(e=+e))return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}},{}]},{},[1])(1)});
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).URLParse=e()}}(function(){return function s(a,i,p){function c(t,e){if(!i[t]){if(!a[t]){var o="function"==typeof require&&require;if(!e&&o)return o(t,!0);if(f)return f(t,!0);var r=new Error("Cannot find module '"+t+"'");throw r.code="MODULE_NOT_FOUND",r}var n=i[t]={exports:{}};a[t][0].call(n.exports,function(e){return c(a[t][1][e]||e)},n,n.exports,s,a,i,p)}return i[t].exports}for(var f="function"==typeof require&&require,e=0;e<p.length;e++)c(p[e]);return c}({1:[function(e,t,o){(function(n){"use strict";var h=e("requires-port"),d=e("querystringify"),o=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,s=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,y=[["#","hash"],["?","query"],["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],a={hash:1,query:1};function m(e){var t,o={},r=typeof(e=e||n.location||{});if("blob:"===e.protocol)o=new w(unescape(e.pathname),{});else if("string"===r)for(t in o=new w(e,{}),a)delete o[t];else if("object"===r){for(t in e)t in a||(o[t]=e[t]);void 0===o.slashes&&(o.slashes=s.test(e.href))}return o}function g(e){var t=o.exec(e);return{protocol:t[1]?t[1].toLowerCase():"",slashes:!!t[2],rest:t[3]}}function w(e,t,o){if(!(this instanceof w))return new w(e,t,o);var r,n,s,a,i,p,c=y.slice(),f=typeof t,l=this,u=0;for("object"!==f&&"string"!==f&&(o=t,t=null),o&&"function"!=typeof o&&(o=d.parse),t=m(t),r=!(n=g(e||"")).protocol&&!n.slashes,l.slashes=n.slashes||r&&t.slashes,l.protocol=n.protocol||t.protocol||"",e=n.rest,n.slashes||(c[2]=[/(.*)/,"pathname"]);u<c.length;u++)s=(a=c[u])[0],p=a[1],s!=s?l[p]=e:"string"==typeof s?~(i=e.indexOf(s))&&("number"==typeof a[2]?(l[p]=e.slice(0,i),e=e.slice(i+a[2])):(l[p]=e.slice(i),e=e.slice(0,i))):(i=s.exec(e))&&(l[p]=i[1],e=e.slice(0,i.index)),l[p]=l[p]||r&&a[3]&&t[p]||"",a[4]&&(l[p]=l[p].toLowerCase());o&&(l.query=o(l.query)),r&&t.slashes&&"/"!==l.pathname.charAt(0)&&(""!==l.pathname||""!==t.pathname)&&(l.pathname=function(e,t){for(var o=(t||"/").split("/").slice(0,-1).concat(e.split("/")),r=o.length,n=o[r-1],s=!1,a=0;r--;)"."===o[r]?o.splice(r,1):".."===o[r]?(o.splice(r,1),a++):a&&(0===r&&(s=!0),o.splice(r,1),a--);return s&&o.unshift(""),"."!==n&&".."!==n||o.push(""),o.join("/")}(l.pathname,t.pathname)),h(l.port,l.protocol)||(l.host=l.hostname,l.port=""),l.username=l.password="",l.auth&&(a=l.auth.split(":"),l.username=a[0]||"",l.password=a[1]||""),l.origin=l.protocol&&l.host&&"file:"!==l.protocol?l.protocol+"//"+l.host:"null",l.href=l.toString()}w.prototype={set:function(e,t,o){var r=this;switch(e){case"query":"string"==typeof t&&t.length&&(t=(o||d.parse)(t)),r[e]=t;break;case"port":r[e]=t,h(t,r.protocol)?t&&(r.host=r.hostname+":"+t):(r.host=r.hostname,r[e]="");break;case"hostname":r[e]=t,r.port&&(t+=":"+r.port),r.host=t;break;case"host":r[e]=t,/:\d+$/.test(t)?(t=t.split(":"),r.port=t.pop(),r.hostname=t.join(":")):(r.hostname=t,r.port="");break;case"protocol":r.protocol=t.toLowerCase(),r.slashes=!o;break;case"pathname":case"hash":if(t){var n="pathname"===e?"/":"#";r[e]=t.charAt(0)!==n?n+t:t}else r[e]=t;break;default:r[e]=t}for(var s=0;s<y.length;s++){var a=y[s];a[4]&&(r[a[1]]=r[a[1]].toLowerCase())}return r.origin=r.protocol&&r.host&&"file:"!==r.protocol?r.protocol+"//"+r.host:"null",r.href=r.toString(),r},toString:function(e){e&&"function"==typeof e||(e=d.stringify);var t,o=this,r=o.protocol;r&&":"!==r.charAt(r.length-1)&&(r+=":");var n=r+(o.slashes?"//":"");return o.username&&(n+=o.username,o.password&&(n+=":"+o.password),n+="@"),n+=o.host+o.pathname,(t="object"==typeof o.query?e(o.query):o.query)&&(n+="?"!==t.charAt(0)?"?"+t:t),o.hash&&(n+=o.hash),n}},w.extractProtocol=g,w.location=m,w.qs=d,t.exports=w}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{querystringify:2,"requires-port":3}],2:[function(e,t,o){"use strict";var n=Object.prototype.hasOwnProperty;function s(e){return decodeURIComponent(e.replace(/\+/g," "))}o.stringify=function(e,t){t=t||"";var o=[];for(var r in"string"!=typeof t&&(t="?"),e)n.call(e,r)&&o.push(encodeURIComponent(r)+"="+encodeURIComponent(e[r]));return o.length?t+o.join("&"):""},o.parse=function(e){for(var t,o=/([^=?&]+)=?([^&]*)/g,r={};t=o.exec(e);r[s(t[1])]=s(t[2]));return r}},{}],3:[function(e,t,o){"use strict";t.exports=function(e,t){if(t=t.split(":")[0],!(e=+e))return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}},{}]},{},[1])(1)});
{
"name": "url-parse",
"version": "1.2.0",
"version": "1.3.0",
"description": "Small footprint URL parser that works seamlessly across Node.js and browser environments",
"main": "index.js",
"scripts": {
"browserify": "mkdir -p dist && browserify index.js -s URLParse | uglifyjs -cm -o dist/url-parse.min.js",
"browserify": "rm -rf dist && mkdir -p dist && browserify index.js -s URLParse -o dist/url-parse.js",
"minify": "uglifyjs dist/url-parse.js --source-map -cm -o dist/url-parse.min.js",
"test": "nyc --reporter=html --reporter=text mocha test/test.js",
"test-browser": "node test/browser.js",
"prepublishOnly": "npm run browserify",
"prepublishOnly": "npm run browserify && npm run minify",
"watch": "mocha --watch test/test.js"

@@ -40,10 +41,10 @@ },

"assume": "~1.5.0",
"browserify": "~14.5.0",
"mocha": "~4.0.0",
"nyc": "~11.3.0",
"browserify": "~16.1.0",
"mocha": "~5.0.0",
"nyc": "~11.6.0",
"pre-commit": "~1.2.0",
"sauce-browsers": "~1.0.0",
"sauce-browsers": "~1.2.0",
"sauce-test": "~1.3.3",
"uglify-js": "~3.1.0"
"uglify-js": "~3.3.0"
}
}
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