Initial commit
[yaffs-website] / node_modules / tiny-lr / node_modules / qs / dist / qs.js
1 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Qs = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2 // Load modules
3
4 var Stringify = require('./stringify');
5 var Parse = require('./parse');
6
7
8 // Declare internals
9
10 var internals = {};
11
12
13 module.exports = {
14     stringify: Stringify,
15     parse: Parse
16 };
17
18 },{"./parse":2,"./stringify":3}],2:[function(require,module,exports){
19 // Load modules
20
21 var Utils = require('./utils');
22
23
24 // Declare internals
25
26 var internals = {
27     delimiter: '&',
28     depth: 5,
29     arrayLimit: 20,
30     parameterLimit: 1000,
31     strictNullHandling: false,
32     plainObjects: false,
33     allowPrototypes: false,
34     allowDots: false
35 };
36
37
38 internals.parseValues = function (str, options) {
39
40     var obj = {};
41     var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
42
43     for (var i = 0, il = parts.length; i < il; ++i) {
44         var part = parts[i];
45         var pos = part.indexOf(']=') === -1 ? part.indexOf('=') : part.indexOf(']=') + 1;
46
47         if (pos === -1) {
48             obj[Utils.decode(part)] = '';
49
50             if (options.strictNullHandling) {
51                 obj[Utils.decode(part)] = null;
52             }
53         }
54         else {
55             var key = Utils.decode(part.slice(0, pos));
56             var val = Utils.decode(part.slice(pos + 1));
57
58             if (!Object.prototype.hasOwnProperty.call(obj, key)) {
59                 obj[key] = val;
60             }
61             else {
62                 obj[key] = [].concat(obj[key]).concat(val);
63             }
64         }
65     }
66
67     return obj;
68 };
69
70
71 internals.parseObject = function (chain, val, options) {
72
73     if (!chain.length) {
74         return val;
75     }
76
77     var root = chain.shift();
78
79     var obj;
80     if (root === '[]') {
81         obj = [];
82         obj = obj.concat(internals.parseObject(chain, val, options));
83     }
84     else {
85         obj = options.plainObjects ? Object.create(null) : {};
86         var cleanRoot = root[0] === '[' && root[root.length - 1] === ']' ? root.slice(1, root.length - 1) : root;
87         var index = parseInt(cleanRoot, 10);
88         var indexString = '' + index;
89         if (!isNaN(index) &&
90             root !== cleanRoot &&
91             indexString === cleanRoot &&
92             index >= 0 &&
93             (options.parseArrays &&
94              index <= options.arrayLimit)) {
95
96             obj = [];
97             obj[index] = internals.parseObject(chain, val, options);
98         }
99         else {
100             obj[cleanRoot] = internals.parseObject(chain, val, options);
101         }
102     }
103
104     return obj;
105 };
106
107
108 internals.parseKeys = function (key, val, options) {
109
110     if (!key) {
111         return;
112     }
113
114     // Transform dot notation to bracket notation
115
116     if (options.allowDots) {
117         key = key.replace(/\.([^\.\[]+)/g, '[$1]');
118     }
119
120     // The regex chunks
121
122     var parent = /^([^\[\]]*)/;
123     var child = /(\[[^\[\]]*\])/g;
124
125     // Get the parent
126
127     var segment = parent.exec(key);
128
129     // Stash the parent if it exists
130
131     var keys = [];
132     if (segment[1]) {
133         // If we aren't using plain objects, optionally prefix keys
134         // that would overwrite object prototype properties
135         if (!options.plainObjects &&
136             Object.prototype.hasOwnProperty(segment[1])) {
137
138             if (!options.allowPrototypes) {
139                 return;
140             }
141         }
142
143         keys.push(segment[1]);
144     }
145
146     // Loop through children appending to the array until we hit depth
147
148     var i = 0;
149     while ((segment = child.exec(key)) !== null && i < options.depth) {
150
151         ++i;
152         if (!options.plainObjects &&
153             Object.prototype.hasOwnProperty(segment[1].replace(/\[|\]/g, ''))) {
154
155             if (!options.allowPrototypes) {
156                 continue;
157             }
158         }
159         keys.push(segment[1]);
160     }
161
162     // If there's a remainder, just add whatever is left
163
164     if (segment) {
165         keys.push('[' + key.slice(segment.index) + ']');
166     }
167
168     return internals.parseObject(keys, val, options);
169 };
170
171
172 module.exports = function (str, options) {
173
174     options = options || {};
175     options.delimiter = typeof options.delimiter === 'string' || Utils.isRegExp(options.delimiter) ? options.delimiter : internals.delimiter;
176     options.depth = typeof options.depth === 'number' ? options.depth : internals.depth;
177     options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : internals.arrayLimit;
178     options.parseArrays = options.parseArrays !== false;
179     options.allowDots = typeof options.allowDots === 'boolean' ? options.allowDots : internals.allowDots;
180     options.plainObjects = typeof options.plainObjects === 'boolean' ? options.plainObjects : internals.plainObjects;
181     options.allowPrototypes = typeof options.allowPrototypes === 'boolean' ? options.allowPrototypes : internals.allowPrototypes;
182     options.parameterLimit = typeof options.parameterLimit === 'number' ? options.parameterLimit : internals.parameterLimit;
183     options.strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : internals.strictNullHandling;
184
185     if (str === '' ||
186         str === null ||
187         typeof str === 'undefined') {
188
189         return options.plainObjects ? Object.create(null) : {};
190     }
191
192     var tempObj = typeof str === 'string' ? internals.parseValues(str, options) : str;
193     var obj = options.plainObjects ? Object.create(null) : {};
194
195     // Iterate over the keys and setup the new object
196
197     var keys = Object.keys(tempObj);
198     for (var i = 0, il = keys.length; i < il; ++i) {
199         var key = keys[i];
200         var newObj = internals.parseKeys(key, tempObj[key], options);
201         obj = Utils.merge(obj, newObj, options);
202     }
203
204     return Utils.compact(obj);
205 };
206
207 },{"./utils":4}],3:[function(require,module,exports){
208 // Load modules
209
210 var Utils = require('./utils');
211
212
213 // Declare internals
214
215 var internals = {
216     delimiter: '&',
217     arrayPrefixGenerators: {
218         brackets: function (prefix, key) {
219
220             return prefix + '[]';
221         },
222         indices: function (prefix, key) {
223
224             return prefix + '[' + key + ']';
225         },
226         repeat: function (prefix, key) {
227
228             return prefix;
229         }
230     },
231     strictNullHandling: false
232 };
233
234
235 internals.stringify = function (obj, prefix, generateArrayPrefix, strictNullHandling, filter) {
236
237     if (typeof filter === 'function') {
238         obj = filter(prefix, obj);
239     }
240     else if (Utils.isBuffer(obj)) {
241         obj = obj.toString();
242     }
243     else if (obj instanceof Date) {
244         obj = obj.toISOString();
245     }
246     else if (obj === null) {
247         if (strictNullHandling) {
248             return Utils.encode(prefix);
249         }
250
251         obj = '';
252     }
253
254     if (typeof obj === 'string' ||
255         typeof obj === 'number' ||
256         typeof obj === 'boolean') {
257
258         return [Utils.encode(prefix) + '=' + Utils.encode(obj)];
259     }
260
261     var values = [];
262
263     if (typeof obj === 'undefined') {
264         return values;
265     }
266
267     var objKeys = Array.isArray(filter) ? filter : Object.keys(obj);
268     for (var i = 0, il = objKeys.length; i < il; ++i) {
269         var key = objKeys[i];
270
271         if (Array.isArray(obj)) {
272             values = values.concat(internals.stringify(obj[key], generateArrayPrefix(prefix, key), generateArrayPrefix, strictNullHandling, filter));
273         }
274         else {
275             values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']', generateArrayPrefix, strictNullHandling, filter));
276         }
277     }
278
279     return values;
280 };
281
282
283 module.exports = function (obj, options) {
284
285     options = options || {};
286     var delimiter = typeof options.delimiter === 'undefined' ? internals.delimiter : options.delimiter;
287     var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : internals.strictNullHandling;
288     var objKeys;
289     var filter;
290     if (typeof options.filter === 'function') {
291         filter = options.filter;
292         obj = filter('', obj);
293     }
294     else if (Array.isArray(options.filter)) {
295         objKeys = filter = options.filter;
296     }
297
298     var keys = [];
299
300     if (typeof obj !== 'object' ||
301         obj === null) {
302
303         return '';
304     }
305
306     var arrayFormat;
307     if (options.arrayFormat in internals.arrayPrefixGenerators) {
308         arrayFormat = options.arrayFormat;
309     }
310     else if ('indices' in options) {
311         arrayFormat = options.indices ? 'indices' : 'repeat';
312     }
313     else {
314         arrayFormat = 'indices';
315     }
316
317     var generateArrayPrefix = internals.arrayPrefixGenerators[arrayFormat];
318
319     if (!objKeys) {
320         objKeys = Object.keys(obj);
321     }
322     for (var i = 0, il = objKeys.length; i < il; ++i) {
323         var key = objKeys[i];
324         keys = keys.concat(internals.stringify(obj[key], key, generateArrayPrefix, strictNullHandling, filter));
325     }
326
327     return keys.join(delimiter);
328 };
329
330 },{"./utils":4}],4:[function(require,module,exports){
331 // Load modules
332
333
334 // Declare internals
335
336 var internals = {};
337 internals.hexTable = new Array(256);
338 for (var h = 0; h < 256; ++h) {
339     internals.hexTable[h] = '%' + ((h < 16 ? '0' : '') + h.toString(16)).toUpperCase();
340 }
341
342
343 exports.arrayToObject = function (source, options) {
344
345     var obj = options.plainObjects ? Object.create(null) : {};
346     for (var i = 0, il = source.length; i < il; ++i) {
347         if (typeof source[i] !== 'undefined') {
348
349             obj[i] = source[i];
350         }
351     }
352
353     return obj;
354 };
355
356
357 exports.merge = function (target, source, options) {
358
359     if (!source) {
360         return target;
361     }
362
363     if (typeof source !== 'object') {
364         if (Array.isArray(target)) {
365             target.push(source);
366         }
367         else if (typeof target === 'object') {
368             target[source] = true;
369         }
370         else {
371             target = [target, source];
372         }
373
374         return target;
375     }
376
377     if (typeof target !== 'object') {
378         target = [target].concat(source);
379         return target;
380     }
381
382     if (Array.isArray(target) &&
383         !Array.isArray(source)) {
384
385         target = exports.arrayToObject(target, options);
386     }
387
388     var keys = Object.keys(source);
389     for (var k = 0, kl = keys.length; k < kl; ++k) {
390         var key = keys[k];
391         var value = source[key];
392
393         if (!Object.prototype.hasOwnProperty.call(target, key)) {
394             target[key] = value;
395         }
396         else {
397             target[key] = exports.merge(target[key], value, options);
398         }
399     }
400
401     return target;
402 };
403
404
405 exports.decode = function (str) {
406
407     try {
408         return decodeURIComponent(str.replace(/\+/g, ' '));
409     } catch (e) {
410         return str;
411     }
412 };
413
414 exports.encode = function (str) {
415
416     // This code was originally written by Brian White (mscdex) for the io.js core querystring library.
417     // It has been adapted here for stricter adherence to RFC 3986
418     if (str.length === 0) {
419         return str;
420     }
421
422     if (typeof str !== 'string') {
423         str = '' + str;
424     }
425
426     var out = '';
427     for (var i = 0, il = str.length; i < il; ++i) {
428         var c = str.charCodeAt(i);
429
430         if (c === 0x2D || // -
431             c === 0x2E || // .
432             c === 0x5F || // _
433             c === 0x7E || // ~
434             (c >= 0x30 && c <= 0x39) || // 0-9
435             (c >= 0x41 && c <= 0x5A) || // a-z
436             (c >= 0x61 && c <= 0x7A)) { // A-Z
437
438             out += str[i];
439             continue;
440         }
441
442         if (c < 0x80) {
443             out += internals.hexTable[c];
444             continue;
445         }
446
447         if (c < 0x800) {
448             out += internals.hexTable[0xC0 | (c >> 6)] + internals.hexTable[0x80 | (c & 0x3F)];
449             continue;
450         }
451
452         if (c < 0xD800 || c >= 0xE000) {
453             out += internals.hexTable[0xE0 | (c >> 12)] + internals.hexTable[0x80 | ((c >> 6) & 0x3F)] + internals.hexTable[0x80 | (c & 0x3F)];
454             continue;
455         }
456
457         ++i;
458         c = 0x10000 + (((c & 0x3FF) << 10) | (str.charCodeAt(i) & 0x3FF));
459         out += internals.hexTable[0xF0 | (c >> 18)] + internals.hexTable[0x80 | ((c >> 12) & 0x3F)] + internals.hexTable[0x80 | ((c >> 6) & 0x3F)] + internals.hexTable[0x80 | (c & 0x3F)];
460     }
461
462     return out;
463 };
464
465 exports.compact = function (obj, refs) {
466
467     if (typeof obj !== 'object' ||
468         obj === null) {
469
470         return obj;
471     }
472
473     refs = refs || [];
474     var lookup = refs.indexOf(obj);
475     if (lookup !== -1) {
476         return refs[lookup];
477     }
478
479     refs.push(obj);
480
481     if (Array.isArray(obj)) {
482         var compacted = [];
483
484         for (var i = 0, il = obj.length; i < il; ++i) {
485             if (typeof obj[i] !== 'undefined') {
486                 compacted.push(obj[i]);
487             }
488         }
489
490         return compacted;
491     }
492
493     var keys = Object.keys(obj);
494     for (i = 0, il = keys.length; i < il; ++i) {
495         var key = keys[i];
496         obj[key] = exports.compact(obj[key], refs);
497     }
498
499     return obj;
500 };
501
502
503 exports.isRegExp = function (obj) {
504
505     return Object.prototype.toString.call(obj) === '[object RegExp]';
506 };
507
508
509 exports.isBuffer = function (obj) {
510
511     if (obj === null ||
512         typeof obj === 'undefined') {
513
514         return false;
515     }
516
517     return !!(obj.constructor &&
518               obj.constructor.isBuffer &&
519               obj.constructor.isBuffer(obj));
520 };
521
522 },{}]},{},[1])(1)
523 });