blob: a6204f2535cfae9095187ce27cdb93fa80a68adc [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001(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.Qs = 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'use strict';
3
4var replace = String.prototype.replace;
5var percentTwenties = /%20/g;
6
7var util = require('./utils');
8
9var Format = {
10 RFC1738: 'RFC1738',
11 RFC3986: 'RFC3986'
12};
13
14module.exports = util.assign(
15 {
16 'default': Format.RFC3986,
17 formatters: {
18 RFC1738: function (value) {
19 return replace.call(value, percentTwenties, '+');
20 },
21 RFC3986: function (value) {
22 return String(value);
23 }
24 }
25 },
26 Format
27);
28
29},{"./utils":5}],2:[function(require,module,exports){
30'use strict';
31
32var stringify = require('./stringify');
33var parse = require('./parse');
34var formats = require('./formats');
35
36module.exports = {
37 formats: formats,
38 parse: parse,
39 stringify: stringify
40};
41
42},{"./formats":1,"./parse":3,"./stringify":4}],3:[function(require,module,exports){
43'use strict';
44
45var utils = require('./utils');
46
47var has = Object.prototype.hasOwnProperty;
48var isArray = Array.isArray;
49
50var defaults = {
51 allowDots: false,
52 allowPrototypes: false,
53 arrayLimit: 20,
54 charset: 'utf-8',
55 charsetSentinel: false,
56 comma: false,
57 decoder: utils.decode,
58 delimiter: '&',
59 depth: 5,
60 ignoreQueryPrefix: false,
61 interpretNumericEntities: false,
62 parameterLimit: 1000,
63 parseArrays: true,
64 plainObjects: false,
65 strictNullHandling: false
66};
67
68var interpretNumericEntities = function (str) {
69 return str.replace(/&#(\d+);/g, function ($0, numberStr) {
70 return String.fromCharCode(parseInt(numberStr, 10));
71 });
72};
73
74var parseArrayValue = function (val, options) {
75 if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) {
76 return val.split(',');
77 }
78
79 return val;
80};
81
82// This is what browsers will submit when the ✓ character occurs in an
83// application/x-www-form-urlencoded body and the encoding of the page containing
84// the form is iso-8859-1, or when the submitted form has an accept-charset
85// attribute of iso-8859-1. Presumably also with other charsets that do not contain
86// the ✓ character, such as us-ascii.
87var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('&#10003;')
88
89// These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
90var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
91
92var parseValues = function parseQueryStringValues(str, options) {
93 var obj = {};
94 var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
95 var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
96 var parts = cleanStr.split(options.delimiter, limit);
97 var skipIndex = -1; // Keep track of where the utf8 sentinel was found
98 var i;
99
100 var charset = options.charset;
101 if (options.charsetSentinel) {
102 for (i = 0; i < parts.length; ++i) {
103 if (parts[i].indexOf('utf8=') === 0) {
104 if (parts[i] === charsetSentinel) {
105 charset = 'utf-8';
106 } else if (parts[i] === isoSentinel) {
107 charset = 'iso-8859-1';
108 }
109 skipIndex = i;
110 i = parts.length; // The eslint settings do not allow break;
111 }
112 }
113 }
114
115 for (i = 0; i < parts.length; ++i) {
116 if (i === skipIndex) {
117 continue;
118 }
119 var part = parts[i];
120
121 var bracketEqualsPos = part.indexOf(']=');
122 var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
123
124 var key, val;
125 if (pos === -1) {
126 key = options.decoder(part, defaults.decoder, charset, 'key');
127 val = options.strictNullHandling ? null : '';
128 } else {
129 key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key');
130 val = utils.maybeMap(
131 parseArrayValue(part.slice(pos + 1), options),
132 function (encodedVal) {
133 return options.decoder(encodedVal, defaults.decoder, charset, 'value');
134 }
135 );
136 }
137
138 if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
139 val = interpretNumericEntities(val);
140 }
141
142 if (part.indexOf('[]=') > -1) {
143 val = isArray(val) ? [val] : val;
144 }
145
146 if (has.call(obj, key)) {
147 obj[key] = utils.combine(obj[key], val);
148 } else {
149 obj[key] = val;
150 }
151 }
152
153 return obj;
154};
155
156var parseObject = function (chain, val, options, valuesParsed) {
157 var leaf = valuesParsed ? val : parseArrayValue(val, options);
158
159 for (var i = chain.length - 1; i >= 0; --i) {
160 var obj;
161 var root = chain[i];
162
163 if (root === '[]' && options.parseArrays) {
164 obj = [].concat(leaf);
165 } else {
166 obj = options.plainObjects ? Object.create(null) : {};
167 var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
168 var index = parseInt(cleanRoot, 10);
169 if (!options.parseArrays && cleanRoot === '') {
170 obj = { 0: leaf };
171 } else if (
172 !isNaN(index)
173 && root !== cleanRoot
174 && String(index) === cleanRoot
175 && index >= 0
176 && (options.parseArrays && index <= options.arrayLimit)
177 ) {
178 obj = [];
179 obj[index] = leaf;
180 } else {
181 obj[cleanRoot] = leaf;
182 }
183 }
184
185 leaf = obj; // eslint-disable-line no-param-reassign
186 }
187
188 return leaf;
189};
190
191var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesParsed) {
192 if (!givenKey) {
193 return;
194 }
195
196 // Transform dot notation to bracket notation
197 var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
198
199 // The regex chunks
200
201 var brackets = /(\[[^[\]]*])/;
202 var child = /(\[[^[\]]*])/g;
203
204 // Get the parent
205
206 var segment = options.depth > 0 && brackets.exec(key);
207 var parent = segment ? key.slice(0, segment.index) : key;
208
209 // Stash the parent if it exists
210
211 var keys = [];
212 if (parent) {
213 // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
214 if (!options.plainObjects && has.call(Object.prototype, parent)) {
215 if (!options.allowPrototypes) {
216 return;
217 }
218 }
219
220 keys.push(parent);
221 }
222
223 // Loop through children appending to the array until we hit depth
224
225 var i = 0;
226 while (options.depth > 0 && (segment = child.exec(key)) !== null && i < options.depth) {
227 i += 1;
228 if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
229 if (!options.allowPrototypes) {
230 return;
231 }
232 }
233 keys.push(segment[1]);
234 }
235
236 // If there's a remainder, just add whatever is left
237
238 if (segment) {
239 keys.push('[' + key.slice(segment.index) + ']');
240 }
241
242 return parseObject(keys, val, options, valuesParsed);
243};
244
245var normalizeParseOptions = function normalizeParseOptions(opts) {
246 if (!opts) {
247 return defaults;
248 }
249
250 if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') {
251 throw new TypeError('Decoder has to be a function.');
252 }
253
254 if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
255 throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
256 }
257 var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;
258
259 return {
260 allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
261 allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes,
262 arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit,
263 charset: charset,
264 charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
265 comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma,
266 decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder,
267 delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter,
268 // eslint-disable-next-line no-implicit-coercion, no-extra-parens
269 depth: (typeof opts.depth === 'number' || opts.depth === false) ? +opts.depth : defaults.depth,
270 ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
271 interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities,
272 parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit,
273 parseArrays: opts.parseArrays !== false,
274 plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects,
275 strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
276 };
277};
278
279module.exports = function (str, opts) {
280 var options = normalizeParseOptions(opts);
281
282 if (str === '' || str === null || typeof str === 'undefined') {
283 return options.plainObjects ? Object.create(null) : {};
284 }
285
286 var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
287 var obj = options.plainObjects ? Object.create(null) : {};
288
289 // Iterate over the keys and setup the new object
290
291 var keys = Object.keys(tempObj);
292 for (var i = 0; i < keys.length; ++i) {
293 var key = keys[i];
294 var newObj = parseKeys(key, tempObj[key], options, typeof str === 'string');
295 obj = utils.merge(obj, newObj, options);
296 }
297
298 return utils.compact(obj);
299};
300
301},{"./utils":5}],4:[function(require,module,exports){
302'use strict';
303
304var utils = require('./utils');
305var formats = require('./formats');
306var has = Object.prototype.hasOwnProperty;
307
308var arrayPrefixGenerators = {
309 brackets: function brackets(prefix) {
310 return prefix + '[]';
311 },
312 comma: 'comma',
313 indices: function indices(prefix, key) {
314 return prefix + '[' + key + ']';
315 },
316 repeat: function repeat(prefix) {
317 return prefix;
318 }
319};
320
321var isArray = Array.isArray;
322var push = Array.prototype.push;
323var pushToArray = function (arr, valueOrArray) {
324 push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
325};
326
327var toISO = Date.prototype.toISOString;
328
329var defaultFormat = formats['default'];
330var defaults = {
331 addQueryPrefix: false,
332 allowDots: false,
333 charset: 'utf-8',
334 charsetSentinel: false,
335 delimiter: '&',
336 encode: true,
337 encoder: utils.encode,
338 encodeValuesOnly: false,
339 format: defaultFormat,
340 formatter: formats.formatters[defaultFormat],
341 // deprecated
342 indices: false,
343 serializeDate: function serializeDate(date) {
344 return toISO.call(date);
345 },
346 skipNulls: false,
347 strictNullHandling: false
348};
349
350var isNonNullishPrimitive = function isNonNullishPrimitive(v) {
351 return typeof v === 'string'
352 || typeof v === 'number'
353 || typeof v === 'boolean'
354 || typeof v === 'symbol'
355 || typeof v === 'bigint';
356};
357
358var stringify = function stringify(
359 object,
360 prefix,
361 generateArrayPrefix,
362 strictNullHandling,
363 skipNulls,
364 encoder,
365 filter,
366 sort,
367 allowDots,
368 serializeDate,
369 formatter,
370 encodeValuesOnly,
371 charset
372) {
373 var obj = object;
374 if (typeof filter === 'function') {
375 obj = filter(prefix, obj);
376 } else if (obj instanceof Date) {
377 obj = serializeDate(obj);
378 } else if (generateArrayPrefix === 'comma' && isArray(obj)) {
379 obj = utils.maybeMap(obj, function (value) {
380 if (value instanceof Date) {
381 return serializeDate(value);
382 }
383 return value;
384 }).join(',');
385 }
386
387 if (obj === null) {
388 if (strictNullHandling) {
389 return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key') : prefix;
390 }
391
392 obj = '';
393 }
394
395 if (isNonNullishPrimitive(obj) || utils.isBuffer(obj)) {
396 if (encoder) {
397 var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key');
398 return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value'))];
399 }
400 return [formatter(prefix) + '=' + formatter(String(obj))];
401 }
402
403 var values = [];
404
405 if (typeof obj === 'undefined') {
406 return values;
407 }
408
409 var objKeys;
410 if (isArray(filter)) {
411 objKeys = filter;
412 } else {
413 var keys = Object.keys(obj);
414 objKeys = sort ? keys.sort(sort) : keys;
415 }
416
417 for (var i = 0; i < objKeys.length; ++i) {
418 var key = objKeys[i];
419 var value = obj[key];
420
421 if (skipNulls && value === null) {
422 continue;
423 }
424
425 var keyPrefix = isArray(obj)
426 ? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix
427 : prefix + (allowDots ? '.' + key : '[' + key + ']');
428
429 pushToArray(values, stringify(
430 value,
431 keyPrefix,
432 generateArrayPrefix,
433 strictNullHandling,
434 skipNulls,
435 encoder,
436 filter,
437 sort,
438 allowDots,
439 serializeDate,
440 formatter,
441 encodeValuesOnly,
442 charset
443 ));
444 }
445
446 return values;
447};
448
449var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
450 if (!opts) {
451 return defaults;
452 }
453
454 if (opts.encoder !== null && opts.encoder !== undefined && typeof opts.encoder !== 'function') {
455 throw new TypeError('Encoder has to be a function.');
456 }
457
458 var charset = opts.charset || defaults.charset;
459 if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
460 throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
461 }
462
463 var format = formats['default'];
464 if (typeof opts.format !== 'undefined') {
465 if (!has.call(formats.formatters, opts.format)) {
466 throw new TypeError('Unknown format option provided.');
467 }
468 format = opts.format;
469 }
470 var formatter = formats.formatters[format];
471
472 var filter = defaults.filter;
473 if (typeof opts.filter === 'function' || isArray(opts.filter)) {
474 filter = opts.filter;
475 }
476
477 return {
478 addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
479 allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
480 charset: charset,
481 charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
482 delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
483 encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
484 encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
485 encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
486 filter: filter,
487 formatter: formatter,
488 serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
489 skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
490 sort: typeof opts.sort === 'function' ? opts.sort : null,
491 strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
492 };
493};
494
495module.exports = function (object, opts) {
496 var obj = object;
497 var options = normalizeStringifyOptions(opts);
498
499 var objKeys;
500 var filter;
501
502 if (typeof options.filter === 'function') {
503 filter = options.filter;
504 obj = filter('', obj);
505 } else if (isArray(options.filter)) {
506 filter = options.filter;
507 objKeys = filter;
508 }
509
510 var keys = [];
511
512 if (typeof obj !== 'object' || obj === null) {
513 return '';
514 }
515
516 var arrayFormat;
517 if (opts && opts.arrayFormat in arrayPrefixGenerators) {
518 arrayFormat = opts.arrayFormat;
519 } else if (opts && 'indices' in opts) {
520 arrayFormat = opts.indices ? 'indices' : 'repeat';
521 } else {
522 arrayFormat = 'indices';
523 }
524
525 var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
526
527 if (!objKeys) {
528 objKeys = Object.keys(obj);
529 }
530
531 if (options.sort) {
532 objKeys.sort(options.sort);
533 }
534
535 for (var i = 0; i < objKeys.length; ++i) {
536 var key = objKeys[i];
537
538 if (options.skipNulls && obj[key] === null) {
539 continue;
540 }
541 pushToArray(keys, stringify(
542 obj[key],
543 key,
544 generateArrayPrefix,
545 options.strictNullHandling,
546 options.skipNulls,
547 options.encode ? options.encoder : null,
548 options.filter,
549 options.sort,
550 options.allowDots,
551 options.serializeDate,
552 options.formatter,
553 options.encodeValuesOnly,
554 options.charset
555 ));
556 }
557
558 var joined = keys.join(options.delimiter);
559 var prefix = options.addQueryPrefix === true ? '?' : '';
560
561 if (options.charsetSentinel) {
562 if (options.charset === 'iso-8859-1') {
563 // encodeURIComponent('&#10003;'), the "numeric entity" representation of a checkmark
564 prefix += 'utf8=%26%2310003%3B&';
565 } else {
566 // encodeURIComponent('✓')
567 prefix += 'utf8=%E2%9C%93&';
568 }
569 }
570
571 return joined.length > 0 ? prefix + joined : '';
572};
573
574},{"./formats":1,"./utils":5}],5:[function(require,module,exports){
575'use strict';
576
577var has = Object.prototype.hasOwnProperty;
578var isArray = Array.isArray;
579
580var hexTable = (function () {
581 var array = [];
582 for (var i = 0; i < 256; ++i) {
583 array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
584 }
585
586 return array;
587}());
588
589var compactQueue = function compactQueue(queue) {
590 while (queue.length > 1) {
591 var item = queue.pop();
592 var obj = item.obj[item.prop];
593
594 if (isArray(obj)) {
595 var compacted = [];
596
597 for (var j = 0; j < obj.length; ++j) {
598 if (typeof obj[j] !== 'undefined') {
599 compacted.push(obj[j]);
600 }
601 }
602
603 item.obj[item.prop] = compacted;
604 }
605 }
606};
607
608var arrayToObject = function arrayToObject(source, options) {
609 var obj = options && options.plainObjects ? Object.create(null) : {};
610 for (var i = 0; i < source.length; ++i) {
611 if (typeof source[i] !== 'undefined') {
612 obj[i] = source[i];
613 }
614 }
615
616 return obj;
617};
618
619var merge = function merge(target, source, options) {
620 /* eslint no-param-reassign: 0 */
621 if (!source) {
622 return target;
623 }
624
625 if (typeof source !== 'object') {
626 if (isArray(target)) {
627 target.push(source);
628 } else if (target && typeof target === 'object') {
629 if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
630 target[source] = true;
631 }
632 } else {
633 return [target, source];
634 }
635
636 return target;
637 }
638
639 if (!target || typeof target !== 'object') {
640 return [target].concat(source);
641 }
642
643 var mergeTarget = target;
644 if (isArray(target) && !isArray(source)) {
645 mergeTarget = arrayToObject(target, options);
646 }
647
648 if (isArray(target) && isArray(source)) {
649 source.forEach(function (item, i) {
650 if (has.call(target, i)) {
651 var targetItem = target[i];
652 if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
653 target[i] = merge(targetItem, item, options);
654 } else {
655 target.push(item);
656 }
657 } else {
658 target[i] = item;
659 }
660 });
661 return target;
662 }
663
664 return Object.keys(source).reduce(function (acc, key) {
665 var value = source[key];
666
667 if (has.call(acc, key)) {
668 acc[key] = merge(acc[key], value, options);
669 } else {
670 acc[key] = value;
671 }
672 return acc;
673 }, mergeTarget);
674};
675
676var assign = function assignSingleSource(target, source) {
677 return Object.keys(source).reduce(function (acc, key) {
678 acc[key] = source[key];
679 return acc;
680 }, target);
681};
682
683var decode = function (str, decoder, charset) {
684 var strWithoutPlus = str.replace(/\+/g, ' ');
685 if (charset === 'iso-8859-1') {
686 // unescape never throws, no try...catch needed:
687 return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
688 }
689 // utf-8
690 try {
691 return decodeURIComponent(strWithoutPlus);
692 } catch (e) {
693 return strWithoutPlus;
694 }
695};
696
697var encode = function encode(str, defaultEncoder, charset) {
698 // This code was originally written by Brian White (mscdex) for the io.js core querystring library.
699 // It has been adapted here for stricter adherence to RFC 3986
700 if (str.length === 0) {
701 return str;
702 }
703
704 var string = str;
705 if (typeof str === 'symbol') {
706 string = Symbol.prototype.toString.call(str);
707 } else if (typeof str !== 'string') {
708 string = String(str);
709 }
710
711 if (charset === 'iso-8859-1') {
712 return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
713 return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
714 });
715 }
716
717 var out = '';
718 for (var i = 0; i < string.length; ++i) {
719 var c = string.charCodeAt(i);
720
721 if (
722 c === 0x2D // -
723 || c === 0x2E // .
724 || c === 0x5F // _
725 || c === 0x7E // ~
726 || (c >= 0x30 && c <= 0x39) // 0-9
727 || (c >= 0x41 && c <= 0x5A) // a-z
728 || (c >= 0x61 && c <= 0x7A) // A-Z
729 ) {
730 out += string.charAt(i);
731 continue;
732 }
733
734 if (c < 0x80) {
735 out = out + hexTable[c];
736 continue;
737 }
738
739 if (c < 0x800) {
740 out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
741 continue;
742 }
743
744 if (c < 0xD800 || c >= 0xE000) {
745 out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
746 continue;
747 }
748
749 i += 1;
750 c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
751 out += hexTable[0xF0 | (c >> 18)]
752 + hexTable[0x80 | ((c >> 12) & 0x3F)]
753 + hexTable[0x80 | ((c >> 6) & 0x3F)]
754 + hexTable[0x80 | (c & 0x3F)];
755 }
756
757 return out;
758};
759
760var compact = function compact(value) {
761 var queue = [{ obj: { o: value }, prop: 'o' }];
762 var refs = [];
763
764 for (var i = 0; i < queue.length; ++i) {
765 var item = queue[i];
766 var obj = item.obj[item.prop];
767
768 var keys = Object.keys(obj);
769 for (var j = 0; j < keys.length; ++j) {
770 var key = keys[j];
771 var val = obj[key];
772 if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
773 queue.push({ obj: obj, prop: key });
774 refs.push(val);
775 }
776 }
777 }
778
779 compactQueue(queue);
780
781 return value;
782};
783
784var isRegExp = function isRegExp(obj) {
785 return Object.prototype.toString.call(obj) === '[object RegExp]';
786};
787
788var isBuffer = function isBuffer(obj) {
789 if (!obj || typeof obj !== 'object') {
790 return false;
791 }
792
793 return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
794};
795
796var combine = function combine(a, b) {
797 return [].concat(a, b);
798};
799
800var maybeMap = function maybeMap(val, fn) {
801 if (isArray(val)) {
802 var mapped = [];
803 for (var i = 0; i < val.length; i += 1) {
804 mapped.push(fn(val[i]));
805 }
806 return mapped;
807 }
808 return fn(val);
809};
810
811module.exports = {
812 arrayToObject: arrayToObject,
813 assign: assign,
814 combine: combine,
815 compact: compact,
816 decode: decode,
817 encode: encode,
818 isBuffer: isBuffer,
819 isRegExp: isRegExp,
820 maybeMap: maybeMap,
821 merge: merge
822};
823
824},{}]},{},[2])(2)
825});