You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

782 lines
24 KiB

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