@mehmetb/rollup-plugin-node-builtins 3.0.1
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/README.md +101 -0
- package/dist/constants.js +474 -0
- package/dist/rollup-plugin-node-builtins.cjs.js +77 -0
- package/dist/rollup-plugin-node-builtins.es6.js +75 -0
- package/package.json +42 -0
- package/src/es6/assert.js +488 -0
- package/src/es6/console.js +13 -0
- package/src/es6/domain.js +100 -0
- package/src/es6/empty.js +1 -0
- package/src/es6/events.js +475 -0
- package/src/es6/http-lib/capability.js +52 -0
- package/src/es6/http-lib/request.js +278 -0
- package/src/es6/http-lib/response.js +185 -0
- package/src/es6/http-lib/to-arraybuffer.js +30 -0
- package/src/es6/http.js +167 -0
- package/src/es6/inherits.js +25 -0
- package/src/es6/os.js +113 -0
- package/src/es6/path.js +234 -0
- package/src/es6/punycode.js +475 -0
- package/src/es6/qs.js +147 -0
- package/src/es6/readable-stream/buffer-list.js +59 -0
- package/src/es6/readable-stream/duplex.js +45 -0
- package/src/es6/readable-stream/passthrough.js +15 -0
- package/src/es6/readable-stream/readable.js +896 -0
- package/src/es6/readable-stream/transform.js +174 -0
- package/src/es6/readable-stream/writable.js +483 -0
- package/src/es6/setimmediate.js +185 -0
- package/src/es6/stream.js +110 -0
- package/src/es6/string-decoder.js +220 -0
- package/src/es6/timers.js +76 -0
- package/src/es6/tty.js +20 -0
- package/src/es6/url.js +745 -0
- package/src/es6/util.js +598 -0
- package/src/es6/vm.js +202 -0
- package/src/es6/zlib-lib/LICENSE +21 -0
- package/src/es6/zlib-lib/adler32.js +31 -0
- package/src/es6/zlib-lib/binding.js +269 -0
- package/src/es6/zlib-lib/crc32.js +40 -0
- package/src/es6/zlib-lib/deflate.js +1862 -0
- package/src/es6/zlib-lib/inffast.js +325 -0
- package/src/es6/zlib-lib/inflate.js +1650 -0
- package/src/es6/zlib-lib/inftrees.js +329 -0
- package/src/es6/zlib-lib/messages.js +11 -0
- package/src/es6/zlib-lib/trees.js +1220 -0
- package/src/es6/zlib-lib/utils.js +73 -0
- package/src/es6/zlib-lib/zstream.js +28 -0
- package/src/es6/zlib.js +635 -0
- package/src/index.js +73 -0
@@ -0,0 +1,475 @@
|
|
1
|
+
/*! https://mths.be/punycode v1.4.1 by @mathias */
|
2
|
+
|
3
|
+
|
4
|
+
/** Highest positive signed 32-bit float value */
|
5
|
+
var maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
|
6
|
+
|
7
|
+
/** Bootstring parameters */
|
8
|
+
var base = 36;
|
9
|
+
var tMin = 1;
|
10
|
+
var tMax = 26;
|
11
|
+
var skew = 38;
|
12
|
+
var damp = 700;
|
13
|
+
var initialBias = 72;
|
14
|
+
var initialN = 128; // 0x80
|
15
|
+
var delimiter = '-'; // '\x2D'
|
16
|
+
|
17
|
+
/** Regular expressions */
|
18
|
+
var regexPunycode = /^xn--/;
|
19
|
+
var regexNonASCII = /[^\x20-\x7E]/; // unprintable ASCII chars + non-ASCII chars
|
20
|
+
var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
|
21
|
+
|
22
|
+
/** Error messages */
|
23
|
+
var errors = {
|
24
|
+
'overflow': 'Overflow: input needs wider integers to process',
|
25
|
+
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
|
26
|
+
'invalid-input': 'Invalid input'
|
27
|
+
};
|
28
|
+
|
29
|
+
/** Convenience shortcuts */
|
30
|
+
var baseMinusTMin = base - tMin;
|
31
|
+
var floor = Math.floor;
|
32
|
+
var stringFromCharCode = String.fromCharCode;
|
33
|
+
|
34
|
+
/*--------------------------------------------------------------------------*/
|
35
|
+
|
36
|
+
/**
|
37
|
+
* A generic error utility function.
|
38
|
+
* @private
|
39
|
+
* @param {String} type The error type.
|
40
|
+
* @returns {Error} Throws a `RangeError` with the applicable error message.
|
41
|
+
*/
|
42
|
+
function error(type) {
|
43
|
+
throw new RangeError(errors[type]);
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* A generic `Array#map` utility function.
|
48
|
+
* @private
|
49
|
+
* @param {Array} array The array to iterate over.
|
50
|
+
* @param {Function} callback The function that gets called for every array
|
51
|
+
* item.
|
52
|
+
* @returns {Array} A new array of values returned by the callback function.
|
53
|
+
*/
|
54
|
+
function map(array, fn) {
|
55
|
+
var length = array.length;
|
56
|
+
var result = [];
|
57
|
+
while (length--) {
|
58
|
+
result[length] = fn(array[length]);
|
59
|
+
}
|
60
|
+
return result;
|
61
|
+
}
|
62
|
+
|
63
|
+
/**
|
64
|
+
* A simple `Array#map`-like wrapper to work with domain name strings or email
|
65
|
+
* addresses.
|
66
|
+
* @private
|
67
|
+
* @param {String} domain The domain name or email address.
|
68
|
+
* @param {Function} callback The function that gets called for every
|
69
|
+
* character.
|
70
|
+
* @returns {Array} A new string of characters returned by the callback
|
71
|
+
* function.
|
72
|
+
*/
|
73
|
+
function mapDomain(string, fn) {
|
74
|
+
var parts = string.split('@');
|
75
|
+
var result = '';
|
76
|
+
if (parts.length > 1) {
|
77
|
+
// In email addresses, only the domain name should be punycoded. Leave
|
78
|
+
// the local part (i.e. everything up to `@`) intact.
|
79
|
+
result = parts[0] + '@';
|
80
|
+
string = parts[1];
|
81
|
+
}
|
82
|
+
// Avoid `split(regex)` for IE8 compatibility. See #17.
|
83
|
+
string = string.replace(regexSeparators, '\x2E');
|
84
|
+
var labels = string.split('.');
|
85
|
+
var encoded = map(labels, fn).join('.');
|
86
|
+
return result + encoded;
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Creates an array containing the numeric code points of each Unicode
|
91
|
+
* character in the string. While JavaScript uses UCS-2 internally,
|
92
|
+
* this function will convert a pair of surrogate halves (each of which
|
93
|
+
* UCS-2 exposes as separate characters) into a single code point,
|
94
|
+
* matching UTF-16.
|
95
|
+
* @see `punycode.ucs2.encode`
|
96
|
+
* @see <https://mathiasbynens.be/notes/javascript-encoding>
|
97
|
+
* @memberOf punycode.ucs2
|
98
|
+
* @name decode
|
99
|
+
* @param {String} string The Unicode input string (UCS-2).
|
100
|
+
* @returns {Array} The new array of code points.
|
101
|
+
*/
|
102
|
+
function ucs2decode(string) {
|
103
|
+
var output = [],
|
104
|
+
counter = 0,
|
105
|
+
length = string.length,
|
106
|
+
value,
|
107
|
+
extra;
|
108
|
+
while (counter < length) {
|
109
|
+
value = string.charCodeAt(counter++);
|
110
|
+
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
|
111
|
+
// high surrogate, and there is a next character
|
112
|
+
extra = string.charCodeAt(counter++);
|
113
|
+
if ((extra & 0xFC00) == 0xDC00) { // low surrogate
|
114
|
+
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
|
115
|
+
} else {
|
116
|
+
// unmatched surrogate; only append this code unit, in case the next
|
117
|
+
// code unit is the high surrogate of a surrogate pair
|
118
|
+
output.push(value);
|
119
|
+
counter--;
|
120
|
+
}
|
121
|
+
} else {
|
122
|
+
output.push(value);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
return output;
|
126
|
+
}
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Creates a string based on an array of numeric code points.
|
130
|
+
* @see `punycode.ucs2.decode`
|
131
|
+
* @memberOf punycode.ucs2
|
132
|
+
* @name encode
|
133
|
+
* @param {Array} codePoints The array of numeric code points.
|
134
|
+
* @returns {String} The new Unicode string (UCS-2).
|
135
|
+
*/
|
136
|
+
function ucs2encode(array) {
|
137
|
+
return map(array, function(value) {
|
138
|
+
var output = '';
|
139
|
+
if (value > 0xFFFF) {
|
140
|
+
value -= 0x10000;
|
141
|
+
output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
|
142
|
+
value = 0xDC00 | value & 0x3FF;
|
143
|
+
}
|
144
|
+
output += stringFromCharCode(value);
|
145
|
+
return output;
|
146
|
+
}).join('');
|
147
|
+
}
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Converts a basic code point into a digit/integer.
|
151
|
+
* @see `digitToBasic()`
|
152
|
+
* @private
|
153
|
+
* @param {Number} codePoint The basic numeric code point value.
|
154
|
+
* @returns {Number} The numeric value of a basic code point (for use in
|
155
|
+
* representing integers) in the range `0` to `base - 1`, or `base` if
|
156
|
+
* the code point does not represent a value.
|
157
|
+
*/
|
158
|
+
function basicToDigit(codePoint) {
|
159
|
+
if (codePoint - 48 < 10) {
|
160
|
+
return codePoint - 22;
|
161
|
+
}
|
162
|
+
if (codePoint - 65 < 26) {
|
163
|
+
return codePoint - 65;
|
164
|
+
}
|
165
|
+
if (codePoint - 97 < 26) {
|
166
|
+
return codePoint - 97;
|
167
|
+
}
|
168
|
+
return base;
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Converts a digit/integer into a basic code point.
|
173
|
+
* @see `basicToDigit()`
|
174
|
+
* @private
|
175
|
+
* @param {Number} digit The numeric value of a basic code point.
|
176
|
+
* @returns {Number} The basic code point whose value (when used for
|
177
|
+
* representing integers) is `digit`, which needs to be in the range
|
178
|
+
* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
|
179
|
+
* used; else, the lowercase form is used. The behavior is undefined
|
180
|
+
* if `flag` is non-zero and `digit` has no uppercase form.
|
181
|
+
*/
|
182
|
+
function digitToBasic(digit, flag) {
|
183
|
+
// 0..25 map to ASCII a..z or A..Z
|
184
|
+
// 26..35 map to ASCII 0..9
|
185
|
+
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
|
186
|
+
}
|
187
|
+
|
188
|
+
/**
|
189
|
+
* Bias adaptation function as per section 3.4 of RFC 3492.
|
190
|
+
* https://tools.ietf.org/html/rfc3492#section-3.4
|
191
|
+
* @private
|
192
|
+
*/
|
193
|
+
function adapt(delta, numPoints, firstTime) {
|
194
|
+
var k = 0;
|
195
|
+
delta = firstTime ? floor(delta / damp) : delta >> 1;
|
196
|
+
delta += floor(delta / numPoints);
|
197
|
+
for ( /* no initialization */ ; delta > baseMinusTMin * tMax >> 1; k += base) {
|
198
|
+
delta = floor(delta / baseMinusTMin);
|
199
|
+
}
|
200
|
+
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
|
201
|
+
}
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Converts a Punycode string of ASCII-only symbols to a string of Unicode
|
205
|
+
* symbols.
|
206
|
+
* @memberOf punycode
|
207
|
+
* @param {String} input The Punycode string of ASCII-only symbols.
|
208
|
+
* @returns {String} The resulting string of Unicode symbols.
|
209
|
+
*/
|
210
|
+
export function decode(input) {
|
211
|
+
// Don't use UCS-2
|
212
|
+
var output = [],
|
213
|
+
inputLength = input.length,
|
214
|
+
out,
|
215
|
+
i = 0,
|
216
|
+
n = initialN,
|
217
|
+
bias = initialBias,
|
218
|
+
basic,
|
219
|
+
j,
|
220
|
+
index,
|
221
|
+
oldi,
|
222
|
+
w,
|
223
|
+
k,
|
224
|
+
digit,
|
225
|
+
t,
|
226
|
+
/** Cached calculation results */
|
227
|
+
baseMinusT;
|
228
|
+
|
229
|
+
// Handle the basic code points: let `basic` be the number of input code
|
230
|
+
// points before the last delimiter, or `0` if there is none, then copy
|
231
|
+
// the first basic code points to the output.
|
232
|
+
|
233
|
+
basic = input.lastIndexOf(delimiter);
|
234
|
+
if (basic < 0) {
|
235
|
+
basic = 0;
|
236
|
+
}
|
237
|
+
|
238
|
+
for (j = 0; j < basic; ++j) {
|
239
|
+
// if it's not a basic code point
|
240
|
+
if (input.charCodeAt(j) >= 0x80) {
|
241
|
+
error('not-basic');
|
242
|
+
}
|
243
|
+
output.push(input.charCodeAt(j));
|
244
|
+
}
|
245
|
+
|
246
|
+
// Main decoding loop: start just after the last delimiter if any basic code
|
247
|
+
// points were copied; start at the beginning otherwise.
|
248
|
+
|
249
|
+
for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */ ) {
|
250
|
+
|
251
|
+
// `index` is the index of the next character to be consumed.
|
252
|
+
// Decode a generalized variable-length integer into `delta`,
|
253
|
+
// which gets added to `i`. The overflow checking is easier
|
254
|
+
// if we increase `i` as we go, then subtract off its starting
|
255
|
+
// value at the end to obtain `delta`.
|
256
|
+
for (oldi = i, w = 1, k = base; /* no condition */ ; k += base) {
|
257
|
+
|
258
|
+
if (index >= inputLength) {
|
259
|
+
error('invalid-input');
|
260
|
+
}
|
261
|
+
|
262
|
+
digit = basicToDigit(input.charCodeAt(index++));
|
263
|
+
|
264
|
+
if (digit >= base || digit > floor((maxInt - i) / w)) {
|
265
|
+
error('overflow');
|
266
|
+
}
|
267
|
+
|
268
|
+
i += digit * w;
|
269
|
+
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
270
|
+
|
271
|
+
if (digit < t) {
|
272
|
+
break;
|
273
|
+
}
|
274
|
+
|
275
|
+
baseMinusT = base - t;
|
276
|
+
if (w > floor(maxInt / baseMinusT)) {
|
277
|
+
error('overflow');
|
278
|
+
}
|
279
|
+
|
280
|
+
w *= baseMinusT;
|
281
|
+
|
282
|
+
}
|
283
|
+
|
284
|
+
out = output.length + 1;
|
285
|
+
bias = adapt(i - oldi, out, oldi == 0);
|
286
|
+
|
287
|
+
// `i` was supposed to wrap around from `out` to `0`,
|
288
|
+
// incrementing `n` each time, so we'll fix that now:
|
289
|
+
if (floor(i / out) > maxInt - n) {
|
290
|
+
error('overflow');
|
291
|
+
}
|
292
|
+
|
293
|
+
n += floor(i / out);
|
294
|
+
i %= out;
|
295
|
+
|
296
|
+
// Insert `n` at position `i` of the output
|
297
|
+
output.splice(i++, 0, n);
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
return ucs2encode(output);
|
302
|
+
}
|
303
|
+
|
304
|
+
/**
|
305
|
+
* Converts a string of Unicode symbols (e.g. a domain name label) to a
|
306
|
+
* Punycode string of ASCII-only symbols.
|
307
|
+
* @memberOf punycode
|
308
|
+
* @param {String} input The string of Unicode symbols.
|
309
|
+
* @returns {String} The resulting Punycode string of ASCII-only symbols.
|
310
|
+
*/
|
311
|
+
export function encode(input) {
|
312
|
+
var n,
|
313
|
+
delta,
|
314
|
+
handledCPCount,
|
315
|
+
basicLength,
|
316
|
+
bias,
|
317
|
+
j,
|
318
|
+
m,
|
319
|
+
q,
|
320
|
+
k,
|
321
|
+
t,
|
322
|
+
currentValue,
|
323
|
+
output = [],
|
324
|
+
/** `inputLength` will hold the number of code points in `input`. */
|
325
|
+
inputLength,
|
326
|
+
/** Cached calculation results */
|
327
|
+
handledCPCountPlusOne,
|
328
|
+
baseMinusT,
|
329
|
+
qMinusT;
|
330
|
+
|
331
|
+
// Convert the input in UCS-2 to Unicode
|
332
|
+
input = ucs2decode(input);
|
333
|
+
|
334
|
+
// Cache the length
|
335
|
+
inputLength = input.length;
|
336
|
+
|
337
|
+
// Initialize the state
|
338
|
+
n = initialN;
|
339
|
+
delta = 0;
|
340
|
+
bias = initialBias;
|
341
|
+
|
342
|
+
// Handle the basic code points
|
343
|
+
for (j = 0; j < inputLength; ++j) {
|
344
|
+
currentValue = input[j];
|
345
|
+
if (currentValue < 0x80) {
|
346
|
+
output.push(stringFromCharCode(currentValue));
|
347
|
+
}
|
348
|
+
}
|
349
|
+
|
350
|
+
handledCPCount = basicLength = output.length;
|
351
|
+
|
352
|
+
// `handledCPCount` is the number of code points that have been handled;
|
353
|
+
// `basicLength` is the number of basic code points.
|
354
|
+
|
355
|
+
// Finish the basic string - if it is not empty - with a delimiter
|
356
|
+
if (basicLength) {
|
357
|
+
output.push(delimiter);
|
358
|
+
}
|
359
|
+
|
360
|
+
// Main encoding loop:
|
361
|
+
while (handledCPCount < inputLength) {
|
362
|
+
|
363
|
+
// All non-basic code points < n have been handled already. Find the next
|
364
|
+
// larger one:
|
365
|
+
for (m = maxInt, j = 0; j < inputLength; ++j) {
|
366
|
+
currentValue = input[j];
|
367
|
+
if (currentValue >= n && currentValue < m) {
|
368
|
+
m = currentValue;
|
369
|
+
}
|
370
|
+
}
|
371
|
+
|
372
|
+
// Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
|
373
|
+
// but guard against overflow
|
374
|
+
handledCPCountPlusOne = handledCPCount + 1;
|
375
|
+
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
|
376
|
+
error('overflow');
|
377
|
+
}
|
378
|
+
|
379
|
+
delta += (m - n) * handledCPCountPlusOne;
|
380
|
+
n = m;
|
381
|
+
|
382
|
+
for (j = 0; j < inputLength; ++j) {
|
383
|
+
currentValue = input[j];
|
384
|
+
|
385
|
+
if (currentValue < n && ++delta > maxInt) {
|
386
|
+
error('overflow');
|
387
|
+
}
|
388
|
+
|
389
|
+
if (currentValue == n) {
|
390
|
+
// Represent delta as a generalized variable-length integer
|
391
|
+
for (q = delta, k = base; /* no condition */ ; k += base) {
|
392
|
+
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
393
|
+
if (q < t) {
|
394
|
+
break;
|
395
|
+
}
|
396
|
+
qMinusT = q - t;
|
397
|
+
baseMinusT = base - t;
|
398
|
+
output.push(
|
399
|
+
stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
|
400
|
+
);
|
401
|
+
q = floor(qMinusT / baseMinusT);
|
402
|
+
}
|
403
|
+
|
404
|
+
output.push(stringFromCharCode(digitToBasic(q, 0)));
|
405
|
+
bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
|
406
|
+
delta = 0;
|
407
|
+
++handledCPCount;
|
408
|
+
}
|
409
|
+
}
|
410
|
+
|
411
|
+
++delta;
|
412
|
+
++n;
|
413
|
+
|
414
|
+
}
|
415
|
+
return output.join('');
|
416
|
+
}
|
417
|
+
|
418
|
+
/**
|
419
|
+
* Converts a Punycode string representing a domain name or an email address
|
420
|
+
* to Unicode. Only the Punycoded parts of the input will be converted, i.e.
|
421
|
+
* it doesn't matter if you call it on a string that has already been
|
422
|
+
* converted to Unicode.
|
423
|
+
* @memberOf punycode
|
424
|
+
* @param {String} input The Punycoded domain name or email address to
|
425
|
+
* convert to Unicode.
|
426
|
+
* @returns {String} The Unicode representation of the given Punycode
|
427
|
+
* string.
|
428
|
+
*/
|
429
|
+
export function toUnicode(input) {
|
430
|
+
return mapDomain(input, function(string) {
|
431
|
+
return regexPunycode.test(string) ?
|
432
|
+
decode(string.slice(4).toLowerCase()) :
|
433
|
+
string;
|
434
|
+
});
|
435
|
+
}
|
436
|
+
|
437
|
+
/**
|
438
|
+
* Converts a Unicode string representing a domain name or an email address to
|
439
|
+
* Punycode. Only the non-ASCII parts of the domain name will be converted,
|
440
|
+
* i.e. it doesn't matter if you call it with a domain that's already in
|
441
|
+
* ASCII.
|
442
|
+
* @memberOf punycode
|
443
|
+
* @param {String} input The domain name or email address to convert, as a
|
444
|
+
* Unicode string.
|
445
|
+
* @returns {String} The Punycode representation of the given domain name or
|
446
|
+
* email address.
|
447
|
+
*/
|
448
|
+
export function toASCII(input) {
|
449
|
+
return mapDomain(input, function(string) {
|
450
|
+
return regexNonASCII.test(string) ?
|
451
|
+
'xn--' + encode(string) :
|
452
|
+
string;
|
453
|
+
});
|
454
|
+
}
|
455
|
+
export var version = '1.4.1';
|
456
|
+
/**
|
457
|
+
* An object of methods to convert from JavaScript's internal character
|
458
|
+
* representation (UCS-2) to Unicode code points, and back.
|
459
|
+
* @see <https://mathiasbynens.be/notes/javascript-encoding>
|
460
|
+
* @memberOf punycode
|
461
|
+
* @type Object
|
462
|
+
*/
|
463
|
+
|
464
|
+
export var ucs2 = {
|
465
|
+
decode: ucs2decode,
|
466
|
+
encode: ucs2encode
|
467
|
+
};
|
468
|
+
export default {
|
469
|
+
version: version,
|
470
|
+
ucs2: ucs2,
|
471
|
+
toASCII: toASCII,
|
472
|
+
toUnicode: toUnicode,
|
473
|
+
encode: encode,
|
474
|
+
decode: decode
|
475
|
+
}
|
package/src/es6/qs.js
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
// copy of this software and associated documentation files (the
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
9
|
+
// following conditions:
|
10
|
+
//
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
12
|
+
// in all copies or substantial portions of the Software.
|
13
|
+
//
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
|
23
|
+
// If obj.hasOwnProperty has been overridden, then calling
|
24
|
+
// obj.hasOwnProperty(prop) will break.
|
25
|
+
// See: https://github.com/joyent/node/issues/1707
|
26
|
+
function hasOwnProperty(obj, prop) {
|
27
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
28
|
+
}
|
29
|
+
var isArray = Array.isArray || function (xs) {
|
30
|
+
return Object.prototype.toString.call(xs) === '[object Array]';
|
31
|
+
};
|
32
|
+
function stringifyPrimitive(v) {
|
33
|
+
switch (typeof v) {
|
34
|
+
case 'string':
|
35
|
+
return v;
|
36
|
+
|
37
|
+
case 'boolean':
|
38
|
+
return v ? 'true' : 'false';
|
39
|
+
|
40
|
+
case 'number':
|
41
|
+
return isFinite(v) ? v : '';
|
42
|
+
|
43
|
+
default:
|
44
|
+
return '';
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
export function stringify (obj, sep, eq, name) {
|
49
|
+
sep = sep || '&';
|
50
|
+
eq = eq || '=';
|
51
|
+
if (obj === null) {
|
52
|
+
obj = undefined;
|
53
|
+
}
|
54
|
+
|
55
|
+
if (typeof obj === 'object') {
|
56
|
+
return map(objectKeys(obj), function(k) {
|
57
|
+
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
|
58
|
+
if (isArray(obj[k])) {
|
59
|
+
return map(obj[k], function(v) {
|
60
|
+
return ks + encodeURIComponent(stringifyPrimitive(v));
|
61
|
+
}).join(sep);
|
62
|
+
} else {
|
63
|
+
return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
|
64
|
+
}
|
65
|
+
}).join(sep);
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
if (!name) return '';
|
70
|
+
return encodeURIComponent(stringifyPrimitive(name)) + eq +
|
71
|
+
encodeURIComponent(stringifyPrimitive(obj));
|
72
|
+
};
|
73
|
+
|
74
|
+
function map (xs, f) {
|
75
|
+
if (xs.map) return xs.map(f);
|
76
|
+
var res = [];
|
77
|
+
for (var i = 0; i < xs.length; i++) {
|
78
|
+
res.push(f(xs[i], i));
|
79
|
+
}
|
80
|
+
return res;
|
81
|
+
}
|
82
|
+
|
83
|
+
var objectKeys = Object.keys || function (obj) {
|
84
|
+
var res = [];
|
85
|
+
for (var key in obj) {
|
86
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
|
87
|
+
}
|
88
|
+
return res;
|
89
|
+
};
|
90
|
+
|
91
|
+
export function parse(qs, sep, eq, options) {
|
92
|
+
sep = sep || '&';
|
93
|
+
eq = eq || '=';
|
94
|
+
var obj = {};
|
95
|
+
|
96
|
+
if (typeof qs !== 'string' || qs.length === 0) {
|
97
|
+
return obj;
|
98
|
+
}
|
99
|
+
|
100
|
+
var regexp = /\+/g;
|
101
|
+
qs = qs.split(sep);
|
102
|
+
|
103
|
+
var maxKeys = 1000;
|
104
|
+
if (options && typeof options.maxKeys === 'number') {
|
105
|
+
maxKeys = options.maxKeys;
|
106
|
+
}
|
107
|
+
|
108
|
+
var len = qs.length;
|
109
|
+
// maxKeys <= 0 means that we should not limit keys count
|
110
|
+
if (maxKeys > 0 && len > maxKeys) {
|
111
|
+
len = maxKeys;
|
112
|
+
}
|
113
|
+
|
114
|
+
for (var i = 0; i < len; ++i) {
|
115
|
+
var x = qs[i].replace(regexp, '%20'),
|
116
|
+
idx = x.indexOf(eq),
|
117
|
+
kstr, vstr, k, v;
|
118
|
+
|
119
|
+
if (idx >= 0) {
|
120
|
+
kstr = x.substr(0, idx);
|
121
|
+
vstr = x.substr(idx + 1);
|
122
|
+
} else {
|
123
|
+
kstr = x;
|
124
|
+
vstr = '';
|
125
|
+
}
|
126
|
+
|
127
|
+
k = decodeURIComponent(kstr);
|
128
|
+
v = decodeURIComponent(vstr);
|
129
|
+
|
130
|
+
if (!hasOwnProperty(obj, k)) {
|
131
|
+
obj[k] = v;
|
132
|
+
} else if (isArray(obj[k])) {
|
133
|
+
obj[k].push(v);
|
134
|
+
} else {
|
135
|
+
obj[k] = [obj[k], v];
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
return obj;
|
140
|
+
};
|
141
|
+
export default {
|
142
|
+
encode: stringify,
|
143
|
+
stringify: stringify,
|
144
|
+
decode: parse,
|
145
|
+
parse: parse
|
146
|
+
}
|
147
|
+
export {stringify as encode, parse as decode};
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import {Buffer} from 'buffer';
|
2
|
+
|
3
|
+
export default BufferList;
|
4
|
+
|
5
|
+
function BufferList() {
|
6
|
+
this.head = null;
|
7
|
+
this.tail = null;
|
8
|
+
this.length = 0;
|
9
|
+
}
|
10
|
+
|
11
|
+
BufferList.prototype.push = function (v) {
|
12
|
+
var entry = { data: v, next: null };
|
13
|
+
if (this.length > 0) this.tail.next = entry;else this.head = entry;
|
14
|
+
this.tail = entry;
|
15
|
+
++this.length;
|
16
|
+
};
|
17
|
+
|
18
|
+
BufferList.prototype.unshift = function (v) {
|
19
|
+
var entry = { data: v, next: this.head };
|
20
|
+
if (this.length === 0) this.tail = entry;
|
21
|
+
this.head = entry;
|
22
|
+
++this.length;
|
23
|
+
};
|
24
|
+
|
25
|
+
BufferList.prototype.shift = function () {
|
26
|
+
if (this.length === 0) return;
|
27
|
+
var ret = this.head.data;
|
28
|
+
if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
|
29
|
+
--this.length;
|
30
|
+
return ret;
|
31
|
+
};
|
32
|
+
|
33
|
+
BufferList.prototype.clear = function () {
|
34
|
+
this.head = this.tail = null;
|
35
|
+
this.length = 0;
|
36
|
+
};
|
37
|
+
|
38
|
+
BufferList.prototype.join = function (s) {
|
39
|
+
if (this.length === 0) return '';
|
40
|
+
var p = this.head;
|
41
|
+
var ret = '' + p.data;
|
42
|
+
while (p = p.next) {
|
43
|
+
ret += s + p.data;
|
44
|
+
}return ret;
|
45
|
+
};
|
46
|
+
|
47
|
+
BufferList.prototype.concat = function (n) {
|
48
|
+
if (this.length === 0) return Buffer.alloc(0);
|
49
|
+
if (this.length === 1) return this.head.data;
|
50
|
+
var ret = Buffer.allocUnsafe(n >>> 0);
|
51
|
+
var p = this.head;
|
52
|
+
var i = 0;
|
53
|
+
while (p) {
|
54
|
+
p.data.copy(ret, i);
|
55
|
+
i += p.data.length;
|
56
|
+
p = p.next;
|
57
|
+
}
|
58
|
+
return ret;
|
59
|
+
};
|