algoliasearch-rails 1.16.3 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +8 -0
  3. data/Gemfile +6 -1
  4. data/Gemfile.lock +3 -3
  5. data/README.md +153 -94
  6. data/VERSION +1 -1
  7. data/algoliasearch-rails.gemspec +1 -1
  8. data/lib/algoliasearch-rails.rb +75 -36
  9. data/spec/spec_helper.rb +7 -0
  10. data/vendor/assets/javascripts/algolia/algoliasearch.angular.js +23 -12
  11. data/vendor/assets/javascripts/algolia/algoliasearch.angular.min.js +2 -2
  12. data/vendor/assets/javascripts/algolia/algoliasearch.jquery.js +23 -12
  13. data/vendor/assets/javascripts/algolia/algoliasearch.jquery.min.js +2 -2
  14. data/vendor/assets/javascripts/algolia/algoliasearch.js +22 -12
  15. data/vendor/assets/javascripts/algolia/algoliasearch.min.js +2 -2
  16. data/vendor/assets/javascripts/algolia/v2/algoliasearch.angular.js +23 -12
  17. data/vendor/assets/javascripts/algolia/v2/algoliasearch.angular.min.js +2 -2
  18. data/vendor/assets/javascripts/algolia/v2/algoliasearch.jquery.js +23 -12
  19. data/vendor/assets/javascripts/algolia/v2/algoliasearch.jquery.min.js +2 -2
  20. data/vendor/assets/javascripts/algolia/v2/algoliasearch.js +22 -12
  21. data/vendor/assets/javascripts/algolia/v2/algoliasearch.min.js +2 -2
  22. data/vendor/assets/javascripts/algolia/v3/algoliasearch.angular.js +2020 -1301
  23. data/vendor/assets/javascripts/algolia/v3/algoliasearch.angular.min.js +3 -3
  24. data/vendor/assets/javascripts/algolia/v3/algoliasearch.jquery.js +2019 -1300
  25. data/vendor/assets/javascripts/algolia/v3/algoliasearch.jquery.min.js +3 -3
  26. data/vendor/assets/javascripts/algolia/v3/algoliasearch.js +2003 -1284
  27. data/vendor/assets/javascripts/algolia/v3/algoliasearch.min.js +3 -3
  28. metadata +5 -6
