PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/ajax/libs//2.2.0/analytics.js

https://gitlab.com/Mirros/cdnjs
JavaScript | 2352 lines | 1390 code | 308 blank | 654 comment | 152 complexity | 461c638117f2a7ad97fcc661f6b19c9b MD5 | raw file
  1. (function outer(modules, cache, entries){
  2. /**
  3. * Global
  4. */
  5. var global = (function(){ return this; })();
  6. /**
  7. * Require `name`.
  8. *
  9. * @param {String} name
  10. * @param {Boolean} jumped
  11. * @api public
  12. */
  13. function require(name, jumped){
  14. if (cache[name]) return cache[name].exports;
  15. if (modules[name]) return call(name, require);
  16. throw new Error('cannot find module "' + name + '"');
  17. }
  18. /**
  19. * Call module `id` and cache it.
  20. *
  21. * @param {Number} id
  22. * @param {Function} require
  23. * @return {Function}
  24. * @api private
  25. */
  26. function call(id, require){
  27. var m = cache[id] = { exports: {} };
  28. var mod = modules[id];
  29. var name = mod[2];
  30. var fn = mod[0];
  31. fn.call(m.exports, function(req){
  32. var dep = modules[id][1][req];
  33. return require(dep ? dep : req);
  34. }, m, m.exports, outer, modules, cache, entries);
  35. // expose as `name`.
  36. if (name) cache[name] = cache[id];
  37. return cache[id].exports;
  38. }
  39. /**
  40. * Require all entries exposing them on global if needed.
  41. */
  42. for (var id in entries) {
  43. if (entries[id]) {
  44. global[entries[id]] = require(id);
  45. } else {
  46. require(id);
  47. }
  48. }
  49. /**
  50. * Duo flag.
  51. */
  52. require.duo = true;
  53. /**
  54. * Expose cache.
  55. */
  56. require.cache = cache;
  57. /**
  58. * Expose modules
  59. */
  60. require.modules = modules;
  61. /**
  62. * Return newest require.
  63. */
  64. return require;
  65. })({
  66. 1: [function(require, module, exports) {
  67. /**
  68. * Expose `defaults`.
  69. */
  70. module.exports = defaults;
  71. function defaults (dest, defaults) {
  72. for (var prop in defaults) {
  73. if (! (prop in dest)) {
  74. dest[prop] = defaults[prop];
  75. }
  76. }
  77. return dest;
  78. };
  79. }, {}],
  80. 2: [function(require, module, exports) {
  81. 'use strict';
  82. /**
  83. * Merge default values.
  84. *
  85. * @param {Object} dest
  86. * @param {Object} defaults
  87. * @return {Object}
  88. * @api public
  89. */
  90. var defaults = function (dest, src, recursive) {
  91. for (var prop in src) {
  92. if (recursive && dest[prop] instanceof Object && src[prop] instanceof Object) {
  93. dest[prop] = defaults(dest[prop], src[prop], true);
  94. } else if (! (prop in dest)) {
  95. dest[prop] = src[prop];
  96. }
  97. }
  98. return dest;
  99. };
  100. /**
  101. * Expose `defaults`.
  102. */
  103. module.exports = defaults;
  104. }, {}],
  105. 3: [function(require, module, exports) {
  106. /**
  107. * Slice reference.
  108. */
  109. var slice = [].slice;
  110. /**
  111. * Bind `obj` to `fn`.
  112. *
  113. * @param {Object} obj
  114. * @param {Function|String} fn or string
  115. * @return {Function}
  116. * @api public
  117. */
  118. module.exports = function(obj, fn){
  119. if ('string' == typeof fn) fn = obj[fn];
  120. if ('function' != typeof fn) throw new Error('bind() requires a function');
  121. var args = slice.call(arguments, 2);
  122. return function(){
  123. return fn.apply(obj, args.concat(slice.call(arguments)));
  124. }
  125. };
  126. }, {}],
  127. 4: [function(require, module, exports) {
  128. /**
  129. * Module dependencies.
  130. */
  131. var type;
  132. try {
  133. type = require('type');
  134. } catch(e){
  135. type = require('type-component');
  136. }
  137. /**
  138. * Module exports.
  139. */
  140. module.exports = clone;
  141. /**
  142. * Clones objects.
  143. *
  144. * @param {Mixed} any object
  145. * @api public
  146. */
  147. function clone(obj){
  148. switch (type(obj)) {
  149. case 'object':
  150. var copy = {};
  151. for (var key in obj) {
  152. if (obj.hasOwnProperty(key)) {
  153. copy[key] = clone(obj[key]);
  154. }
  155. }
  156. return copy;
  157. case 'array':
  158. var copy = new Array(obj.length);
  159. for (var i = 0, l = obj.length; i < l; i++) {
  160. copy[i] = clone(obj[i]);
  161. }
  162. return copy;
  163. case 'regexp':
  164. // from millermedeiros/amd-utils - MIT
  165. var flags = '';
  166. flags += obj.multiline ? 'm' : '';
  167. flags += obj.global ? 'g' : '';
  168. flags += obj.ignoreCase ? 'i' : '';
  169. return new RegExp(obj.source, flags);
  170. case 'date':
  171. return new Date(obj.getTime());
  172. default: // string, number, boolean, …
  173. return obj;
  174. }
  175. }
  176. }, {"type":5}],
  177. 6: [function(require, module, exports) {
  178. /**
  179. * Module dependencies.
  180. */
  181. var type;
  182. try {
  183. type = require('type');
  184. } catch(e){
  185. type = require('type-component');
  186. }
  187. /**
  188. * Module exports.
  189. */
  190. module.exports = clone;
  191. /**
  192. * Clones objects.
  193. *
  194. * @param {Mixed} any object
  195. * @api public
  196. */
  197. function clone(obj){
  198. switch (type(obj)) {
  199. case 'object':
  200. var copy = {};
  201. for (var key in obj) {
  202. if (obj.hasOwnProperty(key)) {
  203. copy[key] = clone(obj[key]);
  204. }
  205. }
  206. return copy;
  207. case 'array':
  208. var copy = new Array(obj.length);
  209. for (var i = 0, l = obj.length; i < l; i++) {
  210. copy[i] = clone(obj[i]);
  211. }
  212. return copy;
  213. case 'regexp':
  214. // from millermedeiros/amd-utils - MIT
  215. var flags = '';
  216. flags += obj.multiline ? 'm' : '';
  217. flags += obj.global ? 'g' : '';
  218. flags += obj.ignoreCase ? 'i' : '';
  219. return new RegExp(obj.source, flags);
  220. case 'date':
  221. return new Date(obj.getTime());
  222. default: // string, number, boolean, …
  223. return obj;
  224. }
  225. }
  226. }, {"type":5}],
  227. 7: [function(require, module, exports) {
  228. /**
  229. * Module dependencies.
  230. */
  231. var type;
  232. try {
  233. type = require('component-type');
  234. } catch (_) {
  235. type = require('type');
  236. }
  237. /**
  238. * Module exports.
  239. */
  240. module.exports = clone;
  241. /**
  242. * Clones objects.
  243. *
  244. * @param {Mixed} any object
  245. * @api public
  246. */
  247. function clone(obj){
  248. switch (type(obj)) {
  249. case 'object':
  250. var copy = {};
  251. for (var key in obj) {
  252. if (obj.hasOwnProperty(key)) {
  253. copy[key] = clone(obj[key]);
  254. }
  255. }
  256. return copy;
  257. case 'array':
  258. var copy = new Array(obj.length);
  259. for (var i = 0, l = obj.length; i < l; i++) {
  260. copy[i] = clone(obj[i]);
  261. }
  262. return copy;
  263. case 'regexp':
  264. // from millermedeiros/amd-utils - MIT
  265. var flags = '';
  266. flags += obj.multiline ? 'm' : '';
  267. flags += obj.global ? 'g' : '';
  268. flags += obj.ignoreCase ? 'i' : '';
  269. return new RegExp(obj.source, flags);
  270. case 'date':
  271. return new Date(obj.getTime());
  272. default: // string, number, boolean, …
  273. return obj;
  274. }
  275. }
  276. }, {"component-type":5,"type":5}],
  277. 8: [function(require, module, exports) {
  278. /**
  279. * Encode.
  280. */
  281. var encode = encodeURIComponent;
  282. /**
  283. * Decode.
  284. */
  285. var decode = decodeURIComponent;
  286. /**
  287. * Set or get cookie `name` with `value` and `options` object.
  288. *
  289. * @param {String} name
  290. * @param {String} value
  291. * @param {Object} options
  292. * @return {Mixed}
  293. * @api public
  294. */
  295. module.exports = function(name, value, options){
  296. switch (arguments.length) {
  297. case 3:
  298. case 2:
  299. return set(name, value, options);
  300. case 1:
  301. return get(name);
  302. default:
  303. return all();
  304. }
  305. };
  306. /**
  307. * Set cookie `name` to `value`.
  308. *
  309. * @param {String} name
  310. * @param {String} value
  311. * @param {Object} options
  312. * @api private
  313. */
  314. function set(name, value, options) {
  315. options = options || {};
  316. var str = encode(name) + '=' + encode(value);
  317. if (null == value) options.maxage = -1;
  318. if (options.maxage) {
  319. options.expires = new Date(+new Date + options.maxage);
  320. }
  321. if (options.path) str += '; path=' + options.path;
  322. if (options.domain) str += '; domain=' + options.domain;
  323. if (options.expires) str += '; expires=' + options.expires.toGMTString();
  324. if (options.secure) str += '; secure';
  325. document.cookie = str;
  326. }
  327. /**
  328. * Return all cookies.
  329. *
  330. * @return {Object}
  331. * @api private
  332. */
  333. function all() {
  334. return parse(document.cookie);
  335. }
  336. /**
  337. * Get cookie `name`.
  338. *
  339. * @param {String} name
  340. * @return {String}
  341. * @api private
  342. */
  343. function get(name) {
  344. return all()[name];
  345. }
  346. /**
  347. * Parse cookie `str`.
  348. *
  349. * @param {String} str
  350. * @return {Object}
  351. * @api private
  352. */
  353. function parse(str) {
  354. var obj = {};
  355. var pairs = str.split(/ *; */);
  356. var pair;
  357. if ('' == pairs[0]) return obj;
  358. for (var i = 0; i < pairs.length; ++i) {
  359. pair = pairs[i].split('=');
  360. obj[decode(pair[0])] = decode(pair[1]);
  361. }
  362. return obj;
  363. }
  364. }, {}],
  365. 9: [function(require, module, exports) {
  366. /**
  367. * Expose `parse`.
  368. */
  369. module.exports = parse;
  370. /**
  371. * Wrap map from jquery.
  372. */
  373. var map = {
  374. legend: [1, '<fieldset>', '</fieldset>'],
  375. tr: [2, '<table><tbody>', '</tbody></table>'],
  376. col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
  377. _default: [0, '', '']
  378. };
  379. map.td =
  380. map.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
  381. map.option =
  382. map.optgroup = [1, '<select multiple="multiple">', '</select>'];
  383. map.thead =
  384. map.tbody =
  385. map.colgroup =
  386. map.caption =
  387. map.tfoot = [1, '<table>', '</table>'];
  388. map.text =
  389. map.circle =
  390. map.ellipse =
  391. map.line =
  392. map.path =
  393. map.polygon =
  394. map.polyline =
  395. map.rect = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>'];
  396. /**
  397. * Parse `html` and return the children.
  398. *
  399. * @param {String} html
  400. * @return {Array}
  401. * @api private
  402. */
  403. function parse(html) {
  404. if ('string' != typeof html) throw new TypeError('String expected');
  405. html = html.replace(/^\s+|\s+$/g, ''); // Remove leading/trailing whitespace
  406. // tag name
  407. var m = /<([\w:]+)/.exec(html);
  408. if (!m) return document.createTextNode(html);
  409. var tag = m[1];
  410. // body support
  411. if (tag == 'body') {
  412. var el = document.createElement('html');
  413. el.innerHTML = html;
  414. return el.removeChild(el.lastChild);
  415. }
  416. // wrap map
  417. var wrap = map[tag] || map._default;
  418. var depth = wrap[0];
  419. var prefix = wrap[1];
  420. var suffix = wrap[2];
  421. var el = document.createElement('div');
  422. el.innerHTML = prefix + html + suffix;
  423. while (depth--) el = el.lastChild;
  424. // one element
  425. if (el.firstChild == el.lastChild) {
  426. return el.removeChild(el.firstChild);
  427. }
  428. // several elements
  429. var fragment = document.createDocumentFragment();
  430. while (el.firstChild) {
  431. fragment.appendChild(el.removeChild(el.firstChild));
  432. }
  433. return fragment;
  434. }
  435. }, {}],
  436. 10: [function(require, module, exports) {
  437. /**
  438. * Module dependencies.
  439. */
  440. var type = require('type');
  441. /**
  442. * HOP reference.
  443. */
  444. var has = Object.prototype.hasOwnProperty;
  445. /**
  446. * Iterate the given `obj` and invoke `fn(val, i)`.
  447. *
  448. * @param {String|Array|Object} obj
  449. * @param {Function} fn
  450. * @api public
  451. */
  452. module.exports = function(obj, fn){
  453. switch (type(obj)) {
  454. case 'array':
  455. return array(obj, fn);
  456. case 'object':
  457. if ('number' == typeof obj.length) return array(obj, fn);
  458. return object(obj, fn);
  459. case 'string':
  460. return string(obj, fn);
  461. }
  462. };
  463. /**
  464. * Iterate string chars.
  465. *
  466. * @param {String} obj
  467. * @param {Function} fn
  468. * @api private
  469. */
  470. function string(obj, fn) {
  471. for (var i = 0; i < obj.length; ++i) {
  472. fn(obj.charAt(i), i);
  473. }
  474. }
  475. /**
  476. * Iterate object keys.
  477. *
  478. * @param {Object} obj
  479. * @param {Function} fn
  480. * @api private
  481. */
  482. function object(obj, fn) {
  483. for (var key in obj) {
  484. if (has.call(obj, key)) {
  485. fn(key, obj[key]);
  486. }
  487. }
  488. }
  489. /**
  490. * Iterate array-ish.
  491. *
  492. * @param {Array|Object} obj
  493. * @param {Function} fn
  494. * @api private
  495. */
  496. function array(obj, fn) {
  497. for (var i = 0; i < obj.length; ++i) {
  498. fn(obj[i], i);
  499. }
  500. }
  501. }, {"type":5}],
  502. 11: [function(require, module, exports) {
  503. /**
  504. * Module dependencies.
  505. */
  506. var type = require('type');
  507. var toFunction = require('to-function');
  508. /**
  509. * HOP reference.
  510. */
  511. var has = Object.prototype.hasOwnProperty;
  512. /**
  513. * Iterate the given `obj` and invoke `fn(val, i)`
  514. * in optional context `ctx`.
  515. *
  516. * @param {String|Array|Object} obj
  517. * @param {Function} fn
  518. * @param {Object} [ctx]
  519. * @api public
  520. */
  521. module.exports = function(obj, fn, ctx){
  522. fn = toFunction(fn);
  523. ctx = ctx || this;
  524. switch (type(obj)) {
  525. case 'array':
  526. return array(obj, fn, ctx);
  527. case 'object':
  528. if ('number' == typeof obj.length) return array(obj, fn, ctx);
  529. return object(obj, fn, ctx);
  530. case 'string':
  531. return string(obj, fn, ctx);
  532. }
  533. };
  534. /**
  535. * Iterate string chars.
  536. *
  537. * @param {String} obj
  538. * @param {Function} fn
  539. * @param {Object} ctx
  540. * @api private
  541. */
  542. function string(obj, fn, ctx) {
  543. for (var i = 0; i < obj.length; ++i) {
  544. fn.call(ctx, obj.charAt(i), i);
  545. }
  546. }
  547. /**
  548. * Iterate object keys.
  549. *
  550. * @param {Object} obj
  551. * @param {Function} fn
  552. * @param {Object} ctx
  553. * @api private
  554. */
  555. function object(obj, fn, ctx) {
  556. for (var key in obj) {
  557. if (has.call(obj, key)) {
  558. fn.call(ctx, key, obj[key]);
  559. }
  560. }
  561. }
  562. /**
  563. * Iterate array-ish.
  564. *
  565. * @param {Array|Object} obj
  566. * @param {Function} fn
  567. * @param {Object} ctx
  568. * @api private
  569. */
  570. function array(obj, fn, ctx) {
  571. for (var i = 0; i < obj.length; ++i) {
  572. fn.call(ctx, obj[i], i);
  573. }
  574. }
  575. }, {"type":5,"to-function":12}],
  576. 13: [function(require, module, exports) {
  577. /**
  578. * Module dependencies.
  579. */
  580. var index = require('indexof');
  581. /**
  582. * Expose `Emitter`.
  583. */
  584. module.exports = Emitter;
  585. /**
  586. * Initialize a new `Emitter`.
  587. *
  588. * @api public
  589. */
  590. function Emitter(obj) {
  591. if (obj) return mixin(obj);
  592. };
  593. /**
  594. * Mixin the emitter properties.
  595. *
  596. * @param {Object} obj
  597. * @return {Object}
  598. * @api private
  599. */
  600. function mixin(obj) {
  601. for (var key in Emitter.prototype) {
  602. obj[key] = Emitter.prototype[key];
  603. }
  604. return obj;
  605. }
  606. /**
  607. * Listen on the given `event` with `fn`.
  608. *
  609. * @param {String} event
  610. * @param {Function} fn
  611. * @return {Emitter}
  612. * @api public
  613. */
  614. Emitter.prototype.on =
  615. Emitter.prototype.addEventListener = function(event, fn){
  616. this._callbacks = this._callbacks || {};
  617. (this._callbacks[event] = this._callbacks[event] || [])
  618. .push(fn);
  619. return this;
  620. };
  621. /**
  622. * Adds an `event` listener that will be invoked a single
  623. * time then automatically removed.
  624. *
  625. * @param {String} event
  626. * @param {Function} fn
  627. * @return {Emitter}
  628. * @api public
  629. */
  630. Emitter.prototype.once = function(event, fn){
  631. var self = this;
  632. this._callbacks = this._callbacks || {};
  633. function on() {
  634. self.off(event, on);
  635. fn.apply(this, arguments);
  636. }
  637. fn._off = on;
  638. this.on(event, on);
  639. return this;
  640. };
  641. /**
  642. * Remove the given callback for `event` or all
  643. * registered callbacks.
  644. *
  645. * @param {String} event
  646. * @param {Function} fn
  647. * @return {Emitter}
  648. * @api public
  649. */
  650. Emitter.prototype.off =
  651. Emitter.prototype.removeListener =
  652. Emitter.prototype.removeAllListeners =
  653. Emitter.prototype.removeEventListener = function(event, fn){
  654. this._callbacks = this._callbacks || {};
  655. // all
  656. if (0 == arguments.length) {
  657. this._callbacks = {};
  658. return this;
  659. }
  660. // specific event
  661. var callbacks = this._callbacks[event];
  662. if (!callbacks) return this;
  663. // remove all handlers
  664. if (1 == arguments.length) {
  665. delete this._callbacks[event];
  666. return this;
  667. }
  668. // remove specific handler
  669. var i = index(callbacks, fn._off || fn);
  670. if (~i) callbacks.splice(i, 1);
  671. return this;
  672. };
  673. /**
  674. * Emit `event` with the given args.
  675. *
  676. * @param {String} event
  677. * @param {Mixed} ...
  678. * @return {Emitter}
  679. */
  680. Emitter.prototype.emit = function(event){
  681. this._callbacks = this._callbacks || {};
  682. var args = [].slice.call(arguments, 1)
  683. , callbacks = this._callbacks[event];
  684. if (callbacks) {
  685. callbacks = callbacks.slice(0);
  686. for (var i = 0, len = callbacks.length; i < len; ++i) {
  687. callbacks[i].apply(this, args);
  688. }
  689. }
  690. return this;
  691. };
  692. /**
  693. * Return array of callbacks for `event`.
  694. *
  695. * @param {String} event
  696. * @return {Array}
  697. * @api public
  698. */
  699. Emitter.prototype.listeners = function(event){
  700. this._callbacks = this._callbacks || {};
  701. return this._callbacks[event] || [];
  702. };
  703. /**
  704. * Check if this emitter has `event` handlers.
  705. *
  706. * @param {String} event
  707. * @return {Boolean}
  708. * @api public
  709. */
  710. Emitter.prototype.hasListeners = function(event){
  711. return !! this.listeners(event).length;
  712. };
  713. }, {"indexof":14}],
  714. 15: [function(require, module, exports) {
  715. /**
  716. * Expose `Emitter`.
  717. */
  718. module.exports = Emitter;
  719. /**
  720. * Initialize a new `Emitter`.
  721. *
  722. * @api public
  723. */
  724. function Emitter(obj) {
  725. if (obj) return mixin(obj);
  726. };
  727. /**
  728. * Mixin the emitter properties.
  729. *
  730. * @param {Object} obj
  731. * @return {Object}
  732. * @api private
  733. */
  734. function mixin(obj) {
  735. for (var key in Emitter.prototype) {
  736. obj[key] = Emitter.prototype[key];
  737. }
  738. return obj;
  739. }
  740. /**
  741. * Listen on the given `event` with `fn`.
  742. *
  743. * @param {String} event
  744. * @param {Function} fn
  745. * @return {Emitter}
  746. * @api public
  747. */
  748. Emitter.prototype.on =
  749. Emitter.prototype.addEventListener = function(event, fn){
  750. this._callbacks = this._callbacks || {};
  751. (this._callbacks[event] = this._callbacks[event] || [])
  752. .push(fn);
  753. return this;
  754. };
  755. /**
  756. * Adds an `event` listener that will be invoked a single
  757. * time then automatically removed.
  758. *
  759. * @param {String} event
  760. * @param {Function} fn
  761. * @return {Emitter}
  762. * @api public
  763. */
  764. Emitter.prototype.once = function(event, fn){
  765. var self = this;
  766. this._callbacks = this._callbacks || {};
  767. function on() {
  768. self.off(event, on);
  769. fn.apply(this, arguments);
  770. }
  771. on.fn = fn;
  772. this.on(event, on);
  773. return this;
  774. };
  775. /**
  776. * Remove the given callback for `event` or all
  777. * registered callbacks.
  778. *
  779. * @param {String} event
  780. * @param {Function} fn
  781. * @return {Emitter}
  782. * @api public
  783. */
  784. Emitter.prototype.off =
  785. Emitter.prototype.removeListener =
  786. Emitter.prototype.removeAllListeners =
  787. Emitter.prototype.removeEventListener = function(event, fn){
  788. this._callbacks = this._callbacks || {};
  789. // all
  790. if (0 == arguments.length) {
  791. this._callbacks = {};
  792. return this;
  793. }
  794. // specific event
  795. var callbacks = this._callbacks[event];
  796. if (!callbacks) return this;
  797. // remove all handlers
  798. if (1 == arguments.length) {
  799. delete this._callbacks[event];
  800. return this;
  801. }
  802. // remove specific handler
  803. var cb;
  804. for (var i = 0; i < callbacks.length; i++) {
  805. cb = callbacks[i];
  806. if (cb === fn || cb.fn === fn) {
  807. callbacks.splice(i, 1);
  808. break;
  809. }
  810. }
  811. return this;
  812. };
  813. /**
  814. * Emit `event` with the given args.
  815. *
  816. * @param {String} event
  817. * @param {Mixed} ...
  818. * @return {Emitter}
  819. */
  820. Emitter.prototype.emit = function(event){
  821. this._callbacks = this._callbacks || {};
  822. var args = [].slice.call(arguments, 1)
  823. , callbacks = this._callbacks[event];
  824. if (callbacks) {
  825. callbacks = callbacks.slice(0);
  826. for (var i = 0, len = callbacks.length; i < len; ++i) {
  827. callbacks[i].apply(this, args);
  828. }
  829. }
  830. return this;
  831. };
  832. /**
  833. * Return array of callbacks for `event`.
  834. *
  835. * @param {String} event
  836. * @return {Array}
  837. * @api public
  838. */
  839. Emitter.prototype.listeners = function(event){
  840. this._callbacks = this._callbacks || {};
  841. return this._callbacks[event] || [];
  842. };
  843. /**
  844. * Check if this emitter has `event` handlers.
  845. *
  846. * @param {String} event
  847. * @return {Boolean}
  848. * @api public
  849. */
  850. Emitter.prototype.hasListeners = function(event){
  851. return !! this.listeners(event).length;
  852. };
  853. }, {}],
  854. 16: [function(require, module, exports) {
  855. /**
  856. * Expose `Emitter`.
  857. */
  858. module.exports = Emitter;
  859. /**
  860. * Initialize a new `Emitter`.
  861. *
  862. * @api public
  863. */
  864. function Emitter(obj) {
  865. if (obj) return mixin(obj);
  866. };
  867. /**
  868. * Mixin the emitter properties.
  869. *
  870. * @param {Object} obj
  871. * @return {Object}
  872. * @api private
  873. */
  874. function mixin(obj) {
  875. for (var key in Emitter.prototype) {
  876. obj[key] = Emitter.prototype[key];
  877. }
  878. return obj;
  879. }
  880. /**
  881. * Listen on the given `event` with `fn`.
  882. *
  883. * @param {String} event
  884. * @param {Function} fn
  885. * @return {Emitter}
  886. * @api public
  887. */
  888. Emitter.prototype.on =
  889. Emitter.prototype.addEventListener = function(event, fn){
  890. this._callbacks = this._callbacks || {};
  891. (this._callbacks[event] = this._callbacks[event] || [])
  892. .push(fn);
  893. return this;
  894. };
  895. /**
  896. * Adds an `event` listener that will be invoked a single
  897. * time then automatically removed.
  898. *
  899. * @param {String} event
  900. * @param {Function} fn
  901. * @return {Emitter}
  902. * @api public
  903. */
  904. Emitter.prototype.once = function(event, fn){
  905. var self = this;
  906. this._callbacks = this._callbacks || {};
  907. function on() {
  908. self.off(event, on);
  909. fn.apply(this, arguments);
  910. }
  911. on.fn = fn;
  912. this.on(event, on);
  913. return this;
  914. };
  915. /**
  916. * Remove the given callback for `event` or all
  917. * registered callbacks.
  918. *
  919. * @param {String} event
  920. * @param {Function} fn
  921. * @return {Emitter}
  922. * @api public
  923. */
  924. Emitter.prototype.off =
  925. Emitter.prototype.removeListener =
  926. Emitter.prototype.removeAllListeners =
  927. Emitter.prototype.removeEventListener = function(event, fn){
  928. this._callbacks = this._callbacks || {};
  929. // all
  930. if (0 == arguments.length) {
  931. this._callbacks = {};
  932. return this;
  933. }
  934. // specific event
  935. var callbacks = this._callbacks[event];
  936. if (!callbacks) return this;
  937. // remove all handlers
  938. if (1 == arguments.length) {
  939. delete this._callbacks[event];
  940. return this;
  941. }
  942. // remove specific handler
  943. var cb;
  944. for (var i = 0; i < callbacks.length; i++) {
  945. cb = callbacks[i];
  946. if (cb === fn || cb.fn === fn) {
  947. callbacks.splice(i, 1);
  948. break;
  949. }
  950. }
  951. return this;
  952. };
  953. /**
  954. * Emit `event` with the given args.
  955. *
  956. * @param {String} event
  957. * @param {Mixed} ...
  958. * @return {Emitter}
  959. */
  960. Emitter.prototype.emit = function(event){
  961. this._callbacks = this._callbacks || {};
  962. var args = [].slice.call(arguments, 1)
  963. , callbacks = this._callbacks[event];
  964. if (callbacks) {
  965. callbacks = callbacks.slice(0);
  966. for (var i = 0, len = callbacks.length; i < len; ++i) {
  967. callbacks[i].apply(this, args);
  968. }
  969. }
  970. return this;
  971. };
  972. /**
  973. * Return array of callbacks for `event`.
  974. *
  975. * @param {String} event
  976. * @return {Array}
  977. * @api public
  978. */
  979. Emitter.prototype.listeners = function(event){
  980. this._callbacks = this._callbacks || {};
  981. return this._callbacks[event] || [];
  982. };
  983. /**
  984. * Check if this emitter has `event` handlers.
  985. *
  986. * @param {String} event
  987. * @return {Boolean}
  988. * @api public
  989. */
  990. Emitter.prototype.hasListeners = function(event){
  991. return !! this.listeners(event).length;
  992. };
  993. }, {}],
  994. 17: [function(require, module, exports) {
  995. /**
  996. * Escape regexp special characters in `str`.
  997. *
  998. * @param {String} str
  999. * @return {String}
  1000. * @api public
  1001. */
  1002. module.exports = function(str){
  1003. return String(str).replace(/([.*+?=^!:${}()|[\]\/\\])/g, '\\$1');
  1004. };
  1005. }, {}],
  1006. 18: [function(require, module, exports) {
  1007. /**
  1008. * Bind `el` event `type` to `fn`.
  1009. *
  1010. * @param {Element} el
  1011. * @param {String} type
  1012. * @param {Function} fn
  1013. * @param {Boolean} capture
  1014. * @return {Function}
  1015. * @api public
  1016. */
  1017. exports.bind = function(el, type, fn, capture){
  1018. if (el.addEventListener) {
  1019. el.addEventListener(type, fn, capture || false);
  1020. } else {
  1021. el.attachEvent('on' + type, fn);
  1022. }
  1023. return fn;
  1024. };
  1025. /**
  1026. * Unbind `el` event `type`'s callback `fn`.
  1027. *
  1028. * @param {Element} el
  1029. * @param {String} type
  1030. * @param {Function} fn
  1031. * @param {Boolean} capture
  1032. * @return {Function}
  1033. * @api public
  1034. */
  1035. exports.unbind = function(el, type, fn, capture){
  1036. if (el.removeEventListener) {
  1037. el.removeEventListener(type, fn, capture || false);
  1038. } else {
  1039. el.detachEvent('on' + type, fn);
  1040. }
  1041. return fn;
  1042. };
  1043. }, {}],
  1044. 14: [function(require, module, exports) {
  1045. module.exports = function(arr, obj){
  1046. if (arr.indexOf) return arr.indexOf(obj);
  1047. for (var i = 0; i < arr.length; ++i) {
  1048. if (arr[i] === obj) return i;
  1049. }
  1050. return -1;
  1051. };
  1052. }, {}],
  1053. 19: [function(require, module, exports) {
  1054. module.exports = function(a, b){
  1055. var fn = function(){};
  1056. fn.prototype = b.prototype;
  1057. a.prototype = new fn;
  1058. a.prototype.constructor = a;
  1059. };
  1060. }, {}],
  1061. 20: [function(require, module, exports) {
  1062. module.exports = function(a, b){
  1063. var fn = function(){};
  1064. fn.prototype = b.prototype;
  1065. a.prototype = new fn;
  1066. a.prototype.constructor = a;
  1067. };
  1068. }, {}],
  1069. 21: [function(require, module, exports) {
  1070. /*
  1071. json2.js
  1072. 2014-02-04
  1073. Public Domain.
  1074. NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
  1075. See http://www.JSON.org/js.html
  1076. This code should be minified before deployment.
  1077. See http://javascript.crockford.com/jsmin.html
  1078. USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
  1079. NOT CONTROL.
  1080. This file creates a global JSON object containing two methods: stringify
  1081. and parse.
  1082. JSON.stringify(value, replacer, space)
  1083. value any JavaScript value, usually an object or array.
  1084. replacer an optional parameter that determines how object
  1085. values are stringified for objects. It can be a
  1086. function or an array of strings.
  1087. space an optional parameter that specifies the indentation
  1088. of nested structures. If it is omitted, the text will
  1089. be packed without extra whitespace. If it is a number,
  1090. it will specify the number of spaces to indent at each
  1091. level. If it is a string (such as '\t' or '&nbsp;'),
  1092. it contains the characters used to indent at each level.
  1093. This method produces a JSON text from a JavaScript value.
  1094. When an object value is found, if the object contains a toJSON
  1095. method, its toJSON method will be called and the result will be
  1096. stringified. A toJSON method does not serialize: it returns the
  1097. value represented by the name/value pair that should be serialized,
  1098. or undefined if nothing should be serialized. The toJSON method
  1099. will be passed the key associated with the value, and this will be
  1100. bound to the value
  1101. For example, this would serialize Dates as ISO strings.
  1102. Date.prototype.toJSON = function (key) {
  1103. function f(n) {
  1104. // Format integers to have at least two digits.
  1105. return n < 10 ? '0' + n : n;
  1106. }
  1107. return this.getUTCFullYear() + '-' +
  1108. f(this.getUTCMonth() + 1) + '-' +
  1109. f(this.getUTCDate()) + 'T' +
  1110. f(this.getUTCHours()) + ':' +
  1111. f(this.getUTCMinutes()) + ':' +
  1112. f(this.getUTCSeconds()) + 'Z';
  1113. };
  1114. You can provide an optional replacer method. It will be passed the
  1115. key and value of each member, with this bound to the containing
  1116. object. The value that is returned from your method will be
  1117. serialized. If your method returns undefined, then the member will
  1118. be excluded from the serialization.
  1119. If the replacer parameter is an array of strings, then it will be
  1120. used to select the members to be serialized. It filters the results
  1121. such that only members with keys listed in the replacer array are
  1122. stringified.
  1123. Values that do not have JSON representations, such as undefined or
  1124. functions, will not be serialized. Such values in objects will be
  1125. dropped; in arrays they will be replaced with null. You can use
  1126. a replacer function to replace those with JSON values.
  1127. JSON.stringify(undefined) returns undefined.
  1128. The optional space parameter produces a stringification of the
  1129. value that is filled with line breaks and indentation to make it
  1130. easier to read.
  1131. If the space parameter is a non-empty string, then that string will
  1132. be used for indentation. If the space parameter is a number, then
  1133. the indentation will be that many spaces.
  1134. Example:
  1135. text = JSON.stringify(['e', {pluribus: 'unum'}]);
  1136. // text is '["e",{"pluribus":"unum"}]'
  1137. text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
  1138. // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
  1139. text = JSON.stringify([new Date()], function (key, value) {
  1140. return this[key] instanceof Date ?
  1141. 'Date(' + this[key] + ')' : value;
  1142. });
  1143. // text is '["Date(---current time---)"]'
  1144. JSON.parse(text, reviver)
  1145. This method parses a JSON text to produce an object or array.
  1146. It can throw a SyntaxError exception.
  1147. The optional reviver parameter is a function that can filter and
  1148. transform the results. It receives each of the keys and values,
  1149. and its return value is used instead of the original value.
  1150. If it returns what it received, then the structure is not modified.
  1151. If it returns undefined then the member is deleted.
  1152. Example:
  1153. // Parse the text. Values that look like ISO date strings will
  1154. // be converted to Date objects.
  1155. myData = JSON.parse(text, function (key, value) {
  1156. var a;
  1157. if (typeof value === 'string') {
  1158. a =
  1159. /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
  1160. if (a) {
  1161. return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
  1162. +a[5], +a[6]));
  1163. }
  1164. }
  1165. return value;
  1166. });
  1167. myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
  1168. var d;
  1169. if (typeof value === 'string' &&
  1170. value.slice(0, 5) === 'Date(' &&
  1171. value.slice(-1) === ')') {
  1172. d = new Date(value.slice(5, -1));
  1173. if (d) {
  1174. return d;
  1175. }
  1176. }
  1177. return value;
  1178. });
  1179. This is a reference implementation. You are free to copy, modify, or
  1180. redistribute.
  1181. */
  1182. /*jslint evil: true, regexp: true */
  1183. /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
  1184. call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
  1185. getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
  1186. lastIndex, length, parse, prototype, push, replace, slice, stringify,
  1187. test, toJSON, toString, valueOf
  1188. */
  1189. // Create a JSON object only if one does not already exist. We create the
  1190. // methods in a closure to avoid creating global variables.
  1191. (function () {
  1192. 'use strict';
  1193. var JSON = module.exports = {};
  1194. function f(n) {
  1195. // Format integers to have at least two digits.
  1196. return n < 10 ? '0' + n : n;
  1197. }
  1198. if (typeof Date.prototype.toJSON !== 'function') {
  1199. Date.prototype.toJSON = function () {
  1200. return isFinite(this.valueOf())
  1201. ? this.getUTCFullYear() + '-' +
  1202. f(this.getUTCMonth() + 1) + '-' +
  1203. f(this.getUTCDate()) + 'T' +
  1204. f(this.getUTCHours()) + ':' +
  1205. f(this.getUTCMinutes()) + ':' +
  1206. f(this.getUTCSeconds()) + 'Z'
  1207. : null;
  1208. };
  1209. String.prototype.toJSON =
  1210. Number.prototype.toJSON =
  1211. Boolean.prototype.toJSON = function () {
  1212. return this.valueOf();
  1213. };
  1214. }
  1215. var cx,
  1216. escapable,
  1217. gap,
  1218. indent,
  1219. meta,
  1220. rep;
  1221. function quote(string) {
  1222. // If the string contains no control characters, no quote characters, and no
  1223. // backslash characters, then we can safely slap some quotes around it.
  1224. // Otherwise we must also replace the offending characters with safe escape
  1225. // sequences.
  1226. escapable.lastIndex = 0;
  1227. return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
  1228. var c = meta[a];
  1229. return typeof c === 'string'
  1230. ? c
  1231. : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  1232. }) + '"' : '"' + string + '"';
  1233. }
  1234. function str(key, holder) {
  1235. // Produce a string from holder[key].
  1236. var i, // The loop counter.
  1237. k, // The member key.
  1238. v, // The member value.
  1239. length,
  1240. mind = gap,
  1241. partial,
  1242. value = holder[key];
  1243. // If the value has a toJSON method, call it to obtain a replacement value.
  1244. if (value && typeof value === 'object' &&
  1245. typeof value.toJSON === 'function') {
  1246. value = value.toJSON(key);
  1247. }
  1248. // If we were called with a replacer function, then call the replacer to
  1249. // obtain a replacement value.
  1250. if (typeof rep === 'function') {
  1251. value = rep.call(holder, key, value);
  1252. }
  1253. // What happens next depends on the value's type.
  1254. switch (typeof value) {
  1255. case 'string':
  1256. return quote(value);
  1257. case 'number':
  1258. // JSON numbers must be finite. Encode non-finite numbers as null.
  1259. return isFinite(value) ? String(value) : 'null';
  1260. case 'boolean':
  1261. case 'null':
  1262. // If the value is a boolean or null, convert it to a string. Note:
  1263. // typeof null does not produce 'null'. The case is included here in
  1264. // the remote chance that this gets fixed someday.
  1265. return String(value);
  1266. // If the type is 'object', we might be dealing with an object or an array or
  1267. // null.
  1268. case 'object':
  1269. // Due to a specification blunder in ECMAScript, typeof null is 'object',
  1270. // so watch out for that case.
  1271. if (!value) {
  1272. return 'null';
  1273. }
  1274. // Make an array to hold the partial results of stringifying this object value.
  1275. gap += indent;
  1276. partial = [];
  1277. // Is the value an array?
  1278. if (Object.prototype.toString.apply(value) === '[object Array]') {
  1279. // The value is an array. Stringify every element. Use null as a placeholder
  1280. // for non-JSON values.
  1281. length = value.length;
  1282. for (i = 0; i < length; i += 1) {
  1283. partial[i] = str(i, value) || 'null';
  1284. }
  1285. // Join all of the elements together, separated with commas, and wrap them in
  1286. // brackets.
  1287. v = partial.length === 0
  1288. ? '[]'
  1289. : gap
  1290. ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
  1291. : '[' + partial.join(',') + ']';
  1292. gap = mind;
  1293. return v;
  1294. }
  1295. // If the replacer is an array, use it to select the members to be stringified.
  1296. if (rep && typeof rep === 'object') {
  1297. length = rep.length;
  1298. for (i = 0; i < length; i += 1) {
  1299. if (typeof rep[i] === 'string') {
  1300. k = rep[i];
  1301. v = str(k, value);
  1302. if (v) {
  1303. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  1304. }
  1305. }
  1306. }
  1307. } else {
  1308. // Otherwise, iterate through all of the keys in the object.
  1309. for (k in value) {
  1310. if (Object.prototype.hasOwnProperty.call(value, k)) {
  1311. v = str(k, value);
  1312. if (v) {
  1313. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  1314. }
  1315. }
  1316. }
  1317. }
  1318. // Join all of the member texts together, separated with commas,
  1319. // and wrap them in braces.
  1320. v = partial.length === 0
  1321. ? '{}'
  1322. : gap
  1323. ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
  1324. : '{' + partial.join(',') + '}';
  1325. gap = mind;
  1326. return v;
  1327. }
  1328. }
  1329. // If the JSON object does not yet have a stringify method, give it one.
  1330. if (typeof JSON.stringify !== 'function') {
  1331. escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  1332. meta = { // table of character substitutions
  1333. '\b': '\\b',
  1334. '\t': '\\t',
  1335. '\n': '\\n',
  1336. '\f': '\\f',
  1337. '\r': '\\r',
  1338. '"' : '\\"',
  1339. '\\': '\\\\'
  1340. };
  1341. JSON.stringify = function (value, replacer, space) {
  1342. // The stringify method takes a value and an optional replacer, and an optional
  1343. // space parameter, and returns a JSON text. The replacer can be a function
  1344. // that can replace values, or an array of strings that will select the keys.
  1345. // A default replacer method can be provided. Use of the space parameter can
  1346. // produce text that is more easily readable.
  1347. var i;
  1348. gap = '';
  1349. indent = '';
  1350. // If the space parameter is a number, make an indent string containing that
  1351. // many spaces.
  1352. if (typeof space === 'number') {
  1353. for (i = 0; i < space; i += 1) {
  1354. indent += ' ';
  1355. }
  1356. // If the space parameter is a string, it will be used as the indent string.
  1357. } else if (typeof space === 'string') {
  1358. indent = space;
  1359. }
  1360. // If there is a replacer, it must be a function or an array.
  1361. // Otherwise, throw an error.
  1362. rep = replacer;
  1363. if (replacer && typeof replacer !== 'function' &&
  1364. (typeof replacer !== 'object' ||
  1365. typeof replacer.length !== 'number')) {
  1366. throw new Error('JSON.stringify');
  1367. }
  1368. // Make a fake root object containing our value under the key of ''.
  1369. // Return the result of stringifying the value.
  1370. return str('', {'': value});
  1371. };
  1372. }
  1373. // If the JSON object does not yet have a parse method, give it one.
  1374. if (typeof JSON.parse !== 'function') {
  1375. cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  1376. JSON.parse = function (text, reviver) {
  1377. // The parse method takes a text and an optional reviver function, and returns
  1378. // a JavaScript value if the text is a valid JSON text.
  1379. var j;
  1380. function walk(holder, key) {
  1381. // The walk method is used to recursively walk the resulting structure so
  1382. // that modifications can be made.
  1383. var k, v, value = holder[key];
  1384. if (value && typeof value === 'object') {
  1385. for (k in value) {
  1386. if (Object.prototype.hasOwnProperty.call(value, k)) {
  1387. v = walk(value, k);
  1388. if (v !== undefined) {
  1389. value[k] = v;
  1390. } else {
  1391. delete value[k];
  1392. }
  1393. }
  1394. }
  1395. }
  1396. return reviver.call(holder, key, value);
  1397. }
  1398. // Parsing happens in four stages. In the first stage, we replace certain
  1399. // Unicode characters with escape sequences. JavaScript handles many characters
  1400. // incorrectly, either silently deleting them, or treating them as line endings.
  1401. text = String(text);
  1402. cx.lastIndex = 0;
  1403. if (cx.test(text)) {
  1404. text = text.replace(cx, function (a) {
  1405. return '\\u' +
  1406. ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  1407. });
  1408. }
  1409. // In the second stage, we run the text against regular expressions that look
  1410. // for non-JSON patterns. We are especially concerned with '()' and 'new'
  1411. // because they can cause invocation, and '=' because it can cause mutation.
  1412. // But just to be safe, we want to reject all unexpected forms.
  1413. // We split the second stage into 4 regexp operations in order to work around
  1414. // crippling inefficiencies in IE's and Safari's regexp engines. First we
  1415. // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
  1416. // replace all simple value tokens with ']' characters. Third, we delete all
  1417. // open brackets that follow a colon or comma or that begin the text. Finally,
  1418. // we look to see that the remaining characters are only whitespace or ']' or
  1419. // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
  1420. if (/^[\],:{}\s]*$/
  1421. .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
  1422. .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
  1423. .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  1424. // In the third stage we use the eval function to compile the text into a
  1425. // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
  1426. // in JavaScript: it can begin a block or an object literal. We wrap the text
  1427. // in parens to eliminate the ambiguity.
  1428. j = eval('(' + text + ')');
  1429. // In the optional fourth stage, we recursively walk the new structure, passing
  1430. // each name/value pair to a reviver function for possible transformation.
  1431. return typeof reviver === 'function'
  1432. ? walk({'': j}, '')
  1433. : j;
  1434. }
  1435. // If the text is not JSON parseable, then a SyntaxError is thrown.
  1436. throw new SyntaxError('JSON.parse');
  1437. };
  1438. }
  1439. }());
  1440. }, {}],
  1441. 22: [function(require, module, exports) {
  1442. /**
  1443. * HOP ref.
  1444. */
  1445. var has = Object.prototype.hasOwnProperty;
  1446. /**
  1447. * Return own keys in `obj`.
  1448. *
  1449. * @param {Object} obj
  1450. * @return {Array}
  1451. * @api public
  1452. */
  1453. exports.keys = Object.keys || function(obj){
  1454. var keys = [];
  1455. for (var key in obj) {
  1456. if (has.call(obj, key)) {
  1457. keys.push(key);
  1458. }
  1459. }
  1460. return keys;
  1461. };
  1462. /**
  1463. * Return own values in `obj`.
  1464. *
  1465. * @param {Object} obj
  1466. * @return {Array}
  1467. * @api public
  1468. */
  1469. exports.values = function(obj){
  1470. var vals = [];
  1471. for (var key in obj) {
  1472. if (has.call(obj, key)) {
  1473. vals.push(obj[key]);
  1474. }
  1475. }
  1476. return vals;
  1477. };
  1478. /**
  1479. * Merge `b` into `a`.
  1480. *
  1481. * @param {Object} a
  1482. * @param {Object} b
  1483. * @return {Object} a
  1484. * @api public
  1485. */
  1486. exports.merge = function(a, b){
  1487. for (var key in b) {
  1488. if (has.call(b, key)) {
  1489. a[key] = b[key];
  1490. }
  1491. }
  1492. return a;
  1493. };
  1494. /**
  1495. * Return length of `obj`.
  1496. *
  1497. * @param {Object} obj
  1498. * @return {Number}
  1499. * @api public
  1500. */
  1501. exports.length = function(obj){
  1502. return exports.keys(obj).length;
  1503. };
  1504. /**
  1505. * Check if `obj` is empty.
  1506. *
  1507. * @param {Object} obj
  1508. * @return {Boolean}
  1509. * @api public
  1510. */
  1511. exports.isEmpty = function(obj){
  1512. return 0 == exports.length(obj);
  1513. };
  1514. }, {}],
  1515. 23: [function(require, module, exports) {
  1516. /**
  1517. * Global Names
  1518. */
  1519. var globals = /\b(this|Array|Date|Object|Math|JSON)\b/g;
  1520. /**
  1521. * Return immediate identifiers parsed from `str`.
  1522. *
  1523. * @param {String} str
  1524. * @param {String|Function} map function or prefix
  1525. * @return {Array}
  1526. * @api public
  1527. */
  1528. module.exports = function(str, fn){
  1529. var p = unique(props(str));
  1530. if (fn && 'string' == typeof fn) fn = prefixed(fn);
  1531. if (fn) return map(str, p, fn);
  1532. return p;
  1533. };
  1534. /**
  1535. * Return immediate identifiers in `str`.
  1536. *
  1537. * @param {String} str
  1538. * @return {Array}
  1539. * @api private
  1540. */
  1541. function props(str) {
  1542. return str
  1543. .replace(/\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\//g, '')
  1544. .replace(globals, '')
  1545. .match(/[$a-zA-Z_]\w*/g)
  1546. || [];
  1547. }
  1548. /**
  1549. * Return `str` with `props` mapped with `fn`.
  1550. *
  1551. * @param {String} str
  1552. * @param {Array} props
  1553. * @param {Function} fn
  1554. * @return {String}
  1555. * @api private
  1556. */
  1557. function map(str, props, fn) {
  1558. var re = /\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\/|[a-zA-Z_]\w*/g;
  1559. return str.replace(re, function(_){
  1560. if ('(' == _[_.length - 1]) return fn(_);
  1561. if (!~props.indexOf(_)) return _;
  1562. return fn(_);
  1563. });
  1564. }
  1565. /**
  1566. * Return unique array.
  1567. *
  1568. * @param {Array} arr
  1569. * @return {Array}
  1570. * @api private
  1571. */
  1572. function unique(arr) {
  1573. var ret = [];
  1574. for (var i = 0; i < arr.length; i++) {
  1575. if (~ret.indexOf(arr[i])) continue;
  1576. ret.push(arr[i]);
  1577. }
  1578. return ret;
  1579. }
  1580. /**
  1581. * Map with prefix `str`.
  1582. */
  1583. function prefixed(str) {
  1584. return function(_){
  1585. return str + _;
  1586. };
  1587. }
  1588. }, {}],
  1589. 24: [function(require, module, exports) {
  1590. /**
  1591. * Module dependencies.
  1592. */
  1593. var encode = encodeURIComponent;
  1594. var decode = decodeURIComponent;
  1595. var trim = require('trim');
  1596. var type = require('type');
  1597. /**
  1598. * Parse the given query `str`.
  1599. *
  1600. * @param {String} str
  1601. * @return {Object}
  1602. * @api public
  1603. */
  1604. exports.parse = function(str){
  1605. if ('string' != typeof str) return {};
  1606. str = trim(str);
  1607. if ('' == str) return {};
  1608. if ('?' == str.charAt(0)) str = str.slice(1);
  1609. var obj = {};
  1610. var pairs = str.split('&');
  1611. for (var i = 0; i < pairs.length; i++) {
  1612. var parts = pairs[i].split('=');
  1613. var key = decode(parts[0]);
  1614. var m;
  1615. if (m = /(\w+)\[(\d+)\]/.exec(key)) {
  1616. obj[m[1]] = obj[m[1]] || [];
  1617. obj[m[1]][m[2]] = decode(parts[1]);
  1618. continue;
  1619. }
  1620. obj[parts[0]] = null == parts[1]
  1621. ? ''
  1622. : decode(parts[1]);
  1623. }
  1624. return obj;
  1625. };
  1626. /**
  1627. * Stringify the given `obj`.
  1628. *
  1629. * @param {Object} obj
  1630. * @return {String}
  1631. * @api public
  1632. */
  1633. exports.stringify = function(obj){
  1634. if (!obj) return '';
  1635. var pairs = [];
  1636. for (var key in obj) {
  1637. var value = obj[key];
  1638. if ('array' == type(value)) {
  1639. for (var i = 0; i < value.length; ++i) {
  1640. pairs.push(encode(key + '[' + i + ']') + '=' + encode(value[i]));
  1641. }
  1642. continue;
  1643. }
  1644. pairs.push(encode(key) + '=' + encode(obj[key]));
  1645. }
  1646. return pairs.join('&');
  1647. };
  1648. }, {"trim":25,"type":5}],
  1649. 26: [function(require, module, exports) {
  1650. /**
  1651. * Module dependencies.
  1652. */
  1653. var encode = encodeURIComponent;
  1654. var decode = decodeURIComponent;
  1655. var trim = require('trim');
  1656. var type = require('type');
  1657. /**
  1658. * Parse the given query `str`.
  1659. *
  1660. * @param {String} str
  1661. * @return {Object}
  1662. * @api public
  1663. */
  1664. exports.parse = function(str){
  1665. if ('string' != typeof str) return {};
  1666. str = trim(str);
  1667. if ('' == str) return {};
  1668. if ('?' == str.charAt(0)) str = str.slice(1);
  1669. var obj = {};
  1670. var pairs = str.split('&');
  1671. for (var i = 0; i < pairs.length; i++) {
  1672. var parts = pairs[i].split('=');
  1673. var key = decode(parts[0]);
  1674. var m;
  1675. if (m = /(\w+)\[(\d+)\]/.exec(key)) {
  1676. obj[m[1]] = obj[m[1]] || [];
  1677. obj[m[1]][m[2]] = decode(parts[1]);
  1678. continue;
  1679. }
  1680. obj[parts[0]] = null == parts[1]
  1681. ? ''
  1682. : decode(parts[1]);
  1683. }
  1684. return obj;
  1685. };
  1686. /**
  1687. * Stringify the given `obj`.
  1688. *
  1689. * @param {Object} obj
  1690. * @return {String}
  1691. * @api public
  1692. */
  1693. exports.stringify = function(obj){
  1694. if (!obj) return '';
  1695. var pairs = [];
  1696. for (var key in obj) {
  1697. var value = obj[key];
  1698. if ('array' == type(value)) {
  1699. for (var i = 0; i < value.length; ++i) {
  1700. pairs.push(encode(key + '[' + i + ']') + '=' + encode(value[i]));
  1701. }
  1702. continue;
  1703. }
  1704. pairs.push(encode(key) + '=' + encode(obj[key]));
  1705. }
  1706. return pairs.join('&');
  1707. };
  1708. }, {"trim":25,"type":5}],
  1709. 27: [function(require, module, exports) {
  1710. /**
  1711. * Module dependencies.
  1712. */
  1713. var Emitter;
  1714. var bind;
  1715. try {
  1716. Emitter = require('emitter');
  1717. bind = require('bind');
  1718. } catch (err) {
  1719. Emitter = require('component-emitter');
  1720. bind = require('component-bind');
  1721. }
  1722. /**
  1723. * Expose `Queue`.
  1724. */
  1725. module.exports = Queue;
  1726. /**
  1727. * Initialize a `Queue` with the given options:
  1728. *
  1729. * - `concurrency` [1]
  1730. * - `timeout` [0]
  1731. *
  1732. * @param {Object} options
  1733. * @api public
  1734. */
  1735. function Queue(options) {
  1736. options = options || {};
  1737. this.timeout = options.timeout || 0;
  1738. this.concurrency = options.concurrency || 1;
  1739. this.pending = 0;
  1740. this.jobs = [];
  1741. }
  1742. /**
  1743. * Mixin emitter.
  1744. */
  1745. Emitter(Queue.prototype);
  1746. /**
  1747. * Return queue length.
  1748. *
  1749. * @return {Number}
  1750. * @api public
  1751. */
  1752. Queue.prototype.length = function(){
  1753. return this.pending + this.jobs.length;
  1754. };
  1755. /**
  1756. * Queue `fn` for execution.
  1757. *
  1758. * @param {Function} fn
  1759. * @param {Function} [cb]
  1760. * @api public
  1761. */
  1762. Queue.prototype.push = function(fn, cb){
  1763. this.jobs.push([fn, cb]);
  1764. setTimeout(bind(this, this.run), 0);
  1765. };
  1766. /**
  1767. * Run jobs at the specified concurrency.
  1768. *
  1769. * @api private
  1770. */
  1771. Queue.prototype.run = function(){
  1772. while (this.pending < this.concurrency) {
  1773. var job = this.jobs.shift();
  1774. if (!job) break;
  1775. this.exec(job);
  1776. }
  1777. };
  1778. /**
  1779. * Execute `job`.
  1780. *
  1781. * @param {Array} job
  1782. * @api private
  1783. */
  1784. Queue.prototype.exec = function(job){
  1785. var self = this;
  1786. var ms = this.timeout;
  1787. var fn = job[0];
  1788. var cb = job[1];
  1789. if (ms) fn = timeout(fn, ms);
  1790. this.pending++;
  1791. fn(function(err, res){
  1792. cb && cb(err, res);
  1793. self.pending--;
  1794. self.run();
  1795. });
  1796. };
  1797. /**
  1798. * Decorate `fn` with a timeout of `ms`.
  1799. *
  1800. * @param {Function} fn
  1801. * @param {Function} ms
  1802. * @return {Function}
  1803. * @api private
  1804. */
  1805. function timeout(fn, ms) {
  1806. return function(cb){
  1807. var done;
  1808. var id = setTimeout(function(){
  1809. done = true;
  1810. var err = new Error('Timeout of ' + ms + 'ms exceeded');
  1811. err.timeout = timeout;
  1812. cb(err);
  1813. }, ms);
  1814. fn(function(err, res){
  1815. if (done) return;
  1816. clearTimeout(id);
  1817. cb(err, res);
  1818. });
  1819. }
  1820. }
  1821. }, {"emitter":15,"bind":3,"component-emitter":15,"component-bind":3}],
  1822. 28: [function(require, module, exports) {
  1823. /**
  1824. * Module exports.
  1825. */
  1826. module.exports = throttle;
  1827. /**
  1828. * Returns a new function that, when invoked, invokes `func` at most one time per
  1829. * `wait` milliseconds.
  1830. *
  1831. * @param {Function} func The `Function` instance to wrap.
  1832. * @param {Number} wait The minimum number of milliseconds that must elapse in between `func` invokations.
  1833. * @return {Function} A new function that wraps the `func` function passed in.
  1834. * @api public
  1835. */
  1836. function throttle (func, wait) {
  1837. var rtn; // return value
  1838. var last = 0; // last invokation timestamp
  1839. return function throttled () {
  1840. var now = new Date().getTime();
  1841. var delta = now - last;
  1842. if (delta >= wait) {
  1843. rtn = func.apply(this, arguments);
  1844. last = now;
  1845. }
  1846. return rtn;
  1847. };
  1848. }
  1849. }, {}],
  1850. 12: [function(require, module, exports) {
  1851. /**
  1852. * Module Dependencies
  1853. */
  1854. var expr;
  1855. try {
  1856. expr = require('props');
  1857. } catch(e) {
  1858. expr = require('component-props');
  1859. }
  1860. /**
  1861. * Expose `toFunction()`.
  1862. */
  1863. module.exports = toFunction;
  1864. /**
  1865. * Convert `obj` to a `Function`.
  1866. *
  1867. * @param {Mixed} obj
  1868. * @return {Function}
  1869. * @api private
  1870. */
  1871. function toFunction(obj) {
  1872. switch ({}.toString.call(obj)) {
  1873. cas