3 var has = Object.prototype.hasOwnProperty;
4 var isArray = Array.isArray;
6 var hexTable = (function () {
8 for (var i = 0; i < 256; ++i) {
9 array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
15 var compactQueue = function compactQueue(queue) {
16 while (queue.length > 1) {
17 var item = queue.pop();
18 var obj = item.obj[item.prop];
23 for (var j = 0; j < obj.length; ++j) {
24 if (typeof obj[j] !== 'undefined') {
25 compacted.push(obj[j]);
29 item.obj[item.prop] = compacted;
34 var arrayToObject = function arrayToObject(source, options) {
35 var obj = options && options.plainObjects ? Object.create(null) : {};
36 for (var i = 0; i < source.length; ++i) {
37 if (typeof source[i] !== 'undefined') {
45 var merge = function merge(target, source, options) {
50 if (typeof source !== 'object') {
51 if (isArray(target)) {
53 } else if (target && typeof target === 'object') {
54 if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
55 target[source] = true;
58 return [target, source];
64 if (!target || typeof target !== 'object') {
65 return [target].concat(source);
68 var mergeTarget = target;
69 if (isArray(target) && !isArray(source)) {
70 mergeTarget = arrayToObject(target, options);
73 if (isArray(target) && isArray(source)) {
74 source.forEach(function (item, i) {
75 if (has.call(target, i)) {
76 var targetItem = target[i];
77 if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
78 target[i] = merge(targetItem, item, options);
89 return Object.keys(source).reduce(function (acc, key) {
90 var value = source[key];
92 if (has.call(acc, key)) {
93 acc[key] = merge(acc[key], value, options);
101 var assign = function assignSingleSource(target, source) {
102 return Object.keys(source).reduce(function (acc, key) {
103 acc[key] = source[key];
108 var decode = function (str, decoder, charset) {
109 var strWithoutPlus = str.replace(/\+/g, ' ');
110 if (charset === 'iso-8859-1') {
111 // unescape never throws, no try...catch needed:
112 return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
116 return decodeURIComponent(strWithoutPlus);
118 return strWithoutPlus;
122 var encode = function encode(str, defaultEncoder, charset) {
123 // This code was originally written by Brian White (mscdex) for the io.js core querystring library.
124 // It has been adapted here for stricter adherence to RFC 3986
125 if (str.length === 0) {
129 var string = typeof str === 'string' ? str : String(str);
131 if (charset === 'iso-8859-1') {
132 return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
133 return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
138 for (var i = 0; i < string.length; ++i) {
139 var c = string.charCodeAt(i);
146 || (c >= 0x30 && c <= 0x39) // 0-9
147 || (c >= 0x41 && c <= 0x5A) // a-z
148 || (c >= 0x61 && c <= 0x7A) // A-Z
150 out += string.charAt(i);
155 out = out + hexTable[c];
160 out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
164 if (c < 0xD800 || c >= 0xE000) {
165 out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
170 c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
171 out += hexTable[0xF0 | (c >> 18)]
172 + hexTable[0x80 | ((c >> 12) & 0x3F)]
173 + hexTable[0x80 | ((c >> 6) & 0x3F)]
174 + hexTable[0x80 | (c & 0x3F)];
180 var compact = function compact(value) {
181 var queue = [{ obj: { o: value }, prop: 'o' }];
184 for (var i = 0; i < queue.length; ++i) {
186 var obj = item.obj[item.prop];
188 var keys = Object.keys(obj);
189 for (var j = 0; j < keys.length; ++j) {
192 if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
193 queue.push({ obj: obj, prop: key });
204 var isRegExp = function isRegExp(obj) {
205 return Object.prototype.toString.call(obj) === '[object RegExp]';
208 var isBuffer = function isBuffer(obj) {
209 if (!obj || typeof obj !== 'object') {
213 return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
216 var combine = function combine(a, b) {
217 return [].concat(a, b);
221 arrayToObject: arrayToObject,