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