source: trip-planner-front/node_modules/url-parse/dist/url-parse.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 18.7 KB
Line 
1(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){
2(function (global){(function (){
3'use strict';
4
5var required = require('requires-port')
6 , qs = require('querystringify')
7 , slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//
8 , protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i
9 , windowsDriveLetter = /^[a-zA-Z]:/
10 , whitespace = '[\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\xA0\\u1680\\u180E\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\u2028\\u2029\\uFEFF]'
11 , left = new RegExp('^'+ whitespace +'+');
12
13/**
14 * Trim a given string.
15 *
16 * @param {String} str String to trim.
17 * @public
18 */
19function trimLeft(str) {
20 return (str ? str : '').toString().replace(left, '');
21}
22
23/**
24 * These are the parse rules for the URL parser, it informs the parser
25 * about:
26 *
27 * 0. The char it Needs to parse, if it's a string it should be done using
28 * indexOf, RegExp using exec and NaN means set as current value.
29 * 1. The property we should set when parsing this value.
30 * 2. Indication if it's backwards or forward parsing, when set as number it's
31 * the value of extra chars that should be split off.
32 * 3. Inherit from location if non existing in the parser.
33 * 4. `toLowerCase` the resulting value.
34 */
35var rules = [
36 ['#', 'hash'], // Extract from the back.
37 ['?', 'query'], // Extract from the back.
38 function sanitize(address, url) { // Sanitize what is left of the address
39 return isSpecial(url.protocol) ? address.replace(/\\/g, '/') : address;
40 },
41 ['/', 'pathname'], // Extract from the back.
42 ['@', 'auth', 1], // Extract from the front.
43 [NaN, 'host', undefined, 1, 1], // Set left over value.
44 [/:(\d+)$/, 'port', undefined, 1], // RegExp the back.
45 [NaN, 'hostname', undefined, 1, 1] // Set left over.
46];
47
48/**
49 * These properties should not be copied or inherited from. This is only needed
50 * for all non blob URL's as a blob URL does not include a hash, only the
51 * origin.
52 *
53 * @type {Object}
54 * @private
55 */
56var ignore = { hash: 1, query: 1 };
57
58/**
59 * The location object differs when your code is loaded through a normal page,
60 * Worker or through a worker using a blob. And with the blobble begins the
61 * trouble as the location object will contain the URL of the blob, not the
62 * location of the page where our code is loaded in. The actual origin is
63 * encoded in the `pathname` so we can thankfully generate a good "default"
64 * location from it so we can generate proper relative URL's again.
65 *
66 * @param {Object|String} loc Optional default location object.
67 * @returns {Object} lolcation object.
68 * @public
69 */
70function lolcation(loc) {
71 var globalVar;
72
73 if (typeof window !== 'undefined') globalVar = window;
74 else if (typeof global !== 'undefined') globalVar = global;
75 else if (typeof self !== 'undefined') globalVar = self;
76 else globalVar = {};
77
78 var location = globalVar.location || {};
79 loc = loc || location;
80
81 var finaldestination = {}
82 , type = typeof loc
83 , key;
84
85 if ('blob:' === loc.protocol) {
86 finaldestination = new Url(unescape(loc.pathname), {});
87 } else if ('string' === type) {
88 finaldestination = new Url(loc, {});
89 for (key in ignore) delete finaldestination[key];
90 } else if ('object' === type) {
91 for (key in loc) {
92 if (key in ignore) continue;
93 finaldestination[key] = loc[key];
94 }
95
96 if (finaldestination.slashes === undefined) {
97 finaldestination.slashes = slashes.test(loc.href);
98 }
99 }
100
101 return finaldestination;
102}
103
104/**
105 * Check whether a protocol scheme is special.
106 *
107 * @param {String} The protocol scheme of the URL
108 * @return {Boolean} `true` if the protocol scheme is special, else `false`
109 * @private
110 */
111function isSpecial(scheme) {
112 return (
113 scheme === 'file:' ||
114 scheme === 'ftp:' ||
115 scheme === 'http:' ||
116 scheme === 'https:' ||
117 scheme === 'ws:' ||
118 scheme === 'wss:'
119 );
120}
121
122/**
123 * @typedef ProtocolExtract
124 * @type Object
125 * @property {String} protocol Protocol matched in the URL, in lowercase.
126 * @property {Boolean} slashes `true` if protocol is followed by "//", else `false`.
127 * @property {String} rest Rest of the URL that is not part of the protocol.
128 */
129
130/**
131 * Extract protocol information from a URL with/without double slash ("//").
132 *
133 * @param {String} address URL we want to extract from.
134 * @param {Object} location
135 * @return {ProtocolExtract} Extracted information.
136 * @private
137 */
138function extractProtocol(address, location) {
139 address = trimLeft(address);
140 location = location || {};
141
142 var match = protocolre.exec(address);
143 var protocol = match[1] ? match[1].toLowerCase() : '';
144 var forwardSlashes = !!match[2];
145 var otherSlashes = !!match[3];
146 var slashesCount = 0;
147 var rest;
148
149 if (forwardSlashes) {
150 if (otherSlashes) {
151 rest = match[2] + match[3] + match[4];
152 slashesCount = match[2].length + match[3].length;
153 } else {
154 rest = match[2] + match[4];
155 slashesCount = match[2].length;
156 }
157 } else {
158 if (otherSlashes) {
159 rest = match[3] + match[4];
160 slashesCount = match[3].length;
161 } else {
162 rest = match[4]
163 }
164 }
165
166 if (protocol === 'file:') {
167 if (slashesCount >= 2) {
168 rest = rest.slice(2);
169 }
170 } else if (isSpecial(protocol)) {
171 rest = match[4];
172 } else if (protocol) {
173 if (forwardSlashes) {
174 rest = rest.slice(2);
175 }
176 } else if (slashesCount >= 2 && isSpecial(location.protocol)) {
177 rest = match[4];
178 }
179
180 return {
181 protocol: protocol,
182 slashes: forwardSlashes || isSpecial(protocol),
183 slashesCount: slashesCount,
184 rest: rest
185 };
186}
187
188/**
189 * Resolve a relative URL pathname against a base URL pathname.
190 *
191 * @param {String} relative Pathname of the relative URL.
192 * @param {String} base Pathname of the base URL.
193 * @return {String} Resolved pathname.
194 * @private
195 */
196function resolve(relative, base) {
197 if (relative === '') return base;
198
199 var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/'))
200 , i = path.length
201 , last = path[i - 1]
202 , unshift = false
203 , up = 0;
204
205 while (i--) {
206 if (path[i] === '.') {
207 path.splice(i, 1);
208 } else if (path[i] === '..') {
209 path.splice(i, 1);
210 up++;
211 } else if (up) {
212 if (i === 0) unshift = true;
213 path.splice(i, 1);
214 up--;
215 }
216 }
217
218 if (unshift) path.unshift('');
219 if (last === '.' || last === '..') path.push('');
220
221 return path.join('/');
222}
223
224/**
225 * The actual URL instance. Instead of returning an object we've opted-in to
226 * create an actual constructor as it's much more memory efficient and
227 * faster and it pleases my OCD.
228 *
229 * It is worth noting that we should not use `URL` as class name to prevent
230 * clashes with the global URL instance that got introduced in browsers.
231 *
232 * @constructor
233 * @param {String} address URL we want to parse.
234 * @param {Object|String} [location] Location defaults for relative paths.
235 * @param {Boolean|Function} [parser] Parser for the query string.
236 * @private
237 */
238function Url(address, location, parser) {
239 address = trimLeft(address);
240
241 if (!(this instanceof Url)) {
242 return new Url(address, location, parser);
243 }
244
245 var relative, extracted, parse, instruction, index, key
246 , instructions = rules.slice()
247 , type = typeof location
248 , url = this
249 , i = 0;
250
251 //
252 // The following if statements allows this module two have compatibility with
253 // 2 different API:
254 //
255 // 1. Node.js's `url.parse` api which accepts a URL, boolean as arguments
256 // where the boolean indicates that the query string should also be parsed.
257 //
258 // 2. The `URL` interface of the browser which accepts a URL, object as
259 // arguments. The supplied object will be used as default values / fall-back
260 // for relative paths.
261 //
262 if ('object' !== type && 'string' !== type) {
263 parser = location;
264 location = null;
265 }
266
267 if (parser && 'function' !== typeof parser) parser = qs.parse;
268
269 location = lolcation(location);
270
271 //
272 // Extract protocol information before running the instructions.
273 //
274 extracted = extractProtocol(address || '', location);
275 relative = !extracted.protocol && !extracted.slashes;
276 url.slashes = extracted.slashes || relative && location.slashes;
277 url.protocol = extracted.protocol || location.protocol || '';
278 address = extracted.rest;
279
280 //
281 // When the authority component is absent the URL starts with a path
282 // component.
283 //
284 if (
285 extracted.protocol === 'file:' && (
286 extracted.slashesCount !== 2 || windowsDriveLetter.test(address)) ||
287 (!extracted.slashes &&
288 (extracted.protocol ||
289 extracted.slashesCount < 2 ||
290 !isSpecial(url.protocol)))
291 ) {
292 instructions[3] = [/(.*)/, 'pathname'];
293 }
294
295 for (; i < instructions.length; i++) {
296 instruction = instructions[i];
297
298 if (typeof instruction === 'function') {
299 address = instruction(address, url);
300 continue;
301 }
302
303 parse = instruction[0];
304 key = instruction[1];
305
306 if (parse !== parse) {
307 url[key] = address;
308 } else if ('string' === typeof parse) {
309 if (~(index = address.indexOf(parse))) {
310 if ('number' === typeof instruction[2]) {
311 url[key] = address.slice(0, index);
312 address = address.slice(index + instruction[2]);
313 } else {
314 url[key] = address.slice(index);
315 address = address.slice(0, index);
316 }
317 }
318 } else if ((index = parse.exec(address))) {
319 url[key] = index[1];
320 address = address.slice(0, index.index);
321 }
322
323 url[key] = url[key] || (
324 relative && instruction[3] ? location[key] || '' : ''
325 );
326
327 //
328 // Hostname, host and protocol should be lowercased so they can be used to
329 // create a proper `origin`.
330 //
331 if (instruction[4]) url[key] = url[key].toLowerCase();
332 }
333
334 //
335 // Also parse the supplied query string in to an object. If we're supplied
336 // with a custom parser as function use that instead of the default build-in
337 // parser.
338 //
339 if (parser) url.query = parser(url.query);
340
341 //
342 // If the URL is relative, resolve the pathname against the base URL.
343 //
344 if (
345 relative
346 && location.slashes
347 && url.pathname.charAt(0) !== '/'
348 && (url.pathname !== '' || location.pathname !== '')
349 ) {
350 url.pathname = resolve(url.pathname, location.pathname);
351 }
352
353 //
354 // Default to a / for pathname if none exists. This normalizes the URL
355 // to always have a /
356 //
357 if (url.pathname.charAt(0) !== '/' && isSpecial(url.protocol)) {
358 url.pathname = '/' + url.pathname;
359 }
360
361 //
362 // We should not add port numbers if they are already the default port number
363 // for a given protocol. As the host also contains the port number we're going
364 // override it with the hostname which contains no port number.
365 //
366 if (!required(url.port, url.protocol)) {
367 url.host = url.hostname;
368 url.port = '';
369 }
370
371 //
372 // Parse down the `auth` for the username and password.
373 //
374 url.username = url.password = '';
375 if (url.auth) {
376 instruction = url.auth.split(':');
377 url.username = instruction[0] || '';
378 url.password = instruction[1] || '';
379 }
380
381 url.origin = url.protocol !== 'file:' && isSpecial(url.protocol) && url.host
382 ? url.protocol +'//'+ url.host
383 : 'null';
384
385 //
386 // The href is just the compiled result.
387 //
388 url.href = url.toString();
389}
390
391/**
392 * This is convenience method for changing properties in the URL instance to
393 * insure that they all propagate correctly.
394 *
395 * @param {String} part Property we need to adjust.
396 * @param {Mixed} value The newly assigned value.
397 * @param {Boolean|Function} fn When setting the query, it will be the function
398 * used to parse the query.
399 * When setting the protocol, double slash will be
400 * removed from the final url if it is true.
401 * @returns {URL} URL instance for chaining.
402 * @public
403 */
404function set(part, value, fn) {
405 var url = this;
406
407 switch (part) {
408 case 'query':
409 if ('string' === typeof value && value.length) {
410 value = (fn || qs.parse)(value);
411 }
412
413 url[part] = value;
414 break;
415
416 case 'port':
417 url[part] = value;
418
419 if (!required(value, url.protocol)) {
420 url.host = url.hostname;
421 url[part] = '';
422 } else if (value) {
423 url.host = url.hostname +':'+ value;
424 }
425
426 break;
427
428 case 'hostname':
429 url[part] = value;
430
431 if (url.port) value += ':'+ url.port;
432 url.host = value;
433 break;
434
435 case 'host':
436 url[part] = value;
437
438 if (/:\d+$/.test(value)) {
439 value = value.split(':');
440 url.port = value.pop();
441 url.hostname = value.join(':');
442 } else {
443 url.hostname = value;
444 url.port = '';
445 }
446
447 break;
448
449 case 'protocol':
450 url.protocol = value.toLowerCase();
451 url.slashes = !fn;
452 break;
453
454 case 'pathname':
455 case 'hash':
456 if (value) {
457 var char = part === 'pathname' ? '/' : '#';
458 url[part] = value.charAt(0) !== char ? char + value : value;
459 } else {
460 url[part] = value;
461 }
462 break;
463
464 default:
465 url[part] = value;
466 }
467
468 for (var i = 0; i < rules.length; i++) {
469 var ins = rules[i];
470
471 if (ins[4]) url[ins[1]] = url[ins[1]].toLowerCase();
472 }
473
474 url.origin = url.protocol !== 'file:' && isSpecial(url.protocol) && url.host
475 ? url.protocol +'//'+ url.host
476 : 'null';
477
478 url.href = url.toString();
479
480 return url;
481}
482
483/**
484 * Transform the properties back in to a valid and full URL string.
485 *
486 * @param {Function} stringify Optional query stringify function.
487 * @returns {String} Compiled version of the URL.
488 * @public
489 */
490function toString(stringify) {
491 if (!stringify || 'function' !== typeof stringify) stringify = qs.stringify;
492
493 var query
494 , url = this
495 , protocol = url.protocol;
496
497 if (protocol && protocol.charAt(protocol.length - 1) !== ':') protocol += ':';
498
499 var result = protocol + (url.slashes || isSpecial(url.protocol) ? '//' : '');
500
501 if (url.username) {
502 result += url.username;
503 if (url.password) result += ':'+ url.password;
504 result += '@';
505 }
506
507 result += url.host + url.pathname;
508
509 query = 'object' === typeof url.query ? stringify(url.query) : url.query;
510 if (query) result += '?' !== query.charAt(0) ? '?'+ query : query;
511
512 if (url.hash) result += url.hash;
513
514 return result;
515}
516
517Url.prototype = { set: set, toString: toString };
518
519//
520// Expose the URL parser and some additional properties that might be useful for
521// others or testing.
522//
523Url.extractProtocol = extractProtocol;
524Url.location = lolcation;
525Url.trimLeft = trimLeft;
526Url.qs = qs;
527
528module.exports = Url;
529
530}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
531},{"querystringify":2,"requires-port":3}],2:[function(require,module,exports){
532'use strict';
533
534var has = Object.prototype.hasOwnProperty
535 , undef;
536
537/**
538 * Decode a URI encoded string.
539 *
540 * @param {String} input The URI encoded string.
541 * @returns {String|Null} The decoded string.
542 * @api private
543 */
544function decode(input) {
545 try {
546 return decodeURIComponent(input.replace(/\+/g, ' '));
547 } catch (e) {
548 return null;
549 }
550}
551
552/**
553 * Attempts to encode a given input.
554 *
555 * @param {String} input The string that needs to be encoded.
556 * @returns {String|Null} The encoded string.
557 * @api private
558 */
559function encode(input) {
560 try {
561 return encodeURIComponent(input);
562 } catch (e) {
563 return null;
564 }
565}
566
567/**
568 * Simple query string parser.
569 *
570 * @param {String} query The query string that needs to be parsed.
571 * @returns {Object}
572 * @api public
573 */
574function querystring(query) {
575 var parser = /([^=?#&]+)=?([^&]*)/g
576 , result = {}
577 , part;
578
579 while (part = parser.exec(query)) {
580 var key = decode(part[1])
581 , value = decode(part[2]);
582
583 //
584 // Prevent overriding of existing properties. This ensures that build-in
585 // methods like `toString` or __proto__ are not overriden by malicious
586 // querystrings.
587 //
588 // In the case if failed decoding, we want to omit the key/value pairs
589 // from the result.
590 //
591 if (key === null || value === null || key in result) continue;
592 result[key] = value;
593 }
594
595 return result;
596}
597
598/**
599 * Transform a query string to an object.
600 *
601 * @param {Object} obj Object that should be transformed.
602 * @param {String} prefix Optional prefix.
603 * @returns {String}
604 * @api public
605 */
606function querystringify(obj, prefix) {
607 prefix = prefix || '';
608
609 var pairs = []
610 , value
611 , key;
612
613 //
614 // Optionally prefix with a '?' if needed
615 //
616 if ('string' !== typeof prefix) prefix = '?';
617
618 for (key in obj) {
619 if (has.call(obj, key)) {
620 value = obj[key];
621
622 //
623 // Edge cases where we actually want to encode the value to an empty
624 // string instead of the stringified value.
625 //
626 if (!value && (value === null || value === undef || isNaN(value))) {
627 value = '';
628 }
629
630 key = encode(key);
631 value = encode(value);
632
633 //
634 // If we failed to encode the strings, we should bail out as we don't
635 // want to add invalid strings to the query.
636 //
637 if (key === null || value === null) continue;
638 pairs.push(key +'='+ value);
639 }
640 }
641
642 return pairs.length ? prefix + pairs.join('&') : '';
643}
644
645//
646// Expose the module.
647//
648exports.stringify = querystringify;
649exports.parse = querystring;
650
651},{}],3:[function(require,module,exports){
652'use strict';
653
654/**
655 * Check if we're required to add a port number.
656 *
657 * @see https://url.spec.whatwg.org/#default-port
658 * @param {Number|String} port Port number we need to check
659 * @param {String} protocol Protocol we need to check against.
660 * @returns {Boolean} Is it a default port for the given protocol
661 * @api private
662 */
663module.exports = function required(port, protocol) {
664 protocol = protocol.split(':')[0];
665 port = +port;
666
667 if (!port) return false;
668
669 switch (protocol) {
670 case 'http':
671 case 'ws':
672 return port !== 80;
673
674 case 'https':
675 case 'wss':
676 return port !== 443;
677
678 case 'ftp':
679 return port !== 21;
680
681 case 'gopher':
682 return port !== 70;
683
684 case 'file':
685 return false;
686 }
687
688 return port !== 0;
689};
690
691},{}]},{},[1])(1)
692});
Note: See TracBrowser for help on using the repository browser.