123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755 |
- (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){(function (){
- 'use strict';
- var required = require('requires-port')
- , qs = require('querystringify')
- , controlOrWhitespace = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/
- , CRHTLF = /[\n\r\t]/g
- , slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//
- , port = /:\d+$/
- , protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i
- , windowsDriveLetter = /^[a-zA-Z]:/;
- function trimLeft(str) {
- return (str ? str : '').toString().replace(controlOrWhitespace, '');
- }
- var rules = [
- ['#', 'hash'],
- ['?', 'query'],
- function sanitize(address, url) {
- return isSpecial(url.protocol) ? address.replace(/\\/g, '/') : address;
- },
- ['/', 'pathname'],
- ['@', 'auth', 1],
- [NaN, 'host', undefined, 1, 1],
- [/:(\d*)$/, 'port', undefined, 1],
- [NaN, 'hostname', undefined, 1, 1]
- ];
- var ignore = { hash: 1, query: 1 };
- function lolcation(loc) {
- var globalVar;
- if (typeof window !== 'undefined') globalVar = window;
- else if (typeof global !== 'undefined') globalVar = global;
- else if (typeof self !== 'undefined') globalVar = self;
- else globalVar = {};
- var location = globalVar.location || {};
- loc = loc || 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;
- }
- function isSpecial(scheme) {
- return (
- scheme === 'file:' ||
- scheme === 'ftp:' ||
- scheme === 'http:' ||
- scheme === 'https:' ||
- scheme === 'ws:' ||
- scheme === 'wss:'
- );
- }
- function extractProtocol(address, location) {
- address = trimLeft(address);
- address = address.replace(CRHTLF, '');
- location = location || {};
- var match = protocolre.exec(address);
- var protocol = match[1] ? match[1].toLowerCase() : '';
- var forwardSlashes = !!match[2];
- var otherSlashes = !!match[3];
- var slashesCount = 0;
- var rest;
- if (forwardSlashes) {
- if (otherSlashes) {
- rest = match[2] + match[3] + match[4];
- slashesCount = match[2].length + match[3].length;
- } else {
- rest = match[2] + match[4];
- slashesCount = match[2].length;
- }
- } else {
- if (otherSlashes) {
- rest = match[3] + match[4];
- slashesCount = match[3].length;
- } else {
- rest = match[4]
- }
- }
- if (protocol === 'file:') {
- if (slashesCount >= 2) {
- rest = rest.slice(2);
- }
- } else if (isSpecial(protocol)) {
- rest = match[4];
- } else if (protocol) {
- if (forwardSlashes) {
- rest = rest.slice(2);
- }
- } else if (slashesCount >= 2 && isSpecial(location.protocol)) {
- rest = match[4];
- }
- return {
- protocol: protocol,
- slashes: forwardSlashes || isSpecial(protocol),
- slashesCount: slashesCount,
- rest: rest
- };
- }
- function resolve(relative, base) {
- if (relative === '') return 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('/');
- }
- function Url(address, location, parser) {
- address = trimLeft(address);
- address = address.replace(CRHTLF, '');
- if (!(this instanceof Url)) {
- return new Url(address, location, parser);
- }
- var relative, extracted, parse, instruction, index, key
- , instructions = rules.slice()
- , type = typeof location
- , url = this
- , i = 0;
-
-
-
-
-
-
-
-
-
-
-
- if ('object' !== type && 'string' !== type) {
- parser = location;
- location = null;
- }
- if (parser && 'function' !== typeof parser) parser = qs.parse;
- location = lolcation(location);
-
-
-
- extracted = extractProtocol(address || '', location);
- relative = !extracted.protocol && !extracted.slashes;
- url.slashes = extracted.slashes || relative && location.slashes;
- url.protocol = extracted.protocol || location.protocol || '';
- address = extracted.rest;
-
-
-
-
- if (
- extracted.protocol === 'file:' && (
- extracted.slashesCount !== 2 || windowsDriveLetter.test(address)) ||
- (!extracted.slashes &&
- (extracted.protocol ||
- extracted.slashesCount < 2 ||
- !isSpecial(url.protocol)))
- ) {
- instructions[3] = [/(.*)/, 'pathname'];
- }
- for (; i < instructions.length; i++) {
- instruction = instructions[i];
- if (typeof instruction === 'function') {
- address = instruction(address, url);
- continue;
- }
- parse = instruction[0];
- key = instruction[1];
- if (parse !== parse) {
- url[key] = address;
- } else if ('string' === typeof parse) {
- index = parse === '@'
- ? address.lastIndexOf(parse)
- : address.indexOf(parse);
- if (~index) {
- 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] || '' : ''
- );
-
-
-
-
- if (instruction[4]) url[key] = url[key].toLowerCase();
- }
-
-
-
-
-
- if (parser) url.query = parser(url.query);
-
-
-
- if (
- relative
- && location.slashes
- && url.pathname.charAt(0) !== '/'
- && (url.pathname !== '' || location.pathname !== '')
- ) {
- url.pathname = resolve(url.pathname, location.pathname);
- }
-
-
-
-
- if (url.pathname.charAt(0) !== '/' && isSpecial(url.protocol)) {
- url.pathname = '/' + url.pathname;
- }
-
-
-
-
-
- if (!required(url.port, url.protocol)) {
- url.host = url.hostname;
- url.port = '';
- }
-
-
-
- url.username = url.password = '';
- if (url.auth) {
- index = url.auth.indexOf(':');
- if (~index) {
- url.username = url.auth.slice(0, index);
- url.username = encodeURIComponent(decodeURIComponent(url.username));
- url.password = url.auth.slice(index + 1);
- url.password = encodeURIComponent(decodeURIComponent(url.password))
- } else {
- url.username = encodeURIComponent(decodeURIComponent(url.auth));
- }
- url.auth = url.password ? url.username +':'+ url.password : url.username;
- }
- url.origin = url.protocol !== 'file:' && isSpecial(url.protocol) && url.host
- ? url.protocol +'//'+ url.host
- : 'null';
-
-
-
- url.href = url.toString();
- }
- function set(part, value, fn) {
- var url = this;
- switch (part) {
- case 'query':
- if ('string' === typeof value && value.length) {
- value = (fn || qs.parse)(value);
- }
- url[part] = value;
- break;
- case 'port':
- 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 (port.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;
- case 'username':
- case 'password':
- url[part] = encodeURIComponent(value);
- break;
- case 'auth':
- var index = value.indexOf(':');
- if (~index) {
- url.username = value.slice(0, index);
- url.username = encodeURIComponent(decodeURIComponent(url.username));
- url.password = value.slice(index + 1);
- url.password = encodeURIComponent(decodeURIComponent(url.password));
- } else {
- url.username = encodeURIComponent(decodeURIComponent(value));
- }
- }
- for (var i = 0; i < rules.length; i++) {
- var ins = rules[i];
- if (ins[4]) url[ins[1]] = url[ins[1]].toLowerCase();
- }
- url.auth = url.password ? url.username +':'+ url.password : url.username;
- url.origin = url.protocol !== 'file:' && isSpecial(url.protocol) && url.host
- ? url.protocol +'//'+ url.host
- : 'null';
- url.href = url.toString();
- return url;
- }
- function toString(stringify) {
- if (!stringify || 'function' !== typeof stringify) stringify = qs.stringify;
- var query
- , url = this
- , host = url.host
- , protocol = url.protocol;
- if (protocol && protocol.charAt(protocol.length - 1) !== ':') protocol += ':';
- var result =
- protocol +
- ((url.protocol && url.slashes) || isSpecial(url.protocol) ? '//' : '');
- if (url.username) {
- result += url.username;
- if (url.password) result += ':'+ url.password;
- result += '@';
- } else if (url.password) {
- result += ':'+ url.password;
- result += '@';
- } else if (
- url.protocol !== 'file:' &&
- isSpecial(url.protocol) &&
- !host &&
- url.pathname !== '/'
- ) {
-
-
-
-
- result += '@';
- }
-
-
-
-
-
- if (host[host.length - 1] === ':' || (port.test(url.hostname) && !url.port)) {
- host += ':';
- }
- result += host + url.pathname;
- query = 'object' === typeof url.query ? stringify(url.query) : url.query;
- if (query) result += '?' !== query.charAt(0) ? '?'+ query : query;
- 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 or testing.
- //
- Url.extractProtocol = extractProtocol;
- Url.location = lolcation;
- Url.trimLeft = trimLeft;
- Url.qs = qs;
- module.exports = Url;
- }).call(this)}).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';
- var has = Object.prototype.hasOwnProperty
- , undef;
- function decode(input) {
- try {
- return decodeURIComponent(input.replace(/\+/g, ' '));
- } catch (e) {
- return null;
- }
- }
- function encode(input) {
- try {
- return encodeURIComponent(input);
- } catch (e) {
- return null;
- }
- }
- function querystring(query) {
- var parser = /([^=?#&]+)=?([^&]*)/g
- , result = {}
- , part;
- while (part = parser.exec(query)) {
- var key = decode(part[1])
- , value = decode(part[2]);
-
-
-
-
-
-
-
-
- if (key === null || value === null || key in result) continue;
- result[key] = value;
- }
- return result;
- }
- function querystringify(obj, prefix) {
- prefix = prefix || '';
- var pairs = []
- , value
- , key;
-
-
-
- if ('string' !== typeof prefix) prefix = '?';
- for (key in obj) {
- if (has.call(obj, key)) {
- value = obj[key];
-
-
-
-
- if (!value && (value === null || value === undef || isNaN(value))) {
- value = '';
- }
- key = encode(key);
- value = encode(value);
-
-
-
-
- if (key === null || value === null) continue;
- pairs.push(key +'='+ value);
- }
- }
- return pairs.length ? prefix + pairs.join('&') : '';
- }
- exports.stringify = querystringify;
- exports.parse = querystring;
- },{}],3:[function(require,module,exports){
- 'use strict';
- module.exports = function required(port, protocol) {
- protocol = protocol.split(':')[0];
- port = +port;
- if (!port) return false;
- switch (protocol) {
- case 'http':
- case 'ws':
- return port !== 80;
- case 'https':
- case 'wss':
- return port !== 443;
- case 'ftp':
- return port !== 21;
- case 'gopher':
- return port !== 70;
- case 'file':
- return false;
- }
- return port !== 0;
- };
- },{}]},{},[1])(1)
- });
|