@@ -1,3 +1,3 @@
1
- /*! algoliasearch 3.18.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
2
- !function(e){var t;"undefined"!=typeof window?t=window:"undefined"!=typeof self&&(t=self),t.ALGOLIA_MIGRATION_LAYER=e()}(function(){return function e(t,o,r){function n(i,a){if(!o[i]){if(!t[i]){var c="function"==typeof require&&require;if(!a&&c)return c(i,!0);if(s)return s(i,!0);var u=new Error("Cannot find module '"+i+"'");throw u.code="MODULE_NOT_FOUND",u}var l=o[i]={exports:{}};t[i][0].call(l.exports,function(e){var o=t[i][1][e];return n(o?o:e)},l,l.exports,e,t,o,r)}return o[i].exports}for(var s="function"==typeof require&&require,i=0;i<r.length;i++)n(r[i]);return n}({1:[function(e,t,o){function r(e,t){for(var o in t)e.setAttribute(o,t[o])}function n(e,t){e.onload=function(){this.onerror=this.onload=null,t(null,e)},e.onerror=function(){this.onerror=this.onload=null,t(new Error("Failed to load "+this.src),e)}}function s(e,t){e.onreadystatechange=function(){"complete"!=this.readyState&&"loaded"!=this.readyState||(this.onreadystatechange=null,t(null,e))}}t.exports=function(e,t,o){var i=document.head||document.getElementsByTagName("head")[0],a=document.createElement("script");"function"==typeof t&&(o=t,t={}),t=t||{},o=o||function(){},a.type=t.type||"text/javascript",a.charset=t.charset||"utf8",a.async=!("async"in t)||!!t.async,a.src=e,t.attrs&&r(a,t.attrs),t.text&&(a.text=""+t.text);var c="onload"in a?n:s;c(a,o),a.onload||n(a,o),i.appendChild(a)}},{}],2:[function(e,t,o){"use strict";function r(e){for(var t=new RegExp("cdn\\.jsdelivr\\.net/algoliasearch/latest/"+e.replace(".","\\.")+"(?:\\.min)?\\.js$"),o=document.getElementsByTagName("script"),r=!1,n=0,s=o.length;n<s;n++)if(o[n].src&&t.test(o[n].src)){r=!0;break}return r}t.exports=r},{}],3:[function(e,t,o){"use strict";function r(t){var o=e(1),r="//cdn.jsdelivr.net/algoliasearch/2/"+t+".min.js",s="-- AlgoliaSearch `latest` warning --\nWarning, you are using the `latest` version string from jsDelivr to load the AlgoliaSearch library.\nUsing `latest` is no more recommended, you should load //cdn.jsdelivr.net/algoliasearch/2/algoliasearch.min.js\n\nAlso, we updated the AlgoliaSearch JavaScript client to V3. If you want to upgrade,\nplease read our migration guide at https://github.com/algolia/algoliasearch-client-js/wiki/Migration-guide-from-2.x.x-to-3.x.x\n-- /AlgoliaSearch `latest` warning --";window.console&&(window.console.warn?window.console.warn(s):window.console.log&&window.console.log(s));try{document.write("<script>window.ALGOLIA_SUPPORTS_DOCWRITE = true</script>"),window.ALGOLIA_SUPPORTS_DOCWRITE===!0?(document.write('<script src="'+r+'"></script>'),n("document.write")()):o(r,n("DOMElement"))}catch(i){o(r,n("DOMElement"))}}function n(e){return function(){var t="AlgoliaSearch: loaded V2 script using "+e;window.console&&window.console.log&&window.console.log(t)}}t.exports=r},{1:1}],4:[function(e,t,o){"use strict";function r(){var e="-- AlgoliaSearch V2 => V3 error --\nYou are trying to use a new version of the AlgoliaSearch JavaScript client with an old notation.\nPlease read our migration guide at https://github.com/algolia/algoliasearch-client-js/wiki/Migration-guide-from-2.x.x-to-3.x.x\n-- /AlgoliaSearch V2 => V3 error --";window.AlgoliaSearch=function(){throw new Error(e)},window.AlgoliaSearchHelper=function(){throw new Error(e)},window.AlgoliaExplainResults=function(){throw new Error(e)}}t.exports=r},{}],5:[function(e,t,o){"use strict";function r(t){var o=e(2),r=e(3),n=e(4);o(t)?r(t):n()}r("algoliasearch.jquery")},{2:2,3:3,4:4}]},{},[5])(5)}),function e(t,o,r){function n(i,a){if(!o[i]){if(!t[i]){var c="function"==typeof require&&require;if(!a&&c)return c(i,!0);if(s)return s(i,!0);var u=new Error("Cannot find module '"+i+"'");throw u.code="MODULE_NOT_FOUND",u}var l=o[i]={exports:{}};t[i][0].call(l.exports,function(e){var o=t[i][1][e];return n(o?o:e)},l,l.exports,e,t,o,r)}return o[i].exports}for(var s="function"==typeof require&&require,i=0;i<r.length;i++)n(r[i]);return n}({1:[function(e,t,o){function r(e){if(e=""+e,!(e.length>1e4)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var o=parseFloat(t[1]),r=(t[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return o*p;case"days":case"day":case"d":return o*l;case"hours":case"hour":case"hrs":case"hr":case"h":return o*u;case"minutes":case"minute":case"mins":case"min":case"m":return o*c;case"seconds":case"second":case"secs":case"sec":case"s":return o*a;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o}}}}function n(e){return e>=l?Math.round(e/l)+"d":e>=u?Math.round(e/u)+"h":e>=c?Math.round(e/c)+"m":e>=a?Math.round(e/a)+"s":e+"ms"}function s(e){return i(e,l,"day")||i(e,u,"hour")||i(e,c,"minute")||i(e,a,"second")||e+" ms"}function i(e,t,o){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+o:Math.ceil(e/t)+" "+o+"s"}var a=1e3,c=60*a,u=60*c,l=24*u,p=365.25*l;t.exports=function(e,t){return t=t||{},"string"==typeof e?r(e):t["long"]?s(e):n(e)}},{}],2:[function(e,t,o){function r(){d&&l&&(d=!1,l.length?p=l.concat(p):h=-1,p.length&&n())}function n(){if(!d){var e=a(r);d=!0;for(var t=p.length;t;){for(l=p,p=[];++h<t;)l&&l[h].run();h=-1,t=p.length}l=null,d=!1,c(e)}}function s(e,t){this.fun=e,this.array=t}function i(){}var a,c,u=t.exports={};!function(){try{a=setTimeout}catch(e){a=function(){throw new Error("setTimeout is not defined")}}try{c=clearTimeout}catch(e){c=function(){throw new Error("clearTimeout is not defined")}}}();var l,p=[],d=!1,h=-1;u.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var o=1;o<arguments.length;o++)t[o-1]=arguments[o];p.push(new s(e,t)),1!==p.length||d||a(n,0)},s.prototype.run=function(){this.fun.apply(null,this.array)},u.title="browser",u.browser=!0,u.env={},u.argv=[],u.version="",u.versions={},u.on=i,u.addListener=i,u.once=i,u.off=i,u.removeListener=i,u.removeAllListeners=i,u.emit=i,u.binding=function(e){throw new Error("process.binding is not supported")},u.cwd=function(){return"/"},u.chdir=function(e){throw new Error("process.chdir is not supported")},u.umask=function(){return 0}},{}],3:[function(e,t,o){function r(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}function n(){var e=arguments,t=this.useColors;if(e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+o.humanize(this.diff),!t)return e;var r="color: "+this.color;e=[e[0],r,"color: inherit"].concat(Array.prototype.slice.call(e,1));var n=0,s=0;return e[0].replace(/%[a-z%]/g,function(e){"%%"!==e&&(n++,"%c"===e&&(s=n))}),e.splice(s,0,r),e}function s(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function i(e){try{null==e?o.storage.removeItem("debug"):o.storage.debug=e}catch(t){}}function a(){var e;try{e=o.storage.debug}catch(t){}return e}function c(){try{return window.localStorage}catch(e){}}o=t.exports=e(4),o.log=s,o.formatArgs=n,o.save=i,o.load=a,o.useColors=r,o.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:c(),o.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],o.formatters.j=function(e){return JSON.stringify(e)},o.enable(a())},{4:4}],4:[function(e,t,o){function r(){return o.colors[l++%o.colors.length]}function n(e){function t(){}function n(){var e=n,t=+new Date,s=t-(u||t);e.diff=s,e.prev=u,e.curr=t,u=t,null==e.useColors&&(e.useColors=o.useColors()),null==e.color&&e.useColors&&(e.color=r());var i=Array.prototype.slice.call(arguments);i[0]=o.coerce(i[0]),"string"!=typeof i[0]&&(i=["%o"].concat(i));var a=0;i[0]=i[0].replace(/%([a-z%])/g,function(t,r){if("%%"===t)return t;a++;var n=o.formatters[r];if("function"==typeof n){var s=i[a];t=n.call(e,s),i.splice(a,1),a--}return t}),"function"==typeof o.formatArgs&&(i=o.formatArgs.apply(e,i));var c=n.log||o.log||console.log.bind(console);c.apply(e,i)}t.enabled=!1,n.enabled=!0;var s=o.enabled(e)?n:t;return s.namespace=e,s}function s(e){o.save(e);for(var t=(e||"").split(/[\s,]+/),r=t.length,n=0;n<r;n++)t[n]&&(e=t[n].replace(/\*/g,".*?"),"-"===e[0]?o.skips.push(new RegExp("^"+e.substr(1)+"$")):o.names.push(new RegExp("^"+e+"$")))}function i(){o.enable("")}function a(e){var t,r;for(t=0,r=o.skips.length;t<r;t++)if(o.skips[t].test(e))return!1;for(t=0,r=o.names.length;t<r;t++)if(o.names[t].test(e))return!0;return!1}function c(e){return e instanceof Error?e.stack||e.message:e}o=t.exports=n,o.coerce=c,o.disable=i,o.enable=s,o.enabled=a,o.humanize=e(1),o.names=[],o.skips=[],o.formatters={};var u,l=0},{1:1}],5:[function(e,t,o){(function(o,r){(function(){"use strict";function n(e){return"function"==typeof e||"object"==typeof e&&null!==e}function s(e){return"function"==typeof e}function i(e){X=e}function a(e){z=e}function c(){return function(){o.nextTick(h)}}function u(){return function(){V(h)}}function l(){var e=0,t=new te(h),o=document.createTextNode("");return t.observe(o,{characterData:!0}),function(){o.data=e=++e%2}}function p(){var e=new MessageChannel;return e.port1.onmessage=h,function(){e.port2.postMessage(0)}}function d(){return function(){setTimeout(h,1)}}function h(){for(var e=0;e<Y;e+=2){var t=ne[e],o=ne[e+1];t(o),ne[e]=void 0,ne[e+1]=void 0}Y=0}function f(){try{var t=e,o=t("vertx");return V=o.runOnLoop||o.runOnContext,u()}catch(r){return d()}}function y(e,t){var o=this,r=new this.constructor(v);void 0===r[ae]&&N(r);var n=o._state;if(n){var s=arguments[n-1];z(function(){U(n,r,s,o._result)})}else q(o,r,e,t);return r}function m(e){var t=this;if(e&&"object"==typeof e&&e.constructor===t)return e;var o=new t(v);return S(o,e),o}function v(){}function g(){return new TypeError("You cannot resolve a promise with itself")}function b(){return new TypeError("A promises callback cannot return that same promise.")}function w(e){try{return e.then}catch(t){return pe.error=t,pe}}function _(e,t,o,r){try{e.call(t,o,r)}catch(n){return n}}function x(e,t,o){z(function(e){var r=!1,n=_(o,t,function(o){r||(r=!0,t!==o?S(e,o):R(e,o))},function(t){r||(r=!0,O(e,t))},"Settle: "+(e._label||" unknown promise"));!r&&n&&(r=!0,O(e,n))},e)}function T(e,t){t._state===ue?R(e,t._result):t._state===le?O(e,t._result):q(t,void 0,function(t){S(e,t)},function(t){O(e,t)})}function j(e,t,o){t.constructor===e.constructor&&o===se&&constructor.resolve===ie?T(e,t):o===pe?O(e,pe.error):void 0===o?R(e,t):s(o)?x(e,t,o):R(e,t)}function S(e,t){e===t?O(e,g()):n(t)?j(e,t,w(t)):R(e,t)}function k(e){e._onerror&&e._onerror(e._result),P(e)}function R(e,t){e._state===ce&&(e._result=t,e._state=ue,0!==e._subscribers.length&&z(P,e))}function O(e,t){e._state===ce&&(e._state=le,e._result=t,z(k,e))}function q(e,t,o,r){var n=e._subscribers,s=n.length;e._onerror=null,n[s]=t,n[s+ue]=o,n[s+le]=r,0===s&&e._state&&z(P,e)}function P(e){var t=e._subscribers,o=e._state;if(0!==t.length){for(var r,n,s=e._result,i=0;i<t.length;i+=3)r=t[i],n=t[i+o],r?U(o,r,n,s):n(s);e._subscribers.length=0}}function E(){this.error=null}function I(e,t){try{return e(t)}catch(o){return de.error=o,de}}function U(e,t,o,r){var n,i,a,c,u=s(o);if(u){if(n=I(o,r),n===de?(c=!0,i=n.error,n=null):a=!0,t===n)return void O(t,b())}else n=r,a=!0;t._state!==ce||(u&&a?S(t,n):c?O(t,i):e===ue?R(t,n):e===le&&O(t,n))}function A(e,t){try{t(function(t){S(e,t)},function(t){O(e,t)})}catch(o){O(e,o)}}function C(){return he++}function N(e){e[ae]=he++,e._state=void 0,e._result=void 0,e._subscribers=[]}function L(e){return new ge(this,e).promise}function D(e){var t=this;return new t($(e)?function(o,r){for(var n=e.length,s=0;s<n;s++)t.resolve(e[s]).then(o,r)}:function(e,t){t(new TypeError("You must pass an array to race."))})}function H(e){var t=this,o=new t(v);return O(o,e),o}function M(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function J(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function K(e){this[ae]=C(),this._result=this._state=void 0,this._subscribers=[],v!==e&&("function"!=typeof e&&M(),this instanceof K?A(this,e):J())}function Q(e,t){this._instanceConstructor=e,this.promise=new e(v),this.promise[ae]||N(this.promise),$(t)?(this._input=t,this.length=t.length,this._remaining=t.length,this._result=new Array(this.length),0===this.length?R(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&R(this.promise,this._result))):O(this.promise,B())}function B(){return new Error("Array Methods must be provided an Array")}function F(){var e;if("undefined"!=typeof r)e=r;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var o=e.Promise;o&&"[object Promise]"===Object.prototype.toString.call(o.resolve())&&!o.cast||(e.Promise=ve)}var G;G=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var V,X,W,$=G,Y=0,z=function(e,t){ne[Y]=e,ne[Y+1]=t,Y+=2,2===Y&&(X?X(h):W())},Z="undefined"!=typeof window?window:void 0,ee=Z||{},te=ee.MutationObserver||ee.WebKitMutationObserver,oe="undefined"==typeof self&&"undefined"!=typeof o&&"[object process]"==={}.toString.call(o),re="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,ne=new Array(1e3);W=oe?c():te?l():re?p():void 0===Z&&"function"==typeof e?f():d();var se=y,ie=m,ae=Math.random().toString(36).substring(16),ce=void 0,ue=1,le=2,pe=new E,de=new E,he=0,fe=L,ye=D,me=H,ve=K;K.all=fe,K.race=ye,K.resolve=ie,K.reject=me,K._setScheduler=i,K._setAsap=a,K._asap=z,K.prototype={constructor:K,then:se,"catch":function(e){return this.then(null,e)}};var ge=Q;Q.prototype._enumerate=function(){for(var e=this.length,t=this._input,o=0;this._state===ce&&o<e;o++)this._eachEntry(t[o],o)},Q.prototype._eachEntry=function(e,t){var o=this._instanceConstructor,r=o.resolve;if(r===ie){var n=w(e);if(n===se&&e._state!==ce)this._settledAt(e._state,t,e._result);else if("function"!=typeof n)this._remaining--,this._result[t]=e;else if(o===ve){var s=new o(v);j(s,e,n),this._willSettleAt(s,t)}else this._willSettleAt(new o(function(t){t(e)}),t)}else this._willSettleAt(r(e),t)},Q.prototype._settledAt=function(e,t,o){var r=this.promise;r._state===ce&&(this._remaining--,e===le?O(r,o):this._result[t]=o),0===this._remaining&&R(r,this._result)},Q.prototype._willSettleAt=function(e,t){var o=this;q(e,void 0,function(e){o._settledAt(ue,t,e)},function(e){o._settledAt(le,t,e)})};var be=F,we={Promise:ve,polyfill:be};"function"==typeof define&&define.amd?define(function(){return we}):"undefined"!=typeof t&&t.exports?t.exports=we:"undefined"!=typeof this&&(this.ES6Promise=we),be()}).call(this)}).call(this,e(2),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{2:2}],6:[function(e,t,o){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function s(e){return"number"==typeof e}function i(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}t.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!s(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,o,r,s,c,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;var l=new Error('Uncaught, unspecified "error" event. ('+t+")");throw l.context=t,l}if(o=this._events[e],a(o))return!1;if(n(o))switch(arguments.length){case 1:o.call(this);break;case 2:o.call(this,arguments[1]);break;case 3:o.call(this,arguments[1],arguments[2]);break;default:s=Array.prototype.slice.call(arguments,1),o.apply(this,s)}else if(i(o))for(s=Array.prototype.slice.call(arguments,1),u=o.slice(),r=u.length,c=0;c<r;c++)u[c].apply(this,s);return!0},r.prototype.addListener=function(e,t){var o;if(!n(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned&&(o=a(this._maxListeners)?r.defaultMaxListeners:this._maxListeners,o&&o>0&&this._events[e].length>o&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function o(){this.removeListener(e,o),r||(r=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var r=!1;return o.listener=t,this.on(e,o),this},r.prototype.removeListener=function(e,t){var o,r,s,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(o=this._events[e],s=o.length,r=-1,o===t||n(o.listener)&&o.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(o)){for(a=s;a-- >0;)if(o[a]===t||o[a].listener&&o[a].listener===t){r=a;break}if(r<0)return this;1===o.length?(o.length=0,delete this._events[e]):o.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,o;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(o=this._events[e],n(o))this.removeListener(e,o);else if(o)for(;o.length;)this.removeListener(e,o[o.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},{}],7:[function(e,t,o){var r=Object.prototype.hasOwnProperty,n=Object.prototype.toString;t.exports=function(e,t,o){if("[object Function]"!==n.call(t))throw new TypeError("iterator must be a function");var s=e.length;if(s===+s)for(var i=0;i<s;i++)t.call(o,e[i],i,e);else for(var a in e)r.call(e,a)&&t.call(o,e[a],a,e)}},{}],8:[function(e,t,o){(function(e){"undefined"!=typeof window?t.exports=window:"undefined"!=typeof e?t.exports=e:"undefined"!=typeof self?t.exports=self:t.exports={}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],9:[function(e,t,o){"function"==typeof Object.create?t.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(e,t){e.super_=t;var o=function(){};o.prototype=t.prototype,e.prototype=new o,e.prototype.constructor=e}},{}],10:[function(e,t,o){var r={}.toString;t.exports=Array.isArray||function(e){return"[object Array]"==r.call(e)}},{}],11:[function(e,t,o){"use strict";function r(e,t){if(e.map)return e.map(t);for(var o=[],r=0;r<e.length;r++)o.push(t(e[r],r));return o}var n=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};t.exports=function(e,t,o,a){return t=t||"&",o=o||"=",null===e&&(e=void 0),"object"==typeof e?r(i(e),function(i){var a=encodeURIComponent(n(i))+o;return s(e[i])?r(e[i],function(e){return a+encodeURIComponent(n(e))}).join(t):a+encodeURIComponent(n(e[i]))}).join(t):a?encodeURIComponent(n(a))+o+encodeURIComponent(n(e)):""};var s=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},i=Object.keys||function(e){var t=[];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.push(o);return t}},{}],12:[function(e,t,o){function r(){c.apply(this,arguments)}function n(){var e="Not implemented in this environment.\nIf you feel this is a mistake, write to support@algolia.com";throw new l.AlgoliaSearchError(e)}t.exports=r;var s=e(14),i=e(25),a=e(26),c=e(13),u=e(9),l=e(27);u(r,c),r.prototype.deleteIndex=function(e,t){return this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(e),hostType:"write",callback:t})},r.prototype.moveIndex=function(e,t,o){var r={operation:"move",destination:t};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(e)+"/operation",body:r,hostType:"write",callback:o})},r.prototype.copyIndex=function(e,t,o){var r={operation:"copy",destination:t};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(e)+"/operation",body:r,hostType:"write",callback:o})},r.prototype.getLogs=function(t,o,r){var n=e(24),s={};return"object"==typeof t?(s=n(t),r=o):0===arguments.length||"function"==typeof t?r=t:1===arguments.length||"function"==typeof o?(r=o,s.offset=t):(s.offset=t,s.length=o),void 0===s.offset&&(s.offset=0),void 0===s.length&&(s.length=10),this._jsonRequest({method:"GET",url:"/1/logs?"+this._getSearchParams(s,""),hostType:"read",callback:r})},r.prototype.listIndexes=function(e,t){var o="";return void 0===e||"function"==typeof e?t=e:o="?page="+e,this._jsonRequest({method:"GET",url:"/1/indexes"+o,hostType:"read",callback:t})},r.prototype.initIndex=function(e){return new s(this,e)},r.prototype.listUserKeys=function(e){return this._jsonRequest({method:"GET",url:"/1/keys",hostType:"read",callback:e})},r.prototype.getUserKeyACL=function(e,t){return this._jsonRequest({method:"GET",url:"/1/keys/"+e,hostType:"read",callback:t})},r.prototype.deleteUserKey=function(e,t){return this._jsonRequest({method:"DELETE",url:"/1/keys/"+e,hostType:"write",callback:t})},r.prototype.addUserKey=function(t,o,r){var n=e(10),s="Usage: client.addUserKey(arrayOfAcls[, params, callback])";if(!n(t))throw new Error(s);1!==arguments.length&&"function"!=typeof o||(r=o,o=null);var i={acl:t};return o&&(i.validity=o.validity,i.maxQueriesPerIPPerHour=o.maxQueriesPerIPPerHour,i.maxHitsPerQuery=o.maxHitsPerQuery,i.indexes=o.indexes,i.description=o.description,o.queryParameters&&(i.queryParameters=this._getSearchParams(o.queryParameters,"")),i.referers=o.referers),this._jsonRequest({method:"POST",url:"/1/keys",body:i,hostType:"write",callback:r})},r.prototype.addUserKeyWithValidity=i(function(e,t,o){return this.addUserKey(e,t,o)},a("client.addUserKeyWithValidity()","client.addUserKey()")),r.prototype.updateUserKey=function(t,o,r,n){var s=e(10),i="Usage: client.updateUserKey(key, arrayOfAcls[, params, callback])";if(!s(o))throw new Error(i);2!==arguments.length&&"function"!=typeof r||(n=r,r=null);var a={acl:o};return r&&(a.validity=r.validity,a.maxQueriesPerIPPerHour=r.maxQueriesPerIPPerHour,a.maxHitsPerQuery=r.maxHitsPerQuery,a.indexes=r.indexes,a.description=r.description,r.queryParameters&&(a.queryParameters=this._getSearchParams(r.queryParameters,"")),a.referers=r.referers),this._jsonRequest({method:"PUT",url:"/1/keys/"+t,body:a,hostType:"write",callback:n})},r.prototype.startQueriesBatch=i(function(){this._batch=[]},a("client.startQueriesBatch()","client.search()")),r.prototype.addQueryInBatch=i(function(e,t,o){this._batch.push({indexName:e,query:t,params:o})},a("client.addQueryInBatch()","client.search()")),r.prototype.sendQueriesBatch=i(function(e){return this.search(this._batch,e)},a("client.sendQueriesBatch()","client.search()")),r.prototype.batch=function(t,o){var r=e(10),n="Usage: client.batch(operations[, callback])";if(!r(t))throw new Error(n);return this._jsonRequest({method:"POST",url:"/1/indexes/*/batch",body:{requests:t},hostType:"write",callback:o})},r.prototype.destroy=n,r.prototype.enableRateLimitForward=n,r.prototype.disableRateLimitForward=n,r.prototype.useSecuredAPIKey=n,r.prototype.disableSecuredAPIKey=n,r.prototype.generateSecuredApiKey=n},{10:10,13:13,14:14,24:24,25:25,26:26,27:27,9:9}],13:[function(e,t,o){function r(t,o,r){var s=e(3)("algoliasearch"),a=e(24),u=e(10),l=e(29),p="Usage: algoliasearch(applicationID, apiKey, opts)";if(r._allowEmptyCredentials!==!0&&!t)throw new c.AlgoliaSearchError("Please provide an application ID. "+p);if(r._allowEmptyCredentials!==!0&&!o)throw new c.AlgoliaSearchError("Please provide an API key. "+p);this.applicationID=t,this.apiKey=o;var d=i([this.applicationID+"-1.algolianet.com",this.applicationID+"-2.algolianet.com",this.applicationID+"-3.algolianet.com"]);this.hosts={read:[],write:[]},this.hostIndex={read:0,write:0},r=r||{};var h=r.protocol||"https:",f=void 0===r.timeout?2e3:r.timeout;if(/:$/.test(h)||(h+=":"),"http:"!==r.protocol&&"https:"!==r.protocol)throw new c.AlgoliaSearchError("protocol must be `http:` or `https:` (was `"+r.protocol+"`)");r.hosts?u(r.hosts)?(this.hosts.read=a(r.hosts),this.hosts.write=a(r.hosts)):(this.hosts.read=a(r.hosts.read),this.hosts.write=a(r.hosts.write)):(this.hosts.read=[this.applicationID+"-dsn.algolia.net"].concat(d),this.hosts.write=[this.applicationID+".algolia.net"].concat(d)),this.hosts.read=l(this.hosts.read,n(h)),this.hosts.write=l(this.hosts.write,n(h)),this.requestTimeout=f,this.extraHeaders=[],this.cache=r._cache||{},this._ua=r._ua,this._useCache=!(void 0!==r._useCache&&!r._cache)||r._useCache,this._useFallback=void 0===r.useFallback||r.useFallback,this._setTimeout=r._setTimeout,s("init done, %j",this)}function n(e){return function(t){return e+"//"+t.toLowerCase()}}function s(e){if(void 0===Array.prototype.toJSON)return JSON.stringify(e);var t=Array.prototype.toJSON;delete Array.prototype.toJSON;var o=JSON.stringify(e);return Array.prototype.toJSON=t,o}function i(e){for(var t,o,r=e.length;0!==r;)o=Math.floor(Math.random()*r),r-=1,t=e[r],e[r]=e[o],e[o]=t;return e}function a(e){var t={};for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var r;r="x-algolia-api-key"===o||"x-algolia-application-id"===o?"**hidden for security purposes**":e[o],t[o]=r}return t}t.exports=r;var c=e(27),u=e(28),l=e(16),p=500;r.prototype.initIndex=function(e){return new l(this,e)},r.prototype.setExtraHeader=function(e,t){this.extraHeaders.push({name:e.toLowerCase(),value:t})},r.prototype.addAlgoliaAgent=function(e){this._ua+=";"+e},r.prototype._jsonRequest=function(t){function o(e,u){function p(e){var t=e&&e.body&&e.body.message&&e.body.status||e.statusCode||e&&e.body&&200;i("received response: statusCode: %s, computed statusCode: %d, headers: %j",e.statusCode,t,e.headers);var o=2===Math.floor(t/100),s=new Date;if(m.push({currentHost:x,headers:a(n),content:r||null,contentLength:void 0!==r?r.length:null,method:u.method,timeout:u.timeout,url:u.url,startTime:_,endTime:s,duration:s-_,statusCode:t}),o)return d._useCache&&l&&(l[w]=e.responseText),e.body;var p=4!==Math.floor(t/100);if(p)return h+=1,g();i("unrecoverable error");var f=new c.AlgoliaSearchError(e.body&&e.body.message,{debugData:m,statusCode:t});return d._promise.reject(f)}function v(e){i("error: %s, stack: %s",e.message,e.stack);var o=new Date;return m.push({currentHost:x,headers:a(n),content:r||null,contentLength:void 0!==r?r.length:null,method:u.method,timeout:u.timeout,url:u.url,startTime:_,endTime:o,duration:o-_}),e instanceof c.AlgoliaSearchError||(e=new c.Unknown(e&&e.message,e)),h+=1,e instanceof c.Unknown||e instanceof c.UnparsableJSON||h>=d.hosts[t.hostType].length&&(f||!y)?(e.debugData=m,d._promise.reject(e)):e instanceof c.RequestTimeout?b():g()}function g(){return i("retrying request"),d.hostIndex[t.hostType]=(d.hostIndex[t.hostType]+1)%d.hosts[t.hostType].length,o(e,u)}function b(){return i("retrying request with higher timeout"),d.hostIndex[t.hostType]=(d.hostIndex[t.hostType]+1)%d.hosts[t.hostType].length,u.timeout=d.requestTimeout*(h+1),o(e,u)}var w,_=new Date;if(d._useCache&&(w=t.url),d._useCache&&r&&(w+="_body_"+u.body),d._useCache&&l&&void 0!==l[w])return i("serving response from cache"),d._promise.resolve(JSON.parse(l[w]));if(h>=d.hosts[t.hostType].length)return!y||f?(i("could not get any response"),d._promise.reject(new c.AlgoliaSearchError("Cannot connect to the AlgoliaSearch API. Send an email to support@algolia.com to report and resolve the issue. Application id was: "+d.applicationID,{debugData:m}))):(i("switching to fallback"),h=0,u.method=t.fallback.method,u.url=t.fallback.url,u.jsonBody=t.fallback.body,u.jsonBody&&(u.body=s(u.jsonBody)),n=d._computeRequestHeaders(),u.timeout=d.requestTimeout*(h+1),d.hostIndex[t.hostType]=0,f=!0,o(d._request.fallback,u));var x=d.hosts[t.hostType][d.hostIndex[t.hostType]],T=x+u.url,j={body:u.body,jsonBody:u.jsonBody,method:u.method,headers:n,timeout:u.timeout,debug:i};return i("method: %s, url: %s, headers: %j, timeout: %d",j.method,T,j.headers,j.timeout),e===d._request.fallback&&i("using fallback"),e.call(d,T,j).then(p,v)}var r,n,i=e(3)("algoliasearch:"+t.url),l=t.cache,d=this,h=0,f=!1,y=d._useFallback&&d._request.fallback&&t.fallback;this.apiKey.length>p&&void 0!==t.body&&void 0!==t.body.params?(t.body.apiKey=this.apiKey,n=this._computeRequestHeaders(!1)):n=this._computeRequestHeaders(),void 0!==t.body&&(r=s(t.body)),i("request start");var m=[],v=o(d._request,{url:t.url,method:t.method,body:r,jsonBody:t.body,timeout:d.requestTimeout*(h+1)});return t.callback?void v.then(function(e){u(function(){t.callback(null,e)},d._setTimeout||setTimeout)},function(e){u(function(){t.callback(e)},d._setTimeout||setTimeout)}):v},r.prototype._getSearchParams=function(e,t){if(void 0===e||null===e)return t;for(var o in e)null!==o&&void 0!==e[o]&&e.hasOwnProperty(o)&&(t+=""===t?"":"&",t+=o+"="+encodeURIComponent("[object Array]"===Object.prototype.toString.call(e[o])?s(e[o]):e[o]));return t},r.prototype._computeRequestHeaders=function(t){var o=e(7),r={"x-algolia-agent":this._ua,"x-algolia-application-id":this.applicationID};return t!==!1&&(r["x-algolia-api-key"]=this.apiKey),this.userToken&&(r["x-algolia-usertoken"]=this.userToken),this.securityTags&&(r["x-algolia-tagfilters"]=this.securityTags),this.extraHeaders&&o(this.extraHeaders,function(e){r[e.name]=e.value}),r},r.prototype.search=function(t,o,r){var n=e(10),s=e(29),i="Usage: client.search(arrayOfQueries[, callback])";if(!n(t))throw new Error(i);"function"==typeof o?(r=o,o={}):void 0===o&&(o={});var a=this,c={requests:s(t,function(e){var t="";return void 0!==e.query&&(t+="query="+encodeURIComponent(e.query)),{indexName:e.indexName,params:a._getSearchParams(e.params,t)}})},u=s(c.requests,function(e,t){return t+"="+encodeURIComponent("/1/indexes/"+encodeURIComponent(e.indexName)+"?"+e.params)}).join("&"),l="/1/indexes/*/queries";return void 0!==o.strategy&&(l+="?strategy="+o.strategy),this._jsonRequest({cache:this.cache,method:"POST",url:l,body:c,hostType:"read",fallback:{method:"GET",url:"/1/indexes/*",body:{params:u}},callback:r})},r.prototype.setSecurityTags=function(e){if("[object Array]"===Object.prototype.toString.call(e)){for(var t=[],o=0;o<e.length;++o)if("[object Array]"===Object.prototype.toString.call(e[o])){for(var r=[],n=0;n<e[o].length;++n)r.push(e[o][n]);t.push("("+r.join(",")+")")}else t.push(e[o]);e=t.join(",")}this.securityTags=e},r.prototype.setUserToken=function(e){this.userToken=e},r.prototype.clearCache=function(){this.cache={}},r.prototype.setRequestTimeout=function(e){e&&(this.requestTimeout=parseInt(e,10))}},{10:10,16:16,24:24,27:27,28:28,29:29,3:3,7:7}],14:[function(e,t,o){function r(){s.apply(this,arguments)}var n=e(9),s=e(16),i=e(25),a=e(26),c=e(28),u=e(27);t.exports=r,n(r,s),r.prototype.addObject=function(e,t,o){var r=this;return 1!==arguments.length&&"function"!=typeof t||(o=t,
3
- t=void 0),this.as._jsonRequest({method:void 0!==t?"PUT":"POST",url:"/1/indexes/"+encodeURIComponent(r.indexName)+(void 0!==t?"/"+encodeURIComponent(t):""),body:e,hostType:"write",callback:o})},r.prototype.addObjects=function(t,o){var r=e(10),n="Usage: index.addObjects(arrayOfObjects[, callback])";if(!r(t))throw new Error(n);for(var s=this,i={requests:[]},a=0;a<t.length;++a){var c={action:"addObject",body:t[a]};i.requests.push(c)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(s.indexName)+"/batch",body:i,hostType:"write",callback:o})},r.prototype.partialUpdateObject=function(e,t,o){1!==arguments.length&&"function"!=typeof t||(o=t,t=void 0);var r=this,n="/1/indexes/"+encodeURIComponent(r.indexName)+"/"+encodeURIComponent(e.objectID)+"/partial";return t===!1&&(n+="?createIfNotExists=false"),this.as._jsonRequest({method:"POST",url:n,body:e,hostType:"write",callback:o})},r.prototype.partialUpdateObjects=function(t,o){var r=e(10),n="Usage: index.partialUpdateObjects(arrayOfObjects[, callback])";if(!r(t))throw new Error(n);for(var s=this,i={requests:[]},a=0;a<t.length;++a){var c={action:"partialUpdateObject",objectID:t[a].objectID,body:t[a]};i.requests.push(c)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(s.indexName)+"/batch",body:i,hostType:"write",callback:o})},r.prototype.saveObject=function(e,t){var o=this;return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(o.indexName)+"/"+encodeURIComponent(e.objectID),body:e,hostType:"write",callback:t})},r.prototype.saveObjects=function(t,o){var r=e(10),n="Usage: index.saveObjects(arrayOfObjects[, callback])";if(!r(t))throw new Error(n);for(var s=this,i={requests:[]},a=0;a<t.length;++a){var c={action:"updateObject",objectID:t[a].objectID,body:t[a]};i.requests.push(c)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(s.indexName)+"/batch",body:i,hostType:"write",callback:o})},r.prototype.deleteObject=function(e,t){if("function"==typeof e||"string"!=typeof e&&"number"!=typeof e){var o=new u.AlgoliaSearchError("Cannot delete an object without an objectID");return t=e,"function"==typeof t?t(o):this.as._promise.reject(o)}var r=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(r.indexName)+"/"+encodeURIComponent(e),hostType:"write",callback:t})},r.prototype.deleteObjects=function(t,o){var r=e(10),n=e(29),s="Usage: index.deleteObjects(arrayOfObjectIDs[, callback])";if(!r(t))throw new Error(s);var i=this,a={requests:n(t,function(e){return{action:"deleteObject",objectID:e,body:{objectID:e}}})};return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(i.indexName)+"/batch",body:a,hostType:"write",callback:o})},r.prototype.deleteByQuery=function(t,o,r){function n(e){if(0===e.nbHits)return e;var t=p(e.hits,function(e){return e.objectID});return d.deleteObjects(t).then(s).then(i)}function s(e){return d.waitTask(e.taskID)}function i(){return d.deleteByQuery(t,o)}function a(){c(function(){r(null)},h._setTimeout||setTimeout)}function u(e){c(function(){r(e)},h._setTimeout||setTimeout)}var l=e(24),p=e(29),d=this,h=d.as;1===arguments.length||"function"==typeof o?(r=o,o={}):o=l(o),o.attributesToRetrieve="objectID",o.hitsPerPage=1e3,o.distinct=!1,this.clearCache();var f=this.search(t,o).then(n);return r?void f.then(a,u):f},r.prototype.browseAll=function(t,o){function r(e){if(!a._stopped){var t;t=void 0!==e?"cursor="+encodeURIComponent(e):l,c._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(u.indexName)+"/browse?"+t,hostType:"read",callback:n})}}function n(e,t){if(!a._stopped)return e?void a._error(e):(a._result(t),void 0===t.cursor?void a._end():void r(t.cursor))}"object"==typeof t&&(o=t,t=void 0);var s=e(30),i=e(15),a=new i,c=this.as,u=this,l=c._getSearchParams(s({},o||{},{query:t}),"");return r(),a},r.prototype.ttAdapter=function(e){var t=this;return function(o,r,n){var s;s="function"==typeof n?n:r,t.search(o,e,function(e,t){return e?void s(e):void s(t.hits)})}},r.prototype.waitTask=function(e,t){function o(){return l._jsonRequest({method:"GET",hostType:"read",url:"/1/indexes/"+encodeURIComponent(u.indexName)+"/task/"+e}).then(function(e){a++;var t=s*a*a;return t>i&&(t=i),"published"!==e.status?l._promise.delay(t).then(o):e})}function r(e){c(function(){t(null,e)},l._setTimeout||setTimeout)}function n(e){c(function(){t(e)},l._setTimeout||setTimeout)}var s=100,i=5e3,a=0,u=this,l=u.as,p=o();return t?void p.then(r,n):p},r.prototype.clearIndex=function(e){var t=this;return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(t.indexName)+"/clear",hostType:"write",callback:e})},r.prototype.getSettings=function(e){var t=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(t.indexName)+"/settings?getVersion=2",hostType:"read",callback:e})},r.prototype.searchSynonyms=function(e,t){return"function"==typeof e?(t=e,e={}):void 0===e&&(e={}),this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/search",body:e,hostType:"read",callback:t})},r.prototype.saveSynonym=function(e,t,o){return"function"==typeof t?(o=t,t={}):void 0===t&&(t={}),this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/"+encodeURIComponent(e.objectID)+"?forwardToSlaves="+(t.forwardToSlaves?"true":"false"),body:e,hostType:"write",callback:o})},r.prototype.getSynonym=function(e,t){return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/"+encodeURIComponent(e),hostType:"read",callback:t})},r.prototype.deleteSynonym=function(e,t,o){return"function"==typeof t?(o=t,t={}):void 0===t&&(t={}),this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/"+encodeURIComponent(e)+"?forwardToSlaves="+(t.forwardToSlaves?"true":"false"),hostType:"write",callback:o})},r.prototype.clearSynonyms=function(e,t){return"function"==typeof e?(t=e,e={}):void 0===e&&(e={}),this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/clear?forwardToSlaves="+(e.forwardToSlaves?"true":"false"),hostType:"write",callback:t})},r.prototype.batchSynonyms=function(e,t,o){return"function"==typeof t?(o=t,t={}):void 0===t&&(t={}),this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/batch?forwardToSlaves="+(t.forwardToSlaves?"true":"false")+"&replaceExistingSynonyms="+(t.replaceExistingSynonyms?"true":"false"),hostType:"write",body:e,callback:o})},r.prototype.setSettings=function(e,t,o){1!==arguments.length&&"function"!=typeof t||(o=t,t={});var r=t.forwardToSlaves||!1,n=this;return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(n.indexName)+"/settings?forwardToSlaves="+(r?"true":"false"),hostType:"write",body:e,callback:o})},r.prototype.listUserKeys=function(e){var t=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(t.indexName)+"/keys",hostType:"read",callback:e})},r.prototype.getUserKeyACL=function(e,t){var o=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(o.indexName)+"/keys/"+e,hostType:"read",callback:t})},r.prototype.deleteUserKey=function(e,t){var o=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(o.indexName)+"/keys/"+e,hostType:"write",callback:t})},r.prototype.addUserKey=function(t,o,r){var n=e(10),s="Usage: index.addUserKey(arrayOfAcls[, params, callback])";if(!n(t))throw new Error(s);1!==arguments.length&&"function"!=typeof o||(r=o,o=null);var i={acl:t};return o&&(i.validity=o.validity,i.maxQueriesPerIPPerHour=o.maxQueriesPerIPPerHour,i.maxHitsPerQuery=o.maxHitsPerQuery,i.description=o.description,o.queryParameters&&(i.queryParameters=this.as._getSearchParams(o.queryParameters,"")),i.referers=o.referers),this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/keys",body:i,hostType:"write",callback:r})},r.prototype.addUserKeyWithValidity=i(function(e,t,o){return this.addUserKey(e,t,o)},a("index.addUserKeyWithValidity()","index.addUserKey()")),r.prototype.updateUserKey=function(t,o,r,n){var s=e(10),i="Usage: index.updateUserKey(key, arrayOfAcls[, params, callback])";if(!s(o))throw new Error(i);2!==arguments.length&&"function"!=typeof r||(n=r,r=null);var a={acl:o};return r&&(a.validity=r.validity,a.maxQueriesPerIPPerHour=r.maxQueriesPerIPPerHour,a.maxHitsPerQuery=r.maxHitsPerQuery,a.description=r.description,r.queryParameters&&(a.queryParameters=this.as._getSearchParams(r.queryParameters,"")),a.referers=r.referers),this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/keys/"+t,body:a,hostType:"write",callback:n})}},{10:10,15:15,16:16,24:24,25:25,26:26,27:27,28:28,29:29,30:30,9:9}],15:[function(e,t,o){"use strict";function r(){}t.exports=r;var n=e(9),s=e(6).EventEmitter;n(r,s),r.prototype.stop=function(){this._stopped=!0,this._clean()},r.prototype._end=function(){this.emit("end"),this._clean()},r.prototype._error=function(e){this.emit("error",e),this._clean()},r.prototype._result=function(e){this.emit("result",e)},r.prototype._clean=function(){this.removeAllListeners("stop"),this.removeAllListeners("end"),this.removeAllListeners("error"),this.removeAllListeners("result")}},{6:6,9:9}],16:[function(e,t,o){function r(e,t){this.indexName=t,this.as=e,this.typeAheadArgs=null,this.typeAheadValueOption=null,this.cache={}}var n=e(23);t.exports=r,r.prototype.clearCache=function(){this.cache={}},r.prototype.search=n("query"),r.prototype.similarSearch=n("similarQuery"),r.prototype.browse=function(t,o,r){var n,s,i=e(30),a=this;0===arguments.length||1===arguments.length&&"function"==typeof arguments[0]?(n=0,r=arguments[0],t=void 0):"number"==typeof arguments[0]?(n=arguments[0],"number"==typeof arguments[1]?s=arguments[1]:"function"==typeof arguments[1]&&(r=arguments[1],s=void 0),t=void 0,o=void 0):"object"==typeof arguments[0]?("function"==typeof arguments[1]&&(r=arguments[1]),o=arguments[0],t=void 0):"string"==typeof arguments[0]&&"function"==typeof arguments[1]&&(r=arguments[1],o=void 0),o=i({},o||{},{page:n,hitsPerPage:s,query:t});var c=this.as._getSearchParams(o,"");return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(a.indexName)+"/browse?"+c,hostType:"read",callback:r})},r.prototype.browseFrom=function(e,t){return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/browse?cursor="+encodeURIComponent(e),hostType:"read",callback:t})},r.prototype._search=function(e,t,o){return this.as._jsonRequest({cache:this.cache,method:"POST",url:t||"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:{params:e},hostType:"read",fallback:{method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName),body:{params:e}},callback:o})},r.prototype.getObject=function(e,t,o){var r=this;1!==arguments.length&&"function"!=typeof t||(o=t,t=void 0);var n="";if(void 0!==t){n="?attributes=";for(var s=0;s<t.length;++s)0!==s&&(n+=","),n+=t[s]}return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(r.indexName)+"/"+encodeURIComponent(e)+n,hostType:"read",callback:o})},r.prototype.getObjects=function(t,o,r){var n=e(10),s=e(29),i="Usage: index.getObjects(arrayOfObjectIDs[, callback])";if(!n(t))throw new Error(i);var a=this;1!==arguments.length&&"function"!=typeof o||(r=o,o=void 0);var c={requests:s(t,function(e){var t={indexName:a.indexName,objectID:e};return o&&(t.attributesToRetrieve=o.join(",")),t})};return this.as._jsonRequest({method:"POST",url:"/1/indexes/*/objects",hostType:"read",body:c,callback:r})},r.prototype.as=null,r.prototype.indexName=null,r.prototype.typeAheadArgs=null,r.prototype.typeAheadValueOption=null},{10:10,23:23,29:29,30:30}],17:[function(e,t,o){(function(t){"use strict";function o(t,n,s){var i=e(24),a=e(20);return s=i(s||{}),void 0===s.protocol&&(s.protocol=a()),s._ua=s._ua||o.ua,new r(t,n,s)}function r(){s.apply(this,arguments)}var n=e(9),s=e(12),i=e(27),a=e(21),c=e(22),u=e(31);window.algoliasearch=e(18),"debug"===t.env.NODE_ENV&&e(3).enable("algoliasearch*"),o.version=e(32),o.ua="Algolia for jQuery "+o.version,o.initPlaces=u(o),window.__algolia={debug:e(3),algoliasearch:o};var l=window.jQuery;l.algolia={Client:o,ua:o.ua,version:o.version},n(r,s),r.prototype._request=function(e,t){return new l.Deferred(function(o){var r=t.body;e=a(e,t.headers);var n={accept:"application/json"};r&&("POST"===t.method?n["content-type"]="application/x-www-form-urlencoded":n["content-type"]="application/json"),l.ajax(e,{type:t.method,timeout:t.timeout,dataType:"json",data:r,headers:n,complete:function(e,t){return"timeout"===t?void o.reject(new i.RequestTimeout):0===e.status?void o.reject(new i.Network({more:e})):void o.resolve({statusCode:e.status,body:e.responseJSON,responseText:e.responseText,headers:e.getAllResponseHeaders()})}})}).promise()},r.prototype._request.fallback=function(e,t){return e=a(e,t.headers),new l.Deferred(function(o){c(e,t,function(e,t){return e?void o.reject(e):void o.resolve(t)})}).promise()},r.prototype._promise={reject:function(e){return new l.Deferred(function(t){t.reject(e)}).promise()},resolve:function(e){return new l.Deferred(function(t){t.resolve(e)}).promise()},delay:function(e){return new l.Deferred(function(t){setTimeout(function(){t.resolve()},e)}).promise()}}}).call(this,e(2))},{12:12,18:18,2:2,20:20,21:21,22:22,24:24,27:27,3:3,31:31,32:32,9:9}],18:[function(e,t,o){"use strict";var r=e(12),n=e(19);t.exports=n(r)},{12:12,19:19}],19:[function(e,t,o){(function(o){"use strict";var r=e(8),n=r.Promise||e(5).Promise;t.exports=function(t,s){function i(t,o,r){var n=e(24),s=e(20);return r=n(r||{}),void 0===r.protocol&&(r.protocol=s()),r._ua=r._ua||i.ua,new a(t,o,r)}function a(){t.apply(this,arguments)}var c=e(9),u=e(27),l=e(21),p=e(22),d=e(31);s=s||"","debug"===o.env.NODE_ENV&&e(3).enable("algoliasearch*"),i.version=e(32),i.ua="Algolia for vanilla JavaScript "+s+i.version,i.initPlaces=d(i),r.__algolia={debug:e(3),algoliasearch:i};var h={hasXMLHttpRequest:"XMLHttpRequest"in r,hasXDomainRequest:"XDomainRequest"in r};return h.hasXMLHttpRequest&&(h.cors="withCredentials"in new XMLHttpRequest,h.timeout="timeout"in new XMLHttpRequest),c(a,t),a.prototype._request=function(e,t){return new n(function(o,r){function n(){if(!c){h.timeout||clearTimeout(a);var e;try{e={body:JSON.parse(d.responseText),responseText:d.responseText,statusCode:d.status,headers:d.getAllResponseHeaders&&d.getAllResponseHeaders()||{}}}catch(t){e=new u.UnparsableJSON({more:d.responseText})}e instanceof u.UnparsableJSON?r(e):o(e)}}function s(e){c||(h.timeout||clearTimeout(a),r(new u.Network({more:e})))}function i(){h.timeout||(c=!0,d.abort()),r(new u.RequestTimeout)}if(!h.cors&&!h.hasXDomainRequest)return void r(new u.Network("CORS not supported"));e=l(e,t.headers);var a,c,p=t.body,d=h.cors?new XMLHttpRequest:new XDomainRequest;d instanceof XMLHttpRequest?d.open(t.method,e,!0):d.open(t.method,e),h.cors&&(p&&("POST"===t.method?d.setRequestHeader("content-type","application/x-www-form-urlencoded"):d.setRequestHeader("content-type","application/json")),d.setRequestHeader("accept","application/json")),d.onprogress=function(){},d.onload=n,d.onerror=s,h.timeout?(d.timeout=t.timeout,d.ontimeout=i):a=setTimeout(i,t.timeout),d.send(p)})},a.prototype._request.fallback=function(e,t){return e=l(e,t.headers),new n(function(o,r){p(e,t,function(e,t){return e?void r(e):void o(t)})})},a.prototype._promise={reject:function(e){return n.reject(e)},resolve:function(e){return n.resolve(e)},delay:function(e){return new n(function(t){setTimeout(t,e)})}},i}}).call(this,e(2))},{2:2,20:20,21:21,22:22,24:24,27:27,3:3,31:31,32:32,5:5,8:8,9:9}],20:[function(e,t,o){"use strict";function r(){var e=window.document.location.protocol;return"http:"!==e&&"https:"!==e&&(e="http:"),e}t.exports=r},{}],21:[function(e,t,o){"use strict";function r(e,t){return e+=/\?/.test(e)?"&":"?",e+n(t)}t.exports=r;var n=e(11)},{11:11}],22:[function(e,t,o){"use strict";function r(e,t,o){function r(){t.debug("JSONP: success"),m||d||(m=!0,p||(t.debug("JSONP: Fail. Script loaded but did not call the callback"),a(),o(new n.JSONPScriptFail)))}function i(){"loaded"!==this.readyState&&"complete"!==this.readyState||r()}function a(){clearTimeout(v),f.onload=null,f.onreadystatechange=null,f.onerror=null,h.removeChild(f)}function c(){try{delete window[y],delete window[y+"_loaded"]}catch(e){window[y]=window[y+"_loaded"]=void 0}}function u(){t.debug("JSONP: Script timeout"),d=!0,a(),o(new n.RequestTimeout)}function l(){t.debug("JSONP: Script error"),m||d||(a(),o(new n.JSONPScriptError))}if("GET"!==t.method)return void o(new Error("Method "+t.method+" "+e+" is not supported by JSONP."));t.debug("JSONP: start");var p=!1,d=!1;s+=1;var h=document.getElementsByTagName("head")[0],f=document.createElement("script"),y="algoliaJSONP_"+s,m=!1;window[y]=function(e){return c(),d?void t.debug("JSONP: Late answer, ignoring"):(p=!0,a(),void o(null,{body:e}))},e+="&callback="+y,t.jsonBody&&t.jsonBody.params&&(e+="&"+t.jsonBody.params);var v=setTimeout(u,t.timeout);f.onreadystatechange=i,f.onload=r,f.onerror=l,f.async=!0,f.defer=!0,f.src=e,h.appendChild(f)}t.exports=r;var n=e(27),s=0},{27:27}],23:[function(e,t,o){function r(e,t){return function(o,r,s){if("function"==typeof o&&"object"==typeof r||"object"==typeof s)throw new n.AlgoliaSearchError("index.search usage is index.search(query, params, cb)");0===arguments.length||"function"==typeof o?(s=o,o=""):1!==arguments.length&&"function"!=typeof r||(s=r,r=void 0),"object"==typeof o&&null!==o?(r=o,o=void 0):void 0!==o&&null!==o||(o="");var i="";return void 0!==o&&(i+=e+"="+encodeURIComponent(o)),void 0!==r&&(i=this.as._getSearchParams(r,i)),this._search(i,t,s)}}t.exports=r;var n=e(27)},{27:27}],24:[function(e,t,o){t.exports=function(e){return JSON.parse(JSON.stringify(e))}},{}],25:[function(e,t,o){t.exports=function(e,t){function o(){return r||(console.log(t),r=!0),e.apply(this,arguments)}var r=!1;return o}},{}],26:[function(e,t,o){t.exports=function(e,t){var o=e.toLowerCase().replace(".","").replace("()","");return"algoliasearch: `"+e+"` was replaced by `"+t+"`. Please see https://github.com/algolia/algoliasearch-client-js/wiki/Deprecated#"+o}},{}],27:[function(e,t,o){"use strict";function r(t,o){var r=e(7),n=this;"function"==typeof Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):n.stack=(new Error).stack||"Cannot get a stacktrace, browser is too old",this.name="AlgoliaSearchError",this.message=t||"Unknown error",o&&r(o,function(e,t){n[t]=e})}function n(e,t){function o(){var o=Array.prototype.slice.call(arguments,0);"string"!=typeof o[0]&&o.unshift(t),r.apply(this,o),this.name="AlgoliaSearch"+e+"Error"}return s(o,r),o}var s=e(9);s(r,Error),t.exports={AlgoliaSearchError:r,UnparsableJSON:n("UnparsableJSON","Could not parse the incoming response as JSON, see err.more for details"),RequestTimeout:n("RequestTimeout","Request timedout before getting a response"),Network:n("Network","Network issue, see err.more for details"),JSONPScriptFail:n("JSONPScriptFail","<script> was loaded but did not call our provided callback"),JSONPScriptError:n("JSONPScriptError","<script> unable to load due to an `error` event on it"),Unknown:n("Unknown","Unknown error occured")}},{7:7,9:9}],28:[function(e,t,o){t.exports=function(e,t){t(e,0)}},{}],29:[function(e,t,o){var r=e(7);t.exports=function(e,t){var o=[];return r(e,function(r,n){o.push(t(r,n,e))}),o}},{7:7}],30:[function(e,t,o){var r=e(7);t.exports=function n(e){var t=Array.prototype.slice.call(arguments);return r(t,function(t){for(var o in t)t.hasOwnProperty(o)&&("object"==typeof e[o]&&"object"==typeof t[o]?e[o]=n({},e[o],t[o]):void 0!==t[o]&&(e[o]=t[o]))}),e}},{7:7}],31:[function(e,t,o){function r(t){return function(o,r,s){var i=e(24);s=s&&i(s)||{},s.hosts=s.hosts||["places-dsn.algolia.net","places-1.algolianet.com","places-2.algolianet.com","places-3.algolianet.com"],0!==arguments.length&&"object"!=typeof o&&void 0!==o||(o="",r="",s._allowEmptyCredentials=!0);var a=t(o,r,s),c=a.initIndex("places");return c.search=n("query","/1/places/query"),c}}t.exports=r;var n=e(23)},{23:23,24:24}],32:[function(e,t,o){"use strict";t.exports="3.18.0"},{}]},{},[17]);
1
+ /*! algoliasearch 3.20.3 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
2
+ !function(e){var t;"undefined"!=typeof window?t=window:"undefined"!=typeof self&&(t=self),t.ALGOLIA_MIGRATION_LAYER=e()}(function(){return function e(t,r,n){function o(s,a){if(!r[s]){if(!t[s]){var c="function"==typeof require&&require;if(!a&&c)return c(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var l=r[s]={exports:{}};t[s][0].call(l.exports,function(e){var r=t[s][1][e];return o(r?r:e)},l,l.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}({1:[function(e,t,r){function n(e,t){for(var r in t)e.setAttribute(r,t[r])}function o(e,t){e.onload=function(){this.onerror=this.onload=null,t(null,e)},e.onerror=function(){this.onerror=this.onload=null,t(new Error("Failed to load "+this.src),e)}}function i(e,t){e.onreadystatechange=function(){"complete"!=this.readyState&&"loaded"!=this.readyState||(this.onreadystatechange=null,t(null,e))}}t.exports=function(e,t,r){var s=document.head||document.getElementsByTagName("head")[0],a=document.createElement("script");"function"==typeof t&&(r=t,t={}),t=t||{},r=r||function(){},a.type=t.type||"text/javascript",a.charset=t.charset||"utf8",a.async=!("async"in t)||!!t.async,a.src=e,t.attrs&&n(a,t.attrs),t.text&&(a.text=""+t.text);var c="onload"in a?o:i;c(a,r),a.onload||o(a,r),s.appendChild(a)}},{}],2:[function(e,t,r){"use strict";function n(e){for(var t=new RegExp("cdn\\.jsdelivr\\.net/algoliasearch/latest/"+e.replace(".","\\.")+"(?:\\.min)?\\.js$"),r=document.getElementsByTagName("script"),n=!1,o=0,i=r.length;o<i;o++)if(r[o].src&&t.test(r[o].src)){n=!0;break}return n}t.exports=n},{}],3:[function(e,t,r){"use strict";function n(t){var r=e(1),n="//cdn.jsdelivr.net/algoliasearch/2/"+t+".min.js",i="-- AlgoliaSearch `latest` warning --\nWarning, you are using the `latest` version string from jsDelivr to load the AlgoliaSearch library.\nUsing `latest` is no more recommended, you should load //cdn.jsdelivr.net/algoliasearch/2/algoliasearch.min.js\n\nAlso, we updated the AlgoliaSearch JavaScript client to V3. If you want to upgrade,\nplease read our migration guide at https://github.com/algolia/algoliasearch-client-js/wiki/Migration-guide-from-2.x.x-to-3.x.x\n-- /AlgoliaSearch `latest` warning --";window.console&&(window.console.warn?window.console.warn(i):window.console.log&&window.console.log(i));try{document.write("<script>window.ALGOLIA_SUPPORTS_DOCWRITE = true</script>"),window.ALGOLIA_SUPPORTS_DOCWRITE===!0?(document.write('<script src="'+n+'"></script>'),o("document.write")()):r(n,o("DOMElement"))}catch(s){r(n,o("DOMElement"))}}function o(e){return function(){var t="AlgoliaSearch: loaded V2 script using "+e;window.console&&window.console.log&&window.console.log(t)}}t.exports=n},{1:1}],4:[function(e,t,r){"use strict";function n(){var e="-- AlgoliaSearch V2 => V3 error --\nYou are trying to use a new version of the AlgoliaSearch JavaScript client with an old notation.\nPlease read our migration guide at https://github.com/algolia/algoliasearch-client-js/wiki/Migration-guide-from-2.x.x-to-3.x.x\n-- /AlgoliaSearch V2 => V3 error --";window.AlgoliaSearch=function(){throw new Error(e)},window.AlgoliaSearchHelper=function(){throw new Error(e)},window.AlgoliaExplainResults=function(){throw new Error(e)}}t.exports=n},{}],5:[function(e,t,r){"use strict";function n(t){var r=e(2),n=e(3),o=e(4);r(t)?n(t):o()}n("algoliasearch.jquery")},{2:2,3:3,4:4}]},{},[5])(5)}),function e(t,r,n){function o(s,a){if(!r[s]){if(!t[s]){var c="function"==typeof require&&require;if(!a&&c)return c(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var l=r[s]={exports:{}};t[s][0].call(l.exports,function(e){var r=t[s][1][e];return o(r?r:e)},l,l.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}({1:[function(e,t,r){(function(n){function o(){return"undefined"!=typeof document&&"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}function i(){var e=arguments,t=this.useColors;if(e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+r.humanize(this.diff),!t)return e;var n="color: "+this.color;e=[e[0],n,"color: inherit"].concat(Array.prototype.slice.call(e,1));var o=0,i=0;return e[0].replace(/%[a-z%]/g,function(e){"%%"!==e&&(o++,"%c"===e&&(i=o))}),e.splice(i,0,n),e}function s(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function a(e){try{null==e?r.storage.removeItem("debug"):r.storage.debug=e}catch(t){}}function c(){try{return r.storage.debug}catch(e){}if("undefined"!=typeof n&&"env"in n)return n.env.DEBUG}function u(){try{return window.localStorage}catch(e){}}r=t.exports=e(2),r.log=s,r.formatArgs=i,r.save=a,r.load=c,r.useColors=o,r.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:u(),r.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],r.formatters.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}},r.enable(c())}).call(this,e(12))},{12:12,2:2}],2:[function(e,t,r){function n(){return r.colors[l++%r.colors.length]}function o(e){function t(){}function o(){var e=o,t=+new Date,i=t-(u||t);e.diff=i,e.prev=u,e.curr=t,u=t,null==e.useColors&&(e.useColors=r.useColors()),null==e.color&&e.useColors&&(e.color=n());for(var s=new Array(arguments.length),a=0;a<s.length;a++)s[a]=arguments[a];s[0]=r.coerce(s[0]),"string"!=typeof s[0]&&(s=["%o"].concat(s));var c=0;s[0]=s[0].replace(/%([a-z%])/g,function(t,n){if("%%"===t)return t;c++;var o=r.formatters[n];if("function"==typeof o){var i=s[c];t=o.call(e,i),s.splice(c,1),c--}return t}),s=r.formatArgs.apply(e,s);var l=o.log||r.log||console.log.bind(console);l.apply(e,s)}t.enabled=!1,o.enabled=!0;var i=r.enabled(e)?o:t;return i.namespace=e,i}function i(e){r.save(e);for(var t=(e||"").split(/[\s,]+/),n=t.length,o=0;o<n;o++)t[o]&&(e=t[o].replace(/[\\^$+?.()|[\]{}]/g,"\\$&").replace(/\*/g,".*?"),"-"===e[0]?r.skips.push(new RegExp("^"+e.substr(1)+"$")):r.names.push(new RegExp("^"+e+"$")))}function s(){r.enable("")}function a(e){var t,n;for(t=0,n=r.skips.length;t<n;t++)if(r.skips[t].test(e))return!1;for(t=0,n=r.names.length;t<n;t++)if(r.names[t].test(e))return!0;return!1}function c(e){return e instanceof Error?e.stack||e.message:e}r=t.exports=o.debug=o,r.coerce=c,r.disable=s,r.enable=i,r.enabled=a,r.humanize=e(9),r.names=[],r.skips=[],r.formatters={};var u,l=0},{9:9}],3:[function(e,t,r){(function(n,o){!function(e,n){"object"==typeof r&&"undefined"!=typeof t?t.exports=n():"function"==typeof define&&define.amd?define(n):e.ES6Promise=n()}(this,function(){"use strict";function t(e){return"function"==typeof e||"object"==typeof e&&null!==e}function r(e){return"function"==typeof e}function i(e){X=e}function s(e){W=e}function a(){return function(){return n.nextTick(h)}}function c(){return"undefined"!=typeof V?function(){V(h)}:p()}function u(){var e=0,t=new Z(h),r=document.createTextNode("");return t.observe(r,{characterData:!0}),function(){r.data=e=++e%2}}function l(){var e=new MessageChannel;return e.port1.onmessage=h,function(){return e.port2.postMessage(0)}}function p(){var e=setTimeout;return function(){return e(h,1)}}function h(){for(var e=0;e<G;e+=2){var t=re[e],r=re[e+1];t(r),re[e]=void 0,re[e+1]=void 0}G=0}function d(){try{var t=e,r=t("vertx");return V=r.runOnLoop||r.runOnContext,c()}catch(n){return p()}}function f(e,t){var r=arguments,n=this,o=new this.constructor(m);void 0===o[oe]&&C(o);var i=n._state;return i?!function(){var e=r[i-1];W(function(){return P(i,o,e,n._result)})}():O(n,o,e,t),o}function y(e){var t=this;if(e&&"object"==typeof e&&e.constructor===t)return e;var r=new t(m);return j(r,e),r}function m(){}function v(){return new TypeError("You cannot resolve a promise with itself")}function g(){return new TypeError("A promises callback cannot return that same promise.")}function b(e){try{return e.then}catch(t){return ce.error=t,ce}}function w(e,t,r,n){try{e.call(t,r,n)}catch(o){return o}}function _(e,t,r){W(function(e){var n=!1,o=w(r,t,function(r){n||(n=!0,t!==r?j(e,r):I(e,r))},function(t){n||(n=!0,k(e,t))},"Settle: "+(e._label||" unknown promise"));!n&&o&&(n=!0,k(e,o))},e)}function x(e,t){t._state===se?I(e,t._result):t._state===ae?k(e,t._result):O(t,void 0,function(t){return j(e,t)},function(t){return k(e,t)})}function T(e,t,n){t.constructor===e.constructor&&n===f&&t.constructor.resolve===y?x(e,t):n===ce?k(e,ce.error):void 0===n?I(e,t):r(n)?_(e,t,n):I(e,t)}function j(e,r){e===r?k(e,v()):t(r)?T(e,r,b(r)):I(e,r)}function S(e){e._onerror&&e._onerror(e._result),R(e)}function I(e,t){e._state===ie&&(e._result=t,e._state=se,0!==e._subscribers.length&&W(R,e))}function k(e,t){e._state===ie&&(e._state=ae,e._result=t,W(S,e))}function O(e,t,r,n){var o=e._subscribers,i=o.length;e._onerror=null,o[i]=t,o[i+se]=r,o[i+ae]=n,0===i&&e._state&&W(R,e)}function R(e){var t=e._subscribers,r=e._state;if(0!==t.length){for(var n=void 0,o=void 0,i=e._result,s=0;s<t.length;s+=3)n=t[s],o=t[s+r],n?P(r,n,o,i):o(i);e._subscribers.length=0}}function A(){this.error=null}function E(e,t){try{return e(t)}catch(r){return ue.error=r,ue}}function P(e,t,n,o){var i=r(n),s=void 0,a=void 0,c=void 0,u=void 0;if(i){if(s=E(n,o),s===ue?(u=!0,a=s.error,s=null):c=!0,t===s)return void k(t,g())}else s=o,c=!0;t._state!==ie||(i&&c?j(t,s):u?k(t,a):e===se?I(t,s):e===ae&&k(t,s))}function q(e,t){try{t(function(t){j(e,t)},function(t){k(e,t)})}catch(r){k(e,r)}}function U(){return le++}function C(e){e[oe]=le++,e._state=void 0,e._result=void 0,e._subscribers=[]}function N(e,t){this._instanceConstructor=e,this.promise=new e(m),this.promise[oe]||C(this.promise),$(t)?(this._input=t,this.length=t.length,this._remaining=t.length,this._result=new Array(this.length),0===this.length?I(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&I(this.promise,this._result))):k(this.promise,D())}function D(){return new Error("Array Methods must be provided an Array")}function L(e){return new N(this,e).promise}function H(e){var t=this;return new t($(e)?function(r,n){for(var o=e.length,i=0;i<o;i++)t.resolve(e[i]).then(r,n)}:function(e,t){return t(new TypeError("You must pass an array to race."))})}function M(e){var t=this,r=new t(m);return k(r,e),r}function J(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function F(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function K(e){this[oe]=U(),this._result=this._state=void 0,this._subscribers=[],m!==e&&("function"!=typeof e&&J(),this instanceof K?q(this,e):F())}function B(){var e=void 0;if("undefined"!=typeof o)e=o;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var r=e.Promise;if(r){var n=null;try{n=Object.prototype.toString.call(r.resolve())}catch(t){}if("[object Promise]"===n&&!r.cast)return}e.Promise=K}var Q=void 0;Q=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var $=Q,G=0,V=void 0,X=void 0,W=function(e,t){re[G]=e,re[G+1]=t,G+=2,2===G&&(X?X(h):ne())},Y="undefined"!=typeof window?window:void 0,z=Y||{},Z=z.MutationObserver||z.WebKitMutationObserver,ee="undefined"==typeof self&&"undefined"!=typeof n&&"[object process]"==={}.toString.call(n),te="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,re=new Array(1e3),ne=void 0;ne=ee?a():Z?u():te?l():void 0===Y&&"function"==typeof e?d():p();var oe=Math.random().toString(36).substring(16),ie=void 0,se=1,ae=2,ce=new A,ue=new A,le=0;return N.prototype._enumerate=function(){for(var e=this.length,t=this._input,r=0;this._state===ie&&r<e;r++)this._eachEntry(t[r],r)},N.prototype._eachEntry=function(e,t){var r=this._instanceConstructor,n=r.resolve;if(n===y){var o=b(e);if(o===f&&e._state!==ie)this._settledAt(e._state,t,e._result);else if("function"!=typeof o)this._remaining--,this._result[t]=e;else if(r===K){var i=new r(m);T(i,e,o),this._willSettleAt(i,t)}else this._willSettleAt(new r(function(t){return t(e)}),t)}else this._willSettleAt(n(e),t)},N.prototype._settledAt=function(e,t,r){var n=this.promise;n._state===ie&&(this._remaining--,e===ae?k(n,r):this._result[t]=r),0===this._remaining&&I(n,this._result)},N.prototype._willSettleAt=function(e,t){var r=this;O(e,void 0,function(e){return r._settledAt(se,t,e)},function(e){return r._settledAt(ae,t,e)})},K.all=L,K.race=H,K.resolve=y,K.reject=M,K._setScheduler=i,K._setAsap=s,K._asap=W,K.prototype={constructor:K,then:f,"catch":function(e){return this.then(null,e)}},K.polyfill=B,K.Promise=K,K})}).call(this,e(12),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{12:12}],4:[function(e,t,r){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function o(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,r,n,i,c,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;var l=new Error('Uncaught, unspecified "error" event. ('+t+")");throw l.context=t,l}if(r=this._events[e],a(r))return!1;if(o(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:i=Array.prototype.slice.call(arguments,1),r.apply(this,i)}else if(s(r))for(i=Array.prototype.slice.call(arguments,1),u=r.slice(),n=u.length,c=0;c<n;c++)u[c].apply(this,i);return!0},n.prototype.addListener=function(e,t){var r;if(!o(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,o(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(r=a(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function r(){this.removeListener(e,r),n||(n=!0,t.apply(this,arguments))}if(!o(t))throw TypeError("listener must be a function");var n=!1;return r.listener=t,this.on(e,r),this},n.prototype.removeListener=function(e,t){var r,n,i,a;if(!o(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],i=r.length,n=-1,r===t||o(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(r)){for(a=i;a-- >0;)if(r[a]===t||r[a].listener&&r[a].listener===t){n=a;break}if(n<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(n,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],o(r))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?o(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(o(t))return 1;if(t)return t.length}return 0},n.listenerCount=function(e,t){return e.listenerCount(t)}},{}],5:[function(e,t,r){var n=Object.prototype.hasOwnProperty,o=Object.prototype.toString;t.exports=function(e,t,r){if("[object Function]"!==o.call(t))throw new TypeError("iterator must be a function");var i=e.length;if(i===+i)for(var s=0;s<i;s++)t.call(r,e[s],s,e);else for(var a in e)n.call(e,a)&&t.call(r,e[a],a,e)}},{}],6:[function(e,t,r){(function(e){"undefined"!=typeof window?t.exports=window:"undefined"!=typeof e?t.exports=e:"undefined"!=typeof self?t.exports=self:t.exports={}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],7:[function(e,t,r){"function"==typeof Object.create?t.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},{}],8:[function(e,t,r){var n={}.toString;t.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},{}],9:[function(e,t,r){function n(e){if(e=String(e),!(e.length>1e4)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var r=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*p;case"days":case"day":case"d":return r*l;case"hours":case"hour":case"hrs":case"hr":case"h":return r*u;case"minutes":case"minute":case"mins":case"min":case"m":return r*c;case"seconds":case"second":case"secs":case"sec":case"s":return r*a;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function o(e){return e>=l?Math.round(e/l)+"d":e>=u?Math.round(e/u)+"h":e>=c?Math.round(e/c)+"m":e>=a?Math.round(e/a)+"s":e+"ms"}function i(e){return s(e,l,"day")||s(e,u,"hour")||s(e,c,"minute")||s(e,a,"second")||e+" ms"}function s(e,t,r){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+r:Math.ceil(e/t)+" "+r+"s"}var a=1e3,c=60*a,u=60*c,l=24*u,p=365.25*l;t.exports=function(e,t){t=t||{};var r=typeof e;if("string"===r&&e.length>0)return n(e);if("number"===r&&isNaN(e)===!1)return t["long"]?i(e):o(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},{}],10:[function(e,t,r){"use strict";var n=Object.prototype.hasOwnProperty,o=Object.prototype.toString,i=Array.prototype.slice,s=e(11),a=Object.prototype.propertyIsEnumerable,c=!a.call({toString:null},"toString"),u=a.call(function(){},"prototype"),l=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],p=function(e){var t=e.constructor;return t&&t.prototype===e},h={$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},d=function(){if("undefined"==typeof window)return!1;for(var e in window)try{if(!h["$"+e]&&n.call(window,e)&&null!==window[e]&&"object"==typeof window[e])try{p(window[e])}catch(t){return!0}}catch(t){return!0}return!1}(),f=function(e){if("undefined"==typeof window||!d)return p(e);try{return p(e)}catch(t){return!1}},y=function(e){var t=null!==e&&"object"==typeof e,r="[object Function]"===o.call(e),i=s(e),a=t&&"[object String]"===o.call(e),p=[];if(!t&&!r&&!i)throw new TypeError("Object.keys called on a non-object");var h=u&&r;if(a&&e.length>0&&!n.call(e,0))for(var d=0;d<e.length;++d)p.push(String(d));if(i&&e.length>0)for(var y=0;y<e.length;++y)p.push(String(y));else for(var m in e)h&&"prototype"===m||!n.call(e,m)||p.push(String(m));if(c)for(var v=f(e),g=0;g<l.length;++g)v&&"constructor"===l[g]||!n.call(e,l[g])||p.push(l[g]);return p};y.shim=function(){if(Object.keys){var e=function(){return 2===(Object.keys(arguments)||"").length}(1,2);if(!e){var t=Object.keys;Object.keys=function(e){return t(s(e)?i.call(e):e)}}}else Object.keys=y;return Object.keys||y},t.exports=y},{11:11}],11:[function(e,t,r){"use strict";var n=Object.prototype.toString;t.exports=function(e){var t=n.call(e),r="[object Arguments]"===t;return r||(r="[object Array]"!==t&&null!==e&&"object"==typeof e&&"number"==typeof e.length&&e.length>=0&&"[object Function]"===n.call(e.callee)),r}},{}],12:[function(e,t,r){function n(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(p===setTimeout)return setTimeout(e,0);if((p===n||!p)&&setTimeout)return p=setTimeout,setTimeout(e,0);try{return p(e,0)}catch(t){try{return p.call(null,e,0)}catch(t){return p.call(this,e,0)}}}function s(e){if(h===clearTimeout)return clearTimeout(e);if((h===o||!h)&&clearTimeout)return h=clearTimeout,clearTimeout(e);try{return h(e)}catch(t){try{return h.call(null,e)}catch(t){return h.call(this,e)}}}function a(){m&&f&&(m=!1,f.length?y=f.concat(y):v=-1,y.length&&c())}function c(){if(!m){var e=i(a);m=!0;for(var t=y.length;t;){for(f=y,y=[];++v<t;)f&&f[v].run();v=-1,t=y.length}f=null,m=!1,s(e)}}function u(e,t){this.fun=e,this.array=t}function l(){}var p,h,d=t.exports={};!function(){try{p="function"==typeof setTimeout?setTimeout:n}catch(e){p=n}try{h="function"==typeof clearTimeout?clearTimeout:o}catch(e){h=o}}();var f,y=[],m=!1,v=-1;d.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];y.push(new u(e,t)),1!==y.length||m||i(c)},u.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=l,d.addListener=l,d.once=l,d.off=l,d.removeListener=l,d.removeAllListeners=l,d.emit=l,d.binding=function(e){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(e){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},{}],13:[function(e,t,r){"use strict";function n(e,t){if(e.map)return e.map(t);for(var r=[],n=0;n<e.length;n++)r.push(t(e[n],n));return r}var o=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};t.exports=function(e,t,r,a){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?n(s(e),function(s){var a=encodeURIComponent(o(s))+r;return i(e[s])?n(e[s],function(e){return a+encodeURIComponent(o(e))}).join(t):a+encodeURIComponent(o(e[s]))}).join(t):a?encodeURIComponent(o(a))+r+encodeURIComponent(o(e)):""};var i=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},s=Object.keys||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return t}},{}],14:[function(e,t,r){function n(){c.apply(this,arguments)}function o(){var e="Not implemented in this environment.\nIf you feel this is a mistake, write to support@algolia.com";throw new l.AlgoliaSearchError(e)}t.exports=n;var i=e(16),s=e(27),a=e(28),c=e(15),u=e(7),l=e(29);u(n,c),n.prototype.deleteIndex=function(e,t){return this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(e),hostType:"write",callback:t})},n.prototype.moveIndex=function(e,t,r){var n={operation:"move",destination:t};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(e)+"/operation",body:n,hostType:"write",callback:r})},n.prototype.copyIndex=function(e,t,r){var n={operation:"copy",destination:t};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(e)+"/operation",body:n,hostType:"write",callback:r})},n.prototype.getLogs=function(t,r,n){var o=e(26),i={};return"object"==typeof t?(i=o(t),n=r):0===arguments.length||"function"==typeof t?n=t:1===arguments.length||"function"==typeof r?(n=r,i.offset=t):(i.offset=t,i.length=r),void 0===i.offset&&(i.offset=0),void 0===i.length&&(i.length=10),this._jsonRequest({method:"GET",url:"/1/logs?"+this._getSearchParams(i,""),hostType:"read",callback:n})},n.prototype.listIndexes=function(e,t){var r="";return void 0===e||"function"==typeof e?t=e:r="?page="+e,this._jsonRequest({method:"GET",url:"/1/indexes"+r,hostType:"read",callback:t})},n.prototype.initIndex=function(e){return new i(this,e)},n.prototype.listUserKeys=function(e){return this._jsonRequest({method:"GET",url:"/1/keys",hostType:"read",callback:e})},n.prototype.getUserKeyACL=function(e,t){return this._jsonRequest({method:"GET",url:"/1/keys/"+e,hostType:"read",callback:t})},n.prototype.deleteUserKey=function(e,t){return this._jsonRequest({method:"DELETE",url:"/1/keys/"+e,hostType:"write",callback:t})},n.prototype.addUserKey=function(t,r,n){var o=e(8),i="Usage: client.addUserKey(arrayOfAcls[, params, callback])";if(!o(t))throw new Error(i);1!==arguments.length&&"function"!=typeof r||(n=r,r=null);var s={acl:t};return r&&(s.validity=r.validity,s.maxQueriesPerIPPerHour=r.maxQueriesPerIPPerHour,s.maxHitsPerQuery=r.maxHitsPerQuery,s.indexes=r.indexes,s.description=r.description,r.queryParameters&&(s.queryParameters=this._getSearchParams(r.queryParameters,"")),s.referers=r.referers),this._jsonRequest({method:"POST",url:"/1/keys",body:s,hostType:"write",callback:n})},n.prototype.addUserKeyWithValidity=s(function(e,t,r){return this.addUserKey(e,t,r)},a("client.addUserKeyWithValidity()","client.addUserKey()")),n.prototype.updateUserKey=function(t,r,n,o){var i=e(8),s="Usage: client.updateUserKey(key, arrayOfAcls[, params, callback])";if(!i(r))throw new Error(s);2!==arguments.length&&"function"!=typeof n||(o=n,n=null);var a={acl:r};return n&&(a.validity=n.validity,a.maxQueriesPerIPPerHour=n.maxQueriesPerIPPerHour,a.maxHitsPerQuery=n.maxHitsPerQuery,a.indexes=n.indexes,a.description=n.description,n.queryParameters&&(a.queryParameters=this._getSearchParams(n.queryParameters,"")),a.referers=n.referers),this._jsonRequest({method:"PUT",url:"/1/keys/"+t,body:a,hostType:"write",callback:o})},n.prototype.startQueriesBatch=s(function(){this._batch=[]},a("client.startQueriesBatch()","client.search()")),n.prototype.addQueryInBatch=s(function(e,t,r){this._batch.push({indexName:e,query:t,params:r})},a("client.addQueryInBatch()","client.search()")),n.prototype.sendQueriesBatch=s(function(e){return this.search(this._batch,e)},a("client.sendQueriesBatch()","client.search()")),n.prototype.batch=function(t,r){var n=e(8),o="Usage: client.batch(operations[, callback])";if(!n(t))throw new Error(o);return this._jsonRequest({method:"POST",url:"/1/indexes/*/batch",body:{requests:t},hostType:"write",callback:r})},n.prototype.destroy=o,n.prototype.enableRateLimitForward=o,n.prototype.disableRateLimitForward=o,n.prototype.useSecuredAPIKey=o,n.prototype.disableSecuredAPIKey=o,n.prototype.generateSecuredApiKey=o},{15:15,16:16,26:26,27:27,28:28,29:29,7:7,8:8}],15:[function(e,t,r){(function(r){function n(t,r,n){var i=e(1)("algoliasearch"),s=e(26),a=e(8),u=e(31),l="Usage: algoliasearch(applicationID, apiKey, opts)";if(n._allowEmptyCredentials!==!0&&!t)throw new c.AlgoliaSearchError("Please provide an application ID. "+l);if(n._allowEmptyCredentials!==!0&&!r)throw new c.AlgoliaSearchError("Please provide an API key. "+l);this.applicationID=t,this.apiKey=r,this.hosts={read:[],write:[]},n=n||{};var p=n.protocol||"https:";if(this._timeouts=n.timeouts||{connect:1e3,read:2e3,write:3e4},n.timeout&&(this._timeouts.connect=this._timeouts.read=this._timeouts.write=n.timeout),/:$/.test(p)||(p+=":"),"http:"!==n.protocol&&"https:"!==n.protocol)throw new c.AlgoliaSearchError("protocol must be `http:` or `https:` (was `"+n.protocol+"`)");if(this._checkAppIdData(),n.hosts)a(n.hosts)?(this.hosts.read=s(n.hosts),this.hosts.write=s(n.hosts)):(this.hosts.read=s(n.hosts.read),this.hosts.write=s(n.hosts.write));else{var h=u(this._shuffleResult,function(e){return t+"-"+e+".algolianet.com"});this.hosts.read=[this.applicationID+"-dsn.algolia.net"].concat(h),this.hosts.write=[this.applicationID+".algolia.net"].concat(h)}this.hosts.read=u(this.hosts.read,o(p)),this.hosts.write=u(this.hosts.write,o(p)),this.extraHeaders=[],this.cache=n._cache||{},this._ua=n._ua,this._useCache=!(void 0!==n._useCache&&!n._cache)||n._useCache,this._useFallback=void 0===n.useFallback||n.useFallback,this._setTimeout=n._setTimeout,i("init done, %j",this)}function o(e){return function(t){return e+"//"+t.toLowerCase()}}function i(e){if(void 0===Array.prototype.toJSON)return JSON.stringify(e);var t=Array.prototype.toJSON;delete Array.prototype.toJSON;var r=JSON.stringify(e);return Array.prototype.toJSON=t,r}function s(e){for(var t,r,n=e.length;0!==n;)r=Math.floor(Math.random()*n),n-=1,t=e[n],e[n]=e[r],e[r]=t;return e}function a(e){var t={};for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var n;n="x-algolia-api-key"===r||"x-algolia-application-id"===r?"**hidden for security purposes**":e[r],t[r]=n}return t}t.exports=n;var c=e(29),u=e(30),l=e(18),p=e(35),h=500,d=r.env.RESET_APP_DATA_TIMER&&parseInt(r.env.RESET_APP_DATA_TIMER,10)||12e4;n.prototype.initIndex=function(e){return new l(this,e)},n.prototype.setExtraHeader=function(e,t){this.extraHeaders.push({name:e.toLowerCase(),value:t})},n.prototype.addAlgoliaAgent=function(e){this._ua.indexOf(";"+e)===-1&&(this._ua+=";"+e)},n.prototype._jsonRequest=function(t){function r(e,u){function h(e){var t=e&&e.body&&e.body.message&&e.body.status||e.statusCode||e&&e.body&&200;s("received response: statusCode: %s, computed statusCode: %d, headers: %j",e.statusCode,t,e.headers);var r=2===Math.floor(t/100),i=new Date;if(m.push({currentHost:x,headers:a(o),content:n||null,contentLength:void 0!==n?n.length:null,method:u.method,timeouts:u.timeouts,url:u.url,startTime:_,endTime:i,duration:i-_,statusCode:t}),r)return p._useCache&&l&&(l[w]=e.responseText),e.body;var h=4!==Math.floor(t/100);if(h)return d+=1,g();s("unrecoverable error");var f=new c.AlgoliaSearchError(e.body&&e.body.message,{debugData:m,statusCode:t});return p._promise.reject(f)}function v(e){s("error: %s, stack: %s",e.message,e.stack);var r=new Date;return m.push({currentHost:x,headers:a(o),content:n||null,contentLength:void 0!==n?n.length:null,method:u.method,timeouts:u.timeouts,url:u.url,startTime:_,endTime:r,duration:r-_}),e instanceof c.AlgoliaSearchError||(e=new c.Unknown(e&&e.message,e)),d+=1,e instanceof c.Unknown||e instanceof c.UnparsableJSON||d>=p.hosts[t.hostType].length&&(f||!y)?(e.debugData=m,p._promise.reject(e)):e instanceof c.RequestTimeout?b():g()}function g(){return s("retrying request"),p._incrementHostIndex(t.hostType),r(e,u)}function b(){return s("retrying request with higher timeout"),p._incrementHostIndex(t.hostType),p._incrementTimeoutMultipler(),u.timeouts=p._getTimeoutsForRequest(t.hostType),r(e,u)}p._checkAppIdData();var w,_=new Date;if(p._useCache&&(w=t.url),p._useCache&&n&&(w+="_body_"+u.body),p._useCache&&l&&void 0!==l[w])return s("serving response from cache"),p._promise.resolve(JSON.parse(l[w]));if(d>=p.hosts[t.hostType].length)return!y||f?(s("could not get any response"),p._promise.reject(new c.AlgoliaSearchError("Cannot connect to the AlgoliaSearch API. Send an email to support@algolia.com to report and resolve the issue. Application id was: "+p.applicationID,{debugData:m}))):(s("switching to fallback"),d=0,u.method=t.fallback.method,u.url=t.fallback.url,
3
+ u.jsonBody=t.fallback.body,u.jsonBody&&(u.body=i(u.jsonBody)),o=p._computeRequestHeaders(),u.timeouts=p._getTimeoutsForRequest(t.hostType),p._setHostIndexByType(0,t.hostType),f=!0,r(p._request.fallback,u));var x=p._getHostByType(t.hostType),T=x+u.url,j={body:u.body,jsonBody:u.jsonBody,method:u.method,headers:o,timeouts:u.timeouts,debug:s};return s("method: %s, url: %s, headers: %j, timeouts: %d",j.method,T,j.headers,j.timeouts),e===p._request.fallback&&s("using fallback"),e.call(p,T,j).then(h,v)}this._checkAppIdData();var n,o,s=e(1)("algoliasearch:"+t.url),l=t.cache,p=this,d=0,f=!1,y=p._useFallback&&p._request.fallback&&t.fallback;this.apiKey.length>h&&void 0!==t.body&&(void 0!==t.body.params||void 0!==t.body.requests)?(t.body.apiKey=this.apiKey,o=this._computeRequestHeaders(!1)):o=this._computeRequestHeaders(),void 0!==t.body&&(n=i(t.body)),s("request start");var m=[],v=r(p._request,{url:t.url,method:t.method,body:n,jsonBody:t.body,timeouts:p._getTimeoutsForRequest(t.hostType)});return t.callback?void v.then(function(e){u(function(){t.callback(null,e)},p._setTimeout||setTimeout)},function(e){u(function(){t.callback(e)},p._setTimeout||setTimeout)}):v},n.prototype._getSearchParams=function(e,t){if(void 0===e||null===e)return t;for(var r in e)null!==r&&void 0!==e[r]&&e.hasOwnProperty(r)&&(t+=""===t?"":"&",t+=r+"="+encodeURIComponent("[object Array]"===Object.prototype.toString.call(e[r])?i(e[r]):e[r]));return t},n.prototype._computeRequestHeaders=function(t){var r=e(5),n={"x-algolia-agent":this._ua,"x-algolia-application-id":this.applicationID};return t!==!1&&(n["x-algolia-api-key"]=this.apiKey),this.userToken&&(n["x-algolia-usertoken"]=this.userToken),this.securityTags&&(n["x-algolia-tagfilters"]=this.securityTags),this.extraHeaders&&r(this.extraHeaders,function(e){n[e.name]=e.value}),n},n.prototype.search=function(t,r,n){var o=e(8),i=e(31),s="Usage: client.search(arrayOfQueries[, callback])";if(!o(t))throw new Error(s);"function"==typeof r?(n=r,r={}):void 0===r&&(r={});var a=this,c={requests:i(t,function(e){var t="";return void 0!==e.query&&(t+="query="+encodeURIComponent(e.query)),{indexName:e.indexName,params:a._getSearchParams(e.params,t)}})},u=i(c.requests,function(e,t){return t+"="+encodeURIComponent("/1/indexes/"+encodeURIComponent(e.indexName)+"?"+e.params)}).join("&"),l="/1/indexes/*/queries";return void 0!==r.strategy&&(l+="?strategy="+r.strategy),this._jsonRequest({cache:this.cache,method:"POST",url:l,body:c,hostType:"read",fallback:{method:"GET",url:"/1/indexes/*",body:{params:u}},callback:n})},n.prototype.setSecurityTags=function(e){if("[object Array]"===Object.prototype.toString.call(e)){for(var t=[],r=0;r<e.length;++r)if("[object Array]"===Object.prototype.toString.call(e[r])){for(var n=[],o=0;o<e[r].length;++o)n.push(e[r][o]);t.push("("+n.join(",")+")")}else t.push(e[r]);e=t.join(",")}this.securityTags=e},n.prototype.setUserToken=function(e){this.userToken=e},n.prototype.clearCache=function(){this.cache={}},n.prototype.setRequestTimeout=function(e){e&&(this._timeouts.connect=this._timeouts.read=this._timeouts.write=e)},n.prototype.setTimeouts=function(e){this._timeouts=e},n.prototype.getTimeouts=function(){return this._timeouts},n.prototype._getAppIdData=function(){var e=p.get(this.applicationID);return null!==e&&this._cacheAppIdData(e),e},n.prototype._setAppIdData=function(e){return e.lastChange=(new Date).getTime(),this._cacheAppIdData(e),p.set(this.applicationID,e)},n.prototype._checkAppIdData=function(){var e=this._getAppIdData(),t=(new Date).getTime();return null===e||t-e.lastChange>d?this._resetInitialAppIdData(e):e},n.prototype._resetInitialAppIdData=function(e){var t=e||{};return t.hostIndexes={read:0,write:0},t.timeoutMultiplier=1,t.shuffleResult=t.shuffleResult||s([1,2,3]),this._setAppIdData(t)},n.prototype._cacheAppIdData=function(e){this._hostIndexes=e.hostIndexes,this._timeoutMultiplier=e.timeoutMultiplier,this._shuffleResult=e.shuffleResult},n.prototype._partialAppIdDataUpdate=function(t){var r=e(5),n=this._getAppIdData();return r(t,function(e,t){n[t]=e}),this._setAppIdData(n)},n.prototype._getHostByType=function(e){return this.hosts[e][this._getHostIndexByType(e)]},n.prototype._getTimeoutMultiplier=function(){return this._timeoutMultiplier},n.prototype._getHostIndexByType=function(e){return this._hostIndexes[e]},n.prototype._setHostIndexByType=function(t,r){var n=e(26),o=n(this._hostIndexes);return o[r]=t,this._partialAppIdDataUpdate({hostIndexes:o}),t},n.prototype._incrementHostIndex=function(e){return this._setHostIndexByType((this._getHostIndexByType(e)+1)%this.hosts[e].length,e)},n.prototype._incrementTimeoutMultipler=function(){var e=Math.max(this._timeoutMultiplier+1,4);return this._partialAppIdDataUpdate({timeoutMultiplier:e})},n.prototype._getTimeoutsForRequest=function(e){return{connect:this._timeouts.connect*this._timeoutMultiplier,complete:this._timeouts[e]*this._timeoutMultiplier}}}).call(this,e(12))},{1:1,12:12,18:18,26:26,29:29,30:30,31:31,35:35,5:5,8:8}],16:[function(e,t,r){function n(){i.apply(this,arguments)}var o=e(7),i=e(18),s=e(27),a=e(28),c=e(30),u=e(29);t.exports=n,o(n,i),n.prototype.addObject=function(e,t,r){var n=this;return 1!==arguments.length&&"function"!=typeof t||(r=t,t=void 0),this.as._jsonRequest({method:void 0!==t?"PUT":"POST",url:"/1/indexes/"+encodeURIComponent(n.indexName)+(void 0!==t?"/"+encodeURIComponent(t):""),body:e,hostType:"write",callback:r})},n.prototype.addObjects=function(t,r){var n=e(8),o="Usage: index.addObjects(arrayOfObjects[, callback])";if(!n(t))throw new Error(o);for(var i=this,s={requests:[]},a=0;a<t.length;++a){var c={action:"addObject",body:t[a]};s.requests.push(c)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(i.indexName)+"/batch",body:s,hostType:"write",callback:r})},n.prototype.partialUpdateObject=function(e,t,r){1!==arguments.length&&"function"!=typeof t||(r=t,t=void 0);var n=this,o="/1/indexes/"+encodeURIComponent(n.indexName)+"/"+encodeURIComponent(e.objectID)+"/partial";return t===!1&&(o+="?createIfNotExists=false"),this.as._jsonRequest({method:"POST",url:o,body:e,hostType:"write",callback:r})},n.prototype.partialUpdateObjects=function(t,r){var n=e(8),o="Usage: index.partialUpdateObjects(arrayOfObjects[, callback])";if(!n(t))throw new Error(o);for(var i=this,s={requests:[]},a=0;a<t.length;++a){var c={action:"partialUpdateObject",objectID:t[a].objectID,body:t[a]};s.requests.push(c)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(i.indexName)+"/batch",body:s,hostType:"write",callback:r})},n.prototype.saveObject=function(e,t){var r=this;return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(r.indexName)+"/"+encodeURIComponent(e.objectID),body:e,hostType:"write",callback:t})},n.prototype.saveObjects=function(t,r){var n=e(8),o="Usage: index.saveObjects(arrayOfObjects[, callback])";if(!n(t))throw new Error(o);for(var i=this,s={requests:[]},a=0;a<t.length;++a){var c={action:"updateObject",objectID:t[a].objectID,body:t[a]};s.requests.push(c)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(i.indexName)+"/batch",body:s,hostType:"write",callback:r})},n.prototype.deleteObject=function(e,t){if("function"==typeof e||"string"!=typeof e&&"number"!=typeof e){var r=new u.AlgoliaSearchError("Cannot delete an object without an objectID");return t=e,"function"==typeof t?t(r):this.as._promise.reject(r)}var n=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(n.indexName)+"/"+encodeURIComponent(e),hostType:"write",callback:t})},n.prototype.deleteObjects=function(t,r){var n=e(8),o=e(31),i="Usage: index.deleteObjects(arrayOfObjectIDs[, callback])";if(!n(t))throw new Error(i);var s=this,a={requests:o(t,function(e){return{action:"deleteObject",objectID:e,body:{objectID:e}}})};return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(s.indexName)+"/batch",body:a,hostType:"write",callback:r})},n.prototype.deleteByQuery=function(t,r,n){function o(e){if(0===e.nbHits)return e;var t=p(e.hits,function(e){return e.objectID});return h.deleteObjects(t).then(i).then(s)}function i(e){return h.waitTask(e.taskID)}function s(){return h.deleteByQuery(t,r)}function a(){c(function(){n(null)},d._setTimeout||setTimeout)}function u(e){c(function(){n(e)},d._setTimeout||setTimeout)}var l=e(26),p=e(31),h=this,d=h.as;1===arguments.length||"function"==typeof r?(n=r,r={}):r=l(r),r.attributesToRetrieve="objectID",r.hitsPerPage=1e3,r.distinct=!1,this.clearCache();var f=this.search(t,r).then(o);return n?void f.then(a,u):f},n.prototype.browseAll=function(t,r){function n(e){if(!a._stopped){var t;t=void 0!==e?"cursor="+encodeURIComponent(e):l,c._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(u.indexName)+"/browse?"+t,hostType:"read",callback:o})}}function o(e,t){if(!a._stopped)return e?void a._error(e):(a._result(t),void 0===t.cursor?void a._end():void n(t.cursor))}"object"==typeof t&&(r=t,t=void 0);var i=e(32),s=e(17),a=new s,c=this.as,u=this,l=c._getSearchParams(i({},r||{},{query:t}),"");return n(),a},n.prototype.ttAdapter=function(e){var t=this;return function(r,n,o){var i;i="function"==typeof o?o:n,t.search(r,e,function(e,t){return e?void i(e):void i(t.hits)})}},n.prototype.waitTask=function(e,t){function r(){return l._jsonRequest({method:"GET",hostType:"read",url:"/1/indexes/"+encodeURIComponent(u.indexName)+"/task/"+e}).then(function(e){a++;var t=i*a*a;return t>s&&(t=s),"published"!==e.status?l._promise.delay(t).then(r):e})}function n(e){c(function(){t(null,e)},l._setTimeout||setTimeout)}function o(e){c(function(){t(e)},l._setTimeout||setTimeout)}var i=100,s=5e3,a=0,u=this,l=u.as,p=r();return t?void p.then(n,o):p},n.prototype.clearIndex=function(e){var t=this;return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(t.indexName)+"/clear",hostType:"write",callback:e})},n.prototype.getSettings=function(e){var t=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(t.indexName)+"/settings?getVersion=2",hostType:"read",callback:e})},n.prototype.searchSynonyms=function(e,t){return"function"==typeof e?(t=e,e={}):void 0===e&&(e={}),this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/search",body:e,hostType:"read",callback:t})},n.prototype.saveSynonym=function(e,t,r){return"function"==typeof t?(r=t,t={}):void 0===t&&(t={}),this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/"+encodeURIComponent(e.objectID)+"?forwardToSlaves="+(t.forwardToSlaves?"true":"false"),body:e,hostType:"write",callback:r})},n.prototype.getSynonym=function(e,t){return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/"+encodeURIComponent(e),hostType:"read",callback:t})},n.prototype.deleteSynonym=function(e,t,r){return"function"==typeof t?(r=t,t={}):void 0===t&&(t={}),this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/"+encodeURIComponent(e)+"?forwardToSlaves="+(t.forwardToSlaves?"true":"false"),hostType:"write",callback:r})},n.prototype.clearSynonyms=function(e,t){return"function"==typeof e?(t=e,e={}):void 0===e&&(e={}),this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/clear?forwardToSlaves="+(e.forwardToSlaves?"true":"false"),hostType:"write",callback:t})},n.prototype.batchSynonyms=function(e,t,r){return"function"==typeof t?(r=t,t={}):void 0===t&&(t={}),this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/synonyms/batch?forwardToSlaves="+(t.forwardToSlaves?"true":"false")+"&replaceExistingSynonyms="+(t.replaceExistingSynonyms?"true":"false"),hostType:"write",body:e,callback:r})},n.prototype.setSettings=function(e,t,r){1!==arguments.length&&"function"!=typeof t||(r=t,t={});var n=t.forwardToSlaves||!1,o=this;return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(o.indexName)+"/settings?forwardToSlaves="+(n?"true":"false"),hostType:"write",body:e,callback:r})},n.prototype.listUserKeys=function(e){var t=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(t.indexName)+"/keys",hostType:"read",callback:e})},n.prototype.getUserKeyACL=function(e,t){var r=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(r.indexName)+"/keys/"+e,hostType:"read",callback:t})},n.prototype.deleteUserKey=function(e,t){var r=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(r.indexName)+"/keys/"+e,hostType:"write",callback:t})},n.prototype.addUserKey=function(t,r,n){var o=e(8),i="Usage: index.addUserKey(arrayOfAcls[, params, callback])";if(!o(t))throw new Error(i);1!==arguments.length&&"function"!=typeof r||(n=r,r=null);var s={acl:t};return r&&(s.validity=r.validity,s.maxQueriesPerIPPerHour=r.maxQueriesPerIPPerHour,s.maxHitsPerQuery=r.maxHitsPerQuery,s.description=r.description,r.queryParameters&&(s.queryParameters=this.as._getSearchParams(r.queryParameters,"")),s.referers=r.referers),this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/keys",body:s,hostType:"write",callback:n})},n.prototype.addUserKeyWithValidity=s(function(e,t,r){return this.addUserKey(e,t,r)},a("index.addUserKeyWithValidity()","index.addUserKey()")),n.prototype.updateUserKey=function(t,r,n,o){var i=e(8),s="Usage: index.updateUserKey(key, arrayOfAcls[, params, callback])";if(!i(r))throw new Error(s);2!==arguments.length&&"function"!=typeof n||(o=n,n=null);var a={acl:r};return n&&(a.validity=n.validity,a.maxQueriesPerIPPerHour=n.maxQueriesPerIPPerHour,a.maxHitsPerQuery=n.maxHitsPerQuery,a.description=n.description,n.queryParameters&&(a.queryParameters=this.as._getSearchParams(n.queryParameters,"")),a.referers=n.referers),this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/keys/"+t,body:a,hostType:"write",callback:o})}},{17:17,18:18,26:26,27:27,28:28,29:29,30:30,31:31,32:32,7:7,8:8}],17:[function(e,t,r){"use strict";function n(){}t.exports=n;var o=e(7),i=e(4).EventEmitter;o(n,i),n.prototype.stop=function(){this._stopped=!0,this._clean()},n.prototype._end=function(){this.emit("end"),this._clean()},n.prototype._error=function(e){this.emit("error",e),this._clean()},n.prototype._result=function(e){this.emit("result",e)},n.prototype._clean=function(){this.removeAllListeners("stop"),this.removeAllListeners("end"),this.removeAllListeners("error"),this.removeAllListeners("result")}},{4:4,7:7}],18:[function(e,t,r){function n(e,t){this.indexName=t,this.as=e,this.typeAheadArgs=null,this.typeAheadValueOption=null,this.cache={}}var o=e(25),i=e(27),s=e(28);t.exports=n,n.prototype.clearCache=function(){this.cache={}},n.prototype.search=o("query"),n.prototype.similarSearch=o("similarQuery"),n.prototype.browse=function(t,r,n){var o,i,s=e(32),a=this;0===arguments.length||1===arguments.length&&"function"==typeof arguments[0]?(o=0,n=arguments[0],t=void 0):"number"==typeof arguments[0]?(o=arguments[0],"number"==typeof arguments[1]?i=arguments[1]:"function"==typeof arguments[1]&&(n=arguments[1],i=void 0),t=void 0,r=void 0):"object"==typeof arguments[0]?("function"==typeof arguments[1]&&(n=arguments[1]),r=arguments[0],t=void 0):"string"==typeof arguments[0]&&"function"==typeof arguments[1]&&(n=arguments[1],r=void 0),r=s({},r||{},{page:o,hitsPerPage:i,query:t});var c=this.as._getSearchParams(r,"");return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(a.indexName)+"/browse?"+c,hostType:"read",callback:n})},n.prototype.browseFrom=function(e,t){return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/browse?cursor="+encodeURIComponent(e),hostType:"read",callback:t})},n.prototype.searchForFacetValues=function(t,r){var n=e(26),o=e(33),i="Usage: index.searchForFacetValues({facetName, facetQuery, ...params}[, callback])";if(void 0===t.facetName||void 0===t.facetQuery)throw new Error(i);var s=t.facetName,a=o(n(t),function(e){return"facetName"===e}),c=this.as._getSearchParams(a,"");return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/facets/"+encodeURIComponent(s)+"/query",hostType:"read",body:{params:c},callback:r})},n.prototype.searchFacet=i(function(e,t){return this.searchForFacetValues(e,t)},s("index.searchFacet(params[, callback])","index.searchForFacetValues(params[, callback])")),n.prototype._search=function(e,t,r){return this.as._jsonRequest({cache:this.cache,method:"POST",url:t||"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:{params:e},hostType:"read",fallback:{method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName),body:{params:e}},callback:r})},n.prototype.getObject=function(e,t,r){var n=this;1!==arguments.length&&"function"!=typeof t||(r=t,t=void 0);var o="";if(void 0!==t){o="?attributes=";for(var i=0;i<t.length;++i)0!==i&&(o+=","),o+=t[i]}return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(n.indexName)+"/"+encodeURIComponent(e)+o,hostType:"read",callback:r})},n.prototype.getObjects=function(t,r,n){var o=e(8),i=e(31),s="Usage: index.getObjects(arrayOfObjectIDs[, callback])";if(!o(t))throw new Error(s);var a=this;1!==arguments.length&&"function"!=typeof r||(n=r,r=void 0);var c={requests:i(t,function(e){var t={indexName:a.indexName,objectID:e};return r&&(t.attributesToRetrieve=r.join(",")),t})};return this.as._jsonRequest({method:"POST",url:"/1/indexes/*/objects",hostType:"read",body:c,callback:n})},n.prototype.as=null,n.prototype.indexName=null,n.prototype.typeAheadArgs=null,n.prototype.typeAheadValueOption=null},{25:25,26:26,27:27,28:28,31:31,32:32,33:33,8:8}],19:[function(e,t,r){(function(t){"use strict";function r(t,o,i){var s=e(26),a=e(22);return i=s(i||{}),void 0===i.protocol&&(i.protocol=a()),i._ua=i._ua||r.ua,new n(t,o,i)}function n(){i.apply(this,arguments)}var o=e(7),i=e(14),s=e(29),a=e(23),c=e(24),u=e(34);window.algoliasearch=e(20),"debug"===t.env.NODE_ENV&&e(1).enable("algoliasearch*"),r.version=e(36),r.ua="Algolia for jQuery "+r.version,r.initPlaces=u(r),window.__algolia={debug:e(1),algoliasearch:r};var l=window.jQuery;l.algolia={Client:r,ua:r.ua,version:r.version},o(n,i),n.prototype._request=function(e,t){return new l.Deferred(function(r){var n=t.body;e=a(e,t.headers);var o={accept:"application/json"};n&&("POST"===t.method?o["content-type"]="application/x-www-form-urlencoded":o["content-type"]="application/json"),l.ajax(e,{type:t.method,timeout:t.timeouts.complete,dataType:"json",data:n,headers:o,complete:function(e,t){return"timeout"===t?void r.reject(new s.RequestTimeout):0===e.status?void r.reject(new s.Network({more:e})):void r.resolve({statusCode:e.status,body:e.responseJSON,responseText:e.responseText,headers:e.getAllResponseHeaders()})}})}).promise()},n.prototype._request.fallback=function(e,t){return e=a(e,t.headers),new l.Deferred(function(r){c(e,t,function(e,t){return e?void r.reject(e):void r.resolve(t)})}).promise()},n.prototype._promise={reject:function(e){return new l.Deferred(function(t){t.reject(e)}).promise()},resolve:function(e){return new l.Deferred(function(t){t.resolve(e)}).promise()},delay:function(e){return new l.Deferred(function(t){setTimeout(function(){t.resolve()},e)}).promise()}}}).call(this,e(12))},{1:1,12:12,14:14,20:20,22:22,23:23,24:24,26:26,29:29,34:34,36:36,7:7}],20:[function(e,t,r){"use strict";var n=e(14),o=e(21);t.exports=o(n)},{14:14,21:21}],21:[function(e,t,r){(function(r){"use strict";var n=e(6),o=n.Promise||e(3).Promise;t.exports=function(t,i){function s(t,r,n){var o=e(26),i=e(22);return n=o(n||{}),void 0===n.protocol&&(n.protocol=i()),n._ua=n._ua||s.ua,new a(t,r,n)}function a(){t.apply(this,arguments)}var c=e(7),u=e(29),l=e(23),p=e(24),h=e(34);i=i||"","debug"===r.env.NODE_ENV&&e(1).enable("algoliasearch*"),s.version=e(36),s.ua="Algolia for vanilla JavaScript "+i+s.version,s.initPlaces=h(s),n.__algolia={debug:e(1),algoliasearch:s};var d={hasXMLHttpRequest:"XMLHttpRequest"in n,hasXDomainRequest:"XDomainRequest"in n};return d.hasXMLHttpRequest&&(d.cors="withCredentials"in new XMLHttpRequest),c(a,t),a.prototype._request=function(e,t){return new o(function(r,n){function o(){if(!f){clearTimeout(h);var e;try{e={body:JSON.parse(m.responseText),responseText:m.responseText,statusCode:m.status,headers:m.getAllResponseHeaders&&m.getAllResponseHeaders()||{}}}catch(t){e=new u.UnparsableJSON({more:m.responseText})}e instanceof u.UnparsableJSON?n(e):r(e)}}function i(e){f||(clearTimeout(h),n(new u.Network({more:e})))}function s(){f=!0,m.abort(),n(new u.RequestTimeout)}function a(){v=!0,clearTimeout(h),h=setTimeout(s,t.timeouts.complete)}function c(){v||a()}function p(){!v&&m.readyState>1&&a()}if(!d.cors&&!d.hasXDomainRequest)return void n(new u.Network("CORS not supported"));e=l(e,t.headers);var h,f,y=t.body,m=d.cors?new XMLHttpRequest:new XDomainRequest,v=!1;h=setTimeout(s,t.timeouts.connect),m.onprogress=c,"onreadystatechange"in m&&(m.onreadystatechange=p),m.onload=o,m.onerror=i,m instanceof XMLHttpRequest?m.open(t.method,e,!0):m.open(t.method,e),d.cors&&(y&&("POST"===t.method?m.setRequestHeader("content-type","application/x-www-form-urlencoded"):m.setRequestHeader("content-type","application/json")),m.setRequestHeader("accept","application/json")),m.send(y)})},a.prototype._request.fallback=function(e,t){return e=l(e,t.headers),new o(function(r,n){p(e,t,function(e,t){return e?void n(e):void r(t)})})},a.prototype._promise={reject:function(e){return o.reject(e)},resolve:function(e){return o.resolve(e)},delay:function(e){return new o(function(t){setTimeout(t,e)})}},s}}).call(this,e(12))},{1:1,12:12,22:22,23:23,24:24,26:26,29:29,3:3,34:34,36:36,6:6,7:7}],22:[function(e,t,r){"use strict";function n(){var e=window.document.location.protocol;return"http:"!==e&&"https:"!==e&&(e="http:"),e}t.exports=n},{}],23:[function(e,t,r){"use strict";function n(e,t){return e+=/\?/.test(e)?"&":"?",e+o(t)}t.exports=n;var o=e(13)},{13:13}],24:[function(e,t,r){"use strict";function n(e,t,r){function n(){t.debug("JSONP: success"),m||h||(m=!0,p||(t.debug("JSONP: Fail. Script loaded but did not call the callback"),a(),r(new o.JSONPScriptFail)))}function s(){"loaded"!==this.readyState&&"complete"!==this.readyState||n()}function a(){clearTimeout(v),f.onload=null,f.onreadystatechange=null,f.onerror=null,d.removeChild(f)}function c(){try{delete window[y],delete window[y+"_loaded"]}catch(e){window[y]=window[y+"_loaded"]=void 0}}function u(){t.debug("JSONP: Script timeout"),h=!0,a(),r(new o.RequestTimeout)}function l(){t.debug("JSONP: Script error"),m||h||(a(),r(new o.JSONPScriptError))}if("GET"!==t.method)return void r(new Error("Method "+t.method+" "+e+" is not supported by JSONP."));t.debug("JSONP: start");var p=!1,h=!1;i+=1;var d=document.getElementsByTagName("head")[0],f=document.createElement("script"),y="algoliaJSONP_"+i,m=!1;window[y]=function(e){return c(),h?void t.debug("JSONP: Late answer, ignoring"):(p=!0,a(),void r(null,{body:e}))},e+="&callback="+y,t.jsonBody&&t.jsonBody.params&&(e+="&"+t.jsonBody.params);var v=setTimeout(u,t.timeouts.complete);f.onreadystatechange=s,f.onload=n,f.onerror=l,f.async=!0,f.defer=!0,f.src=e,d.appendChild(f)}t.exports=n;var o=e(29),i=0},{29:29}],25:[function(e,t,r){function n(e,t){return function(r,n,i){if("function"==typeof r&&"object"==typeof n||"object"==typeof i)throw new o.AlgoliaSearchError("index.search usage is index.search(query, params, cb)");0===arguments.length||"function"==typeof r?(i=r,r=""):1!==arguments.length&&"function"!=typeof n||(i=n,n=void 0),"object"==typeof r&&null!==r?(n=r,r=void 0):void 0!==r&&null!==r||(r="");var s="";return void 0!==r&&(s+=e+"="+encodeURIComponent(r)),void 0!==n&&(s=this.as._getSearchParams(n,s)),this._search(s,t,i)}}t.exports=n;var o=e(29)},{29:29}],26:[function(e,t,r){t.exports=function(e){return JSON.parse(JSON.stringify(e))}},{}],27:[function(e,t,r){t.exports=function(e,t){function r(){return n||(console.log(t),n=!0),e.apply(this,arguments)}var n=!1;return r}},{}],28:[function(e,t,r){t.exports=function(e,t){var r=e.toLowerCase().replace(".","").replace("()","");return"algoliasearch: `"+e+"` was replaced by `"+t+"`. Please see https://github.com/algolia/algoliasearch-client-js/wiki/Deprecated#"+r}},{}],29:[function(e,t,r){"use strict";function n(t,r){var n=e(5),o=this;"function"==typeof Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):o.stack=(new Error).stack||"Cannot get a stacktrace, browser is too old",this.name="AlgoliaSearchError",this.message=t||"Unknown error",r&&n(r,function(e,t){o[t]=e})}function o(e,t){function r(){var r=Array.prototype.slice.call(arguments,0);"string"!=typeof r[0]&&r.unshift(t),n.apply(this,r),this.name="AlgoliaSearch"+e+"Error"}return i(r,n),r}var i=e(7);i(n,Error),t.exports={AlgoliaSearchError:n,UnparsableJSON:o("UnparsableJSON","Could not parse the incoming response as JSON, see err.more for details"),RequestTimeout:o("RequestTimeout","Request timedout before getting a response"),Network:o("Network","Network issue, see err.more for details"),JSONPScriptFail:o("JSONPScriptFail","<script> was loaded but did not call our provided callback"),JSONPScriptError:o("JSONPScriptError","<script> unable to load due to an `error` event on it"),Unknown:o("Unknown","Unknown error occured")}},{5:5,7:7}],30:[function(e,t,r){t.exports=function(e,t){t(e,0)}},{}],31:[function(e,t,r){var n=e(5);t.exports=function(e,t){var r=[];return n(e,function(n,o){r.push(t(n,o,e))}),r}},{5:5}],32:[function(e,t,r){var n=e(5);t.exports=function o(e){var t=Array.prototype.slice.call(arguments);return n(t,function(t){for(var r in t)t.hasOwnProperty(r)&&("object"==typeof e[r]&&"object"==typeof t[r]?e[r]=o({},e[r],t[r]):void 0!==t[r]&&(e[r]=t[r]))}),e}},{5:5}],33:[function(e,t,r){t.exports=function(t,r){var n=e(10),o=e(5),i={};return o(n(t),function(e){r(e)!==!0&&(i[e]=t[e])}),i}},{10:10,5:5}],34:[function(e,t,r){function n(t){return function(r,n,i){var s=e(26);i=i&&s(i)||{},i.hosts=i.hosts||["places-dsn.algolia.net","places-1.algolianet.com","places-2.algolianet.com","places-3.algolianet.com"],0!==arguments.length&&"object"!=typeof r&&void 0!==r||(r="",n="",i._allowEmptyCredentials=!0);var a=t(r,n,i),c=a.initIndex("places");return c.search=o("query","/1/places/query"),c}}t.exports=n;var o=e(25)},{25:25,26:26}],35:[function(e,t,r){(function(r){function n(e,t){return 1===arguments.length?s.get(e):s.set(e,t)}function o(){try{return"localStorage"in r&&null!==r.localStorage&&!r.localStorage[c]&&(r.localStorage.setItem(c,JSON.stringify({})),!0)}catch(e){return!1}}function i(){try{r.localStorage.removeItem(c)}catch(e){}}var s,a=e(1)("algoliasearch:src/hostIndexState.js"),c="algoliasearch-client-js",u={state:{},set:function(e,t){return this.state[e]=t,this.state[e]},get:function(e){return this.state[e]||null}},l={set:function(e,t){try{var n=JSON.parse(r.localStorage[c]);return n[e]=t,r.localStorage[c]=JSON.stringify(n),n[e]}catch(o){return a("localStorage set failed with",o),i(),s=u,s.set(e,t)}},get:function(e){return JSON.parse(r.localStorage[c])[e]||null}};s=o()?l:u,t.exports={get:n,set:n}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{1:1}],36:[function(e,t,r){"use strict";t.exports="3.20.3"},{}]},{},[19]);
@@ -1,4 +1,4 @@
1
- /*! algoliasearch 3.18.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
1
+ /*! algoliasearch 3.20.3 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
2
2
  (function(f){var g;if(typeof window!=='undefined'){g=window}else if(typeof self!=='undefined'){g=self}g.ALGOLIA_MIGRATION_LAYER=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){
3
3
 
4
4
  module.exports = function load (src, opts, cb) {
@@ -200,258 +200,7 @@ function migrationLayer(buildName) {
200
200
 
201
201
  },{"2":2,"3":3,"4":4}]},{},[5])(5)
202
202
  });(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.algoliasearch = 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){
203
- /**
204
- * Helpers.
205
- */
206
-
207
- var s = 1000;
208
- var m = s * 60;
209
- var h = m * 60;
210
- var d = h * 24;
211
- var y = d * 365.25;
212
-
213
- /**
214
- * Parse or format the given `val`.
215
- *
216
- * Options:
217
- *
218
- * - `long` verbose formatting [false]
219
- *
220
- * @param {String|Number} val
221
- * @param {Object} options
222
- * @return {String|Number}
223
- * @api public
224
- */
225
-
226
- module.exports = function(val, options){
227
- options = options || {};
228
- if ('string' == typeof val) return parse(val);
229
- // long, short were "future reserved words in js", YUI compressor fail on them
230
- // https://github.com/algolia/algoliasearch-client-js/issues/113#issuecomment-111978606
231
- // https://github.com/yui/yuicompressor/issues/47
232
- // https://github.com/rauchg/ms.js/pull/40
233
- return options['long']
234
- ? _long(val)
235
- : _short(val);
236
- };
237
-
238
- /**
239
- * Parse the given `str` and return milliseconds.
240
- *
241
- * @param {String} str
242
- * @return {Number}
243
- * @api private
244
- */
245
-
246
- function parse(str) {
247
- str = '' + str;
248
- if (str.length > 10000) return;
249
- var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
250
- if (!match) return;
251
- var n = parseFloat(match[1]);
252
- var type = (match[2] || 'ms').toLowerCase();
253
- switch (type) {
254
- case 'years':
255
- case 'year':
256
- case 'yrs':
257
- case 'yr':
258
- case 'y':
259
- return n * y;
260
- case 'days':
261
- case 'day':
262
- case 'd':
263
- return n * d;
264
- case 'hours':
265
- case 'hour':
266
- case 'hrs':
267
- case 'hr':
268
- case 'h':
269
- return n * h;
270
- case 'minutes':
271
- case 'minute':
272
- case 'mins':
273
- case 'min':
274
- case 'm':
275
- return n * m;
276
- case 'seconds':
277
- case 'second':
278
- case 'secs':
279
- case 'sec':
280
- case 's':
281
- return n * s;
282
- case 'milliseconds':
283
- case 'millisecond':
284
- case 'msecs':
285
- case 'msec':
286
- case 'ms':
287
- return n;
288
- }
289
- }
290
-
291
- /**
292
- * Short format for `ms`.
293
- *
294
- * @param {Number} ms
295
- * @return {String}
296
- * @api private
297
- */
298
-
299
- function _short(ms) {
300
- if (ms >= d) return Math.round(ms / d) + 'd';
301
- if (ms >= h) return Math.round(ms / h) + 'h';
302
- if (ms >= m) return Math.round(ms / m) + 'm';
303
- if (ms >= s) return Math.round(ms / s) + 's';
304
- return ms + 'ms';
305
- }
306
-
307
- /**
308
- * Long format for `ms`.
309
- *
310
- * @param {Number} ms
311
- * @return {String}
312
- * @api private
313
- */
314
-
315
- function _long(ms) {
316
- return plural(ms, d, 'day')
317
- || plural(ms, h, 'hour')
318
- || plural(ms, m, 'minute')
319
- || plural(ms, s, 'second')
320
- || ms + ' ms';
321
- }
322
-
323
- /**
324
- * Pluralization helper.
325
- */
326
-
327
- function plural(ms, n, name) {
328
- if (ms < n) return;
329
- if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
330
- return Math.ceil(ms / n) + ' ' + name + 's';
331
- }
332
-
333
- },{}],2:[function(require,module,exports){
334
- // shim for using process in browser
335
-
336
- var process = module.exports = {};
337
-
338
- // cached from whatever global is present so that test runners that stub it
339
- // don't break things. But we need to wrap it in a try catch in case it is
340
- // wrapped in strict mode code which doesn't define any globals. It's inside a
341
- // function because try/catches deoptimize in certain engines.
342
-
343
- var cachedSetTimeout;
344
- var cachedClearTimeout;
345
-
346
- (function () {
347
- try {
348
- cachedSetTimeout = setTimeout;
349
- } catch (e) {
350
- cachedSetTimeout = function () {
351
- throw new Error('setTimeout is not defined');
352
- }
353
- }
354
- try {
355
- cachedClearTimeout = clearTimeout;
356
- } catch (e) {
357
- cachedClearTimeout = function () {
358
- throw new Error('clearTimeout is not defined');
359
- }
360
- }
361
- } ())
362
- var queue = [];
363
- var draining = false;
364
- var currentQueue;
365
- var queueIndex = -1;
366
-
367
- function cleanUpNextTick() {
368
- if (!draining || !currentQueue) {
369
- return;
370
- }
371
- draining = false;
372
- if (currentQueue.length) {
373
- queue = currentQueue.concat(queue);
374
- } else {
375
- queueIndex = -1;
376
- }
377
- if (queue.length) {
378
- drainQueue();
379
- }
380
- }
381
-
382
- function drainQueue() {
383
- if (draining) {
384
- return;
385
- }
386
- var timeout = cachedSetTimeout(cleanUpNextTick);
387
- draining = true;
388
-
389
- var len = queue.length;
390
- while(len) {
391
- currentQueue = queue;
392
- queue = [];
393
- while (++queueIndex < len) {
394
- if (currentQueue) {
395
- currentQueue[queueIndex].run();
396
- }
397
- }
398
- queueIndex = -1;
399
- len = queue.length;
400
- }
401
- currentQueue = null;
402
- draining = false;
403
- cachedClearTimeout(timeout);
404
- }
405
-
406
- process.nextTick = function (fun) {
407
- var args = new Array(arguments.length - 1);
408
- if (arguments.length > 1) {
409
- for (var i = 1; i < arguments.length; i++) {
410
- args[i - 1] = arguments[i];
411
- }
412
- }
413
- queue.push(new Item(fun, args));
414
- if (queue.length === 1 && !draining) {
415
- cachedSetTimeout(drainQueue, 0);
416
- }
417
- };
418
-
419
- // v8 likes predictible objects
420
- function Item(fun, array) {
421
- this.fun = fun;
422
- this.array = array;
423
- }
424
- Item.prototype.run = function () {
425
- this.fun.apply(null, this.array);
426
- };
427
- process.title = 'browser';
428
- process.browser = true;
429
- process.env = {};
430
- process.argv = [];
431
- process.version = ''; // empty string to avoid regexp issues
432
- process.versions = {};
433
-
434
- function noop() {}
435
-
436
- process.on = noop;
437
- process.addListener = noop;
438
- process.once = noop;
439
- process.off = noop;
440
- process.removeListener = noop;
441
- process.removeAllListeners = noop;
442
- process.emit = noop;
443
-
444
- process.binding = function (name) {
445
- throw new Error('process.binding is not supported');
446
- };
447
-
448
- process.cwd = function () { return '/' };
449
- process.chdir = function (dir) {
450
- throw new Error('process.chdir is not supported');
451
- };
452
- process.umask = function() { return 0; };
453
-
454
- },{}],3:[function(require,module,exports){
203
+ (function (process){
455
204
 
456
205
  /**
457
206
  * This is the web browser implementation of `debug()`.
@@ -459,7 +208,7 @@ process.umask = function() { return 0; };
459
208
  * Expose `debug()` as the module.
460
209
  */
461
210
 
462
- exports = module.exports = require(4);
211
+ exports = module.exports = require(2);
463
212
  exports.log = log;
464
213
  exports.formatArgs = formatArgs;
465
214
  exports.save = save;
@@ -493,7 +242,8 @@ exports.colors = [
493
242
 
494
243
  function useColors() {
495
244
  // is webkit? http://stackoverflow.com/a/16459606/376773
496
- return ('WebkitAppearance' in document.documentElement.style) ||
245
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
246
+ return (typeof document !== 'undefined' && 'WebkitAppearance' in document.documentElement.style) ||
497
247
  // is firebug? http://stackoverflow.com/a/398120/376773
498
248
  (window.console && (console.firebug || (console.exception && console.table))) ||
499
249
  // is firefox >= v31?
@@ -506,7 +256,11 @@ function useColors() {
506
256
  */
507
257
 
508
258
  exports.formatters.j = function(v) {
509
- return JSON.stringify(v);
259
+ try {
260
+ return JSON.stringify(v);
261
+ } catch (err) {
262
+ return '[UnexpectedJSONParseError]: ' + err.message;
263
+ }
510
264
  };
511
265
 
512
266
 
@@ -593,9 +347,13 @@ function save(namespaces) {
593
347
  function load() {
594
348
  var r;
595
349
  try {
596
- r = exports.storage.debug;
350
+ return exports.storage.debug;
597
351
  } catch(e) {}
598
- return r;
352
+
353
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
354
+ if (typeof process !== 'undefined' && 'env' in process) {
355
+ return process.env.DEBUG;
356
+ }
599
357
  }
600
358
 
601
359
  /**
@@ -621,7 +379,8 @@ function localstorage(){
621
379
  } catch (e) {}
622
380
  }
623
381
 
624
- },{"4":4}],4:[function(require,module,exports){
382
+ }).call(this,require(12))
383
+ },{"12":12,"2":2}],2:[function(require,module,exports){
625
384
 
626
385
  /**
627
386
  * This is the common logic for both the Node.js and web browser
@@ -630,12 +389,12 @@ function localstorage(){
630
389
  * Expose `debug()` as the module.
631
390
  */
632
391
 
633
- exports = module.exports = debug;
392
+ exports = module.exports = debug.debug = debug;
634
393
  exports.coerce = coerce;
635
394
  exports.disable = disable;
636
395
  exports.enable = enable;
637
396
  exports.enabled = enabled;
638
- exports.humanize = require(1);
397
+ exports.humanize = require(9);
639
398
 
640
399
  /**
641
400
  * The currently active debug mode names, and names to skip.
@@ -707,7 +466,10 @@ function debug(namespace) {
707
466
  if (null == self.useColors) self.useColors = exports.useColors();
708
467
  if (null == self.color && self.useColors) self.color = selectColor();
709
468
 
710
- var args = Array.prototype.slice.call(arguments);
469
+ var args = new Array(arguments.length);
470
+ for (var i = 0; i < args.length; i++) {
471
+ args[i] = arguments[i];
472
+ }
711
473
 
712
474
  args[0] = exports.coerce(args[0]);
713
475
 
@@ -734,9 +496,9 @@ function debug(namespace) {
734
496
  return match;
735
497
  });
736
498
 
737
- if ('function' === typeof exports.formatArgs) {
738
- args = exports.formatArgs.apply(self, args);
739
- }
499
+ // apply env-specific formatting
500
+ args = exports.formatArgs.apply(self, args);
501
+
740
502
  var logFn = enabled.log || exports.log || console.log.bind(console);
741
503
  logFn.apply(self, args);
742
504
  }
@@ -765,7 +527,7 @@ function enable(namespaces) {
765
527
 
766
528
  for (var i = 0; i < len; i++) {
767
529
  if (!split[i]) continue; // ignore empty strings
768
- namespaces = split[i].replace(/\*/g, '.*?');
530
+ namespaces = split[i].replace(/[\\^$+?.()|[\]{}]/g, '\\$&').replace(/\*/g, '.*?');
769
531
  if (namespaces[0] === '-') {
770
532
  exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
771
533
  } else {
@@ -820,970 +582,1167 @@ function coerce(val) {
820
582
  return val;
821
583
  }
822
584
 
823
- },{"1":1}],5:[function(require,module,exports){
585
+ },{"9":9}],3:[function(require,module,exports){
824
586
  (function (process,global){
825
587
  /*!
826
588
  * @overview es6-promise - a tiny implementation of Promises/A+.
827
589
  * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
828
590
  * @license Licensed under MIT license
829
- * See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE
830
- * @version 3.2.1
591
+ * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
592
+ * @version 4.0.5
831
593
  */
832
594
 
833
- (function() {
834
- "use strict";
835
- function lib$es6$promise$utils$$objectOrFunction(x) {
836
- return typeof x === 'function' || (typeof x === 'object' && x !== null);
837
- }
595
+ (function (global, factory) {
596
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
597
+ typeof define === 'function' && define.amd ? define(factory) :
598
+ (global.ES6Promise = factory());
599
+ }(this, (function () { 'use strict';
838
600
 
839
- function lib$es6$promise$utils$$isFunction(x) {
840
- return typeof x === 'function';
841
- }
601
+ function objectOrFunction(x) {
602
+ return typeof x === 'function' || typeof x === 'object' && x !== null;
603
+ }
842
604
 
843
- function lib$es6$promise$utils$$isMaybeThenable(x) {
844
- return typeof x === 'object' && x !== null;
845
- }
605
+ function isFunction(x) {
606
+ return typeof x === 'function';
607
+ }
846
608
 
847
- var lib$es6$promise$utils$$_isArray;
848
- if (!Array.isArray) {
849
- lib$es6$promise$utils$$_isArray = function (x) {
850
- return Object.prototype.toString.call(x) === '[object Array]';
851
- };
609
+ var _isArray = undefined;
610
+ if (!Array.isArray) {
611
+ _isArray = function (x) {
612
+ return Object.prototype.toString.call(x) === '[object Array]';
613
+ };
614
+ } else {
615
+ _isArray = Array.isArray;
616
+ }
617
+
618
+ var isArray = _isArray;
619
+
620
+ var len = 0;
621
+ var vertxNext = undefined;
622
+ var customSchedulerFn = undefined;
623
+
624
+ var asap = function asap(callback, arg) {
625
+ queue[len] = callback;
626
+ queue[len + 1] = arg;
627
+ len += 2;
628
+ if (len === 2) {
629
+ // If len is 2, that means that we need to schedule an async flush.
630
+ // If additional callbacks are queued before the queue is flushed, they
631
+ // will be processed by this flush that we are scheduling.
632
+ if (customSchedulerFn) {
633
+ customSchedulerFn(flush);
852
634
  } else {
853
- lib$es6$promise$utils$$_isArray = Array.isArray;
635
+ scheduleFlush();
854
636
  }
637
+ }
638
+ };
855
639
 
856
- var lib$es6$promise$utils$$isArray = lib$es6$promise$utils$$_isArray;
857
- var lib$es6$promise$asap$$len = 0;
858
- var lib$es6$promise$asap$$vertxNext;
859
- var lib$es6$promise$asap$$customSchedulerFn;
860
-
861
- var lib$es6$promise$asap$$asap = function asap(callback, arg) {
862
- lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback;
863
- lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len + 1] = arg;
864
- lib$es6$promise$asap$$len += 2;
865
- if (lib$es6$promise$asap$$len === 2) {
866
- // If len is 2, that means that we need to schedule an async flush.
867
- // If additional callbacks are queued before the queue is flushed, they
868
- // will be processed by this flush that we are scheduling.
869
- if (lib$es6$promise$asap$$customSchedulerFn) {
870
- lib$es6$promise$asap$$customSchedulerFn(lib$es6$promise$asap$$flush);
871
- } else {
872
- lib$es6$promise$asap$$scheduleFlush();
873
- }
874
- }
875
- }
640
+ function setScheduler(scheduleFn) {
641
+ customSchedulerFn = scheduleFn;
642
+ }
876
643
 
877
- function lib$es6$promise$asap$$setScheduler(scheduleFn) {
878
- lib$es6$promise$asap$$customSchedulerFn = scheduleFn;
879
- }
644
+ function setAsap(asapFn) {
645
+ asap = asapFn;
646
+ }
880
647
 
881
- function lib$es6$promise$asap$$setAsap(asapFn) {
882
- lib$es6$promise$asap$$asap = asapFn;
883
- }
648
+ var browserWindow = typeof window !== 'undefined' ? window : undefined;
649
+ var browserGlobal = browserWindow || {};
650
+ var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
651
+ var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]';
884
652
 
885
- var lib$es6$promise$asap$$browserWindow = (typeof window !== 'undefined') ? window : undefined;
886
- var lib$es6$promise$asap$$browserGlobal = lib$es6$promise$asap$$browserWindow || {};
887
- var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver;
888
- var lib$es6$promise$asap$$isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
889
-
890
- // test for web worker but not in IE10
891
- var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' &&
892
- typeof importScripts !== 'undefined' &&
893
- typeof MessageChannel !== 'undefined';
894
-
895
- // node
896
- function lib$es6$promise$asap$$useNextTick() {
897
- // node version 0.10.x displays a deprecation warning when nextTick is used recursively
898
- // see https://github.com/cujojs/when/issues/410 for details
899
- return function() {
900
- process.nextTick(lib$es6$promise$asap$$flush);
901
- };
902
- }
653
+ // test for web worker but not in IE10
654
+ var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
903
655
 
904
- // vertx
905
- function lib$es6$promise$asap$$useVertxTimer() {
906
- return function() {
907
- lib$es6$promise$asap$$vertxNext(lib$es6$promise$asap$$flush);
908
- };
909
- }
656
+ // node
657
+ function useNextTick() {
658
+ // node version 0.10.x displays a deprecation warning when nextTick is used recursively
659
+ // see https://github.com/cujojs/when/issues/410 for details
660
+ return function () {
661
+ return process.nextTick(flush);
662
+ };
663
+ }
910
664
 
911
- function lib$es6$promise$asap$$useMutationObserver() {
912
- var iterations = 0;
913
- var observer = new lib$es6$promise$asap$$BrowserMutationObserver(lib$es6$promise$asap$$flush);
914
- var node = document.createTextNode('');
915
- observer.observe(node, { characterData: true });
665
+ // vertx
666
+ function useVertxTimer() {
667
+ if (typeof vertxNext !== 'undefined') {
668
+ return function () {
669
+ vertxNext(flush);
670
+ };
671
+ }
916
672
 
917
- return function() {
918
- node.data = (iterations = ++iterations % 2);
919
- };
920
- }
673
+ return useSetTimeout();
674
+ }
921
675
 
922
- // web worker
923
- function lib$es6$promise$asap$$useMessageChannel() {
924
- var channel = new MessageChannel();
925
- channel.port1.onmessage = lib$es6$promise$asap$$flush;
926
- return function () {
927
- channel.port2.postMessage(0);
928
- };
929
- }
676
+ function useMutationObserver() {
677
+ var iterations = 0;
678
+ var observer = new BrowserMutationObserver(flush);
679
+ var node = document.createTextNode('');
680
+ observer.observe(node, { characterData: true });
930
681
 
931
- function lib$es6$promise$asap$$useSetTimeout() {
932
- return function() {
933
- setTimeout(lib$es6$promise$asap$$flush, 1);
934
- };
935
- }
682
+ return function () {
683
+ node.data = iterations = ++iterations % 2;
684
+ };
685
+ }
936
686
 
937
- var lib$es6$promise$asap$$queue = new Array(1000);
938
- function lib$es6$promise$asap$$flush() {
939
- for (var i = 0; i < lib$es6$promise$asap$$len; i+=2) {
940
- var callback = lib$es6$promise$asap$$queue[i];
941
- var arg = lib$es6$promise$asap$$queue[i+1];
687
+ // web worker
688
+ function useMessageChannel() {
689
+ var channel = new MessageChannel();
690
+ channel.port1.onmessage = flush;
691
+ return function () {
692
+ return channel.port2.postMessage(0);
693
+ };
694
+ }
942
695
 
943
- callback(arg);
696
+ function useSetTimeout() {
697
+ // Store setTimeout reference so es6-promise will be unaffected by
698
+ // other code modifying setTimeout (like sinon.useFakeTimers())
699
+ var globalSetTimeout = setTimeout;
700
+ return function () {
701
+ return globalSetTimeout(flush, 1);
702
+ };
703
+ }
944
704
 
945
- lib$es6$promise$asap$$queue[i] = undefined;
946
- lib$es6$promise$asap$$queue[i+1] = undefined;
947
- }
705
+ var queue = new Array(1000);
706
+ function flush() {
707
+ for (var i = 0; i < len; i += 2) {
708
+ var callback = queue[i];
709
+ var arg = queue[i + 1];
948
710
 
949
- lib$es6$promise$asap$$len = 0;
950
- }
711
+ callback(arg);
951
712
 
952
- function lib$es6$promise$asap$$attemptVertx() {
953
- try {
954
- var r = require;
955
- var vertx = r('vertx');
956
- lib$es6$promise$asap$$vertxNext = vertx.runOnLoop || vertx.runOnContext;
957
- return lib$es6$promise$asap$$useVertxTimer();
958
- } catch(e) {
959
- return lib$es6$promise$asap$$useSetTimeout();
960
- }
961
- }
713
+ queue[i] = undefined;
714
+ queue[i + 1] = undefined;
715
+ }
962
716
 
963
- var lib$es6$promise$asap$$scheduleFlush;
964
- // Decide what async method to use to triggering processing of queued callbacks:
965
- if (lib$es6$promise$asap$$isNode) {
966
- lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useNextTick();
967
- } else if (lib$es6$promise$asap$$BrowserMutationObserver) {
968
- lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMutationObserver();
969
- } else if (lib$es6$promise$asap$$isWorker) {
970
- lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMessageChannel();
971
- } else if (lib$es6$promise$asap$$browserWindow === undefined && typeof require === 'function') {
972
- lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$attemptVertx();
973
- } else {
974
- lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout();
975
- }
976
- function lib$es6$promise$then$$then(onFulfillment, onRejection) {
977
- var parent = this;
717
+ len = 0;
718
+ }
978
719
 
979
- var child = new this.constructor(lib$es6$promise$$internal$$noop);
720
+ function attemptVertx() {
721
+ try {
722
+ var r = require;
723
+ var vertx = r('vertx');
724
+ vertxNext = vertx.runOnLoop || vertx.runOnContext;
725
+ return useVertxTimer();
726
+ } catch (e) {
727
+ return useSetTimeout();
728
+ }
729
+ }
980
730
 
981
- if (child[lib$es6$promise$$internal$$PROMISE_ID] === undefined) {
982
- lib$es6$promise$$internal$$makePromise(child);
983
- }
731
+ var scheduleFlush = undefined;
732
+ // Decide what async method to use to triggering processing of queued callbacks:
733
+ if (isNode) {
734
+ scheduleFlush = useNextTick();
735
+ } else if (BrowserMutationObserver) {
736
+ scheduleFlush = useMutationObserver();
737
+ } else if (isWorker) {
738
+ scheduleFlush = useMessageChannel();
739
+ } else if (browserWindow === undefined && typeof require === 'function') {
740
+ scheduleFlush = attemptVertx();
741
+ } else {
742
+ scheduleFlush = useSetTimeout();
743
+ }
984
744
 
985
- var state = parent._state;
745
+ function then(onFulfillment, onRejection) {
746
+ var _arguments = arguments;
986
747
 
987
- if (state) {
988
- var callback = arguments[state - 1];
989
- lib$es6$promise$asap$$asap(function(){
990
- lib$es6$promise$$internal$$invokeCallback(state, child, callback, parent._result);
991
- });
992
- } else {
993
- lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection);
994
- }
748
+ var parent = this;
995
749
 
996
- return child;
997
- }
998
- var lib$es6$promise$then$$default = lib$es6$promise$then$$then;
999
- function lib$es6$promise$promise$resolve$$resolve(object) {
1000
- /*jshint validthis:true */
1001
- var Constructor = this;
750
+ var child = new this.constructor(noop);
1002
751
 
1003
- if (object && typeof object === 'object' && object.constructor === Constructor) {
1004
- return object;
1005
- }
752
+ if (child[PROMISE_ID] === undefined) {
753
+ makePromise(child);
754
+ }
1006
755
 
1007
- var promise = new Constructor(lib$es6$promise$$internal$$noop);
1008
- lib$es6$promise$$internal$$resolve(promise, object);
1009
- return promise;
1010
- }
1011
- var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve;
1012
- var lib$es6$promise$$internal$$PROMISE_ID = Math.random().toString(36).substring(16);
756
+ var _state = parent._state;
1013
757
 
1014
- function lib$es6$promise$$internal$$noop() {}
758
+ if (_state) {
759
+ (function () {
760
+ var callback = _arguments[_state - 1];
761
+ asap(function () {
762
+ return invokeCallback(_state, child, callback, parent._result);
763
+ });
764
+ })();
765
+ } else {
766
+ subscribe(parent, child, onFulfillment, onRejection);
767
+ }
1015
768
 
1016
- var lib$es6$promise$$internal$$PENDING = void 0;
1017
- var lib$es6$promise$$internal$$FULFILLED = 1;
1018
- var lib$es6$promise$$internal$$REJECTED = 2;
769
+ return child;
770
+ }
1019
771
 
1020
- var lib$es6$promise$$internal$$GET_THEN_ERROR = new lib$es6$promise$$internal$$ErrorObject();
772
+ /**
773
+ `Promise.resolve` returns a promise that will become resolved with the
774
+ passed `value`. It is shorthand for the following:
1021
775
 
1022
- function lib$es6$promise$$internal$$selfFulfillment() {
1023
- return new TypeError("You cannot resolve a promise with itself");
1024
- }
776
+ ```javascript
777
+ let promise = new Promise(function(resolve, reject){
778
+ resolve(1);
779
+ });
1025
780
 
1026
- function lib$es6$promise$$internal$$cannotReturnOwn() {
1027
- return new TypeError('A promises callback cannot return that same promise.');
1028
- }
781
+ promise.then(function(value){
782
+ // value === 1
783
+ });
784
+ ```
1029
785
 
1030
- function lib$es6$promise$$internal$$getThen(promise) {
1031
- try {
1032
- return promise.then;
1033
- } catch(error) {
1034
- lib$es6$promise$$internal$$GET_THEN_ERROR.error = error;
1035
- return lib$es6$promise$$internal$$GET_THEN_ERROR;
1036
- }
1037
- }
786
+ Instead of writing the above, your code now simply becomes the following:
1038
787
 
1039
- function lib$es6$promise$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) {
1040
- try {
1041
- then.call(value, fulfillmentHandler, rejectionHandler);
1042
- } catch(e) {
1043
- return e;
1044
- }
1045
- }
788
+ ```javascript
789
+ let promise = Promise.resolve(1);
1046
790
 
1047
- function lib$es6$promise$$internal$$handleForeignThenable(promise, thenable, then) {
1048
- lib$es6$promise$asap$$asap(function(promise) {
1049
- var sealed = false;
1050
- var error = lib$es6$promise$$internal$$tryThen(then, thenable, function(value) {
1051
- if (sealed) { return; }
1052
- sealed = true;
1053
- if (thenable !== value) {
1054
- lib$es6$promise$$internal$$resolve(promise, value);
1055
- } else {
1056
- lib$es6$promise$$internal$$fulfill(promise, value);
1057
- }
1058
- }, function(reason) {
1059
- if (sealed) { return; }
1060
- sealed = true;
791
+ promise.then(function(value){
792
+ // value === 1
793
+ });
794
+ ```
795
+
796
+ @method resolve
797
+ @static
798
+ @param {Any} value value that the returned promise will be resolved with
799
+ Useful for tooling.
800
+ @return {Promise} a promise that will become fulfilled with the given
801
+ `value`
802
+ */
803
+ function resolve(object) {
804
+ /*jshint validthis:true */
805
+ var Constructor = this;
1061
806
 
1062
- lib$es6$promise$$internal$$reject(promise, reason);
1063
- }, 'Settle: ' + (promise._label || ' unknown promise'));
807
+ if (object && typeof object === 'object' && object.constructor === Constructor) {
808
+ return object;
809
+ }
1064
810
 
1065
- if (!sealed && error) {
1066
- sealed = true;
1067
- lib$es6$promise$$internal$$reject(promise, error);
1068
- }
1069
- }, promise);
1070
- }
811
+ var promise = new Constructor(noop);
812
+ _resolve(promise, object);
813
+ return promise;
814
+ }
1071
815
 
1072
- function lib$es6$promise$$internal$$handleOwnThenable(promise, thenable) {
1073
- if (thenable._state === lib$es6$promise$$internal$$FULFILLED) {
1074
- lib$es6$promise$$internal$$fulfill(promise, thenable._result);
1075
- } else if (thenable._state === lib$es6$promise$$internal$$REJECTED) {
1076
- lib$es6$promise$$internal$$reject(promise, thenable._result);
1077
- } else {
1078
- lib$es6$promise$$internal$$subscribe(thenable, undefined, function(value) {
1079
- lib$es6$promise$$internal$$resolve(promise, value);
1080
- }, function(reason) {
1081
- lib$es6$promise$$internal$$reject(promise, reason);
1082
- });
1083
- }
1084
- }
816
+ var PROMISE_ID = Math.random().toString(36).substring(16);
1085
817
 
1086
- function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable, then) {
1087
- if (maybeThenable.constructor === promise.constructor &&
1088
- then === lib$es6$promise$then$$default &&
1089
- constructor.resolve === lib$es6$promise$promise$resolve$$default) {
1090
- lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable);
1091
- } else {
1092
- if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) {
1093
- lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error);
1094
- } else if (then === undefined) {
1095
- lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
1096
- } else if (lib$es6$promise$utils$$isFunction(then)) {
1097
- lib$es6$promise$$internal$$handleForeignThenable(promise, maybeThenable, then);
1098
- } else {
1099
- lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
1100
- }
1101
- }
1102
- }
818
+ function noop() {}
1103
819
 
1104
- function lib$es6$promise$$internal$$resolve(promise, value) {
1105
- if (promise === value) {
1106
- lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$selfFulfillment());
1107
- } else if (lib$es6$promise$utils$$objectOrFunction(value)) {
1108
- lib$es6$promise$$internal$$handleMaybeThenable(promise, value, lib$es6$promise$$internal$$getThen(value));
1109
- } else {
1110
- lib$es6$promise$$internal$$fulfill(promise, value);
1111
- }
1112
- }
820
+ var PENDING = void 0;
821
+ var FULFILLED = 1;
822
+ var REJECTED = 2;
1113
823
 
1114
- function lib$es6$promise$$internal$$publishRejection(promise) {
1115
- if (promise._onerror) {
1116
- promise._onerror(promise._result);
1117
- }
824
+ var GET_THEN_ERROR = new ErrorObject();
1118
825
 
1119
- lib$es6$promise$$internal$$publish(promise);
1120
- }
826
+ function selfFulfillment() {
827
+ return new TypeError("You cannot resolve a promise with itself");
828
+ }
829
+
830
+ function cannotReturnOwn() {
831
+ return new TypeError('A promises callback cannot return that same promise.');
832
+ }
1121
833
 
1122
- function lib$es6$promise$$internal$$fulfill(promise, value) {
1123
- if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
834
+ function getThen(promise) {
835
+ try {
836
+ return promise.then;
837
+ } catch (error) {
838
+ GET_THEN_ERROR.error = error;
839
+ return GET_THEN_ERROR;
840
+ }
841
+ }
1124
842
 
1125
- promise._result = value;
1126
- promise._state = lib$es6$promise$$internal$$FULFILLED;
843
+ function tryThen(then, value, fulfillmentHandler, rejectionHandler) {
844
+ try {
845
+ then.call(value, fulfillmentHandler, rejectionHandler);
846
+ } catch (e) {
847
+ return e;
848
+ }
849
+ }
1127
850
 
1128
- if (promise._subscribers.length !== 0) {
1129
- lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, promise);
851
+ function handleForeignThenable(promise, thenable, then) {
852
+ asap(function (promise) {
853
+ var sealed = false;
854
+ var error = tryThen(then, thenable, function (value) {
855
+ if (sealed) {
856
+ return;
857
+ }
858
+ sealed = true;
859
+ if (thenable !== value) {
860
+ _resolve(promise, value);
861
+ } else {
862
+ fulfill(promise, value);
863
+ }
864
+ }, function (reason) {
865
+ if (sealed) {
866
+ return;
1130
867
  }
868
+ sealed = true;
869
+
870
+ _reject(promise, reason);
871
+ }, 'Settle: ' + (promise._label || ' unknown promise'));
872
+
873
+ if (!sealed && error) {
874
+ sealed = true;
875
+ _reject(promise, error);
1131
876
  }
877
+ }, promise);
878
+ }
1132
879
 
1133
- function lib$es6$promise$$internal$$reject(promise, reason) {
1134
- if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; }
1135
- promise._state = lib$es6$promise$$internal$$REJECTED;
1136
- promise._result = reason;
880
+ function handleOwnThenable(promise, thenable) {
881
+ if (thenable._state === FULFILLED) {
882
+ fulfill(promise, thenable._result);
883
+ } else if (thenable._state === REJECTED) {
884
+ _reject(promise, thenable._result);
885
+ } else {
886
+ subscribe(thenable, undefined, function (value) {
887
+ return _resolve(promise, value);
888
+ }, function (reason) {
889
+ return _reject(promise, reason);
890
+ });
891
+ }
892
+ }
1137
893
 
1138
- lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publishRejection, promise);
894
+ function handleMaybeThenable(promise, maybeThenable, then$$) {
895
+ if (maybeThenable.constructor === promise.constructor && then$$ === then && maybeThenable.constructor.resolve === resolve) {
896
+ handleOwnThenable(promise, maybeThenable);
897
+ } else {
898
+ if (then$$ === GET_THEN_ERROR) {
899
+ _reject(promise, GET_THEN_ERROR.error);
900
+ } else if (then$$ === undefined) {
901
+ fulfill(promise, maybeThenable);
902
+ } else if (isFunction(then$$)) {
903
+ handleForeignThenable(promise, maybeThenable, then$$);
904
+ } else {
905
+ fulfill(promise, maybeThenable);
1139
906
  }
907
+ }
908
+ }
909
+
910
+ function _resolve(promise, value) {
911
+ if (promise === value) {
912
+ _reject(promise, selfFulfillment());
913
+ } else if (objectOrFunction(value)) {
914
+ handleMaybeThenable(promise, value, getThen(value));
915
+ } else {
916
+ fulfill(promise, value);
917
+ }
918
+ }
1140
919
 
1141
- function lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection) {
1142
- var subscribers = parent._subscribers;
1143
- var length = subscribers.length;
920
+ function publishRejection(promise) {
921
+ if (promise._onerror) {
922
+ promise._onerror(promise._result);
923
+ }
1144
924
 
1145
- parent._onerror = null;
925
+ publish(promise);
926
+ }
1146
927
 
1147
- subscribers[length] = child;
1148
- subscribers[length + lib$es6$promise$$internal$$FULFILLED] = onFulfillment;
1149
- subscribers[length + lib$es6$promise$$internal$$REJECTED] = onRejection;
928
+ function fulfill(promise, value) {
929
+ if (promise._state !== PENDING) {
930
+ return;
931
+ }
1150
932
 
1151
- if (length === 0 && parent._state) {
1152
- lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, parent);
1153
- }
1154
- }
933
+ promise._result = value;
934
+ promise._state = FULFILLED;
1155
935
 
1156
- function lib$es6$promise$$internal$$publish(promise) {
1157
- var subscribers = promise._subscribers;
1158
- var settled = promise._state;
936
+ if (promise._subscribers.length !== 0) {
937
+ asap(publish, promise);
938
+ }
939
+ }
1159
940
 
1160
- if (subscribers.length === 0) { return; }
941
+ function _reject(promise, reason) {
942
+ if (promise._state !== PENDING) {
943
+ return;
944
+ }
945
+ promise._state = REJECTED;
946
+ promise._result = reason;
1161
947
 
1162
- var child, callback, detail = promise._result;
948
+ asap(publishRejection, promise);
949
+ }
1163
950
 
1164
- for (var i = 0; i < subscribers.length; i += 3) {
1165
- child = subscribers[i];
1166
- callback = subscribers[i + settled];
951
+ function subscribe(parent, child, onFulfillment, onRejection) {
952
+ var _subscribers = parent._subscribers;
953
+ var length = _subscribers.length;
1167
954
 
1168
- if (child) {
1169
- lib$es6$promise$$internal$$invokeCallback(settled, child, callback, detail);
1170
- } else {
1171
- callback(detail);
1172
- }
1173
- }
955
+ parent._onerror = null;
1174
956
 
1175
- promise._subscribers.length = 0;
1176
- }
957
+ _subscribers[length] = child;
958
+ _subscribers[length + FULFILLED] = onFulfillment;
959
+ _subscribers[length + REJECTED] = onRejection;
1177
960
 
1178
- function lib$es6$promise$$internal$$ErrorObject() {
1179
- this.error = null;
1180
- }
961
+ if (length === 0 && parent._state) {
962
+ asap(publish, parent);
963
+ }
964
+ }
1181
965
 
1182
- var lib$es6$promise$$internal$$TRY_CATCH_ERROR = new lib$es6$promise$$internal$$ErrorObject();
966
+ function publish(promise) {
967
+ var subscribers = promise._subscribers;
968
+ var settled = promise._state;
1183
969
 
1184
- function lib$es6$promise$$internal$$tryCatch(callback, detail) {
1185
- try {
1186
- return callback(detail);
1187
- } catch(e) {
1188
- lib$es6$promise$$internal$$TRY_CATCH_ERROR.error = e;
1189
- return lib$es6$promise$$internal$$TRY_CATCH_ERROR;
1190
- }
970
+ if (subscribers.length === 0) {
971
+ return;
972
+ }
973
+
974
+ var child = undefined,
975
+ callback = undefined,
976
+ detail = promise._result;
977
+
978
+ for (var i = 0; i < subscribers.length; i += 3) {
979
+ child = subscribers[i];
980
+ callback = subscribers[i + settled];
981
+
982
+ if (child) {
983
+ invokeCallback(settled, child, callback, detail);
984
+ } else {
985
+ callback(detail);
1191
986
  }
987
+ }
1192
988
 
1193
- function lib$es6$promise$$internal$$invokeCallback(settled, promise, callback, detail) {
1194
- var hasCallback = lib$es6$promise$utils$$isFunction(callback),
1195
- value, error, succeeded, failed;
989
+ promise._subscribers.length = 0;
990
+ }
1196
991
 
1197
- if (hasCallback) {
1198
- value = lib$es6$promise$$internal$$tryCatch(callback, detail);
992
+ function ErrorObject() {
993
+ this.error = null;
994
+ }
1199
995
 
1200
- if (value === lib$es6$promise$$internal$$TRY_CATCH_ERROR) {
1201
- failed = true;
1202
- error = value.error;
1203
- value = null;
1204
- } else {
1205
- succeeded = true;
1206
- }
996
+ var TRY_CATCH_ERROR = new ErrorObject();
1207
997
 
1208
- if (promise === value) {
1209
- lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$cannotReturnOwn());
1210
- return;
1211
- }
998
+ function tryCatch(callback, detail) {
999
+ try {
1000
+ return callback(detail);
1001
+ } catch (e) {
1002
+ TRY_CATCH_ERROR.error = e;
1003
+ return TRY_CATCH_ERROR;
1004
+ }
1005
+ }
1212
1006
 
1213
- } else {
1214
- value = detail;
1215
- succeeded = true;
1216
- }
1007
+ function invokeCallback(settled, promise, callback, detail) {
1008
+ var hasCallback = isFunction(callback),
1009
+ value = undefined,
1010
+ error = undefined,
1011
+ succeeded = undefined,
1012
+ failed = undefined;
1217
1013
 
1218
- if (promise._state !== lib$es6$promise$$internal$$PENDING) {
1219
- // noop
1220
- } else if (hasCallback && succeeded) {
1221
- lib$es6$promise$$internal$$resolve(promise, value);
1222
- } else if (failed) {
1223
- lib$es6$promise$$internal$$reject(promise, error);
1224
- } else if (settled === lib$es6$promise$$internal$$FULFILLED) {
1225
- lib$es6$promise$$internal$$fulfill(promise, value);
1226
- } else if (settled === lib$es6$promise$$internal$$REJECTED) {
1227
- lib$es6$promise$$internal$$reject(promise, value);
1228
- }
1229
- }
1014
+ if (hasCallback) {
1015
+ value = tryCatch(callback, detail);
1230
1016
 
1231
- function lib$es6$promise$$internal$$initializePromise(promise, resolver) {
1232
- try {
1233
- resolver(function resolvePromise(value){
1234
- lib$es6$promise$$internal$$resolve(promise, value);
1235
- }, function rejectPromise(reason) {
1236
- lib$es6$promise$$internal$$reject(promise, reason);
1237
- });
1238
- } catch(e) {
1239
- lib$es6$promise$$internal$$reject(promise, e);
1240
- }
1017
+ if (value === TRY_CATCH_ERROR) {
1018
+ failed = true;
1019
+ error = value.error;
1020
+ value = null;
1021
+ } else {
1022
+ succeeded = true;
1241
1023
  }
1242
1024
 
1243
- var lib$es6$promise$$internal$$id = 0;
1244
- function lib$es6$promise$$internal$$nextId() {
1245
- return lib$es6$promise$$internal$$id++;
1025
+ if (promise === value) {
1026
+ _reject(promise, cannotReturnOwn());
1027
+ return;
1246
1028
  }
1029
+ } else {
1030
+ value = detail;
1031
+ succeeded = true;
1032
+ }
1247
1033
 
1248
- function lib$es6$promise$$internal$$makePromise(promise) {
1249
- promise[lib$es6$promise$$internal$$PROMISE_ID] = lib$es6$promise$$internal$$id++;
1250
- promise._state = undefined;
1251
- promise._result = undefined;
1252
- promise._subscribers = [];
1034
+ if (promise._state !== PENDING) {
1035
+ // noop
1036
+ } else if (hasCallback && succeeded) {
1037
+ _resolve(promise, value);
1038
+ } else if (failed) {
1039
+ _reject(promise, error);
1040
+ } else if (settled === FULFILLED) {
1041
+ fulfill(promise, value);
1042
+ } else if (settled === REJECTED) {
1043
+ _reject(promise, value);
1253
1044
  }
1045
+ }
1254
1046
 
1255
- function lib$es6$promise$promise$all$$all(entries) {
1256
- return new lib$es6$promise$enumerator$$default(this, entries).promise;
1257
- }
1258
- var lib$es6$promise$promise$all$$default = lib$es6$promise$promise$all$$all;
1259
- function lib$es6$promise$promise$race$$race(entries) {
1260
- /*jshint validthis:true */
1261
- var Constructor = this;
1262
-
1263
- if (!lib$es6$promise$utils$$isArray(entries)) {
1264
- return new Constructor(function(resolve, reject) {
1265
- reject(new TypeError('You must pass an array to race.'));
1266
- });
1267
- } else {
1268
- return new Constructor(function(resolve, reject) {
1269
- var length = entries.length;
1270
- for (var i = 0; i < length; i++) {
1271
- Constructor.resolve(entries[i]).then(resolve, reject);
1272
- }
1273
- });
1047
+ function initializePromise(promise, resolver) {
1048
+ try {
1049
+ resolver(function resolvePromise(value) {
1050
+ _resolve(promise, value);
1051
+ }, function rejectPromise(reason) {
1052
+ _reject(promise, reason);
1053
+ });
1054
+ } catch (e) {
1055
+ _reject(promise, e);
1056
+ }
1057
+ }
1058
+
1059
+ var id = 0;
1060
+ function nextId() {
1061
+ return id++;
1062
+ }
1063
+
1064
+ function makePromise(promise) {
1065
+ promise[PROMISE_ID] = id++;
1066
+ promise._state = undefined;
1067
+ promise._result = undefined;
1068
+ promise._subscribers = [];
1069
+ }
1070
+
1071
+ function Enumerator(Constructor, input) {
1072
+ this._instanceConstructor = Constructor;
1073
+ this.promise = new Constructor(noop);
1074
+
1075
+ if (!this.promise[PROMISE_ID]) {
1076
+ makePromise(this.promise);
1077
+ }
1078
+
1079
+ if (isArray(input)) {
1080
+ this._input = input;
1081
+ this.length = input.length;
1082
+ this._remaining = input.length;
1083
+
1084
+ this._result = new Array(this.length);
1085
+
1086
+ if (this.length === 0) {
1087
+ fulfill(this.promise, this._result);
1088
+ } else {
1089
+ this.length = this.length || 0;
1090
+ this._enumerate();
1091
+ if (this._remaining === 0) {
1092
+ fulfill(this.promise, this._result);
1274
1093
  }
1275
1094
  }
1276
- var lib$es6$promise$promise$race$$default = lib$es6$promise$promise$race$$race;
1277
- function lib$es6$promise$promise$reject$$reject(reason) {
1278
- /*jshint validthis:true */
1279
- var Constructor = this;
1280
- var promise = new Constructor(lib$es6$promise$$internal$$noop);
1281
- lib$es6$promise$$internal$$reject(promise, reason);
1282
- return promise;
1283
- }
1284
- var lib$es6$promise$promise$reject$$default = lib$es6$promise$promise$reject$$reject;
1095
+ } else {
1096
+ _reject(this.promise, validationError());
1097
+ }
1098
+ }
1285
1099
 
1100
+ function validationError() {
1101
+ return new Error('Array Methods must be provided an Array');
1102
+ };
1286
1103
 
1287
- function lib$es6$promise$promise$$needsResolver() {
1288
- throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
1289
- }
1104
+ Enumerator.prototype._enumerate = function () {
1105
+ var length = this.length;
1106
+ var _input = this._input;
1290
1107
 
1291
- function lib$es6$promise$promise$$needsNew() {
1292
- throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
1293
- }
1108
+ for (var i = 0; this._state === PENDING && i < length; i++) {
1109
+ this._eachEntry(_input[i], i);
1110
+ }
1111
+ };
1294
1112
 
1295
- var lib$es6$promise$promise$$default = lib$es6$promise$promise$$Promise;
1296
- /**
1297
- Promise objects represent the eventual result of an asynchronous operation. The
1298
- primary way of interacting with a promise is through its `then` method, which
1299
- registers callbacks to receive either a promise's eventual value or the reason
1300
- why the promise cannot be fulfilled.
1113
+ Enumerator.prototype._eachEntry = function (entry, i) {
1114
+ var c = this._instanceConstructor;
1115
+ var resolve$$ = c.resolve;
1116
+
1117
+ if (resolve$$ === resolve) {
1118
+ var _then = getThen(entry);
1119
+
1120
+ if (_then === then && entry._state !== PENDING) {
1121
+ this._settledAt(entry._state, i, entry._result);
1122
+ } else if (typeof _then !== 'function') {
1123
+ this._remaining--;
1124
+ this._result[i] = entry;
1125
+ } else if (c === Promise) {
1126
+ var promise = new c(noop);
1127
+ handleMaybeThenable(promise, entry, _then);
1128
+ this._willSettleAt(promise, i);
1129
+ } else {
1130
+ this._willSettleAt(new c(function (resolve$$) {
1131
+ return resolve$$(entry);
1132
+ }), i);
1133
+ }
1134
+ } else {
1135
+ this._willSettleAt(resolve$$(entry), i);
1136
+ }
1137
+ };
1301
1138
 
1302
- Terminology
1303
- -----------
1139
+ Enumerator.prototype._settledAt = function (state, i, value) {
1140
+ var promise = this.promise;
1304
1141
 
1305
- - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
1306
- - `thenable` is an object or function that defines a `then` method.
1307
- - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
1308
- - `exception` is a value that is thrown using the throw statement.
1309
- - `reason` is a value that indicates why a promise was rejected.
1310
- - `settled` the final resting state of a promise, fulfilled or rejected.
1142
+ if (promise._state === PENDING) {
1143
+ this._remaining--;
1311
1144
 
1312
- A promise can be in one of three states: pending, fulfilled, or rejected.
1145
+ if (state === REJECTED) {
1146
+ _reject(promise, value);
1147
+ } else {
1148
+ this._result[i] = value;
1149
+ }
1150
+ }
1313
1151
 
1314
- Promises that are fulfilled have a fulfillment value and are in the fulfilled
1315
- state. Promises that are rejected have a rejection reason and are in the
1316
- rejected state. A fulfillment value is never a thenable.
1152
+ if (this._remaining === 0) {
1153
+ fulfill(promise, this._result);
1154
+ }
1155
+ };
1317
1156
 
1318
- Promises can also be said to *resolve* a value. If this value is also a
1319
- promise, then the original promise's settled state will match the value's
1320
- settled state. So a promise that *resolves* a promise that rejects will
1321
- itself reject, and a promise that *resolves* a promise that fulfills will
1322
- itself fulfill.
1157
+ Enumerator.prototype._willSettleAt = function (promise, i) {
1158
+ var enumerator = this;
1323
1159
 
1160
+ subscribe(promise, undefined, function (value) {
1161
+ return enumerator._settledAt(FULFILLED, i, value);
1162
+ }, function (reason) {
1163
+ return enumerator._settledAt(REJECTED, i, reason);
1164
+ });
1165
+ };
1324
1166
 
1325
- Basic Usage:
1326
- ------------
1167
+ /**
1168
+ `Promise.all` accepts an array of promises, and returns a new promise which
1169
+ is fulfilled with an array of fulfillment values for the passed promises, or
1170
+ rejected with the reason of the first passed promise to be rejected. It casts all
1171
+ elements of the passed iterable to promises as it runs this algorithm.
1327
1172
 
1328
- ```js
1329
- var promise = new Promise(function(resolve, reject) {
1330
- // on success
1331
- resolve(value);
1173
+ Example:
1332
1174
 
1333
- // on failure
1334
- reject(reason);
1335
- });
1175
+ ```javascript
1176
+ let promise1 = resolve(1);
1177
+ let promise2 = resolve(2);
1178
+ let promise3 = resolve(3);
1179
+ let promises = [ promise1, promise2, promise3 ];
1336
1180
 
1337
- promise.then(function(value) {
1338
- // on fulfillment
1339
- }, function(reason) {
1340
- // on rejection
1341
- });
1342
- ```
1343
-
1344
- Advanced Usage:
1345
- ---------------
1346
-
1347
- Promises shine when abstracting away asynchronous interactions such as
1348
- `XMLHttpRequest`s.
1349
-
1350
- ```js
1351
- function getJSON(url) {
1352
- return new Promise(function(resolve, reject){
1353
- var xhr = new XMLHttpRequest();
1354
-
1355
- xhr.open('GET', url);
1356
- xhr.onreadystatechange = handler;
1357
- xhr.responseType = 'json';
1358
- xhr.setRequestHeader('Accept', 'application/json');
1359
- xhr.send();
1360
-
1361
- function handler() {
1362
- if (this.readyState === this.DONE) {
1363
- if (this.status === 200) {
1364
- resolve(this.response);
1365
- } else {
1366
- reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
1367
- }
1368
- }
1369
- };
1370
- });
1371
- }
1181
+ Promise.all(promises).then(function(array){
1182
+ // The array here would be [ 1, 2, 3 ];
1183
+ });
1184
+ ```
1372
1185
 
1373
- getJSON('/posts.json').then(function(json) {
1374
- // on fulfillment
1375
- }, function(reason) {
1376
- // on rejection
1377
- });
1378
- ```
1186
+ If any of the `promises` given to `all` are rejected, the first promise
1187
+ that is rejected will be given as an argument to the returned promises's
1188
+ rejection handler. For example:
1379
1189
 
1380
- Unlike callbacks, promises are great composable primitives.
1190
+ Example:
1381
1191
 
1382
- ```js
1383
- Promise.all([
1384
- getJSON('/posts'),
1385
- getJSON('/comments')
1386
- ]).then(function(values){
1387
- values[0] // => postsJSON
1388
- values[1] // => commentsJSON
1192
+ ```javascript
1193
+ let promise1 = resolve(1);
1194
+ let promise2 = reject(new Error("2"));
1195
+ let promise3 = reject(new Error("3"));
1196
+ let promises = [ promise1, promise2, promise3 ];
1389
1197
 
1390
- return values;
1391
- });
1392
- ```
1393
-
1394
- @class Promise
1395
- @param {function} resolver
1396
- Useful for tooling.
1397
- @constructor
1398
- */
1399
- function lib$es6$promise$promise$$Promise(resolver) {
1400
- this[lib$es6$promise$$internal$$PROMISE_ID] = lib$es6$promise$$internal$$nextId();
1401
- this._result = this._state = undefined;
1402
- this._subscribers = [];
1403
-
1404
- if (lib$es6$promise$$internal$$noop !== resolver) {
1405
- typeof resolver !== 'function' && lib$es6$promise$promise$$needsResolver();
1406
- this instanceof lib$es6$promise$promise$$Promise ? lib$es6$promise$$internal$$initializePromise(this, resolver) : lib$es6$promise$promise$$needsNew();
1407
- }
1408
- }
1198
+ Promise.all(promises).then(function(array){
1199
+ // Code here never runs because there are rejected promises!
1200
+ }, function(error) {
1201
+ // error.message === "2"
1202
+ });
1203
+ ```
1204
+
1205
+ @method all
1206
+ @static
1207
+ @param {Array} entries array of promises
1208
+ @param {String} label optional string for labeling the promise.
1209
+ Useful for tooling.
1210
+ @return {Promise} promise that is fulfilled when all `promises` have been
1211
+ fulfilled, or rejected if any of them become rejected.
1212
+ @static
1213
+ */
1214
+ function all(entries) {
1215
+ return new Enumerator(this, entries).promise;
1216
+ }
1409
1217
 
1410
- lib$es6$promise$promise$$Promise.all = lib$es6$promise$promise$all$$default;
1411
- lib$es6$promise$promise$$Promise.race = lib$es6$promise$promise$race$$default;
1412
- lib$es6$promise$promise$$Promise.resolve = lib$es6$promise$promise$resolve$$default;
1413
- lib$es6$promise$promise$$Promise.reject = lib$es6$promise$promise$reject$$default;
1414
- lib$es6$promise$promise$$Promise._setScheduler = lib$es6$promise$asap$$setScheduler;
1415
- lib$es6$promise$promise$$Promise._setAsap = lib$es6$promise$asap$$setAsap;
1416
- lib$es6$promise$promise$$Promise._asap = lib$es6$promise$asap$$asap;
1417
-
1418
- lib$es6$promise$promise$$Promise.prototype = {
1419
- constructor: lib$es6$promise$promise$$Promise,
1420
-
1421
- /**
1422
- The primary way of interacting with a promise is through its `then` method,
1423
- which registers callbacks to receive either a promise's eventual value or the
1424
- reason why the promise cannot be fulfilled.
1425
-
1426
- ```js
1427
- findUser().then(function(user){
1428
- // user is available
1429
- }, function(reason){
1430
- // user is unavailable, and you are given the reason why
1431
- });
1432
- ```
1433
-
1434
- Chaining
1435
- --------
1436
-
1437
- The return value of `then` is itself a promise. This second, 'downstream'
1438
- promise is resolved with the return value of the first promise's fulfillment
1439
- or rejection handler, or rejected if the handler throws an exception.
1440
-
1441
- ```js
1442
- findUser().then(function (user) {
1443
- return user.name;
1444
- }, function (reason) {
1445
- return 'default name';
1446
- }).then(function (userName) {
1447
- // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
1448
- // will be `'default name'`
1449
- });
1218
+ /**
1219
+ `Promise.race` returns a new promise which is settled in the same way as the
1220
+ first passed promise to settle.
1450
1221
 
1451
- findUser().then(function (user) {
1452
- throw new Error('Found user, but still unhappy');
1453
- }, function (reason) {
1454
- throw new Error('`findUser` rejected and we're unhappy');
1455
- }).then(function (value) {
1456
- // never reached
1457
- }, function (reason) {
1458
- // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
1459
- // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
1460
- });
1461
- ```
1462
- If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
1463
-
1464
- ```js
1465
- findUser().then(function (user) {
1466
- throw new PedagogicalException('Upstream error');
1467
- }).then(function (value) {
1468
- // never reached
1469
- }).then(function (value) {
1470
- // never reached
1471
- }, function (reason) {
1472
- // The `PedgagocialException` is propagated all the way down to here
1473
- });
1474
- ```
1222
+ Example:
1475
1223
 
1476
- Assimilation
1477
- ------------
1224
+ ```javascript
1225
+ let promise1 = new Promise(function(resolve, reject){
1226
+ setTimeout(function(){
1227
+ resolve('promise 1');
1228
+ }, 200);
1229
+ });
1478
1230
 
1479
- Sometimes the value you want to propagate to a downstream promise can only be
1480
- retrieved asynchronously. This can be achieved by returning a promise in the
1481
- fulfillment or rejection handler. The downstream promise will then be pending
1482
- until the returned promise is settled. This is called *assimilation*.
1231
+ let promise2 = new Promise(function(resolve, reject){
1232
+ setTimeout(function(){
1233
+ resolve('promise 2');
1234
+ }, 100);
1235
+ });
1483
1236
 
1484
- ```js
1485
- findUser().then(function (user) {
1486
- return findCommentsByAuthor(user);
1487
- }).then(function (comments) {
1488
- // The user's comments are now available
1489
- });
1490
- ```
1237
+ Promise.race([promise1, promise2]).then(function(result){
1238
+ // result === 'promise 2' because it was resolved before promise1
1239
+ // was resolved.
1240
+ });
1241
+ ```
1242
+
1243
+ `Promise.race` is deterministic in that only the state of the first
1244
+ settled promise matters. For example, even if other promises given to the
1245
+ `promises` array argument are resolved, but the first settled promise has
1246
+ become rejected before the other promises became fulfilled, the returned
1247
+ promise will become rejected:
1248
+
1249
+ ```javascript
1250
+ let promise1 = new Promise(function(resolve, reject){
1251
+ setTimeout(function(){
1252
+ resolve('promise 1');
1253
+ }, 200);
1254
+ });
1491
1255
 
1492
- If the assimliated promise rejects, then the downstream promise will also reject.
1256
+ let promise2 = new Promise(function(resolve, reject){
1257
+ setTimeout(function(){
1258
+ reject(new Error('promise 2'));
1259
+ }, 100);
1260
+ });
1493
1261
 
1494
- ```js
1495
- findUser().then(function (user) {
1496
- return findCommentsByAuthor(user);
1497
- }).then(function (comments) {
1498
- // If `findCommentsByAuthor` fulfills, we'll have the value here
1499
- }, function (reason) {
1500
- // If `findCommentsByAuthor` rejects, we'll have the reason here
1501
- });
1502
- ```
1262
+ Promise.race([promise1, promise2]).then(function(result){
1263
+ // Code here never runs
1264
+ }, function(reason){
1265
+ // reason.message === 'promise 2' because promise 2 became rejected before
1266
+ // promise 1 became fulfilled
1267
+ });
1268
+ ```
1503
1269
 
1504
- Simple Example
1505
- --------------
1270
+ An example real-world use case is implementing timeouts:
1506
1271
 
1507
- Synchronous Example
1272
+ ```javascript
1273
+ Promise.race([ajax('foo.json'), timeout(5000)])
1274
+ ```
1508
1275
 
1509
- ```javascript
1510
- var result;
1276
+ @method race
1277
+ @static
1278
+ @param {Array} promises array of promises to observe
1279
+ Useful for tooling.
1280
+ @return {Promise} a promise which settles in the same way as the first passed
1281
+ promise to settle.
1282
+ */
1283
+ function race(entries) {
1284
+ /*jshint validthis:true */
1285
+ var Constructor = this;
1511
1286
 
1512
- try {
1513
- result = findResult();
1514
- // success
1515
- } catch(reason) {
1516
- // failure
1287
+ if (!isArray(entries)) {
1288
+ return new Constructor(function (_, reject) {
1289
+ return reject(new TypeError('You must pass an array to race.'));
1290
+ });
1291
+ } else {
1292
+ return new Constructor(function (resolve, reject) {
1293
+ var length = entries.length;
1294
+ for (var i = 0; i < length; i++) {
1295
+ Constructor.resolve(entries[i]).then(resolve, reject);
1517
1296
  }
1518
- ```
1297
+ });
1298
+ }
1299
+ }
1519
1300
 
1520
- Errback Example
1301
+ /**
1302
+ `Promise.reject` returns a promise rejected with the passed `reason`.
1303
+ It is shorthand for the following:
1521
1304
 
1522
- ```js
1523
- findResult(function(result, err){
1524
- if (err) {
1525
- // failure
1526
- } else {
1527
- // success
1528
- }
1529
- });
1530
- ```
1305
+ ```javascript
1306
+ let promise = new Promise(function(resolve, reject){
1307
+ reject(new Error('WHOOPS'));
1308
+ });
1531
1309
 
1532
- Promise Example;
1310
+ promise.then(function(value){
1311
+ // Code here doesn't run because the promise is rejected!
1312
+ }, function(reason){
1313
+ // reason.message === 'WHOOPS'
1314
+ });
1315
+ ```
1533
1316
 
1534
- ```javascript
1535
- findResult().then(function(result){
1536
- // success
1537
- }, function(reason){
1538
- // failure
1539
- });
1540
- ```
1317
+ Instead of writing the above, your code now simply becomes the following:
1541
1318
 
1542
- Advanced Example
1543
- --------------
1319
+ ```javascript
1320
+ let promise = Promise.reject(new Error('WHOOPS'));
1544
1321
 
1545
- Synchronous Example
1322
+ promise.then(function(value){
1323
+ // Code here doesn't run because the promise is rejected!
1324
+ }, function(reason){
1325
+ // reason.message === 'WHOOPS'
1326
+ });
1327
+ ```
1546
1328
 
1547
- ```javascript
1548
- var author, books;
1329
+ @method reject
1330
+ @static
1331
+ @param {Any} reason value that the returned promise will be rejected with.
1332
+ Useful for tooling.
1333
+ @return {Promise} a promise rejected with the given `reason`.
1334
+ */
1335
+ function reject(reason) {
1336
+ /*jshint validthis:true */
1337
+ var Constructor = this;
1338
+ var promise = new Constructor(noop);
1339
+ _reject(promise, reason);
1340
+ return promise;
1341
+ }
1549
1342
 
1550
- try {
1551
- author = findAuthor();
1552
- books = findBooksByAuthor(author);
1553
- // success
1554
- } catch(reason) {
1555
- // failure
1556
- }
1557
- ```
1343
+ function needsResolver() {
1344
+ throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
1345
+ }
1558
1346
 
1559
- Errback Example
1347
+ function needsNew() {
1348
+ throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
1349
+ }
1560
1350
 
1561
- ```js
1351
+ /**
1352
+ Promise objects represent the eventual result of an asynchronous operation. The
1353
+ primary way of interacting with a promise is through its `then` method, which
1354
+ registers callbacks to receive either a promise's eventual value or the reason
1355
+ why the promise cannot be fulfilled.
1562
1356
 
1563
- function foundBooks(books) {
1357
+ Terminology
1358
+ -----------
1564
1359
 
1565
- }
1360
+ - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
1361
+ - `thenable` is an object or function that defines a `then` method.
1362
+ - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
1363
+ - `exception` is a value that is thrown using the throw statement.
1364
+ - `reason` is a value that indicates why a promise was rejected.
1365
+ - `settled` the final resting state of a promise, fulfilled or rejected.
1566
1366
 
1567
- function failure(reason) {
1367
+ A promise can be in one of three states: pending, fulfilled, or rejected.
1568
1368
 
1569
- }
1369
+ Promises that are fulfilled have a fulfillment value and are in the fulfilled
1370
+ state. Promises that are rejected have a rejection reason and are in the
1371
+ rejected state. A fulfillment value is never a thenable.
1570
1372
 
1571
- findAuthor(function(author, err){
1572
- if (err) {
1573
- failure(err);
1574
- // failure
1575
- } else {
1576
- try {
1577
- findBoooksByAuthor(author, function(books, err) {
1578
- if (err) {
1579
- failure(err);
1580
- } else {
1581
- try {
1582
- foundBooks(books);
1583
- } catch(reason) {
1584
- failure(reason);
1585
- }
1586
- }
1587
- });
1588
- } catch(error) {
1589
- failure(err);
1590
- }
1591
- // success
1592
- }
1593
- });
1594
- ```
1373
+ Promises can also be said to *resolve* a value. If this value is also a
1374
+ promise, then the original promise's settled state will match the value's
1375
+ settled state. So a promise that *resolves* a promise that rejects will
1376
+ itself reject, and a promise that *resolves* a promise that fulfills will
1377
+ itself fulfill.
1595
1378
 
1596
- Promise Example;
1597
1379
 
1598
- ```javascript
1599
- findAuthor().
1600
- then(findBooksByAuthor).
1601
- then(function(books){
1602
- // found books
1603
- }).catch(function(reason){
1604
- // something went wrong
1605
- });
1606
- ```
1607
-
1608
- @method then
1609
- @param {Function} onFulfilled
1610
- @param {Function} onRejected
1611
- Useful for tooling.
1612
- @return {Promise}
1613
- */
1614
- then: lib$es6$promise$then$$default,
1615
-
1616
- /**
1617
- `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
1618
- as the catch block of a try/catch statement.
1619
-
1620
- ```js
1621
- function findAuthor(){
1622
- throw new Error('couldn't find that author');
1623
- }
1380
+ Basic Usage:
1381
+ ------------
1624
1382
 
1625
- // synchronous
1626
- try {
1627
- findAuthor();
1628
- } catch(reason) {
1629
- // something went wrong
1630
- }
1383
+ ```js
1384
+ let promise = new Promise(function(resolve, reject) {
1385
+ // on success
1386
+ resolve(value);
1631
1387
 
1632
- // async with promises
1633
- findAuthor().catch(function(reason){
1634
- // something went wrong
1635
- });
1636
- ```
1637
-
1638
- @method catch
1639
- @param {Function} onRejection
1640
- Useful for tooling.
1641
- @return {Promise}
1642
- */
1643
- 'catch': function(onRejection) {
1644
- return this.then(null, onRejection);
1645
- }
1646
- };
1647
- var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator;
1648
- function lib$es6$promise$enumerator$$Enumerator(Constructor, input) {
1649
- this._instanceConstructor = Constructor;
1650
- this.promise = new Constructor(lib$es6$promise$$internal$$noop);
1388
+ // on failure
1389
+ reject(reason);
1390
+ });
1651
1391
 
1652
- if (!this.promise[lib$es6$promise$$internal$$PROMISE_ID]) {
1653
- lib$es6$promise$$internal$$makePromise(this.promise);
1654
- }
1392
+ promise.then(function(value) {
1393
+ // on fulfillment
1394
+ }, function(reason) {
1395
+ // on rejection
1396
+ });
1397
+ ```
1655
1398
 
1656
- if (lib$es6$promise$utils$$isArray(input)) {
1657
- this._input = input;
1658
- this.length = input.length;
1659
- this._remaining = input.length;
1399
+ Advanced Usage:
1400
+ ---------------
1660
1401
 
1661
- this._result = new Array(this.length);
1402
+ Promises shine when abstracting away asynchronous interactions such as
1403
+ `XMLHttpRequest`s.
1662
1404
 
1663
- if (this.length === 0) {
1664
- lib$es6$promise$$internal$$fulfill(this.promise, this._result);
1665
- } else {
1666
- this.length = this.length || 0;
1667
- this._enumerate();
1668
- if (this._remaining === 0) {
1669
- lib$es6$promise$$internal$$fulfill(this.promise, this._result);
1405
+ ```js
1406
+ function getJSON(url) {
1407
+ return new Promise(function(resolve, reject){
1408
+ let xhr = new XMLHttpRequest();
1409
+
1410
+ xhr.open('GET', url);
1411
+ xhr.onreadystatechange = handler;
1412
+ xhr.responseType = 'json';
1413
+ xhr.setRequestHeader('Accept', 'application/json');
1414
+ xhr.send();
1415
+
1416
+ function handler() {
1417
+ if (this.readyState === this.DONE) {
1418
+ if (this.status === 200) {
1419
+ resolve(this.response);
1420
+ } else {
1421
+ reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
1670
1422
  }
1671
1423
  }
1672
- } else {
1673
- lib$es6$promise$$internal$$reject(this.promise, lib$es6$promise$enumerator$$validationError());
1674
- }
1675
- }
1676
-
1677
- function lib$es6$promise$enumerator$$validationError() {
1678
- return new Error('Array Methods must be provided an Array');
1679
- }
1424
+ };
1425
+ });
1426
+ }
1680
1427
 
1681
- lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function() {
1682
- var length = this.length;
1683
- var input = this._input;
1428
+ getJSON('/posts.json').then(function(json) {
1429
+ // on fulfillment
1430
+ }, function(reason) {
1431
+ // on rejection
1432
+ });
1433
+ ```
1684
1434
 
1685
- for (var i = 0; this._state === lib$es6$promise$$internal$$PENDING && i < length; i++) {
1686
- this._eachEntry(input[i], i);
1687
- }
1688
- };
1435
+ Unlike callbacks, promises are great composable primitives.
1689
1436
 
1690
- lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) {
1691
- var c = this._instanceConstructor;
1692
- var resolve = c.resolve;
1693
-
1694
- if (resolve === lib$es6$promise$promise$resolve$$default) {
1695
- var then = lib$es6$promise$$internal$$getThen(entry);
1696
-
1697
- if (then === lib$es6$promise$then$$default &&
1698
- entry._state !== lib$es6$promise$$internal$$PENDING) {
1699
- this._settledAt(entry._state, i, entry._result);
1700
- } else if (typeof then !== 'function') {
1701
- this._remaining--;
1702
- this._result[i] = entry;
1703
- } else if (c === lib$es6$promise$promise$$default) {
1704
- var promise = new c(lib$es6$promise$$internal$$noop);
1705
- lib$es6$promise$$internal$$handleMaybeThenable(promise, entry, then);
1706
- this._willSettleAt(promise, i);
1707
- } else {
1708
- this._willSettleAt(new c(function(resolve) { resolve(entry); }), i);
1709
- }
1710
- } else {
1711
- this._willSettleAt(resolve(entry), i);
1712
- }
1713
- };
1437
+ ```js
1438
+ Promise.all([
1439
+ getJSON('/posts'),
1440
+ getJSON('/comments')
1441
+ ]).then(function(values){
1442
+ values[0] // => postsJSON
1443
+ values[1] // => commentsJSON
1714
1444
 
1715
- lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) {
1716
- var promise = this.promise;
1445
+ return values;
1446
+ });
1447
+ ```
1717
1448
 
1718
- if (promise._state === lib$es6$promise$$internal$$PENDING) {
1719
- this._remaining--;
1449
+ @class Promise
1450
+ @param {function} resolver
1451
+ Useful for tooling.
1452
+ @constructor
1453
+ */
1454
+ function Promise(resolver) {
1455
+ this[PROMISE_ID] = nextId();
1456
+ this._result = this._state = undefined;
1457
+ this._subscribers = [];
1458
+
1459
+ if (noop !== resolver) {
1460
+ typeof resolver !== 'function' && needsResolver();
1461
+ this instanceof Promise ? initializePromise(this, resolver) : needsNew();
1462
+ }
1463
+ }
1720
1464
 
1721
- if (state === lib$es6$promise$$internal$$REJECTED) {
1722
- lib$es6$promise$$internal$$reject(promise, value);
1723
- } else {
1724
- this._result[i] = value;
1725
- }
1465
+ Promise.all = all;
1466
+ Promise.race = race;
1467
+ Promise.resolve = resolve;
1468
+ Promise.reject = reject;
1469
+ Promise._setScheduler = setScheduler;
1470
+ Promise._setAsap = setAsap;
1471
+ Promise._asap = asap;
1472
+
1473
+ Promise.prototype = {
1474
+ constructor: Promise,
1475
+
1476
+ /**
1477
+ The primary way of interacting with a promise is through its `then` method,
1478
+ which registers callbacks to receive either a promise's eventual value or the
1479
+ reason why the promise cannot be fulfilled.
1480
+
1481
+ ```js
1482
+ findUser().then(function(user){
1483
+ // user is available
1484
+ }, function(reason){
1485
+ // user is unavailable, and you are given the reason why
1486
+ });
1487
+ ```
1488
+
1489
+ Chaining
1490
+ --------
1491
+
1492
+ The return value of `then` is itself a promise. This second, 'downstream'
1493
+ promise is resolved with the return value of the first promise's fulfillment
1494
+ or rejection handler, or rejected if the handler throws an exception.
1495
+
1496
+ ```js
1497
+ findUser().then(function (user) {
1498
+ return user.name;
1499
+ }, function (reason) {
1500
+ return 'default name';
1501
+ }).then(function (userName) {
1502
+ // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
1503
+ // will be `'default name'`
1504
+ });
1505
+
1506
+ findUser().then(function (user) {
1507
+ throw new Error('Found user, but still unhappy');
1508
+ }, function (reason) {
1509
+ throw new Error('`findUser` rejected and we're unhappy');
1510
+ }).then(function (value) {
1511
+ // never reached
1512
+ }, function (reason) {
1513
+ // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
1514
+ // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
1515
+ });
1516
+ ```
1517
+ If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
1518
+
1519
+ ```js
1520
+ findUser().then(function (user) {
1521
+ throw new PedagogicalException('Upstream error');
1522
+ }).then(function (value) {
1523
+ // never reached
1524
+ }).then(function (value) {
1525
+ // never reached
1526
+ }, function (reason) {
1527
+ // The `PedgagocialException` is propagated all the way down to here
1528
+ });
1529
+ ```
1530
+
1531
+ Assimilation
1532
+ ------------
1533
+
1534
+ Sometimes the value you want to propagate to a downstream promise can only be
1535
+ retrieved asynchronously. This can be achieved by returning a promise in the
1536
+ fulfillment or rejection handler. The downstream promise will then be pending
1537
+ until the returned promise is settled. This is called *assimilation*.
1538
+
1539
+ ```js
1540
+ findUser().then(function (user) {
1541
+ return findCommentsByAuthor(user);
1542
+ }).then(function (comments) {
1543
+ // The user's comments are now available
1544
+ });
1545
+ ```
1546
+
1547
+ If the assimliated promise rejects, then the downstream promise will also reject.
1548
+
1549
+ ```js
1550
+ findUser().then(function (user) {
1551
+ return findCommentsByAuthor(user);
1552
+ }).then(function (comments) {
1553
+ // If `findCommentsByAuthor` fulfills, we'll have the value here
1554
+ }, function (reason) {
1555
+ // If `findCommentsByAuthor` rejects, we'll have the reason here
1556
+ });
1557
+ ```
1558
+
1559
+ Simple Example
1560
+ --------------
1561
+
1562
+ Synchronous Example
1563
+
1564
+ ```javascript
1565
+ let result;
1566
+
1567
+ try {
1568
+ result = findResult();
1569
+ // success
1570
+ } catch(reason) {
1571
+ // failure
1572
+ }
1573
+ ```
1574
+
1575
+ Errback Example
1576
+
1577
+ ```js
1578
+ findResult(function(result, err){
1579
+ if (err) {
1580
+ // failure
1581
+ } else {
1582
+ // success
1726
1583
  }
1727
-
1728
- if (this._remaining === 0) {
1729
- lib$es6$promise$$internal$$fulfill(promise, this._result);
1584
+ });
1585
+ ```
1586
+
1587
+ Promise Example;
1588
+
1589
+ ```javascript
1590
+ findResult().then(function(result){
1591
+ // success
1592
+ }, function(reason){
1593
+ // failure
1594
+ });
1595
+ ```
1596
+
1597
+ Advanced Example
1598
+ --------------
1599
+
1600
+ Synchronous Example
1601
+
1602
+ ```javascript
1603
+ let author, books;
1604
+
1605
+ try {
1606
+ author = findAuthor();
1607
+ books = findBooksByAuthor(author);
1608
+ // success
1609
+ } catch(reason) {
1610
+ // failure
1611
+ }
1612
+ ```
1613
+
1614
+ Errback Example
1615
+
1616
+ ```js
1617
+
1618
+ function foundBooks(books) {
1619
+
1620
+ }
1621
+
1622
+ function failure(reason) {
1623
+
1624
+ }
1625
+
1626
+ findAuthor(function(author, err){
1627
+ if (err) {
1628
+ failure(err);
1629
+ // failure
1630
+ } else {
1631
+ try {
1632
+ findBoooksByAuthor(author, function(books, err) {
1633
+ if (err) {
1634
+ failure(err);
1635
+ } else {
1636
+ try {
1637
+ foundBooks(books);
1638
+ } catch(reason) {
1639
+ failure(reason);
1640
+ }
1641
+ }
1642
+ });
1643
+ } catch(error) {
1644
+ failure(err);
1645
+ }
1646
+ // success
1730
1647
  }
1731
- };
1648
+ });
1649
+ ```
1650
+
1651
+ Promise Example;
1652
+
1653
+ ```javascript
1654
+ findAuthor().
1655
+ then(findBooksByAuthor).
1656
+ then(function(books){
1657
+ // found books
1658
+ }).catch(function(reason){
1659
+ // something went wrong
1660
+ });
1661
+ ```
1662
+
1663
+ @method then
1664
+ @param {Function} onFulfilled
1665
+ @param {Function} onRejected
1666
+ Useful for tooling.
1667
+ @return {Promise}
1668
+ */
1669
+ then: then,
1670
+
1671
+ /**
1672
+ `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
1673
+ as the catch block of a try/catch statement.
1674
+
1675
+ ```js
1676
+ function findAuthor(){
1677
+ throw new Error('couldn't find that author');
1678
+ }
1679
+
1680
+ // synchronous
1681
+ try {
1682
+ findAuthor();
1683
+ } catch(reason) {
1684
+ // something went wrong
1685
+ }
1686
+
1687
+ // async with promises
1688
+ findAuthor().catch(function(reason){
1689
+ // something went wrong
1690
+ });
1691
+ ```
1692
+
1693
+ @method catch
1694
+ @param {Function} onRejection
1695
+ Useful for tooling.
1696
+ @return {Promise}
1697
+ */
1698
+ 'catch': function _catch(onRejection) {
1699
+ return this.then(null, onRejection);
1700
+ }
1701
+ };
1732
1702
 
1733
- lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) {
1734
- var enumerator = this;
1703
+ function polyfill() {
1704
+ var local = undefined;
1735
1705
 
1736
- lib$es6$promise$$internal$$subscribe(promise, undefined, function(value) {
1737
- enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value);
1738
- }, function(reason) {
1739
- enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason);
1740
- });
1741
- };
1742
- function lib$es6$promise$polyfill$$polyfill() {
1743
- var local;
1744
-
1745
- if (typeof global !== 'undefined') {
1746
- local = global;
1747
- } else if (typeof self !== 'undefined') {
1748
- local = self;
1749
- } else {
1750
- try {
1751
- local = Function('return this')();
1752
- } catch (e) {
1753
- throw new Error('polyfill failed because global object is unavailable in this environment');
1754
- }
1755
- }
1706
+ if (typeof global !== 'undefined') {
1707
+ local = global;
1708
+ } else if (typeof self !== 'undefined') {
1709
+ local = self;
1710
+ } else {
1711
+ try {
1712
+ local = Function('return this')();
1713
+ } catch (e) {
1714
+ throw new Error('polyfill failed because global object is unavailable in this environment');
1715
+ }
1716
+ }
1756
1717
 
1757
- var P = local.Promise;
1718
+ var P = local.Promise;
1758
1719
 
1759
- if (P && Object.prototype.toString.call(P.resolve()) === '[object Promise]' && !P.cast) {
1760
- return;
1761
- }
1720
+ if (P) {
1721
+ var promiseToString = null;
1722
+ try {
1723
+ promiseToString = Object.prototype.toString.call(P.resolve());
1724
+ } catch (e) {
1725
+ // silently ignored
1726
+ }
1762
1727
 
1763
- local.Promise = lib$es6$promise$promise$$default;
1728
+ if (promiseToString === '[object Promise]' && !P.cast) {
1729
+ return;
1730
+ }
1764
1731
  }
1765
- var lib$es6$promise$polyfill$$default = lib$es6$promise$polyfill$$polyfill;
1766
1732
 
1767
- var lib$es6$promise$umd$$ES6Promise = {
1768
- 'Promise': lib$es6$promise$promise$$default,
1769
- 'polyfill': lib$es6$promise$polyfill$$default
1770
- };
1733
+ local.Promise = Promise;
1734
+ }
1771
1735
 
1772
- /* global define:true module:true window: true */
1773
- if (typeof define === 'function' && define['amd']) {
1774
- define(function() { return lib$es6$promise$umd$$ES6Promise; });
1775
- } else if (typeof module !== 'undefined' && module['exports']) {
1776
- module['exports'] = lib$es6$promise$umd$$ES6Promise;
1777
- } else if (typeof this !== 'undefined') {
1778
- this['ES6Promise'] = lib$es6$promise$umd$$ES6Promise;
1779
- }
1736
+ // Strange compat..
1737
+ Promise.polyfill = polyfill;
1738
+ Promise.Promise = Promise;
1780
1739
 
1781
- lib$es6$promise$polyfill$$default();
1782
- }).call(this);
1740
+ return Promise;
1783
1741
 
1742
+ })));
1784
1743
 
1785
- }).call(this,require(2),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
1786
- },{"2":2}],6:[function(require,module,exports){
1744
+ }).call(this,require(12),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
1745
+ },{"12":12}],4:[function(require,module,exports){
1787
1746
  // Copyright Joyent, Inc. and other Node contributors.
1788
1747
  //
1789
1748
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -2087,76 +2046,570 @@ function isUndefined(arg) {
2087
2046
  return arg === void 0;
2088
2047
  }
2089
2048
 
2090
- },{}],7:[function(require,module,exports){
2091
-
2092
- var hasOwn = Object.prototype.hasOwnProperty;
2093
- var toString = Object.prototype.toString;
2094
-
2095
- module.exports = function forEach (obj, fn, ctx) {
2096
- if (toString.call(fn) !== '[object Function]') {
2097
- throw new TypeError('iterator must be a function');
2049
+ },{}],5:[function(require,module,exports){
2050
+
2051
+ var hasOwn = Object.prototype.hasOwnProperty;
2052
+ var toString = Object.prototype.toString;
2053
+
2054
+ module.exports = function forEach (obj, fn, ctx) {
2055
+ if (toString.call(fn) !== '[object Function]') {
2056
+ throw new TypeError('iterator must be a function');
2057
+ }
2058
+ var l = obj.length;
2059
+ if (l === +l) {
2060
+ for (var i = 0; i < l; i++) {
2061
+ fn.call(ctx, obj[i], i, obj);
2062
+ }
2063
+ } else {
2064
+ for (var k in obj) {
2065
+ if (hasOwn.call(obj, k)) {
2066
+ fn.call(ctx, obj[k], k, obj);
2067
+ }
2068
+ }
2069
+ }
2070
+ };
2071
+
2072
+
2073
+ },{}],6:[function(require,module,exports){
2074
+ (function (global){
2075
+ if (typeof window !== "undefined") {
2076
+ module.exports = window;
2077
+ } else if (typeof global !== "undefined") {
2078
+ module.exports = global;
2079
+ } else if (typeof self !== "undefined"){
2080
+ module.exports = self;
2081
+ } else {
2082
+ module.exports = {};
2083
+ }
2084
+
2085
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
2086
+ },{}],7:[function(require,module,exports){
2087
+ if (typeof Object.create === 'function') {
2088
+ // implementation from standard node.js 'util' module
2089
+ module.exports = function inherits(ctor, superCtor) {
2090
+ ctor.super_ = superCtor
2091
+ ctor.prototype = Object.create(superCtor.prototype, {
2092
+ constructor: {
2093
+ value: ctor,
2094
+ enumerable: false,
2095
+ writable: true,
2096
+ configurable: true
2097
+ }
2098
+ });
2099
+ };
2100
+ } else {
2101
+ // old school shim for old browsers
2102
+ module.exports = function inherits(ctor, superCtor) {
2103
+ ctor.super_ = superCtor
2104
+ var TempCtor = function () {}
2105
+ TempCtor.prototype = superCtor.prototype
2106
+ ctor.prototype = new TempCtor()
2107
+ ctor.prototype.constructor = ctor
2108
+ }
2109
+ }
2110
+
2111
+ },{}],8:[function(require,module,exports){
2112
+ var toString = {}.toString;
2113
+
2114
+ module.exports = Array.isArray || function (arr) {
2115
+ return toString.call(arr) == '[object Array]';
2116
+ };
2117
+
2118
+ },{}],9:[function(require,module,exports){
2119
+ /**
2120
+ * Helpers.
2121
+ */
2122
+
2123
+ var s = 1000
2124
+ var m = s * 60
2125
+ var h = m * 60
2126
+ var d = h * 24
2127
+ var y = d * 365.25
2128
+
2129
+ /**
2130
+ * Parse or format the given `val`.
2131
+ *
2132
+ * Options:
2133
+ *
2134
+ * - `long` verbose formatting [false]
2135
+ *
2136
+ * @param {String|Number} val
2137
+ * @param {Object} options
2138
+ * @throws {Error} throw an error if val is not a non-empty string or a number
2139
+ * @return {String|Number}
2140
+ * @api public
2141
+ */
2142
+
2143
+ module.exports = function (val, options) {
2144
+ options = options || {}
2145
+ var type = typeof val
2146
+ if (type === 'string' && val.length > 0) {
2147
+ return parse(val)
2148
+ } else if (type === 'number' && isNaN(val) === false) {
2149
+ return options.long ?
2150
+ fmtLong(val) :
2151
+ fmtShort(val)
2152
+ }
2153
+ throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val))
2154
+ }
2155
+
2156
+ /**
2157
+ * Parse the given `str` and return milliseconds.
2158
+ *
2159
+ * @param {String} str
2160
+ * @return {Number}
2161
+ * @api private
2162
+ */
2163
+
2164
+ function parse(str) {
2165
+ str = String(str)
2166
+ if (str.length > 10000) {
2167
+ return
2168
+ }
2169
+ var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str)
2170
+ if (!match) {
2171
+ return
2172
+ }
2173
+ var n = parseFloat(match[1])
2174
+ var type = (match[2] || 'ms').toLowerCase()
2175
+ switch (type) {
2176
+ case 'years':
2177
+ case 'year':
2178
+ case 'yrs':
2179
+ case 'yr':
2180
+ case 'y':
2181
+ return n * y
2182
+ case 'days':
2183
+ case 'day':
2184
+ case 'd':
2185
+ return n * d
2186
+ case 'hours':
2187
+ case 'hour':
2188
+ case 'hrs':
2189
+ case 'hr':
2190
+ case 'h':
2191
+ return n * h
2192
+ case 'minutes':
2193
+ case 'minute':
2194
+ case 'mins':
2195
+ case 'min':
2196
+ case 'm':
2197
+ return n * m
2198
+ case 'seconds':
2199
+ case 'second':
2200
+ case 'secs':
2201
+ case 'sec':
2202
+ case 's':
2203
+ return n * s
2204
+ case 'milliseconds':
2205
+ case 'millisecond':
2206
+ case 'msecs':
2207
+ case 'msec':
2208
+ case 'ms':
2209
+ return n
2210
+ default:
2211
+ return undefined
2212
+ }
2213
+ }
2214
+
2215
+ /**
2216
+ * Short format for `ms`.
2217
+ *
2218
+ * @param {Number} ms
2219
+ * @return {String}
2220
+ * @api private
2221
+ */
2222
+
2223
+ function fmtShort(ms) {
2224
+ if (ms >= d) {
2225
+ return Math.round(ms / d) + 'd'
2226
+ }
2227
+ if (ms >= h) {
2228
+ return Math.round(ms / h) + 'h'
2229
+ }
2230
+ if (ms >= m) {
2231
+ return Math.round(ms / m) + 'm'
2232
+ }
2233
+ if (ms >= s) {
2234
+ return Math.round(ms / s) + 's'
2235
+ }
2236
+ return ms + 'ms'
2237
+ }
2238
+
2239
+ /**
2240
+ * Long format for `ms`.
2241
+ *
2242
+ * @param {Number} ms
2243
+ * @return {String}
2244
+ * @api private
2245
+ */
2246
+
2247
+ function fmtLong(ms) {
2248
+ return plural(ms, d, 'day') ||
2249
+ plural(ms, h, 'hour') ||
2250
+ plural(ms, m, 'minute') ||
2251
+ plural(ms, s, 'second') ||
2252
+ ms + ' ms'
2253
+ }
2254
+
2255
+ /**
2256
+ * Pluralization helper.
2257
+ */
2258
+
2259
+ function plural(ms, n, name) {
2260
+ if (ms < n) {
2261
+ return
2262
+ }
2263
+ if (ms < n * 1.5) {
2264
+ return Math.floor(ms / n) + ' ' + name
2265
+ }
2266
+ return Math.ceil(ms / n) + ' ' + name + 's'
2267
+ }
2268
+
2269
+ },{}],10:[function(require,module,exports){
2270
+ 'use strict';
2271
+
2272
+ // modified from https://github.com/es-shims/es5-shim
2273
+ var has = Object.prototype.hasOwnProperty;
2274
+ var toStr = Object.prototype.toString;
2275
+ var slice = Array.prototype.slice;
2276
+ var isArgs = require(11);
2277
+ var isEnumerable = Object.prototype.propertyIsEnumerable;
2278
+ var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
2279
+ var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
2280
+ var dontEnums = [
2281
+ 'toString',
2282
+ 'toLocaleString',
2283
+ 'valueOf',
2284
+ 'hasOwnProperty',
2285
+ 'isPrototypeOf',
2286
+ 'propertyIsEnumerable',
2287
+ 'constructor'
2288
+ ];
2289
+ var equalsConstructorPrototype = function (o) {
2290
+ var ctor = o.constructor;
2291
+ return ctor && ctor.prototype === o;
2292
+ };
2293
+ var excludedKeys = {
2294
+ $console: true,
2295
+ $external: true,
2296
+ $frame: true,
2297
+ $frameElement: true,
2298
+ $frames: true,
2299
+ $innerHeight: true,
2300
+ $innerWidth: true,
2301
+ $outerHeight: true,
2302
+ $outerWidth: true,
2303
+ $pageXOffset: true,
2304
+ $pageYOffset: true,
2305
+ $parent: true,
2306
+ $scrollLeft: true,
2307
+ $scrollTop: true,
2308
+ $scrollX: true,
2309
+ $scrollY: true,
2310
+ $self: true,
2311
+ $webkitIndexedDB: true,
2312
+ $webkitStorageInfo: true,
2313
+ $window: true
2314
+ };
2315
+ var hasAutomationEqualityBug = (function () {
2316
+ /* global window */
2317
+ if (typeof window === 'undefined') { return false; }
2318
+ for (var k in window) {
2319
+ try {
2320
+ if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
2321
+ try {
2322
+ equalsConstructorPrototype(window[k]);
2323
+ } catch (e) {
2324
+ return true;
2325
+ }
2326
+ }
2327
+ } catch (e) {
2328
+ return true;
2329
+ }
2330
+ }
2331
+ return false;
2332
+ }());
2333
+ var equalsConstructorPrototypeIfNotBuggy = function (o) {
2334
+ /* global window */
2335
+ if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
2336
+ return equalsConstructorPrototype(o);
2337
+ }
2338
+ try {
2339
+ return equalsConstructorPrototype(o);
2340
+ } catch (e) {
2341
+ return false;
2342
+ }
2343
+ };
2344
+
2345
+ var keysShim = function keys(object) {
2346
+ var isObject = object !== null && typeof object === 'object';
2347
+ var isFunction = toStr.call(object) === '[object Function]';
2348
+ var isArguments = isArgs(object);
2349
+ var isString = isObject && toStr.call(object) === '[object String]';
2350
+ var theKeys = [];
2351
+
2352
+ if (!isObject && !isFunction && !isArguments) {
2353
+ throw new TypeError('Object.keys called on a non-object');
2354
+ }
2355
+
2356
+ var skipProto = hasProtoEnumBug && isFunction;
2357
+ if (isString && object.length > 0 && !has.call(object, 0)) {
2358
+ for (var i = 0; i < object.length; ++i) {
2359
+ theKeys.push(String(i));
2360
+ }
2361
+ }
2362
+
2363
+ if (isArguments && object.length > 0) {
2364
+ for (var j = 0; j < object.length; ++j) {
2365
+ theKeys.push(String(j));
2366
+ }
2367
+ } else {
2368
+ for (var name in object) {
2369
+ if (!(skipProto && name === 'prototype') && has.call(object, name)) {
2370
+ theKeys.push(String(name));
2371
+ }
2372
+ }
2373
+ }
2374
+
2375
+ if (hasDontEnumBug) {
2376
+ var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
2377
+
2378
+ for (var k = 0; k < dontEnums.length; ++k) {
2379
+ if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
2380
+ theKeys.push(dontEnums[k]);
2381
+ }
2382
+ }
2383
+ }
2384
+ return theKeys;
2385
+ };
2386
+
2387
+ keysShim.shim = function shimObjectKeys() {
2388
+ if (Object.keys) {
2389
+ var keysWorksWithArguments = (function () {
2390
+ // Safari 5.0 bug
2391
+ return (Object.keys(arguments) || '').length === 2;
2392
+ }(1, 2));
2393
+ if (!keysWorksWithArguments) {
2394
+ var originalKeys = Object.keys;
2395
+ Object.keys = function keys(object) {
2396
+ if (isArgs(object)) {
2397
+ return originalKeys(slice.call(object));
2398
+ } else {
2399
+ return originalKeys(object);
2400
+ }
2401
+ };
2402
+ }
2403
+ } else {
2404
+ Object.keys = keysShim;
2405
+ }
2406
+ return Object.keys || keysShim;
2407
+ };
2408
+
2409
+ module.exports = keysShim;
2410
+
2411
+ },{"11":11}],11:[function(require,module,exports){
2412
+ 'use strict';
2413
+
2414
+ var toStr = Object.prototype.toString;
2415
+
2416
+ module.exports = function isArguments(value) {
2417
+ var str = toStr.call(value);
2418
+ var isArgs = str === '[object Arguments]';
2419
+ if (!isArgs) {
2420
+ isArgs = str !== '[object Array]' &&
2421
+ value !== null &&
2422
+ typeof value === 'object' &&
2423
+ typeof value.length === 'number' &&
2424
+ value.length >= 0 &&
2425
+ toStr.call(value.callee) === '[object Function]';
2426
+ }
2427
+ return isArgs;
2428
+ };
2429
+
2430
+ },{}],12:[function(require,module,exports){
2431
+ // shim for using process in browser
2432
+ var process = module.exports = {};
2433
+
2434
+ // cached from whatever global is present so that test runners that stub it
2435
+ // don't break things. But we need to wrap it in a try catch in case it is
2436
+ // wrapped in strict mode code which doesn't define any globals. It's inside a
2437
+ // function because try/catches deoptimize in certain engines.
2438
+
2439
+ var cachedSetTimeout;
2440
+ var cachedClearTimeout;
2441
+
2442
+ function defaultSetTimout() {
2443
+ throw new Error('setTimeout has not been defined');
2444
+ }
2445
+ function defaultClearTimeout () {
2446
+ throw new Error('clearTimeout has not been defined');
2447
+ }
2448
+ (function () {
2449
+ try {
2450
+ if (typeof setTimeout === 'function') {
2451
+ cachedSetTimeout = setTimeout;
2452
+ } else {
2453
+ cachedSetTimeout = defaultSetTimout;
2454
+ }
2455
+ } catch (e) {
2456
+ cachedSetTimeout = defaultSetTimout;
2457
+ }
2458
+ try {
2459
+ if (typeof clearTimeout === 'function') {
2460
+ cachedClearTimeout = clearTimeout;
2461
+ } else {
2462
+ cachedClearTimeout = defaultClearTimeout;
2463
+ }
2464
+ } catch (e) {
2465
+ cachedClearTimeout = defaultClearTimeout;
2466
+ }
2467
+ } ())
2468
+ function runTimeout(fun) {
2469
+ if (cachedSetTimeout === setTimeout) {
2470
+ //normal enviroments in sane situations
2471
+ return setTimeout(fun, 0);
2472
+ }
2473
+ // if setTimeout wasn't available but was latter defined
2474
+ if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
2475
+ cachedSetTimeout = setTimeout;
2476
+ return setTimeout(fun, 0);
2477
+ }
2478
+ try {
2479
+ // when when somebody has screwed with setTimeout but no I.E. maddness
2480
+ return cachedSetTimeout(fun, 0);
2481
+ } catch(e){
2482
+ try {
2483
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
2484
+ return cachedSetTimeout.call(null, fun, 0);
2485
+ } catch(e){
2486
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
2487
+ return cachedSetTimeout.call(this, fun, 0);
2488
+ }
2489
+ }
2490
+
2491
+
2492
+ }
2493
+ function runClearTimeout(marker) {
2494
+ if (cachedClearTimeout === clearTimeout) {
2495
+ //normal enviroments in sane situations
2496
+ return clearTimeout(marker);
2497
+ }
2498
+ // if clearTimeout wasn't available but was latter defined
2499
+ if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
2500
+ cachedClearTimeout = clearTimeout;
2501
+ return clearTimeout(marker);
2502
+ }
2503
+ try {
2504
+ // when when somebody has screwed with setTimeout but no I.E. maddness
2505
+ return cachedClearTimeout(marker);
2506
+ } catch (e){
2507
+ try {
2508
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
2509
+ return cachedClearTimeout.call(null, marker);
2510
+ } catch (e){
2511
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
2512
+ // Some versions of I.E. have different rules for clearTimeout vs setTimeout
2513
+ return cachedClearTimeout.call(this, marker);
2514
+ }
2515
+ }
2516
+
2517
+
2518
+
2519
+ }
2520
+ var queue = [];
2521
+ var draining = false;
2522
+ var currentQueue;
2523
+ var queueIndex = -1;
2524
+
2525
+ function cleanUpNextTick() {
2526
+ if (!draining || !currentQueue) {
2527
+ return;
2528
+ }
2529
+ draining = false;
2530
+ if (currentQueue.length) {
2531
+ queue = currentQueue.concat(queue);
2532
+ } else {
2533
+ queueIndex = -1;
2534
+ }
2535
+ if (queue.length) {
2536
+ drainQueue();
2537
+ }
2538
+ }
2539
+
2540
+ function drainQueue() {
2541
+ if (draining) {
2542
+ return;
2098
2543
  }
2099
- var l = obj.length;
2100
- if (l === +l) {
2101
- for (var i = 0; i < l; i++) {
2102
- fn.call(ctx, obj[i], i, obj);
2103
- }
2104
- } else {
2105
- for (var k in obj) {
2106
- if (hasOwn.call(obj, k)) {
2107
- fn.call(ctx, obj[k], k, obj);
2544
+ var timeout = runTimeout(cleanUpNextTick);
2545
+ draining = true;
2546
+
2547
+ var len = queue.length;
2548
+ while(len) {
2549
+ currentQueue = queue;
2550
+ queue = [];
2551
+ while (++queueIndex < len) {
2552
+ if (currentQueue) {
2553
+ currentQueue[queueIndex].run();
2108
2554
  }
2109
2555
  }
2556
+ queueIndex = -1;
2557
+ len = queue.length;
2558
+ }
2559
+ currentQueue = null;
2560
+ draining = false;
2561
+ runClearTimeout(timeout);
2562
+ }
2563
+
2564
+ process.nextTick = function (fun) {
2565
+ var args = new Array(arguments.length - 1);
2566
+ if (arguments.length > 1) {
2567
+ for (var i = 1; i < arguments.length; i++) {
2568
+ args[i - 1] = arguments[i];
2569
+ }
2570
+ }
2571
+ queue.push(new Item(fun, args));
2572
+ if (queue.length === 1 && !draining) {
2573
+ runTimeout(drainQueue);
2110
2574
  }
2111
2575
  };
2112
2576
 
2113
-
2114
- },{}],8:[function(require,module,exports){
2115
- (function (global){
2116
- if (typeof window !== "undefined") {
2117
- module.exports = window;
2118
- } else if (typeof global !== "undefined") {
2119
- module.exports = global;
2120
- } else if (typeof self !== "undefined"){
2121
- module.exports = self;
2122
- } else {
2123
- module.exports = {};
2577
+ // v8 likes predictible objects
2578
+ function Item(fun, array) {
2579
+ this.fun = fun;
2580
+ this.array = array;
2124
2581
  }
2582
+ Item.prototype.run = function () {
2583
+ this.fun.apply(null, this.array);
2584
+ };
2585
+ process.title = 'browser';
2586
+ process.browser = true;
2587
+ process.env = {};
2588
+ process.argv = [];
2589
+ process.version = ''; // empty string to avoid regexp issues
2590
+ process.versions = {};
2125
2591
 
2126
- }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
2127
- },{}],9:[function(require,module,exports){
2128
- if (typeof Object.create === 'function') {
2129
- // implementation from standard node.js 'util' module
2130
- module.exports = function inherits(ctor, superCtor) {
2131
- ctor.super_ = superCtor
2132
- ctor.prototype = Object.create(superCtor.prototype, {
2133
- constructor: {
2134
- value: ctor,
2135
- enumerable: false,
2136
- writable: true,
2137
- configurable: true
2138
- }
2139
- });
2140
- };
2141
- } else {
2142
- // old school shim for old browsers
2143
- module.exports = function inherits(ctor, superCtor) {
2144
- ctor.super_ = superCtor
2145
- var TempCtor = function () {}
2146
- TempCtor.prototype = superCtor.prototype
2147
- ctor.prototype = new TempCtor()
2148
- ctor.prototype.constructor = ctor
2149
- }
2150
- }
2592
+ function noop() {}
2151
2593
 
2152
- },{}],10:[function(require,module,exports){
2153
- var toString = {}.toString;
2594
+ process.on = noop;
2595
+ process.addListener = noop;
2596
+ process.once = noop;
2597
+ process.off = noop;
2598
+ process.removeListener = noop;
2599
+ process.removeAllListeners = noop;
2600
+ process.emit = noop;
2154
2601
 
2155
- module.exports = Array.isArray || function (arr) {
2156
- return toString.call(arr) == '[object Array]';
2602
+ process.binding = function (name) {
2603
+ throw new Error('process.binding is not supported');
2604
+ };
2605
+
2606
+ process.cwd = function () { return '/' };
2607
+ process.chdir = function (dir) {
2608
+ throw new Error('process.chdir is not supported');
2157
2609
  };
2610
+ process.umask = function() { return 0; };
2158
2611
 
2159
- },{}],11:[function(require,module,exports){
2612
+ },{}],13:[function(require,module,exports){
2160
2613
  // Copyright Joyent, Inc. and other Node contributors.
2161
2614
  //
2162
2615
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -2243,15 +2696,15 @@ var objectKeys = Object.keys || function (obj) {
2243
2696
  return res;
2244
2697
  };
2245
2698
 
2246
- },{}],12:[function(require,module,exports){
2699
+ },{}],14:[function(require,module,exports){
2247
2700
  module.exports = AlgoliaSearch;
2248
2701
 
2249
- var Index = require(14);
2250
- var deprecate = require(24);
2251
- var deprecatedMessage = require(25);
2252
- var AlgoliaSearchCore = require(13);
2253
- var inherits = require(9);
2254
- var errors = require(26);
2702
+ var Index = require(16);
2703
+ var deprecate = require(26);
2704
+ var deprecatedMessage = require(27);
2705
+ var AlgoliaSearchCore = require(15);
2706
+ var inherits = require(7);
2707
+ var errors = require(28);
2255
2708
 
2256
2709
  function AlgoliaSearch() {
2257
2710
  AlgoliaSearchCore.apply(this, arguments);
@@ -2332,7 +2785,7 @@ AlgoliaSearch.prototype.copyIndex = function(srcIndexName, dstIndexName, callbac
2332
2785
  * content: the server answer that contains the task ID
2333
2786
  */
2334
2787
  AlgoliaSearch.prototype.getLogs = function(offset, length, callback) {
2335
- var clone = require(23);
2788
+ var clone = require(25);
2336
2789
  var params = {};
2337
2790
  if (typeof offset === 'object') {
2338
2791
  // getLogs(params)
@@ -2484,7 +2937,7 @@ AlgoliaSearch.prototype.deleteUserKey = function(key, callback) {
2484
2937
  * @see {@link https://www.algolia.com/doc/rest_api#AddKey|Algolia REST API Documentation}
2485
2938
  */
2486
2939
  AlgoliaSearch.prototype.addUserKey = function(acls, params, callback) {
2487
- var isArray = require(10);
2940
+ var isArray = require(8);
2488
2941
  var usage = 'Usage: client.addUserKey(arrayOfAcls[, params, callback])';
2489
2942
 
2490
2943
  if (!isArray(acls)) {
@@ -2569,7 +3022,7 @@ AlgoliaSearch.prototype.addUserKeyWithValidity = deprecate(function(acls, params
2569
3022
  * @see {@link https://www.algolia.com/doc/rest_api#UpdateIndexKey|Algolia REST API Documentation}
2570
3023
  */
2571
3024
  AlgoliaSearch.prototype.updateUserKey = function(key, acls, params, callback) {
2572
- var isArray = require(10);
3025
+ var isArray = require(8);
2573
3026
  var usage = 'Usage: client.updateUserKey(key, arrayOfAcls[, params, callback])';
2574
3027
 
2575
3028
  if (!isArray(acls)) {
@@ -2670,7 +3123,7 @@ AlgoliaSearch.prototype.sendQueriesBatch = deprecate(function sendQueriesBatchDe
2670
3123
  * }], cb)
2671
3124
  */
2672
3125
  AlgoliaSearch.prototype.batch = function(operations, callback) {
2673
- var isArray = require(10);
3126
+ var isArray = require(8);
2674
3127
  var usage = 'Usage: client.batch(operations[, callback])';
2675
3128
 
2676
3129
  if (!isArray(operations)) {
@@ -2703,15 +3156,22 @@ function notImplemented() {
2703
3156
  throw new errors.AlgoliaSearchError(message);
2704
3157
  }
2705
3158
 
2706
- },{"10":10,"13":13,"14":14,"23":23,"24":24,"25":25,"26":26,"9":9}],13:[function(require,module,exports){
3159
+ },{"15":15,"16":16,"25":25,"26":26,"27":27,"28":28,"7":7,"8":8}],15:[function(require,module,exports){
3160
+ (function (process){
2707
3161
  module.exports = AlgoliaSearchCore;
2708
3162
 
2709
- var errors = require(26);
2710
- var exitPromise = require(27);
2711
- var IndexCore = require(16);
3163
+ var errors = require(28);
3164
+ var exitPromise = require(29);
3165
+ var IndexCore = require(18);
3166
+ var store = require(34);
2712
3167
 
2713
- // We will always put the API KEY in the JSON body in case of too long API KEY
3168
+ // We will always put the API KEY in the JSON body in case of too long API KEY,
3169
+ // to avoid query string being too long and failing in various conditions (our server limit, browser limit,
3170
+ // proxies limit)
2714
3171
  var MAX_API_KEY_LENGTH = 500;
3172
+ var RESET_APP_DATA_TIMER =
3173
+ process.env.RESET_APP_DATA_TIMER && parseInt(process.env.RESET_APP_DATA_TIMER, 10) ||
3174
+ 60 * 2 * 1000; // after 2 minutes reset to first host
2715
3175
 
2716
3176
  /*
2717
3177
  * Algolia Search library initialization
@@ -2739,11 +3199,11 @@ var MAX_API_KEY_LENGTH = 500;
2739
3199
  * If you provide them, you will less benefit from our HA implementation
2740
3200
  */
2741
3201
  function AlgoliaSearchCore(applicationID, apiKey, opts) {
2742
- var debug = require(3)('algoliasearch');
3202
+ var debug = require(1)('algoliasearch');
2743
3203
 
2744
- var clone = require(23);
2745
- var isArray = require(10);
2746
- var map = require(28);
3204
+ var clone = require(25);
3205
+ var isArray = require(8);
3206
+ var map = require(30);
2747
3207
 
2748
3208
  var usage = 'Usage: algoliasearch(applicationID, apiKey, opts)';
2749
3209
 
@@ -2758,25 +3218,24 @@ function AlgoliaSearchCore(applicationID, apiKey, opts) {
2758
3218
  this.applicationID = applicationID;
2759
3219
  this.apiKey = apiKey;
2760
3220
 
2761
- var defaultHosts = shuffle([
2762
- this.applicationID + '-1.algolianet.com',
2763
- this.applicationID + '-2.algolianet.com',
2764
- this.applicationID + '-3.algolianet.com'
2765
- ]);
2766
3221
  this.hosts = {
2767
3222
  read: [],
2768
3223
  write: []
2769
3224
  };
2770
3225
 
2771
- this.hostIndex = {
2772
- read: 0,
2773
- write: 0
2774
- };
2775
-
2776
3226
  opts = opts || {};
2777
3227
 
2778
3228
  var protocol = opts.protocol || 'https:';
2779
- var timeout = opts.timeout === undefined ? 2000 : opts.timeout;
3229
+ this._timeouts = opts.timeouts || {
3230
+ connect: 1 * 1000, // 500ms connect is GPRS latency
3231
+ read: 2 * 1000,
3232
+ write: 30 * 1000
3233
+ };
3234
+
3235
+ // backward compat, if opts.timeout is passed, we use it to configure all timeouts like before
3236
+ if (opts.timeout) {
3237
+ this._timeouts.connect = this._timeouts.read = this._timeouts.write = opts.timeout;
3238
+ }
2780
3239
 
2781
3240
  // while we advocate for colon-at-the-end values: 'http:' for `opts.protocol`
2782
3241
  // we also accept `http` and `https`. It's a common error.
@@ -2788,11 +3247,19 @@ function AlgoliaSearchCore(applicationID, apiKey, opts) {
2788
3247
  throw new errors.AlgoliaSearchError('protocol must be `http:` or `https:` (was `' + opts.protocol + '`)');
2789
3248
  }
2790
3249
 
2791
- // no hosts given, add defaults
3250
+ this._checkAppIdData();
3251
+
2792
3252
  if (!opts.hosts) {
3253
+ var defaultHosts = map(this._shuffleResult, function(hostNumber) {
3254
+ return applicationID + '-' + hostNumber + '.algolianet.com';
3255
+ });
3256
+
3257
+ // no hosts given, compute defaults
2793
3258
  this.hosts.read = [this.applicationID + '-dsn.algolia.net'].concat(defaultHosts);
2794
3259
  this.hosts.write = [this.applicationID + '.algolia.net'].concat(defaultHosts);
2795
3260
  } else if (isArray(opts.hosts)) {
3261
+ // when passing custom hosts, we need to have a different host index if the number
3262
+ // of write/read hosts are different.
2796
3263
  this.hosts.read = clone(opts.hosts);
2797
3264
  this.hosts.write = clone(opts.hosts);
2798
3265
  } else {
@@ -2803,7 +3270,6 @@ function AlgoliaSearchCore(applicationID, apiKey, opts) {
2803
3270
  // add protocol and lowercase hosts
2804
3271
  this.hosts.read = map(this.hosts.read, prepareHost(protocol));
2805
3272
  this.hosts.write = map(this.hosts.write, prepareHost(protocol));
2806
- this.requestTimeout = timeout;
2807
3273
 
2808
3274
  this.extraHeaders = [];
2809
3275
 
@@ -2848,14 +3314,18 @@ AlgoliaSearchCore.prototype.setExtraHeader = function(name, value) {
2848
3314
  * @param algoliaAgent the agent to add
2849
3315
  */
2850
3316
  AlgoliaSearchCore.prototype.addAlgoliaAgent = function(algoliaAgent) {
2851
- this._ua += ';' + algoliaAgent;
3317
+ if (this._ua.indexOf(';' + algoliaAgent) === -1) {
3318
+ this._ua += ';' + algoliaAgent;
3319
+ }
2852
3320
  };
2853
3321
 
2854
3322
  /*
2855
3323
  * Wrapper that try all hosts to maximize the quality of service
2856
3324
  */
2857
3325
  AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
2858
- var requestDebug = require(3)('algoliasearch:' + initialOpts.url);
3326
+ this._checkAppIdData();
3327
+
3328
+ var requestDebug = require(1)('algoliasearch:' + initialOpts.url);
2859
3329
 
2860
3330
  var body;
2861
3331
  var cache = initialOpts.cache;
@@ -2865,7 +3335,12 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
2865
3335
  var hasFallback = client._useFallback && client._request.fallback && initialOpts.fallback;
2866
3336
  var headers;
2867
3337
 
2868
- if (this.apiKey.length > MAX_API_KEY_LENGTH && initialOpts.body !== undefined && initialOpts.body.params !== undefined) {
3338
+ if (
3339
+ this.apiKey.length > MAX_API_KEY_LENGTH &&
3340
+ initialOpts.body !== undefined &&
3341
+ (initialOpts.body.params !== undefined || // index.search()
3342
+ initialOpts.body.requests !== undefined) // client.search()
3343
+ ) {
2869
3344
  initialOpts.body.apiKey = this.apiKey;
2870
3345
  headers = this._computeRequestHeaders(false);
2871
3346
  } else {
@@ -2880,6 +3355,8 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
2880
3355
  var debugData = [];
2881
3356
 
2882
3357
  function doRequest(requester, reqOpts) {
3358
+ client._checkAppIdData();
3359
+
2883
3360
  var startTime = new Date();
2884
3361
  var cacheID;
2885
3362
 
@@ -2926,13 +3403,13 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
2926
3403
  // re-compute headers, they could be omitting the API KEY
2927
3404
  headers = client._computeRequestHeaders();
2928
3405
 
2929
- reqOpts.timeout = client.requestTimeout * (tries + 1);
2930
- client.hostIndex[initialOpts.hostType] = 0;
3406
+ reqOpts.timeouts = client._getTimeoutsForRequest(initialOpts.hostType);
3407
+ client._setHostIndexByType(0, initialOpts.hostType);
2931
3408
  usingFallback = true; // the current request is now using fallback
2932
3409
  return doRequest(client._request.fallback, reqOpts);
2933
3410
  }
2934
3411
 
2935
- var currentHost = client.hosts[initialOpts.hostType][client.hostIndex[initialOpts.hostType]];
3412
+ var currentHost = client._getHostByType(initialOpts.hostType);
2936
3413
 
2937
3414
  var url = currentHost + reqOpts.url;
2938
3415
  var options = {
@@ -2940,12 +3417,12 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
2940
3417
  jsonBody: reqOpts.jsonBody,
2941
3418
  method: reqOpts.method,
2942
3419
  headers: headers,
2943
- timeout: reqOpts.timeout,
3420
+ timeouts: reqOpts.timeouts,
2944
3421
  debug: requestDebug
2945
3422
  };
2946
3423
 
2947
- requestDebug('method: %s, url: %s, headers: %j, timeout: %d',
2948
- options.method, url, options.headers, options.timeout);
3424
+ requestDebug('method: %s, url: %s, headers: %j, timeouts: %d',
3425
+ options.method, url, options.headers, options.timeouts);
2949
3426
 
2950
3427
  if (requester === client._request.fallback) {
2951
3428
  requestDebug('using fallback');
@@ -2988,7 +3465,7 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
2988
3465
  content: body || null,
2989
3466
  contentLength: body !== undefined ? body.length : null,
2990
3467
  method: reqOpts.method,
2991
- timeout: reqOpts.timeout,
3468
+ timeouts: reqOpts.timeouts,
2992
3469
  url: reqOpts.url,
2993
3470
  startTime: startTime,
2994
3471
  endTime: endTime,
@@ -3041,7 +3518,7 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
3041
3518
  content: body || null,
3042
3519
  contentLength: body !== undefined ? body.length : null,
3043
3520
  method: reqOpts.method,
3044
- timeout: reqOpts.timeout,
3521
+ timeouts: reqOpts.timeouts,
3045
3522
  url: reqOpts.url,
3046
3523
  startTime: startTime,
3047
3524
  endTime: endTime,
@@ -3081,14 +3558,15 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
3081
3558
 
3082
3559
  function retryRequest() {
3083
3560
  requestDebug('retrying request');
3084
- client.hostIndex[initialOpts.hostType] = (client.hostIndex[initialOpts.hostType] + 1) % client.hosts[initialOpts.hostType].length;
3561
+ client._incrementHostIndex(initialOpts.hostType);
3085
3562
  return doRequest(requester, reqOpts);
3086
3563
  }
3087
3564
 
3088
3565
  function retryRequestWithHigherTimeout() {
3089
3566
  requestDebug('retrying request with higher timeout');
3090
- client.hostIndex[initialOpts.hostType] = (client.hostIndex[initialOpts.hostType] + 1) % client.hosts[initialOpts.hostType].length;
3091
- reqOpts.timeout = client.requestTimeout * (tries + 1);
3567
+ client._incrementHostIndex(initialOpts.hostType);
3568
+ client._incrementTimeoutMultipler();
3569
+ reqOpts.timeouts = client._getTimeoutsForRequest(initialOpts.hostType);
3092
3570
  return doRequest(requester, reqOpts);
3093
3571
  }
3094
3572
  }
@@ -3099,7 +3577,7 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
3099
3577
  method: initialOpts.method,
3100
3578
  body: body,
3101
3579
  jsonBody: initialOpts.body,
3102
- timeout: client.requestTimeout * (tries + 1)
3580
+ timeouts: client._getTimeoutsForRequest(initialOpts.hostType)
3103
3581
  }
3104
3582
  );
3105
3583
 
@@ -3137,7 +3615,7 @@ AlgoliaSearchCore.prototype._getSearchParams = function(args, params) {
3137
3615
  };
3138
3616
 
3139
3617
  AlgoliaSearchCore.prototype._computeRequestHeaders = function(withAPIKey) {
3140
- var forEach = require(7);
3618
+ var forEach = require(5);
3141
3619
 
3142
3620
  var requestHeaders = {
3143
3621
  'x-algolia-agent': this._ua,
@@ -3179,8 +3657,8 @@ AlgoliaSearchCore.prototype._computeRequestHeaders = function(withAPIKey) {
3179
3657
  * @return {Promise|undefined} Returns a promise if no callback given
3180
3658
  */
3181
3659
  AlgoliaSearchCore.prototype.search = function(queries, opts, callback) {
3182
- var isArray = require(10);
3183
- var map = require(28);
3660
+ var isArray = require(8);
3661
+ var map = require(30);
3184
3662
 
3185
3663
  var usage = 'Usage: client.search(arrayOfQueries[, callback])';
3186
3664
 
@@ -3288,13 +3766,113 @@ AlgoliaSearchCore.prototype.clearCache = function() {
3288
3766
 
3289
3767
  /**
3290
3768
  * Set the number of milliseconds a request can take before automatically being terminated.
3291
- *
3769
+ * @deprecated
3292
3770
  * @param {Number} milliseconds
3293
3771
  */
3294
3772
  AlgoliaSearchCore.prototype.setRequestTimeout = function(milliseconds) {
3295
3773
  if (milliseconds) {
3296
- this.requestTimeout = parseInt(milliseconds, 10);
3774
+ this._timeouts.connect = this._timeouts.read = this._timeouts.write = milliseconds;
3775
+ }
3776
+ };
3777
+
3778
+ /**
3779
+ * Set the three different (connect, read, write) timeouts to be used when requesting
3780
+ * @param {Object} timeouts
3781
+ */
3782
+ AlgoliaSearchCore.prototype.setTimeouts = function(timeouts) {
3783
+ this._timeouts = timeouts;
3784
+ };
3785
+
3786
+ /**
3787
+ * Get the three different (connect, read, write) timeouts to be used when requesting
3788
+ * @param {Object} timeouts
3789
+ */
3790
+ AlgoliaSearchCore.prototype.getTimeouts = function() {
3791
+ return this._timeouts;
3792
+ };
3793
+
3794
+ AlgoliaSearchCore.prototype._getAppIdData = function() {
3795
+ var data = store.get(this.applicationID);
3796
+ if (data !== null) this._cacheAppIdData(data);
3797
+ return data;
3798
+ };
3799
+
3800
+ AlgoliaSearchCore.prototype._setAppIdData = function(data) {
3801
+ data.lastChange = (new Date()).getTime();
3802
+ this._cacheAppIdData(data);
3803
+ return store.set(this.applicationID, data);
3804
+ };
3805
+
3806
+ AlgoliaSearchCore.prototype._checkAppIdData = function() {
3807
+ var data = this._getAppIdData();
3808
+ var now = (new Date()).getTime();
3809
+ if (data === null || now - data.lastChange > RESET_APP_DATA_TIMER) {
3810
+ return this._resetInitialAppIdData(data);
3297
3811
  }
3812
+
3813
+ return data;
3814
+ };
3815
+
3816
+ AlgoliaSearchCore.prototype._resetInitialAppIdData = function(data) {
3817
+ var newData = data || {};
3818
+ newData.hostIndexes = {read: 0, write: 0};
3819
+ newData.timeoutMultiplier = 1;
3820
+ newData.shuffleResult = newData.shuffleResult || shuffle([1, 2, 3]);
3821
+ return this._setAppIdData(newData);
3822
+ };
3823
+
3824
+ AlgoliaSearchCore.prototype._cacheAppIdData = function(data) {
3825
+ this._hostIndexes = data.hostIndexes;
3826
+ this._timeoutMultiplier = data.timeoutMultiplier;
3827
+ this._shuffleResult = data.shuffleResult;
3828
+ };
3829
+
3830
+ AlgoliaSearchCore.prototype._partialAppIdDataUpdate = function(newData) {
3831
+ var foreach = require(5);
3832
+ var currentData = this._getAppIdData();
3833
+ foreach(newData, function(value, key) {
3834
+ currentData[key] = value;
3835
+ });
3836
+
3837
+ return this._setAppIdData(currentData);
3838
+ };
3839
+
3840
+ AlgoliaSearchCore.prototype._getHostByType = function(hostType) {
3841
+ return this.hosts[hostType][this._getHostIndexByType(hostType)];
3842
+ };
3843
+
3844
+ AlgoliaSearchCore.prototype._getTimeoutMultiplier = function() {
3845
+ return this._timeoutMultiplier;
3846
+ };
3847
+
3848
+ AlgoliaSearchCore.prototype._getHostIndexByType = function(hostType) {
3849
+ return this._hostIndexes[hostType];
3850
+ };
3851
+
3852
+ AlgoliaSearchCore.prototype._setHostIndexByType = function(hostIndex, hostType) {
3853
+ var clone = require(25);
3854
+ var newHostIndexes = clone(this._hostIndexes);
3855
+ newHostIndexes[hostType] = hostIndex;
3856
+ this._partialAppIdDataUpdate({hostIndexes: newHostIndexes});
3857
+ return hostIndex;
3858
+ };
3859
+
3860
+ AlgoliaSearchCore.prototype._incrementHostIndex = function(hostType) {
3861
+ return this._setHostIndexByType(
3862
+ (this._getHostIndexByType(hostType) + 1) % this.hosts[hostType].length, hostType
3863
+ );
3864
+ };
3865
+
3866
+ AlgoliaSearchCore.prototype._incrementTimeoutMultipler = function() {
3867
+ var timeoutMultiplier = Math.max(this._timeoutMultiplier + 1, 4);
3868
+ return this._partialAppIdDataUpdate({timeoutMultiplier: timeoutMultiplier});
3869
+ };
3870
+
3871
+ AlgoliaSearchCore.prototype._getTimeoutsForRequest = function(hostType) {
3872
+ return {
3873
+ connect: this._timeouts.connect * this._timeoutMultiplier,
3874
+ complete: this._timeouts[hostType] * this._timeoutMultiplier
3875
+ };
3298
3876
  };
3299
3877
 
3300
3878
  function prepareHost(protocol) {
@@ -3365,13 +3943,14 @@ function removeCredentials(headers) {
3365
3943
  return newHeaders;
3366
3944
  }
3367
3945
 
3368
- },{"10":10,"16":16,"23":23,"26":26,"27":27,"28":28,"3":3,"7":7}],14:[function(require,module,exports){
3369
- var inherits = require(9);
3370
- var IndexCore = require(16);
3371
- var deprecate = require(24);
3372
- var deprecatedMessage = require(25);
3373
- var exitPromise = require(27);
3374
- var errors = require(26);
3946
+ }).call(this,require(12))
3947
+ },{"1":1,"12":12,"18":18,"25":25,"28":28,"29":29,"30":30,"34":34,"5":5,"8":8}],16:[function(require,module,exports){
3948
+ var inherits = require(7);
3949
+ var IndexCore = require(18);
3950
+ var deprecate = require(26);
3951
+ var deprecatedMessage = require(27);
3952
+ var exitPromise = require(29);
3953
+ var errors = require(28);
3375
3954
 
3376
3955
  module.exports = Index;
3377
3956
 
@@ -3420,7 +3999,7 @@ Index.prototype.addObject = function(content, objectID, callback) {
3420
3999
  * content: the server answer that updateAt and taskID
3421
4000
  */
3422
4001
  Index.prototype.addObjects = function(objects, callback) {
3423
- var isArray = require(10);
4002
+ var isArray = require(8);
3424
4003
  var usage = 'Usage: index.addObjects(arrayOfObjects[, callback])';
3425
4004
 
3426
4005
  if (!isArray(objects)) {
@@ -3487,7 +4066,7 @@ Index.prototype.partialUpdateObject = function(partialObject, createIfNotExists,
3487
4066
  * content: the server answer that updateAt and taskID
3488
4067
  */
3489
4068
  Index.prototype.partialUpdateObjects = function(objects, callback) {
3490
- var isArray = require(10);
4069
+ var isArray = require(8);
3491
4070
  var usage = 'Usage: index.partialUpdateObjects(arrayOfObjects[, callback])';
3492
4071
 
3493
4072
  if (!isArray(objects)) {
@@ -3543,7 +4122,7 @@ Index.prototype.saveObject = function(object, callback) {
3543
4122
  * content: the server answer that updateAt and taskID
3544
4123
  */
3545
4124
  Index.prototype.saveObjects = function(objects, callback) {
3546
- var isArray = require(10);
4125
+ var isArray = require(8);
3547
4126
  var usage = 'Usage: index.saveObjects(arrayOfObjects[, callback])';
3548
4127
 
3549
4128
  if (!isArray(objects)) {
@@ -3608,8 +4187,8 @@ Index.prototype.deleteObject = function(objectID, callback) {
3608
4187
  * content: the server answer that contains 3 elements: createAt, taskId and objectID
3609
4188
  */
3610
4189
  Index.prototype.deleteObjects = function(objectIDs, callback) {
3611
- var isArray = require(10);
3612
- var map = require(28);
4190
+ var isArray = require(8);
4191
+ var map = require(30);
3613
4192
 
3614
4193
  var usage = 'Usage: index.deleteObjects(arrayOfObjectIDs[, callback])';
3615
4194
 
@@ -3648,8 +4227,8 @@ Index.prototype.deleteObjects = function(objectIDs, callback) {
3648
4227
  * error: null or Error('message')
3649
4228
  */
3650
4229
  Index.prototype.deleteByQuery = function(query, params, callback) {
3651
- var clone = require(23);
3652
- var map = require(28);
4230
+ var clone = require(25);
4231
+ var map = require(30);
3653
4232
 
3654
4233
  var indexObj = this;
3655
4234
  var client = indexObj.as;
@@ -3759,9 +4338,9 @@ Index.prototype.browseAll = function(query, queryParameters) {
3759
4338
  query = undefined;
3760
4339
  }
3761
4340
 
3762
- var merge = require(29);
4341
+ var merge = require(31);
3763
4342
 
3764
- var IndexBrowser = require(15);
4343
+ var IndexBrowser = require(17);
3765
4344
 
3766
4345
  var browser = new IndexBrowser();
3767
4346
  var client = this.as;
@@ -4221,7 +4800,7 @@ Index.prototype.deleteUserKey = function(key, callback) {
4221
4800
  * @see {@link https://www.algolia.com/doc/rest_api#AddIndexKey|Algolia REST API Documentation}
4222
4801
  */
4223
4802
  Index.prototype.addUserKey = function(acls, params, callback) {
4224
- var isArray = require(10);
4803
+ var isArray = require(8);
4225
4804
  var usage = 'Usage: index.addUserKey(arrayOfAcls[, params, callback])';
4226
4805
 
4227
4806
  if (!isArray(acls)) {
@@ -4304,7 +4883,7 @@ Index.prototype.addUserKeyWithValidity = deprecate(function deprecatedAddUserKey
4304
4883
  * @see {@link https://www.algolia.com/doc/rest_api#UpdateIndexKey|Algolia REST API Documentation}
4305
4884
  */
4306
4885
  Index.prototype.updateUserKey = function(key, acls, params, callback) {
4307
- var isArray = require(10);
4886
+ var isArray = require(8);
4308
4887
  var usage = 'Usage: index.updateUserKey(key, arrayOfAcls[, params, callback])';
4309
4888
 
4310
4889
  if (!isArray(acls)) {
@@ -4342,15 +4921,15 @@ Index.prototype.updateUserKey = function(key, acls, params, callback) {
4342
4921
  });
4343
4922
  };
4344
4923
 
4345
- },{"10":10,"15":15,"16":16,"23":23,"24":24,"25":25,"26":26,"27":27,"28":28,"29":29,"9":9}],15:[function(require,module,exports){
4924
+ },{"17":17,"18":18,"25":25,"26":26,"27":27,"28":28,"29":29,"30":30,"31":31,"7":7,"8":8}],17:[function(require,module,exports){
4346
4925
  'use strict';
4347
4926
 
4348
4927
  // This is the object returned by the `index.browseAll()` method
4349
4928
 
4350
4929
  module.exports = IndexBrowser;
4351
4930
 
4352
- var inherits = require(9);
4353
- var EventEmitter = require(6).EventEmitter;
4931
+ var inherits = require(7);
4932
+ var EventEmitter = require(4).EventEmitter;
4354
4933
 
4355
4934
  function IndexBrowser() {
4356
4935
  }
@@ -4383,8 +4962,10 @@ IndexBrowser.prototype._clean = function() {
4383
4962
  this.removeAllListeners('result');
4384
4963
  };
4385
4964
 
4386
- },{"6":6,"9":9}],16:[function(require,module,exports){
4387
- var buildSearchMethod = require(22);
4965
+ },{"4":4,"7":7}],18:[function(require,module,exports){
4966
+ var buildSearchMethod = require(24);
4967
+ var deprecate = require(26);
4968
+ var deprecatedMessage = require(27);
4388
4969
 
4389
4970
  module.exports = IndexCore;
4390
4971
 
@@ -4536,7 +5117,7 @@ IndexCore.prototype.similarSearch = buildSearchMethod('similarQuery');
4536
5117
  * @see {@link https://www.algolia.com/doc/rest_api#Browse|Algolia REST API Documentation}
4537
5118
  */
4538
5119
  IndexCore.prototype.browse = function(query, queryParameters, callback) {
4539
- var merge = require(29);
5120
+ var merge = require(31);
4540
5121
 
4541
5122
  var indexObj = this;
4542
5123
 
@@ -4616,6 +5197,50 @@ IndexCore.prototype.browseFrom = function(cursor, callback) {
4616
5197
  });
4617
5198
  };
4618
5199
 
5200
+ /*
5201
+ * Search for facet values
5202
+ * https://www.algolia.com/doc/rest-api/search#search-for-facet-values
5203
+ *
5204
+ * @param {string} params.facetName Facet name, name of the attribute to search for values in.
5205
+ * Must be declared as a facet
5206
+ * @param {string} params.facetQuery Query for the facet search
5207
+ * @param {string} [params.*] Any search parameter of Algolia,
5208
+ * see https://www.algolia.com/doc/api-client/javascript/search#search-parameters
5209
+ * Pagination is not supported. The page and hitsPerPage parameters will be ignored.
5210
+ * @param callback (optional)
5211
+ */
5212
+ IndexCore.prototype.searchForFacetValues = function(params, callback) {
5213
+ var clone = require(25);
5214
+ var omit = require(32);
5215
+ var usage = 'Usage: index.searchForFacetValues({facetName, facetQuery, ...params}[, callback])';
5216
+
5217
+ if (params.facetName === undefined || params.facetQuery === undefined) {
5218
+ throw new Error(usage);
5219
+ }
5220
+
5221
+ var facetName = params.facetName;
5222
+ var filteredParams = omit(clone(params), function(keyName) {
5223
+ return keyName === 'facetName';
5224
+ });
5225
+ var searchParameters = this.as._getSearchParams(filteredParams, '');
5226
+
5227
+ return this.as._jsonRequest({
5228
+ method: 'POST',
5229
+ url: '/1/indexes/' +
5230
+ encodeURIComponent(this.indexName) + '/facets/' + encodeURIComponent(facetName) + '/query',
5231
+ hostType: 'read',
5232
+ body: {params: searchParameters},
5233
+ callback: callback
5234
+ });
5235
+ };
5236
+
5237
+ IndexCore.prototype.searchFacet = deprecate(function(params, callback) {
5238
+ return this.searchForFacetValues(params, callback);
5239
+ }, deprecatedMessage(
5240
+ 'index.searchFacet(params[, callback])',
5241
+ 'index.searchForFacetValues(params[, callback])'
5242
+ ));
5243
+
4619
5244
  IndexCore.prototype._search = function(params, url, callback) {
4620
5245
  return this.as._jsonRequest({
4621
5246
  cache: this.cache,
@@ -4674,8 +5299,8 @@ IndexCore.prototype.getObject = function(objectID, attrs, callback) {
4674
5299
  * @param objectIDs the array of unique identifier of objects to retrieve
4675
5300
  */
4676
5301
  IndexCore.prototype.getObjects = function(objectIDs, attributesToRetrieve, callback) {
4677
- var isArray = require(10);
4678
- var map = require(28);
5302
+ var isArray = require(8);
5303
+ var map = require(30);
4679
5304
 
4680
5305
  var usage = 'Usage: index.getObjects(arrayOfObjectIDs[, callback])';
4681
5306
 
@@ -4719,40 +5344,40 @@ IndexCore.prototype.indexName = null;
4719
5344
  IndexCore.prototype.typeAheadArgs = null;
4720
5345
  IndexCore.prototype.typeAheadValueOption = null;
4721
5346
 
4722
- },{"10":10,"22":22,"28":28,"29":29}],17:[function(require,module,exports){
5347
+ },{"24":24,"25":25,"26":26,"27":27,"30":30,"31":31,"32":32,"8":8}],19:[function(require,module,exports){
4723
5348
  'use strict';
4724
5349
 
4725
- var AlgoliaSearch = require(12);
4726
- var createAlgoliasearch = require(18);
5350
+ var AlgoliaSearch = require(14);
5351
+ var createAlgoliasearch = require(20);
4727
5352
 
4728
5353
  module.exports = createAlgoliasearch(AlgoliaSearch);
4729
5354
 
4730
- },{"12":12,"18":18}],18:[function(require,module,exports){
5355
+ },{"14":14,"20":20}],20:[function(require,module,exports){
4731
5356
  (function (process){
4732
5357
  'use strict';
4733
5358
 
4734
- var global = require(8);
4735
- var Promise = global.Promise || require(5).Promise;
5359
+ var global = require(6);
5360
+ var Promise = global.Promise || require(3).Promise;
4736
5361
 
4737
5362
  // This is the standalone browser build entry point
4738
5363
  // Browser implementation of the Algolia Search JavaScript client,
4739
5364
  // using XMLHttpRequest, XDomainRequest and JSONP as fallback
4740
5365
  module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
4741
- var inherits = require(9);
4742
- var errors = require(26);
4743
- var inlineHeaders = require(20);
4744
- var jsonpRequest = require(21);
4745
- var places = require(30);
5366
+ var inherits = require(7);
5367
+ var errors = require(28);
5368
+ var inlineHeaders = require(22);
5369
+ var jsonpRequest = require(23);
5370
+ var places = require(33);
4746
5371
  uaSuffix = uaSuffix || '';
4747
5372
 
4748
5373
  if (process.env.NODE_ENV === 'debug') {
4749
- require(3).enable('algoliasearch*');
5374
+ require(1).enable('algoliasearch*');
4750
5375
  }
4751
5376
 
4752
5377
  function algoliasearch(applicationID, apiKey, opts) {
4753
- var cloneDeep = require(23);
5378
+ var cloneDeep = require(25);
4754
5379
 
4755
- var getDocumentProtocol = require(19);
5380
+ var getDocumentProtocol = require(21);
4756
5381
 
4757
5382
  opts = cloneDeep(opts || {});
4758
5383
 
@@ -4765,14 +5390,14 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
4765
5390
  return new AlgoliaSearchBrowser(applicationID, apiKey, opts);
4766
5391
  }
4767
5392
 
4768
- algoliasearch.version = require(31);
5393
+ algoliasearch.version = require(35);
4769
5394
  algoliasearch.ua = 'Algolia for vanilla JavaScript ' + uaSuffix + algoliasearch.version;
4770
5395
  algoliasearch.initPlaces = places(algoliasearch);
4771
5396
 
4772
5397
  // we expose into window no matter how we are used, this will allow
4773
5398
  // us to easily debug any website running algolia
4774
5399
  global.__algolia = {
4775
- debug: require(3),
5400
+ debug: require(1),
4776
5401
  algoliasearch: algoliasearch
4777
5402
  };
4778
5403
 
@@ -4783,7 +5408,6 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
4783
5408
 
4784
5409
  if (support.hasXMLHttpRequest) {
4785
5410
  support.cors = 'withCredentials' in new XMLHttpRequest();
4786
- support.timeout = 'timeout' in new XMLHttpRequest();
4787
5411
  }
4788
5412
 
4789
5413
  function AlgoliaSearchBrowser() {
@@ -4806,8 +5430,20 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
4806
5430
 
4807
5431
  var body = opts.body;
4808
5432
  var req = support.cors ? new XMLHttpRequest() : new XDomainRequest();
4809
- var ontimeout;
5433
+ var reqTimeout;
4810
5434
  var timedOut;
5435
+ var connected = false;
5436
+
5437
+ reqTimeout = setTimeout(onTimeout, opts.timeouts.connect);
5438
+ // we set an empty onprogress listener
5439
+ // so that XDomainRequest on IE9 is not aborted
5440
+ // refs:
5441
+ // - https://github.com/algolia/algoliasearch-client-js/issues/76
5442
+ // - https://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handlers-not-specified?forum=iewebdevelopment
5443
+ req.onprogress = onProgress;
5444
+ if ('onreadystatechange' in req) req.onreadystatechange = onReadyStateChange;
5445
+ req.onload = onLoad;
5446
+ req.onerror = onError;
4811
5447
 
4812
5448
  // do not rely on default XHR async flag, as some analytics code like hotjar
4813
5449
  // breaks it and set it to false by default
@@ -4817,6 +5453,7 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
4817
5453
  req.open(opts.method, url);
4818
5454
  }
4819
5455
 
5456
+ // headers are meant to be sent after open
4820
5457
  if (support.cors) {
4821
5458
  if (body) {
4822
5459
  if (opts.method === 'POST') {
@@ -4829,40 +5466,18 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
4829
5466
  req.setRequestHeader('accept', 'application/json');
4830
5467
  }
4831
5468
 
4832
- // we set an empty onprogress listener
4833
- // so that XDomainRequest on IE9 is not aborted
4834
- // refs:
4835
- // - https://github.com/algolia/algoliasearch-client-js/issues/76
4836
- // - https://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handlers-not-specified?forum=iewebdevelopment
4837
- req.onprogress = function noop() {};
4838
-
4839
- req.onload = load;
4840
- req.onerror = error;
4841
-
4842
- if (support.timeout) {
4843
- // .timeout supported by both XHR and XDR,
4844
- // we do receive timeout event, tested
4845
- req.timeout = opts.timeout;
4846
-
4847
- req.ontimeout = timeout;
4848
- } else {
4849
- ontimeout = setTimeout(timeout, opts.timeout);
4850
- }
4851
-
4852
5469
  req.send(body);
4853
5470
 
4854
5471
  // event object not received in IE8, at least
4855
5472
  // but we do not use it, still important to note
4856
- function load(/* event */) {
5473
+ function onLoad(/* event */) {
4857
5474
  // When browser does not supports req.timeout, we can
4858
5475
  // have both a load and timeout event, since handled by a dumb setTimeout
4859
5476
  if (timedOut) {
4860
5477
  return;
4861
5478
  }
4862
5479
 
4863
- if (!support.timeout) {
4864
- clearTimeout(ontimeout);
4865
- }
5480
+ clearTimeout(reqTimeout);
4866
5481
 
4867
5482
  var out;
4868
5483
 
@@ -4887,14 +5502,12 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
4887
5502
  }
4888
5503
  }
4889
5504
 
4890
- function error(event) {
5505
+ function onError(event) {
4891
5506
  if (timedOut) {
4892
5507
  return;
4893
5508
  }
4894
5509
 
4895
- if (!support.timeout) {
4896
- clearTimeout(ontimeout);
4897
- }
5510
+ clearTimeout(reqTimeout);
4898
5511
 
4899
5512
  // error event is trigerred both with XDR/XHR on:
4900
5513
  // - DNS error
@@ -4906,14 +5519,26 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
4906
5519
  );
4907
5520
  }
4908
5521
 
4909
- function timeout() {
4910
- if (!support.timeout) {
4911
- timedOut = true;
4912
- req.abort();
4913
- }
5522
+ function onTimeout() {
5523
+ timedOut = true;
5524
+ req.abort();
4914
5525
 
4915
5526
  reject(new errors.RequestTimeout());
4916
5527
  }
5528
+
5529
+ function onConnect() {
5530
+ connected = true;
5531
+ clearTimeout(reqTimeout);
5532
+ reqTimeout = setTimeout(onTimeout, opts.timeouts.complete);
5533
+ }
5534
+
5535
+ function onProgress() {
5536
+ if (!connected) onConnect();
5537
+ }
5538
+
5539
+ function onReadyStateChange() {
5540
+ if (!connected && req.readyState > 1) onConnect();
5541
+ }
4917
5542
  });
4918
5543
  };
4919
5544
 
@@ -4949,8 +5574,8 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
4949
5574
  return algoliasearch;
4950
5575
  };
4951
5576
 
4952
- }).call(this,require(2))
4953
- },{"19":19,"2":2,"20":20,"21":21,"23":23,"26":26,"3":3,"30":30,"31":31,"5":5,"8":8,"9":9}],19:[function(require,module,exports){
5577
+ }).call(this,require(12))
5578
+ },{"1":1,"12":12,"21":21,"22":22,"23":23,"25":25,"28":28,"3":3,"33":33,"35":35,"6":6,"7":7}],21:[function(require,module,exports){
4954
5579
  'use strict';
4955
5580
 
4956
5581
  module.exports = getDocumentProtocol;
@@ -4966,12 +5591,12 @@ function getDocumentProtocol() {
4966
5591
  return protocol;
4967
5592
  }
4968
5593
 
4969
- },{}],20:[function(require,module,exports){
5594
+ },{}],22:[function(require,module,exports){
4970
5595
  'use strict';
4971
5596
 
4972
5597
  module.exports = inlineHeaders;
4973
5598
 
4974
- var encode = require(11);
5599
+ var encode = require(13);
4975
5600
 
4976
5601
  function inlineHeaders(url, headers) {
4977
5602
  if (/\?/.test(url)) {
@@ -4983,12 +5608,12 @@ function inlineHeaders(url, headers) {
4983
5608
  return url + encode(headers);
4984
5609
  }
4985
5610
 
4986
- },{"11":11}],21:[function(require,module,exports){
5611
+ },{"13":13}],23:[function(require,module,exports){
4987
5612
  'use strict';
4988
5613
 
4989
5614
  module.exports = jsonpRequest;
4990
5615
 
4991
- var errors = require(26);
5616
+ var errors = require(28);
4992
5617
 
4993
5618
  var JSONPCounter = 0;
4994
5619
 
@@ -5037,7 +5662,7 @@ function jsonpRequest(url, opts, cb) {
5037
5662
  url += '&' + opts.jsonBody.params;
5038
5663
  }
5039
5664
 
5040
- var ontimeout = setTimeout(timeout, opts.timeout);
5665
+ var ontimeout = setTimeout(timeout, opts.timeouts.complete);
5041
5666
 
5042
5667
  // script onreadystatechange needed only for
5043
5668
  // <= IE8
@@ -5110,10 +5735,10 @@ function jsonpRequest(url, opts, cb) {
5110
5735
  }
5111
5736
  }
5112
5737
 
5113
- },{"26":26}],22:[function(require,module,exports){
5738
+ },{"28":28}],24:[function(require,module,exports){
5114
5739
  module.exports = buildSearchMethod;
5115
5740
 
5116
- var errors = require(26);
5741
+ var errors = require(28);
5117
5742
 
5118
5743
  function buildSearchMethod(queryParam, url) {
5119
5744
  return function search(query, args, callback) {
@@ -5158,12 +5783,12 @@ function buildSearchMethod(queryParam, url) {
5158
5783
  };
5159
5784
  }
5160
5785
 
5161
- },{"26":26}],23:[function(require,module,exports){
5786
+ },{"28":28}],25:[function(require,module,exports){
5162
5787
  module.exports = function clone(obj) {
5163
5788
  return JSON.parse(JSON.stringify(obj));
5164
5789
  };
5165
5790
 
5166
- },{}],24:[function(require,module,exports){
5791
+ },{}],26:[function(require,module,exports){
5167
5792
  module.exports = function deprecate(fn, message) {
5168
5793
  var warned = false;
5169
5794
 
@@ -5180,7 +5805,7 @@ module.exports = function deprecate(fn, message) {
5180
5805
  return deprecated;
5181
5806
  };
5182
5807
 
5183
- },{}],25:[function(require,module,exports){
5808
+ },{}],27:[function(require,module,exports){
5184
5809
  module.exports = function deprecatedMessage(previousUsage, newUsage) {
5185
5810
  var githubAnchorLink = previousUsage.toLowerCase()
5186
5811
  .replace('.', '')
@@ -5190,17 +5815,17 @@ module.exports = function deprecatedMessage(previousUsage, newUsage) {
5190
5815
  '`. Please see https://github.com/algolia/algoliasearch-client-js/wiki/Deprecated#' + githubAnchorLink;
5191
5816
  };
5192
5817
 
5193
- },{}],26:[function(require,module,exports){
5818
+ },{}],28:[function(require,module,exports){
5194
5819
  'use strict';
5195
5820
 
5196
5821
  // This file hosts our error definitions
5197
5822
  // We use custom error "types" so that we can act on them when we need it
5198
5823
  // e.g.: if error instanceof errors.UnparsableJSON then..
5199
5824
 
5200
- var inherits = require(9);
5825
+ var inherits = require(7);
5201
5826
 
5202
5827
  function AlgoliaSearchError(message, extraProperties) {
5203
- var forEach = require(7);
5828
+ var forEach = require(5);
5204
5829
 
5205
5830
  var error = this;
5206
5831
 
@@ -5270,7 +5895,7 @@ module.exports = {
5270
5895
  )
5271
5896
  };
5272
5897
 
5273
- },{"7":7,"9":9}],27:[function(require,module,exports){
5898
+ },{"5":5,"7":7}],29:[function(require,module,exports){
5274
5899
  // Parse cloud does not supports setTimeout
5275
5900
  // We do not store a setTimeout reference in the client everytime
5276
5901
  // We only fallback to a fake setTimeout when not available
@@ -5279,8 +5904,8 @@ module.exports = function exitPromise(fn, _setTimeout) {
5279
5904
  _setTimeout(fn, 0);
5280
5905
  };
5281
5906
 
5282
- },{}],28:[function(require,module,exports){
5283
- var foreach = require(7);
5907
+ },{}],30:[function(require,module,exports){
5908
+ var foreach = require(5);
5284
5909
 
5285
5910
  module.exports = function map(arr, fn) {
5286
5911
  var newArr = [];
@@ -5290,8 +5915,8 @@ module.exports = function map(arr, fn) {
5290
5915
  return newArr;
5291
5916
  };
5292
5917
 
5293
- },{"7":7}],29:[function(require,module,exports){
5294
- var foreach = require(7);
5918
+ },{"5":5}],31:[function(require,module,exports){
5919
+ var foreach = require(5);
5295
5920
 
5296
5921
  module.exports = function merge(destination/* , sources */) {
5297
5922
  var sources = Array.prototype.slice.call(arguments);
@@ -5311,14 +5936,30 @@ module.exports = function merge(destination/* , sources */) {
5311
5936
  return destination;
5312
5937
  };
5313
5938
 
5314
- },{"7":7}],30:[function(require,module,exports){
5939
+ },{"5":5}],32:[function(require,module,exports){
5940
+ module.exports = function omit(obj, test) {
5941
+ var keys = require(10);
5942
+ var foreach = require(5);
5943
+
5944
+ var filtered = {};
5945
+
5946
+ foreach(keys(obj), function doFilter(keyName) {
5947
+ if (test(keyName) !== true) {
5948
+ filtered[keyName] = obj[keyName];
5949
+ }
5950
+ });
5951
+
5952
+ return filtered;
5953
+ };
5954
+
5955
+ },{"10":10,"5":5}],33:[function(require,module,exports){
5315
5956
  module.exports = createPlacesClient;
5316
5957
 
5317
- var buildSearchMethod = require(22);
5958
+ var buildSearchMethod = require(24);
5318
5959
 
5319
5960
  function createPlacesClient(algoliasearch) {
5320
5961
  return function places(appID, apiKey, opts) {
5321
- var cloneDeep = require(23);
5962
+ var cloneDeep = require(25);
5322
5963
 
5323
5964
  opts = opts && cloneDeep(opts) || {};
5324
5965
  opts.hosts = opts.hosts || [
@@ -5342,10 +5983,88 @@ function createPlacesClient(algoliasearch) {
5342
5983
  };
5343
5984
  }
5344
5985
 
5345
- },{"22":22,"23":23}],31:[function(require,module,exports){
5986
+ },{"24":24,"25":25}],34:[function(require,module,exports){
5987
+ (function (global){
5988
+ var debug = require(1)('algoliasearch:src/hostIndexState.js');
5989
+ var localStorageNamespace = 'algoliasearch-client-js';
5990
+
5991
+ var store;
5992
+ var moduleStore = {
5993
+ state: {},
5994
+ set: function(key, data) {
5995
+ this.state[key] = data;
5996
+ return this.state[key];
5997
+ },
5998
+ get: function(key) {
5999
+ return this.state[key] || null;
6000
+ }
6001
+ };
6002
+
6003
+ var localStorageStore = {
6004
+ set: function(key, data) {
6005
+ try {
6006
+ var namespace = JSON.parse(global.localStorage[localStorageNamespace]);
6007
+ namespace[key] = data;
6008
+ global.localStorage[localStorageNamespace] = JSON.stringify(namespace);
6009
+ return namespace[key];
6010
+ } catch (e) {
6011
+ debug('localStorage set failed with', e);
6012
+ cleanup();
6013
+ store = moduleStore;
6014
+ return store.set(key, data);
6015
+ }
6016
+ },
6017
+ get: function(key) {
6018
+ return JSON.parse(global.localStorage[localStorageNamespace])[key] || null;
6019
+ }
6020
+ };
6021
+
6022
+ store = supportsLocalStorage() ? localStorageStore : moduleStore;
6023
+
6024
+ module.exports = {
6025
+ get: getOrSet,
6026
+ set: getOrSet
6027
+ };
6028
+
6029
+ function getOrSet(key, data) {
6030
+ if (arguments.length === 1) {
6031
+ return store.get(key);
6032
+ }
6033
+
6034
+ return store.set(key, data);
6035
+ }
6036
+
6037
+ function supportsLocalStorage() {
6038
+ try {
6039
+ if ('localStorage' in global &&
6040
+ global.localStorage !== null &&
6041
+ !global.localStorage[localStorageNamespace]) {
6042
+ // actual creation of the namespace
6043
+ global.localStorage.setItem(localStorageNamespace, JSON.stringify({}));
6044
+ return true;
6045
+ }
6046
+
6047
+ return false;
6048
+ } catch (_) {
6049
+ return false;
6050
+ }
6051
+ }
6052
+
6053
+ // In case of any error on localStorage, we clean our own namespace, this should handle
6054
+ // quota errors when a lot of keys + data are used
6055
+ function cleanup() {
6056
+ try {
6057
+ global.localStorage.removeItem(localStorageNamespace);
6058
+ } catch (_) {
6059
+ // nothing to do
6060
+ }
6061
+ }
6062
+
6063
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
6064
+ },{"1":1}],35:[function(require,module,exports){
5346
6065
  'use strict';
5347
6066
 
5348
- module.exports = '3.18.0';
6067
+ module.exports = '3.20.3';
5349
6068
 
5350
- },{}]},{},[17])(17)
6069
+ },{}]},{},[19])(19)
5351
6070
  });