@leofcoin/chain 1.5.45 → 1.5.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/exports/browser/{index-c3bd3090.js → _polyfill-node.child_process-JsWeMPst.js} +1999 -5
- package/exports/browser/_polyfill-node.url-0PWARF9f.js +1196 -0
- package/exports/browser/browser-dc41c03f-jgWsLNN0.js +188 -0
- package/exports/browser/chain.js +3 -3
- package/exports/browser/client-f193279c-PJq43OyI.js +601 -0
- package/exports/browser/{index-687f692b-bcdff490.js → index-81687e93-b2xmOHmO.js} +2 -2
- package/exports/browser/index-fd97ecae-IP8WPUJ5.js +7876 -0
- package/exports/browser/{messages-1c117282-a35a5fbc.js → messages-cccb78db-oHb8zKmC.js} +2 -2
- package/exports/browser/{node-browser-2c421007.js → node-browser-DDilILXh.js} +11 -251
- package/exports/browser/node-browser.js +2 -2
- package/exports/browser/workers/block-worker.js +1 -1
- package/exports/browser/workers/machine-worker.js +1 -1
- package/exports/workers/block-worker.js +1 -1
- package/exports/workers/machine-worker.js +1 -1
- package/package.json +3 -2
- /package/exports/browser/{browser-2c73e2ef-2c73e2ef.js → browser-2c73e2ef-AyxSBUXj.js} +0 -0
- /package/exports/browser/{password-4357020e.js → password-JCRBtU5A.js} +0 -0
- /package/exports/browser/{qr-scanner-worker.min-c002e984-c002e984.js → qr-scanner-worker.min-c002e984-RaSiJc_R.js} +0 -0
- /package/exports/browser/workers/{worker-dab33545.js → worker-JZNHw6gH.js} +0 -0
- /package/exports/workers/{worker-dab33545.js → worker-JZNHw6gH.js} +0 -0
|
@@ -0,0 +1,1196 @@
|
|
|
1
|
+
import { g as global } from './_polyfill-node.child_process-JsWeMPst.js';
|
|
2
|
+
|
|
3
|
+
/*! https://mths.be/punycode v1.4.1 by @mathias */
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/** Highest positive signed 32-bit float value */
|
|
7
|
+
var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
|
|
8
|
+
|
|
9
|
+
/** Bootstring parameters */
|
|
10
|
+
var base = 36;
|
|
11
|
+
var tMin = 1;
|
|
12
|
+
var tMax = 26;
|
|
13
|
+
var skew = 38;
|
|
14
|
+
var damp = 700;
|
|
15
|
+
var initialBias = 72;
|
|
16
|
+
var initialN = 128; // 0x80
|
|
17
|
+
var delimiter = '-'; // '\x2D'
|
|
18
|
+
var regexNonASCII = /[^\x20-\x7E]/; // unprintable ASCII chars + non-ASCII chars
|
|
19
|
+
var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
|
|
20
|
+
|
|
21
|
+
/** Error messages */
|
|
22
|
+
var errors = {
|
|
23
|
+
'overflow': 'Overflow: input needs wider integers to process',
|
|
24
|
+
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
|
|
25
|
+
'invalid-input': 'Invalid input'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Convenience shortcuts */
|
|
29
|
+
var baseMinusTMin = base - tMin;
|
|
30
|
+
var floor = Math.floor;
|
|
31
|
+
var stringFromCharCode = String.fromCharCode;
|
|
32
|
+
|
|
33
|
+
/*--------------------------------------------------------------------------*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A generic error utility function.
|
|
37
|
+
* @private
|
|
38
|
+
* @param {String} type The error type.
|
|
39
|
+
* @returns {Error} Throws a `RangeError` with the applicable error message.
|
|
40
|
+
*/
|
|
41
|
+
function error(type) {
|
|
42
|
+
throw new RangeError(errors[type]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A generic `Array#map` utility function.
|
|
47
|
+
* @private
|
|
48
|
+
* @param {Array} array The array to iterate over.
|
|
49
|
+
* @param {Function} callback The function that gets called for every array
|
|
50
|
+
* item.
|
|
51
|
+
* @returns {Array} A new array of values returned by the callback function.
|
|
52
|
+
*/
|
|
53
|
+
function map$1(array, fn) {
|
|
54
|
+
var length = array.length;
|
|
55
|
+
var result = [];
|
|
56
|
+
while (length--) {
|
|
57
|
+
result[length] = fn(array[length]);
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A simple `Array#map`-like wrapper to work with domain name strings or email
|
|
64
|
+
* addresses.
|
|
65
|
+
* @private
|
|
66
|
+
* @param {String} domain The domain name or email address.
|
|
67
|
+
* @param {Function} callback The function that gets called for every
|
|
68
|
+
* character.
|
|
69
|
+
* @returns {Array} A new string of characters returned by the callback
|
|
70
|
+
* function.
|
|
71
|
+
*/
|
|
72
|
+
function mapDomain(string, fn) {
|
|
73
|
+
var parts = string.split('@');
|
|
74
|
+
var result = '';
|
|
75
|
+
if (parts.length > 1) {
|
|
76
|
+
// In email addresses, only the domain name should be punycoded. Leave
|
|
77
|
+
// the local part (i.e. everything up to `@`) intact.
|
|
78
|
+
result = parts[0] + '@';
|
|
79
|
+
string = parts[1];
|
|
80
|
+
}
|
|
81
|
+
// Avoid `split(regex)` for IE8 compatibility. See #17.
|
|
82
|
+
string = string.replace(regexSeparators, '\x2E');
|
|
83
|
+
var labels = string.split('.');
|
|
84
|
+
var encoded = map$1(labels, fn).join('.');
|
|
85
|
+
return result + encoded;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Creates an array containing the numeric code points of each Unicode
|
|
90
|
+
* character in the string. While JavaScript uses UCS-2 internally,
|
|
91
|
+
* this function will convert a pair of surrogate halves (each of which
|
|
92
|
+
* UCS-2 exposes as separate characters) into a single code point,
|
|
93
|
+
* matching UTF-16.
|
|
94
|
+
* @see `punycode.ucs2.encode`
|
|
95
|
+
* @see <https://mathiasbynens.be/notes/javascript-encoding>
|
|
96
|
+
* @memberOf punycode.ucs2
|
|
97
|
+
* @name decode
|
|
98
|
+
* @param {String} string The Unicode input string (UCS-2).
|
|
99
|
+
* @returns {Array} The new array of code points.
|
|
100
|
+
*/
|
|
101
|
+
function ucs2decode(string) {
|
|
102
|
+
var output = [],
|
|
103
|
+
counter = 0,
|
|
104
|
+
length = string.length,
|
|
105
|
+
value,
|
|
106
|
+
extra;
|
|
107
|
+
while (counter < length) {
|
|
108
|
+
value = string.charCodeAt(counter++);
|
|
109
|
+
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
|
|
110
|
+
// high surrogate, and there is a next character
|
|
111
|
+
extra = string.charCodeAt(counter++);
|
|
112
|
+
if ((extra & 0xFC00) == 0xDC00) { // low surrogate
|
|
113
|
+
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
|
|
114
|
+
} else {
|
|
115
|
+
// unmatched surrogate; only append this code unit, in case the next
|
|
116
|
+
// code unit is the high surrogate of a surrogate pair
|
|
117
|
+
output.push(value);
|
|
118
|
+
counter--;
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
output.push(value);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return output;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Converts a digit/integer into a basic code point.
|
|
129
|
+
* @see `basicToDigit()`
|
|
130
|
+
* @private
|
|
131
|
+
* @param {Number} digit The numeric value of a basic code point.
|
|
132
|
+
* @returns {Number} The basic code point whose value (when used for
|
|
133
|
+
* representing integers) is `digit`, which needs to be in the range
|
|
134
|
+
* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
|
|
135
|
+
* used; else, the lowercase form is used. The behavior is undefined
|
|
136
|
+
* if `flag` is non-zero and `digit` has no uppercase form.
|
|
137
|
+
*/
|
|
138
|
+
function digitToBasic(digit, flag) {
|
|
139
|
+
// 0..25 map to ASCII a..z or A..Z
|
|
140
|
+
// 26..35 map to ASCII 0..9
|
|
141
|
+
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Bias adaptation function as per section 3.4 of RFC 3492.
|
|
146
|
+
* https://tools.ietf.org/html/rfc3492#section-3.4
|
|
147
|
+
* @private
|
|
148
|
+
*/
|
|
149
|
+
function adapt(delta, numPoints, firstTime) {
|
|
150
|
+
var k = 0;
|
|
151
|
+
delta = firstTime ? floor(delta / damp) : delta >> 1;
|
|
152
|
+
delta += floor(delta / numPoints);
|
|
153
|
+
for ( /* no initialization */ ; delta > baseMinusTMin * tMax >> 1; k += base) {
|
|
154
|
+
delta = floor(delta / baseMinusTMin);
|
|
155
|
+
}
|
|
156
|
+
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Converts a string of Unicode symbols (e.g. a domain name label) to a
|
|
161
|
+
* Punycode string of ASCII-only symbols.
|
|
162
|
+
* @memberOf punycode
|
|
163
|
+
* @param {String} input The string of Unicode symbols.
|
|
164
|
+
* @returns {String} The resulting Punycode string of ASCII-only symbols.
|
|
165
|
+
*/
|
|
166
|
+
function encode(input) {
|
|
167
|
+
var n,
|
|
168
|
+
delta,
|
|
169
|
+
handledCPCount,
|
|
170
|
+
basicLength,
|
|
171
|
+
bias,
|
|
172
|
+
j,
|
|
173
|
+
m,
|
|
174
|
+
q,
|
|
175
|
+
k,
|
|
176
|
+
t,
|
|
177
|
+
currentValue,
|
|
178
|
+
output = [],
|
|
179
|
+
/** `inputLength` will hold the number of code points in `input`. */
|
|
180
|
+
inputLength,
|
|
181
|
+
/** Cached calculation results */
|
|
182
|
+
handledCPCountPlusOne,
|
|
183
|
+
baseMinusT,
|
|
184
|
+
qMinusT;
|
|
185
|
+
|
|
186
|
+
// Convert the input in UCS-2 to Unicode
|
|
187
|
+
input = ucs2decode(input);
|
|
188
|
+
|
|
189
|
+
// Cache the length
|
|
190
|
+
inputLength = input.length;
|
|
191
|
+
|
|
192
|
+
// Initialize the state
|
|
193
|
+
n = initialN;
|
|
194
|
+
delta = 0;
|
|
195
|
+
bias = initialBias;
|
|
196
|
+
|
|
197
|
+
// Handle the basic code points
|
|
198
|
+
for (j = 0; j < inputLength; ++j) {
|
|
199
|
+
currentValue = input[j];
|
|
200
|
+
if (currentValue < 0x80) {
|
|
201
|
+
output.push(stringFromCharCode(currentValue));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
handledCPCount = basicLength = output.length;
|
|
206
|
+
|
|
207
|
+
// `handledCPCount` is the number of code points that have been handled;
|
|
208
|
+
// `basicLength` is the number of basic code points.
|
|
209
|
+
|
|
210
|
+
// Finish the basic string - if it is not empty - with a delimiter
|
|
211
|
+
if (basicLength) {
|
|
212
|
+
output.push(delimiter);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Main encoding loop:
|
|
216
|
+
while (handledCPCount < inputLength) {
|
|
217
|
+
|
|
218
|
+
// All non-basic code points < n have been handled already. Find the next
|
|
219
|
+
// larger one:
|
|
220
|
+
for (m = maxInt, j = 0; j < inputLength; ++j) {
|
|
221
|
+
currentValue = input[j];
|
|
222
|
+
if (currentValue >= n && currentValue < m) {
|
|
223
|
+
m = currentValue;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
|
|
228
|
+
// but guard against overflow
|
|
229
|
+
handledCPCountPlusOne = handledCPCount + 1;
|
|
230
|
+
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
|
|
231
|
+
error('overflow');
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
delta += (m - n) * handledCPCountPlusOne;
|
|
235
|
+
n = m;
|
|
236
|
+
|
|
237
|
+
for (j = 0; j < inputLength; ++j) {
|
|
238
|
+
currentValue = input[j];
|
|
239
|
+
|
|
240
|
+
if (currentValue < n && ++delta > maxInt) {
|
|
241
|
+
error('overflow');
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (currentValue == n) {
|
|
245
|
+
// Represent delta as a generalized variable-length integer
|
|
246
|
+
for (q = delta, k = base; /* no condition */ ; k += base) {
|
|
247
|
+
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
|
248
|
+
if (q < t) {
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
qMinusT = q - t;
|
|
252
|
+
baseMinusT = base - t;
|
|
253
|
+
output.push(
|
|
254
|
+
stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
|
|
255
|
+
);
|
|
256
|
+
q = floor(qMinusT / baseMinusT);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
output.push(stringFromCharCode(digitToBasic(q, 0)));
|
|
260
|
+
bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
|
|
261
|
+
delta = 0;
|
|
262
|
+
++handledCPCount;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
++delta;
|
|
267
|
+
++n;
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
return output.join('');
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Converts a Unicode string representing a domain name or an email address to
|
|
275
|
+
* Punycode. Only the non-ASCII parts of the domain name will be converted,
|
|
276
|
+
* i.e. it doesn't matter if you call it with a domain that's already in
|
|
277
|
+
* ASCII.
|
|
278
|
+
* @memberOf punycode
|
|
279
|
+
* @param {String} input The domain name or email address to convert, as a
|
|
280
|
+
* Unicode string.
|
|
281
|
+
* @returns {String} The Punycode representation of the given domain name or
|
|
282
|
+
* email address.
|
|
283
|
+
*/
|
|
284
|
+
function toASCII(input) {
|
|
285
|
+
return mapDomain(input, function(string) {
|
|
286
|
+
return regexNonASCII.test(string) ?
|
|
287
|
+
'xn--' + encode(string) :
|
|
288
|
+
string;
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function isNull(arg) {
|
|
293
|
+
return arg === null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function isNullOrUndefined(arg) {
|
|
297
|
+
return arg == null;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function isString(arg) {
|
|
301
|
+
return typeof arg === 'string';
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function isObject(arg) {
|
|
305
|
+
return typeof arg === 'object' && arg !== null;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
309
|
+
//
|
|
310
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
311
|
+
// copy of this software and associated documentation files (the
|
|
312
|
+
// "Software"), to deal in the Software without restriction, including
|
|
313
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
314
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
315
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
316
|
+
// following conditions:
|
|
317
|
+
//
|
|
318
|
+
// The above copyright notice and this permission notice shall be included
|
|
319
|
+
// in all copies or substantial portions of the Software.
|
|
320
|
+
//
|
|
321
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
322
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
323
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
324
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
325
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
326
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
327
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
// If obj.hasOwnProperty has been overridden, then calling
|
|
331
|
+
// obj.hasOwnProperty(prop) will break.
|
|
332
|
+
// See: https://github.com/joyent/node/issues/1707
|
|
333
|
+
function hasOwnProperty(obj, prop) {
|
|
334
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
335
|
+
}
|
|
336
|
+
var isArray = Array.isArray || function (xs) {
|
|
337
|
+
return Object.prototype.toString.call(xs) === '[object Array]';
|
|
338
|
+
};
|
|
339
|
+
function stringifyPrimitive(v) {
|
|
340
|
+
switch (typeof v) {
|
|
341
|
+
case 'string':
|
|
342
|
+
return v;
|
|
343
|
+
|
|
344
|
+
case 'boolean':
|
|
345
|
+
return v ? 'true' : 'false';
|
|
346
|
+
|
|
347
|
+
case 'number':
|
|
348
|
+
return isFinite(v) ? v : '';
|
|
349
|
+
|
|
350
|
+
default:
|
|
351
|
+
return '';
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function stringify (obj, sep, eq, name) {
|
|
356
|
+
sep = sep || '&';
|
|
357
|
+
eq = eq || '=';
|
|
358
|
+
if (obj === null) {
|
|
359
|
+
obj = undefined;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (typeof obj === 'object') {
|
|
363
|
+
return map(objectKeys(obj), function(k) {
|
|
364
|
+
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
|
|
365
|
+
if (isArray(obj[k])) {
|
|
366
|
+
return map(obj[k], function(v) {
|
|
367
|
+
return ks + encodeURIComponent(stringifyPrimitive(v));
|
|
368
|
+
}).join(sep);
|
|
369
|
+
} else {
|
|
370
|
+
return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
|
|
371
|
+
}
|
|
372
|
+
}).join(sep);
|
|
373
|
+
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (!name) return '';
|
|
377
|
+
return encodeURIComponent(stringifyPrimitive(name)) + eq +
|
|
378
|
+
encodeURIComponent(stringifyPrimitive(obj));
|
|
379
|
+
}
|
|
380
|
+
function map (xs, f) {
|
|
381
|
+
if (xs.map) return xs.map(f);
|
|
382
|
+
var res = [];
|
|
383
|
+
for (var i = 0; i < xs.length; i++) {
|
|
384
|
+
res.push(f(xs[i], i));
|
|
385
|
+
}
|
|
386
|
+
return res;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
var objectKeys = Object.keys || function (obj) {
|
|
390
|
+
var res = [];
|
|
391
|
+
for (var key in obj) {
|
|
392
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
|
|
393
|
+
}
|
|
394
|
+
return res;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
function parse$1(qs, sep, eq, options) {
|
|
398
|
+
sep = sep || '&';
|
|
399
|
+
eq = eq || '=';
|
|
400
|
+
var obj = {};
|
|
401
|
+
|
|
402
|
+
if (typeof qs !== 'string' || qs.length === 0) {
|
|
403
|
+
return obj;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
var regexp = /\+/g;
|
|
407
|
+
qs = qs.split(sep);
|
|
408
|
+
|
|
409
|
+
var maxKeys = 1000;
|
|
410
|
+
if (options && typeof options.maxKeys === 'number') {
|
|
411
|
+
maxKeys = options.maxKeys;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
var len = qs.length;
|
|
415
|
+
// maxKeys <= 0 means that we should not limit keys count
|
|
416
|
+
if (maxKeys > 0 && len > maxKeys) {
|
|
417
|
+
len = maxKeys;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
for (var i = 0; i < len; ++i) {
|
|
421
|
+
var x = qs[i].replace(regexp, '%20'),
|
|
422
|
+
idx = x.indexOf(eq),
|
|
423
|
+
kstr, vstr, k, v;
|
|
424
|
+
|
|
425
|
+
if (idx >= 0) {
|
|
426
|
+
kstr = x.substr(0, idx);
|
|
427
|
+
vstr = x.substr(idx + 1);
|
|
428
|
+
} else {
|
|
429
|
+
kstr = x;
|
|
430
|
+
vstr = '';
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
k = decodeURIComponent(kstr);
|
|
434
|
+
v = decodeURIComponent(vstr);
|
|
435
|
+
|
|
436
|
+
if (!hasOwnProperty(obj, k)) {
|
|
437
|
+
obj[k] = v;
|
|
438
|
+
} else if (isArray(obj[k])) {
|
|
439
|
+
obj[k].push(v);
|
|
440
|
+
} else {
|
|
441
|
+
obj[k] = [obj[k], v];
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return obj;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// WHATWG API
|
|
449
|
+
const URL = global.URL;
|
|
450
|
+
const URLSearchParams = global.URLSearchParams;
|
|
451
|
+
var _polyfillNode_url = {
|
|
452
|
+
parse: urlParse,
|
|
453
|
+
resolve: urlResolve,
|
|
454
|
+
resolveObject: urlResolveObject,
|
|
455
|
+
fileURLToPath: urlFileURLToPath,
|
|
456
|
+
format: urlFormat,
|
|
457
|
+
Url: Url,
|
|
458
|
+
|
|
459
|
+
// WHATWG API
|
|
460
|
+
URL,
|
|
461
|
+
URLSearchParams,
|
|
462
|
+
};
|
|
463
|
+
function Url() {
|
|
464
|
+
this.protocol = null;
|
|
465
|
+
this.slashes = null;
|
|
466
|
+
this.auth = null;
|
|
467
|
+
this.host = null;
|
|
468
|
+
this.port = null;
|
|
469
|
+
this.hostname = null;
|
|
470
|
+
this.hash = null;
|
|
471
|
+
this.search = null;
|
|
472
|
+
this.query = null;
|
|
473
|
+
this.pathname = null;
|
|
474
|
+
this.path = null;
|
|
475
|
+
this.href = null;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Reference: RFC 3986, RFC 1808, RFC 2396
|
|
479
|
+
|
|
480
|
+
// define these here so at least they only have to be
|
|
481
|
+
// compiled once on the first module load.
|
|
482
|
+
var protocolPattern = /^([a-z0-9.+-]+:)/i,
|
|
483
|
+
portPattern = /:[0-9]*$/,
|
|
484
|
+
|
|
485
|
+
// Special case for a simple path URL
|
|
486
|
+
simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
|
|
487
|
+
|
|
488
|
+
// RFC 2396: characters reserved for delimiting URLs.
|
|
489
|
+
// We actually just auto-escape these.
|
|
490
|
+
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
|
|
491
|
+
|
|
492
|
+
// RFC 2396: characters not allowed for various reasons.
|
|
493
|
+
unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
|
|
494
|
+
|
|
495
|
+
// Allowed by RFCs, but cause of XSS attacks. Always escape these.
|
|
496
|
+
autoEscape = ['\''].concat(unwise),
|
|
497
|
+
// Characters that are never ever allowed in a hostname.
|
|
498
|
+
// Note that any invalid chars are also handled, but these
|
|
499
|
+
// are the ones that are *expected* to be seen, so we fast-path
|
|
500
|
+
// them.
|
|
501
|
+
nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
|
|
502
|
+
hostEndingChars = ['/', '?', '#'],
|
|
503
|
+
hostnameMaxLen = 255,
|
|
504
|
+
hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
|
|
505
|
+
hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
|
|
506
|
+
// protocols that can allow "unsafe" and "unwise" chars.
|
|
507
|
+
unsafeProtocol = {
|
|
508
|
+
'javascript': true,
|
|
509
|
+
'javascript:': true
|
|
510
|
+
},
|
|
511
|
+
// protocols that never have a hostname.
|
|
512
|
+
hostlessProtocol = {
|
|
513
|
+
'javascript': true,
|
|
514
|
+
'javascript:': true
|
|
515
|
+
},
|
|
516
|
+
// protocols that always contain a // bit.
|
|
517
|
+
slashedProtocol = {
|
|
518
|
+
'http': true,
|
|
519
|
+
'https': true,
|
|
520
|
+
'ftp': true,
|
|
521
|
+
'gopher': true,
|
|
522
|
+
'file': true,
|
|
523
|
+
'http:': true,
|
|
524
|
+
'https:': true,
|
|
525
|
+
'ftp:': true,
|
|
526
|
+
'gopher:': true,
|
|
527
|
+
'file:': true
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
function urlParse(url, parseQueryString, slashesDenoteHost) {
|
|
531
|
+
if (url && isObject(url) && url instanceof Url) return url;
|
|
532
|
+
|
|
533
|
+
var u = new Url;
|
|
534
|
+
u.parse(url, parseQueryString, slashesDenoteHost);
|
|
535
|
+
return u;
|
|
536
|
+
}
|
|
537
|
+
Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|
538
|
+
return parse(this, url, parseQueryString, slashesDenoteHost);
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
function parse(self, url, parseQueryString, slashesDenoteHost) {
|
|
542
|
+
if (!isString(url)) {
|
|
543
|
+
throw new TypeError('Parameter \'url\' must be a string, not ' + typeof url);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// Copy chrome, IE, opera backslash-handling behavior.
|
|
547
|
+
// Back slashes before the query string get converted to forward slashes
|
|
548
|
+
// See: https://code.google.com/p/chromium/issues/detail?id=25916
|
|
549
|
+
var queryIndex = url.indexOf('?'),
|
|
550
|
+
splitter =
|
|
551
|
+
(queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
|
|
552
|
+
uSplit = url.split(splitter),
|
|
553
|
+
slashRegex = /\\/g;
|
|
554
|
+
uSplit[0] = uSplit[0].replace(slashRegex, '/');
|
|
555
|
+
url = uSplit.join(splitter);
|
|
556
|
+
|
|
557
|
+
var rest = url;
|
|
558
|
+
|
|
559
|
+
// trim before proceeding.
|
|
560
|
+
// This is to support parse stuff like " http://foo.com \n"
|
|
561
|
+
rest = rest.trim();
|
|
562
|
+
|
|
563
|
+
if (!slashesDenoteHost && url.split('#').length === 1) {
|
|
564
|
+
// Try fast path regexp
|
|
565
|
+
var simplePath = simplePathPattern.exec(rest);
|
|
566
|
+
if (simplePath) {
|
|
567
|
+
self.path = rest;
|
|
568
|
+
self.href = rest;
|
|
569
|
+
self.pathname = simplePath[1];
|
|
570
|
+
if (simplePath[2]) {
|
|
571
|
+
self.search = simplePath[2];
|
|
572
|
+
if (parseQueryString) {
|
|
573
|
+
self.query = parse$1(self.search.substr(1));
|
|
574
|
+
} else {
|
|
575
|
+
self.query = self.search.substr(1);
|
|
576
|
+
}
|
|
577
|
+
} else if (parseQueryString) {
|
|
578
|
+
self.search = '';
|
|
579
|
+
self.query = {};
|
|
580
|
+
}
|
|
581
|
+
return self;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
var proto = protocolPattern.exec(rest);
|
|
586
|
+
if (proto) {
|
|
587
|
+
proto = proto[0];
|
|
588
|
+
var lowerProto = proto.toLowerCase();
|
|
589
|
+
self.protocol = lowerProto;
|
|
590
|
+
rest = rest.substr(proto.length);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// figure out if it's got a host
|
|
594
|
+
// user@server is *always* interpreted as a hostname, and url
|
|
595
|
+
// resolution will treat //foo/bar as host=foo,path=bar because that's
|
|
596
|
+
// how the browser resolves relative URLs.
|
|
597
|
+
if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
|
|
598
|
+
var slashes = rest.substr(0, 2) === '//';
|
|
599
|
+
if (slashes && !(proto && hostlessProtocol[proto])) {
|
|
600
|
+
rest = rest.substr(2);
|
|
601
|
+
self.slashes = true;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
var i, hec, l, p;
|
|
605
|
+
if (!hostlessProtocol[proto] &&
|
|
606
|
+
(slashes || (proto && !slashedProtocol[proto]))) {
|
|
607
|
+
|
|
608
|
+
// there's a hostname.
|
|
609
|
+
// the first instance of /, ?, ;, or # ends the host.
|
|
610
|
+
//
|
|
611
|
+
// If there is an @ in the hostname, then non-host chars *are* allowed
|
|
612
|
+
// to the left of the last @ sign, unless some host-ending character
|
|
613
|
+
// comes *before* the @-sign.
|
|
614
|
+
// URLs are obnoxious.
|
|
615
|
+
//
|
|
616
|
+
// ex:
|
|
617
|
+
// http://a@b@c/ => user:a@b host:c
|
|
618
|
+
// http://a@b?@c => user:a host:c path:/?@c
|
|
619
|
+
|
|
620
|
+
// v0.12 TODO(isaacs): This is not quite how Chrome does things.
|
|
621
|
+
// Review our test case against browsers more comprehensively.
|
|
622
|
+
|
|
623
|
+
// find the first instance of any hostEndingChars
|
|
624
|
+
var hostEnd = -1;
|
|
625
|
+
for (i = 0; i < hostEndingChars.length; i++) {
|
|
626
|
+
hec = rest.indexOf(hostEndingChars[i]);
|
|
627
|
+
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
|
|
628
|
+
hostEnd = hec;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// at this point, either we have an explicit point where the
|
|
632
|
+
// auth portion cannot go past, or the last @ char is the decider.
|
|
633
|
+
var auth, atSign;
|
|
634
|
+
if (hostEnd === -1) {
|
|
635
|
+
// atSign can be anywhere.
|
|
636
|
+
atSign = rest.lastIndexOf('@');
|
|
637
|
+
} else {
|
|
638
|
+
// atSign must be in auth portion.
|
|
639
|
+
// http://a@b/c@d => host:b auth:a path:/c@d
|
|
640
|
+
atSign = rest.lastIndexOf('@', hostEnd);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// Now we have a portion which is definitely the auth.
|
|
644
|
+
// Pull that off.
|
|
645
|
+
if (atSign !== -1) {
|
|
646
|
+
auth = rest.slice(0, atSign);
|
|
647
|
+
rest = rest.slice(atSign + 1);
|
|
648
|
+
self.auth = decodeURIComponent(auth);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// the host is the remaining to the left of the first non-host char
|
|
652
|
+
hostEnd = -1;
|
|
653
|
+
for (i = 0; i < nonHostChars.length; i++) {
|
|
654
|
+
hec = rest.indexOf(nonHostChars[i]);
|
|
655
|
+
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
|
|
656
|
+
hostEnd = hec;
|
|
657
|
+
}
|
|
658
|
+
// if we still have not hit it, then the entire thing is a host.
|
|
659
|
+
if (hostEnd === -1)
|
|
660
|
+
hostEnd = rest.length;
|
|
661
|
+
|
|
662
|
+
self.host = rest.slice(0, hostEnd);
|
|
663
|
+
rest = rest.slice(hostEnd);
|
|
664
|
+
|
|
665
|
+
// pull out port.
|
|
666
|
+
parseHost(self);
|
|
667
|
+
|
|
668
|
+
// we've indicated that there is a hostname,
|
|
669
|
+
// so even if it's empty, it has to be present.
|
|
670
|
+
self.hostname = self.hostname || '';
|
|
671
|
+
|
|
672
|
+
// if hostname begins with [ and ends with ]
|
|
673
|
+
// assume that it's an IPv6 address.
|
|
674
|
+
var ipv6Hostname = self.hostname[0] === '[' &&
|
|
675
|
+
self.hostname[self.hostname.length - 1] === ']';
|
|
676
|
+
|
|
677
|
+
// validate a little.
|
|
678
|
+
if (!ipv6Hostname) {
|
|
679
|
+
var hostparts = self.hostname.split(/\./);
|
|
680
|
+
for (i = 0, l = hostparts.length; i < l; i++) {
|
|
681
|
+
var part = hostparts[i];
|
|
682
|
+
if (!part) continue;
|
|
683
|
+
if (!part.match(hostnamePartPattern)) {
|
|
684
|
+
var newpart = '';
|
|
685
|
+
for (var j = 0, k = part.length; j < k; j++) {
|
|
686
|
+
if (part.charCodeAt(j) > 127) {
|
|
687
|
+
// we replace non-ASCII char with a temporary placeholder
|
|
688
|
+
// we need this to make sure size of hostname is not
|
|
689
|
+
// broken by replacing non-ASCII by nothing
|
|
690
|
+
newpart += 'x';
|
|
691
|
+
} else {
|
|
692
|
+
newpart += part[j];
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
// we test again with ASCII char only
|
|
696
|
+
if (!newpart.match(hostnamePartPattern)) {
|
|
697
|
+
var validParts = hostparts.slice(0, i);
|
|
698
|
+
var notHost = hostparts.slice(i + 1);
|
|
699
|
+
var bit = part.match(hostnamePartStart);
|
|
700
|
+
if (bit) {
|
|
701
|
+
validParts.push(bit[1]);
|
|
702
|
+
notHost.unshift(bit[2]);
|
|
703
|
+
}
|
|
704
|
+
if (notHost.length) {
|
|
705
|
+
rest = '/' + notHost.join('.') + rest;
|
|
706
|
+
}
|
|
707
|
+
self.hostname = validParts.join('.');
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
if (self.hostname.length > hostnameMaxLen) {
|
|
715
|
+
self.hostname = '';
|
|
716
|
+
} else {
|
|
717
|
+
// hostnames are always lower case.
|
|
718
|
+
self.hostname = self.hostname.toLowerCase();
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
if (!ipv6Hostname) {
|
|
722
|
+
// IDNA Support: Returns a punycoded representation of "domain".
|
|
723
|
+
// It only converts parts of the domain name that
|
|
724
|
+
// have non-ASCII characters, i.e. it doesn't matter if
|
|
725
|
+
// you call it with a domain that already is ASCII-only.
|
|
726
|
+
self.hostname = toASCII(self.hostname);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
p = self.port ? ':' + self.port : '';
|
|
730
|
+
var h = self.hostname || '';
|
|
731
|
+
self.host = h + p;
|
|
732
|
+
self.href += self.host;
|
|
733
|
+
|
|
734
|
+
// strip [ and ] from the hostname
|
|
735
|
+
// the host field still retains them, though
|
|
736
|
+
if (ipv6Hostname) {
|
|
737
|
+
self.hostname = self.hostname.substr(1, self.hostname.length - 2);
|
|
738
|
+
if (rest[0] !== '/') {
|
|
739
|
+
rest = '/' + rest;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// now rest is set to the post-host stuff.
|
|
745
|
+
// chop off any delim chars.
|
|
746
|
+
if (!unsafeProtocol[lowerProto]) {
|
|
747
|
+
|
|
748
|
+
// First, make 100% sure that any "autoEscape" chars get
|
|
749
|
+
// escaped, even if encodeURIComponent doesn't think they
|
|
750
|
+
// need to be.
|
|
751
|
+
for (i = 0, l = autoEscape.length; i < l; i++) {
|
|
752
|
+
var ae = autoEscape[i];
|
|
753
|
+
if (rest.indexOf(ae) === -1)
|
|
754
|
+
continue;
|
|
755
|
+
var esc = encodeURIComponent(ae);
|
|
756
|
+
if (esc === ae) {
|
|
757
|
+
esc = escape(ae);
|
|
758
|
+
}
|
|
759
|
+
rest = rest.split(ae).join(esc);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
// chop off from the tail first.
|
|
765
|
+
var hash = rest.indexOf('#');
|
|
766
|
+
if (hash !== -1) {
|
|
767
|
+
// got a fragment string.
|
|
768
|
+
self.hash = rest.substr(hash);
|
|
769
|
+
rest = rest.slice(0, hash);
|
|
770
|
+
}
|
|
771
|
+
var qm = rest.indexOf('?');
|
|
772
|
+
if (qm !== -1) {
|
|
773
|
+
self.search = rest.substr(qm);
|
|
774
|
+
self.query = rest.substr(qm + 1);
|
|
775
|
+
if (parseQueryString) {
|
|
776
|
+
self.query = parse$1(self.query);
|
|
777
|
+
}
|
|
778
|
+
rest = rest.slice(0, qm);
|
|
779
|
+
} else if (parseQueryString) {
|
|
780
|
+
// no query string, but parseQueryString still requested
|
|
781
|
+
self.search = '';
|
|
782
|
+
self.query = {};
|
|
783
|
+
}
|
|
784
|
+
if (rest) self.pathname = rest;
|
|
785
|
+
if (slashedProtocol[lowerProto] &&
|
|
786
|
+
self.hostname && !self.pathname) {
|
|
787
|
+
self.pathname = '/';
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
//to support http.request
|
|
791
|
+
if (self.pathname || self.search) {
|
|
792
|
+
p = self.pathname || '';
|
|
793
|
+
var s = self.search || '';
|
|
794
|
+
self.path = p + s;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// finally, reconstruct the href based on what has been validated.
|
|
798
|
+
self.href = format(self);
|
|
799
|
+
return self;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
function urlFileURLToPath(path) {
|
|
803
|
+
if (typeof path === 'string')
|
|
804
|
+
path = new Url().parse(path);
|
|
805
|
+
else if (!(path instanceof Url))
|
|
806
|
+
throw new TypeError('The "path" argument must be of type string or an instance of URL. Received type ' + (typeof path) + String(path));
|
|
807
|
+
if (path.protocol !== 'file:')
|
|
808
|
+
throw new TypeError('The URL must be of scheme file');
|
|
809
|
+
return getPathFromURLPosix(path);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
function getPathFromURLPosix(url) {
|
|
813
|
+
const pathname = url.pathname;
|
|
814
|
+
for (let n = 0; n < pathname.length; n++) {
|
|
815
|
+
if (pathname[n] === '%') {
|
|
816
|
+
const third = pathname.codePointAt(n + 2) | 0x20;
|
|
817
|
+
if (pathname[n + 1] === '2' && third === 102) {
|
|
818
|
+
throw new TypeError(
|
|
819
|
+
'must not include encoded / characters'
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
return decodeURIComponent(pathname);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// format a parsed object into a url string
|
|
828
|
+
function urlFormat(obj) {
|
|
829
|
+
// ensure it's an object, and not a string url.
|
|
830
|
+
// If it's an obj, this is a no-op.
|
|
831
|
+
// this way, you can call url_format() on strings
|
|
832
|
+
// to clean up potentially wonky urls.
|
|
833
|
+
if (isString(obj)) obj = parse({}, obj);
|
|
834
|
+
return format(obj);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
function format(self) {
|
|
838
|
+
var auth = self.auth || '';
|
|
839
|
+
if (auth) {
|
|
840
|
+
auth = encodeURIComponent(auth);
|
|
841
|
+
auth = auth.replace(/%3A/i, ':');
|
|
842
|
+
auth += '@';
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
var protocol = self.protocol || '',
|
|
846
|
+
pathname = self.pathname || '',
|
|
847
|
+
hash = self.hash || '',
|
|
848
|
+
host = false,
|
|
849
|
+
query = '';
|
|
850
|
+
|
|
851
|
+
if (self.host) {
|
|
852
|
+
host = auth + self.host;
|
|
853
|
+
} else if (self.hostname) {
|
|
854
|
+
host = auth + (self.hostname.indexOf(':') === -1 ?
|
|
855
|
+
self.hostname :
|
|
856
|
+
'[' + this.hostname + ']');
|
|
857
|
+
if (self.port) {
|
|
858
|
+
host += ':' + self.port;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
if (self.query &&
|
|
863
|
+
isObject(self.query) &&
|
|
864
|
+
Object.keys(self.query).length) {
|
|
865
|
+
query = stringify(self.query);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
var search = self.search || (query && ('?' + query)) || '';
|
|
869
|
+
|
|
870
|
+
if (protocol && protocol.substr(-1) !== ':') protocol += ':';
|
|
871
|
+
|
|
872
|
+
// only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
|
|
873
|
+
// unless they had them to begin with.
|
|
874
|
+
if (self.slashes ||
|
|
875
|
+
(!protocol || slashedProtocol[protocol]) && host !== false) {
|
|
876
|
+
host = '//' + (host || '');
|
|
877
|
+
if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
|
|
878
|
+
} else if (!host) {
|
|
879
|
+
host = '';
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
|
|
883
|
+
if (search && search.charAt(0) !== '?') search = '?' + search;
|
|
884
|
+
|
|
885
|
+
pathname = pathname.replace(/[?#]/g, function(match) {
|
|
886
|
+
return encodeURIComponent(match);
|
|
887
|
+
});
|
|
888
|
+
search = search.replace('#', '%23');
|
|
889
|
+
|
|
890
|
+
return protocol + host + pathname + search + hash;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
Url.prototype.format = function() {
|
|
894
|
+
return format(this);
|
|
895
|
+
};
|
|
896
|
+
|
|
897
|
+
function urlResolve(source, relative) {
|
|
898
|
+
return urlParse(source, false, true).resolve(relative);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
Url.prototype.resolve = function(relative) {
|
|
902
|
+
return this.resolveObject(urlParse(relative, false, true)).format();
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
function urlResolveObject(source, relative) {
|
|
906
|
+
if (!source) return relative;
|
|
907
|
+
return urlParse(source, false, true).resolveObject(relative);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
Url.prototype.resolveObject = function(relative) {
|
|
911
|
+
if (isString(relative)) {
|
|
912
|
+
var rel = new Url();
|
|
913
|
+
rel.parse(relative, false, true);
|
|
914
|
+
relative = rel;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
var result = new Url();
|
|
918
|
+
var tkeys = Object.keys(this);
|
|
919
|
+
for (var tk = 0; tk < tkeys.length; tk++) {
|
|
920
|
+
var tkey = tkeys[tk];
|
|
921
|
+
result[tkey] = this[tkey];
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// hash is always overridden, no matter what.
|
|
925
|
+
// even href="" will remove it.
|
|
926
|
+
result.hash = relative.hash;
|
|
927
|
+
|
|
928
|
+
// if the relative url is empty, then there's nothing left to do here.
|
|
929
|
+
if (relative.href === '') {
|
|
930
|
+
result.href = result.format();
|
|
931
|
+
return result;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// hrefs like //foo/bar always cut to the protocol.
|
|
935
|
+
if (relative.slashes && !relative.protocol) {
|
|
936
|
+
// take everything except the protocol from relative
|
|
937
|
+
var rkeys = Object.keys(relative);
|
|
938
|
+
for (var rk = 0; rk < rkeys.length; rk++) {
|
|
939
|
+
var rkey = rkeys[rk];
|
|
940
|
+
if (rkey !== 'protocol')
|
|
941
|
+
result[rkey] = relative[rkey];
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
//urlParse appends trailing / to urls like http://www.example.com
|
|
945
|
+
if (slashedProtocol[result.protocol] &&
|
|
946
|
+
result.hostname && !result.pathname) {
|
|
947
|
+
result.path = result.pathname = '/';
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
result.href = result.format();
|
|
951
|
+
return result;
|
|
952
|
+
}
|
|
953
|
+
var relPath;
|
|
954
|
+
if (relative.protocol && relative.protocol !== result.protocol) {
|
|
955
|
+
// if it's a known url protocol, then changing
|
|
956
|
+
// the protocol does weird things
|
|
957
|
+
// first, if it's not file:, then we MUST have a host,
|
|
958
|
+
// and if there was a path
|
|
959
|
+
// to begin with, then we MUST have a path.
|
|
960
|
+
// if it is file:, then the host is dropped,
|
|
961
|
+
// because that's known to be hostless.
|
|
962
|
+
// anything else is assumed to be absolute.
|
|
963
|
+
if (!slashedProtocol[relative.protocol]) {
|
|
964
|
+
var keys = Object.keys(relative);
|
|
965
|
+
for (var v = 0; v < keys.length; v++) {
|
|
966
|
+
var k = keys[v];
|
|
967
|
+
result[k] = relative[k];
|
|
968
|
+
}
|
|
969
|
+
result.href = result.format();
|
|
970
|
+
return result;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
result.protocol = relative.protocol;
|
|
974
|
+
if (!relative.host && !hostlessProtocol[relative.protocol]) {
|
|
975
|
+
relPath = (relative.pathname || '').split('/');
|
|
976
|
+
while (relPath.length && !(relative.host = relPath.shift()));
|
|
977
|
+
if (!relative.host) relative.host = '';
|
|
978
|
+
if (!relative.hostname) relative.hostname = '';
|
|
979
|
+
if (relPath[0] !== '') relPath.unshift('');
|
|
980
|
+
if (relPath.length < 2) relPath.unshift('');
|
|
981
|
+
result.pathname = relPath.join('/');
|
|
982
|
+
} else {
|
|
983
|
+
result.pathname = relative.pathname;
|
|
984
|
+
}
|
|
985
|
+
result.search = relative.search;
|
|
986
|
+
result.query = relative.query;
|
|
987
|
+
result.host = relative.host || '';
|
|
988
|
+
result.auth = relative.auth;
|
|
989
|
+
result.hostname = relative.hostname || relative.host;
|
|
990
|
+
result.port = relative.port;
|
|
991
|
+
// to support http.request
|
|
992
|
+
if (result.pathname || result.search) {
|
|
993
|
+
var p = result.pathname || '';
|
|
994
|
+
var s = result.search || '';
|
|
995
|
+
result.path = p + s;
|
|
996
|
+
}
|
|
997
|
+
result.slashes = result.slashes || relative.slashes;
|
|
998
|
+
result.href = result.format();
|
|
999
|
+
return result;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
|
|
1003
|
+
isRelAbs = (
|
|
1004
|
+
relative.host ||
|
|
1005
|
+
relative.pathname && relative.pathname.charAt(0) === '/'
|
|
1006
|
+
),
|
|
1007
|
+
mustEndAbs = (isRelAbs || isSourceAbs ||
|
|
1008
|
+
(result.host && relative.pathname)),
|
|
1009
|
+
removeAllDots = mustEndAbs,
|
|
1010
|
+
srcPath = result.pathname && result.pathname.split('/') || [],
|
|
1011
|
+
psychotic = result.protocol && !slashedProtocol[result.protocol];
|
|
1012
|
+
relPath = relative.pathname && relative.pathname.split('/') || [];
|
|
1013
|
+
// if the url is a non-slashed url, then relative
|
|
1014
|
+
// links like ../.. should be able
|
|
1015
|
+
// to crawl up to the hostname, as well. This is strange.
|
|
1016
|
+
// result.protocol has already been set by now.
|
|
1017
|
+
// Later on, put the first path part into the host field.
|
|
1018
|
+
if (psychotic) {
|
|
1019
|
+
result.hostname = '';
|
|
1020
|
+
result.port = null;
|
|
1021
|
+
if (result.host) {
|
|
1022
|
+
if (srcPath[0] === '') srcPath[0] = result.host;
|
|
1023
|
+
else srcPath.unshift(result.host);
|
|
1024
|
+
}
|
|
1025
|
+
result.host = '';
|
|
1026
|
+
if (relative.protocol) {
|
|
1027
|
+
relative.hostname = null;
|
|
1028
|
+
relative.port = null;
|
|
1029
|
+
if (relative.host) {
|
|
1030
|
+
if (relPath[0] === '') relPath[0] = relative.host;
|
|
1031
|
+
else relPath.unshift(relative.host);
|
|
1032
|
+
}
|
|
1033
|
+
relative.host = null;
|
|
1034
|
+
}
|
|
1035
|
+
mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
|
|
1036
|
+
}
|
|
1037
|
+
var authInHost;
|
|
1038
|
+
if (isRelAbs) {
|
|
1039
|
+
// it's absolute.
|
|
1040
|
+
result.host = (relative.host || relative.host === '') ?
|
|
1041
|
+
relative.host : result.host;
|
|
1042
|
+
result.hostname = (relative.hostname || relative.hostname === '') ?
|
|
1043
|
+
relative.hostname : result.hostname;
|
|
1044
|
+
result.search = relative.search;
|
|
1045
|
+
result.query = relative.query;
|
|
1046
|
+
srcPath = relPath;
|
|
1047
|
+
// fall through to the dot-handling below.
|
|
1048
|
+
} else if (relPath.length) {
|
|
1049
|
+
// it's relative
|
|
1050
|
+
// throw away the existing file, and take the new path instead.
|
|
1051
|
+
if (!srcPath) srcPath = [];
|
|
1052
|
+
srcPath.pop();
|
|
1053
|
+
srcPath = srcPath.concat(relPath);
|
|
1054
|
+
result.search = relative.search;
|
|
1055
|
+
result.query = relative.query;
|
|
1056
|
+
} else if (!isNullOrUndefined(relative.search)) {
|
|
1057
|
+
// just pull out the search.
|
|
1058
|
+
// like href='?foo'.
|
|
1059
|
+
// Put this after the other two cases because it simplifies the booleans
|
|
1060
|
+
if (psychotic) {
|
|
1061
|
+
result.hostname = result.host = srcPath.shift();
|
|
1062
|
+
//occationaly the auth can get stuck only in host
|
|
1063
|
+
//this especially happens in cases like
|
|
1064
|
+
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
|
|
1065
|
+
authInHost = result.host && result.host.indexOf('@') > 0 ?
|
|
1066
|
+
result.host.split('@') : false;
|
|
1067
|
+
if (authInHost) {
|
|
1068
|
+
result.auth = authInHost.shift();
|
|
1069
|
+
result.host = result.hostname = authInHost.shift();
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
result.search = relative.search;
|
|
1073
|
+
result.query = relative.query;
|
|
1074
|
+
//to support http.request
|
|
1075
|
+
if (!isNull(result.pathname) || !isNull(result.search)) {
|
|
1076
|
+
result.path = (result.pathname ? result.pathname : '') +
|
|
1077
|
+
(result.search ? result.search : '');
|
|
1078
|
+
}
|
|
1079
|
+
result.href = result.format();
|
|
1080
|
+
return result;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
if (!srcPath.length) {
|
|
1084
|
+
// no path at all. easy.
|
|
1085
|
+
// we've already handled the other stuff above.
|
|
1086
|
+
result.pathname = null;
|
|
1087
|
+
//to support http.request
|
|
1088
|
+
if (result.search) {
|
|
1089
|
+
result.path = '/' + result.search;
|
|
1090
|
+
} else {
|
|
1091
|
+
result.path = null;
|
|
1092
|
+
}
|
|
1093
|
+
result.href = result.format();
|
|
1094
|
+
return result;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// if a url ENDs in . or .., then it must get a trailing slash.
|
|
1098
|
+
// however, if it ends in anything else non-slashy,
|
|
1099
|
+
// then it must NOT get a trailing slash.
|
|
1100
|
+
var last = srcPath.slice(-1)[0];
|
|
1101
|
+
var hasTrailingSlash = (
|
|
1102
|
+
(result.host || relative.host || srcPath.length > 1) &&
|
|
1103
|
+
(last === '.' || last === '..') || last === '');
|
|
1104
|
+
|
|
1105
|
+
// strip single dots, resolve double dots to parent dir
|
|
1106
|
+
// if the path tries to go above the root, `up` ends up > 0
|
|
1107
|
+
var up = 0;
|
|
1108
|
+
for (var i = srcPath.length; i >= 0; i--) {
|
|
1109
|
+
last = srcPath[i];
|
|
1110
|
+
if (last === '.') {
|
|
1111
|
+
srcPath.splice(i, 1);
|
|
1112
|
+
} else if (last === '..') {
|
|
1113
|
+
srcPath.splice(i, 1);
|
|
1114
|
+
up++;
|
|
1115
|
+
} else if (up) {
|
|
1116
|
+
srcPath.splice(i, 1);
|
|
1117
|
+
up--;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// if the path is allowed to go above the root, restore leading ..s
|
|
1122
|
+
if (!mustEndAbs && !removeAllDots) {
|
|
1123
|
+
for (; up--; up) {
|
|
1124
|
+
srcPath.unshift('..');
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
if (mustEndAbs && srcPath[0] !== '' &&
|
|
1129
|
+
(!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
|
|
1130
|
+
srcPath.unshift('');
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
|
|
1134
|
+
srcPath.push('');
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
var isAbsolute = srcPath[0] === '' ||
|
|
1138
|
+
(srcPath[0] && srcPath[0].charAt(0) === '/');
|
|
1139
|
+
|
|
1140
|
+
// put the host back
|
|
1141
|
+
if (psychotic) {
|
|
1142
|
+
result.hostname = result.host = isAbsolute ? '' :
|
|
1143
|
+
srcPath.length ? srcPath.shift() : '';
|
|
1144
|
+
//occationaly the auth can get stuck only in host
|
|
1145
|
+
//this especially happens in cases like
|
|
1146
|
+
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
|
|
1147
|
+
authInHost = result.host && result.host.indexOf('@') > 0 ?
|
|
1148
|
+
result.host.split('@') : false;
|
|
1149
|
+
if (authInHost) {
|
|
1150
|
+
result.auth = authInHost.shift();
|
|
1151
|
+
result.host = result.hostname = authInHost.shift();
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
mustEndAbs = mustEndAbs || (result.host && srcPath.length);
|
|
1156
|
+
|
|
1157
|
+
if (mustEndAbs && !isAbsolute) {
|
|
1158
|
+
srcPath.unshift('');
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
if (!srcPath.length) {
|
|
1162
|
+
result.pathname = null;
|
|
1163
|
+
result.path = null;
|
|
1164
|
+
} else {
|
|
1165
|
+
result.pathname = srcPath.join('/');
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
//to support request.http
|
|
1169
|
+
if (!isNull(result.pathname) || !isNull(result.search)) {
|
|
1170
|
+
result.path = (result.pathname ? result.pathname : '') +
|
|
1171
|
+
(result.search ? result.search : '');
|
|
1172
|
+
}
|
|
1173
|
+
result.auth = relative.auth || result.auth;
|
|
1174
|
+
result.slashes = result.slashes || relative.slashes;
|
|
1175
|
+
result.href = result.format();
|
|
1176
|
+
return result;
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
Url.prototype.parseHost = function() {
|
|
1180
|
+
return parseHost(this);
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
function parseHost(self) {
|
|
1184
|
+
var host = self.host;
|
|
1185
|
+
var port = portPattern.exec(host);
|
|
1186
|
+
if (port) {
|
|
1187
|
+
port = port[0];
|
|
1188
|
+
if (port !== ':') {
|
|
1189
|
+
self.port = port.substr(1);
|
|
1190
|
+
}
|
|
1191
|
+
host = host.substr(0, host.length - port.length);
|
|
1192
|
+
}
|
|
1193
|
+
if (host) self.hostname = host;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
export { URL, URLSearchParams, Url, _polyfillNode_url as default, urlFileURLToPath as fileURLToPath, urlFormat as format, urlParse as parse, urlResolve as resolve, urlResolveObject as resolveObject };
|