Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Last active December 26, 2017 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nolanlawson/5d326f3692bc65cf89fd to your computer and use it in GitHub Desktop.
Save nolanlawson/5d326f3692bc65cf89fd to your computer and use it in GitHub Desktop.
PouchDB Quick Search demo
<html>
<body>
<pre id="display"></pre>
<script src="//cdn.jsdelivr.net/pouchdb/3/pouchdb.min.js"></script>
<script src="pouchdb.quick-search.min.js"></script>
<script src="index.js"></script>
</body>
</html>
(function () {
var pouch;
var doc = {_id: 'mydoc', title: "Guess who?", text: "It's-a me, Mario!"};
function log(str) {
document.getElementById('display').innerHTML += str + '\n';
}
// destroy the db so you can see the document being put
// each time you load the page. obviously you wouldn't want
// to do this in production.
PouchDB.destroy('mydb').then(function () {
pouch = new PouchDB('mydb');
}).then(function () {
log('putting doc: ' + JSON.stringify(doc));
return pouch.put(doc);
}).then(function () {
var query = {
query: 'mario',
fields: ['title', 'text'],
include_docs: true,
highlighting: true
};
log('searching with query: ' + JSON.stringify(query));
return pouch.search(query);
}).then(function (res) {
log('result: ' + JSON.stringify(res));
});
})();
!function e(t,n,r){function o(u,s){if(!n[u]){if(!t[u]){var a="function"==typeof require&&require;if(!s&&a)return a(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var c=n[u]={exports:{}};t[u][0].call(c.exports,function(e){var n=t[u][1][e];return o(n?n:e)},c,c.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,t,n){function r(e,t){return e+t}function o(e,t){return t.pipeline.run(p.tokenizer(e))}function i(e,t){var n;if(e.deepField){n=t;for(var r=0,o=e.deepField.length;o>r;r++)n=n&&n[e.deepField[r]]}else n=t[e.field];return n&&(Array.isArray(n)?n=n.join(" "):"string"!=typeof n&&(n=n.toString())),n}function u(e,t,n,r){return function(u,s){if(!f(u,n,r)){for(var a=[],c=0,l=e.length;l>c;c++){var h,d=e[c],p=i(d,u);if(p){for(var v=o(p,t),y=0,g=v.length;g>y;y++){var b=v[y],k=e.length>1?c:void 0;s(m+b,k)}h=Math.sqrt(v.length)}else h=0;a.push(h)}s(w+u._id,a)}}}function s(e,t,n,o,i){var u=Object.keys(n).map(function(u){var s=n[u],a=o[u],c=e.map(function(e){return s.map(function(n,r){var o=a[r];if(!(e in n))return 0;var u=t[e],s=n[e],c=s/u,f=1/u,l=i[r].boost;return c*f*l/o}).reduce(r,0)}),f=0;return c.forEach(function(e){e>f&&(f=e)}),{id:u,score:f}});return u.sort(function(e,t){return e.score<t.score?1:e.score>t.score?-1:0}),u}function a(e,t){return y.all(t.map(function(t){return e.get(t.id)})).then(function(e){e.forEach(function(e,n){t[n].doc=e})}).then(function(){return t})}function c(e,t,n,r,o){var u=t.highlighting_pre||"<strong>",s=t.highlighting_post||"</strong>";return y.all(n.map(function(t){return y.resolve().then(function(){return t.doc?t.doc:e.get(t.id)}).then(function(e){t.highlighting={},o[t.id].forEach(function(n,o){var a=r[o],c=a.field,f=i(a,e);Object.keys(n).forEach(function(e){var n=new RegExp("("+e+"[a-z]*)","gi"),r=u+"$1"+s;f=f.replace(n,r),t.highlighting[c]=f})})})})).then(function(){return n})}function f(e,t,n){try{return!(!t||t(e))}catch(r){return n.emit("error",r),!0}}var l="undefined"!=typeof self?self:"undefined"!=typeof window?window:{},h=e("pouchdb-mapreduce-no-ddocs");Object.keys(h).forEach(function(e){n[e]=h[e]});var d=e("./pouch-utils"),p=e("lunr"),v=e("uniq"),y=d.Promise,g={},m="a",w="b";n.search=d.toPromise(function(e,t){var n=this;e=d.extend(!0,{},e);var r=e.query||e.q,i="mm"in e?parseFloat(e.mm)/100:1,f=e.fields,h=e.highlighting,y=e.include_docs,b=e.destroy,k=e.stale,_=e.limit,x=e.build,S=e.skip||0,E=e.language||"en",A=e.filter;if(Array.isArray(f)){var j={};f.forEach(function(e){j[e]=1}),f=j}var O=Object.keys(f).map(function(e){var t=-1!==e.indexOf(".")&&e.split(".");return{field:e,deepField:t,boost:f[e]}}),F=g[E];F||(F=g[E]=p(),"en"!==E&&F.use(l.lunr[E]));var I={language:E,fields:O.map(function(e){return e.field}).sort()};A&&(I.filter=A.toString());var N="search-"+d.MD5(JSON.stringify(I)),T=u(O,F,A,n),P={saveAs:N};if(b)return P.destroy=!0,n._search_query(T,P,t);if(x)return delete P.stale,P.limit=0,void n._search_query(T,P).then(function(){t(null,{ok:!0})})["catch"](t);var C=v(o(r,F));return C.length?(P.keys=C.map(function(e){return m+e}),"string"==typeof k&&(P.stale=k),void n._search_query(T,P).then(function(r){if(!r.rows.length)return t(null,{rows:[]});var o={},u={};if(r.rows.forEach(function(e){var t=e.key.substring(1),n=e.value||0;if(t in u?u[t]++:u[t]=1,!(e.id in o))for(var r=o[e.id]=[],i=0;i<O.length;i++)r[i]={};var s=o[e.id][n];t in s?s[t]++:s[t]=1}),C.length>1&&Object.keys(o).forEach(function(e){var t={},n=o[e];Object.keys(n).forEach(function(e){Object.keys(n[e]).forEach(function(e){t[e]=!0})});var r=Object.keys(t).length,u=r/C.length;Math.floor(100*u)/100<i&&delete o[e]}),!Object.keys(o).length)return t(null,{rows:[]});var f=Object.keys(o).map(function(e){return w+e}),l={saveAs:N,keys:f};return n._search_query(T,l).then(function(e){var t={};e.rows.forEach(function(e){t[e.id]=e.value});var n=s(C,u,o,t,O);return n}).then(function(e){return"number"==typeof _&&_>=0?e.slice(S,S+_):S>0?e.slice(S):e}).then(function(e){return y?a(n,e):e}).then(function(t){return h?c(n,e,t,O,o):t}).then(function(e){t(null,{rows:e})})})["catch"](t)):t(null,{rows:[]})}),"undefined"!=typeof window&&window.PouchDB&&window.PouchDB.plugin(n)},{"./pouch-utils":37,lunr:24,"pouchdb-mapreduce-no-ddocs":29,uniq:36}],2:[function(e,t){"use strict";function n(e){return function(){var t=arguments.length;if(t){for(var n=[],r=-1;++r<t;)n[r]=arguments[r];return e.call(this,n)}return e.call(this,[])}}t.exports=n},{}],3:[function(){},{}],4:[function(e,t){var n=t.exports={};n.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){var t=e.source;if((t===window||null===t)&&"process-tick"===e.data&&(e.stopPropagation(),n.length>0)){var r=n.shift();r()}},!0),function(e){n.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.binding=function(){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw new Error("process.chdir is not supported")}},{}],5:[function(e,t){t.exports="function"==typeof Object.create?function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},{}],6:[function(e,t){"use strict";function n(){}t.exports=n},{}],7:[function(e,t){"use strict";function n(e){function t(e,t){function r(e){c[t]=e,++f===n&!a&&(a=!0,s.resolve(h,c))}i(e).then(r,function(e){a||(a=!0,s.reject(h,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return o(new TypeError("must be an array"));var n=e.length,a=!1;if(!n)return i([]);for(var c=new Array(n),f=0,l=-1,h=new r(u);++l<n;)t(e[l],l);return h}var r=e("./promise"),o=e("./reject"),i=e("./resolve"),u=e("./INTERNAL"),s=e("./handlers");t.exports=n},{"./INTERNAL":6,"./handlers":8,"./promise":10,"./reject":13,"./resolve":14}],8:[function(e,t,n){"use strict";function r(e){var t=e&&e.then;return e&&"object"==typeof e&&"function"==typeof t?function(){t.apply(e,arguments)}:void 0}var o=e("./tryCatch"),i=e("./resolveThenable"),u=e("./states");n.resolve=function(e,t){var s=o(r,t);if("error"===s.status)return n.reject(e,s.value);var a=s.value;if(a)i.safely(e,a);else{e.state=u.FULFILLED,e.outcome=t;for(var c=-1,f=e.queue.length;++c<f;)e.queue[c].callFulfilled(t)}return e},n.reject=function(e,t){e.state=u.REJECTED,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e}},{"./resolveThenable":15,"./states":16,"./tryCatch":17}],9:[function(e,t,n){t.exports=n=e("./promise"),n.resolve=e("./resolve"),n.reject=e("./reject"),n.all=e("./all"),n.race=e("./race")},{"./all":7,"./promise":10,"./race":12,"./reject":13,"./resolve":14}],10:[function(e,t){"use strict";function n(e){if(!(this instanceof n))return new n(e);if("function"!=typeof e)throw new TypeError("reslover must be a function");this.state=u.PENDING,this.queue=[],this.outcome=void 0,e!==o&&i.safely(this,e)}var r=e("./unwrap"),o=e("./INTERNAL"),i=e("./resolveThenable"),u=e("./states"),s=e("./queueItem");t.exports=n,n.prototype["catch"]=function(e){return this.then(null,e)},n.prototype.then=function(e,t){if("function"!=typeof e&&this.state===u.FULFILLED||"function"!=typeof t&&this.state===u.REJECTED)return this;var i=new n(o);if(this.state!==u.PENDING){var a=this.state===u.FULFILLED?e:t;r(i,a,this.outcome)}else this.queue.push(new s(i,e,t));return i}},{"./INTERNAL":6,"./queueItem":11,"./resolveThenable":15,"./states":16,"./unwrap":18}],11:[function(e,t){"use strict";function n(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}var r=e("./handlers"),o=e("./unwrap");t.exports=n,n.prototype.callFulfilled=function(e){r.resolve(this.promise,e)},n.prototype.otherCallFulfilled=function(e){o(this.promise,this.onFulfilled,e)},n.prototype.callRejected=function(e){r.reject(this.promise,e)},n.prototype.otherCallRejected=function(e){o(this.promise,this.onRejected,e)}},{"./handlers":8,"./unwrap":18}],12:[function(e,t){"use strict";function n(e){function t(e){i(e).then(function(e){a||(a=!0,s.resolve(f,e))},function(e){a||(a=!0,s.reject(f,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return o(new TypeError("must be an array"));var n=e.length,a=!1;if(!n)return i([]);for(var c=-1,f=new r(u);++c<n;)t(e[c]);return f}var r=e("./promise"),o=e("./reject"),i=e("./resolve"),u=e("./INTERNAL"),s=e("./handlers");t.exports=n},{"./INTERNAL":6,"./handlers":8,"./promise":10,"./reject":13,"./resolve":14}],13:[function(e,t){"use strict";function n(e){var t=new r(o);return i.reject(t,e)}var r=e("./promise"),o=e("./INTERNAL"),i=e("./handlers");t.exports=n},{"./INTERNAL":6,"./handlers":8,"./promise":10}],14:[function(e,t){"use strict";function n(e){if(e)return e instanceof r?e:i.resolve(new r(o),e);var t=typeof e;switch(t){case"boolean":return u;case"undefined":return a;case"object":return s;case"number":return c;case"string":return f}}var r=e("./promise"),o=e("./INTERNAL"),i=e("./handlers");t.exports=n;var u=i.resolve(new r(o),!1),s=i.resolve(new r(o),null),a=i.resolve(new r(o),void 0),c=i.resolve(new r(o),0),f=i.resolve(new r(o),"")},{"./INTERNAL":6,"./handlers":8,"./promise":10}],15:[function(e,t,n){"use strict";function r(e,t){function n(t){s||(s=!0,o.reject(e,t))}function r(t){s||(s=!0,o.resolve(e,t))}function u(){t(r,n)}var s=!1,a=i(u);"error"===a.status&&n(a.value)}var o=e("./handlers"),i=e("./tryCatch");n.safely=r},{"./handlers":8,"./tryCatch":17}],16:[function(e,t,n){n.REJECTED=["REJECTED"],n.FULFILLED=["FULFILLED"],n.PENDING=["PENDING"]},{}],17:[function(e,t){"use strict";function n(e,t){var n={};try{n.value=e(t),n.status="success"}catch(r){n.status="error",n.value=r}return n}t.exports=n},{}],18:[function(e,t){"use strict";function n(e,t,n){r(function(){var r;try{r=t(n)}catch(i){return o.reject(e,i)}r===e?o.reject(e,new TypeError("Cannot resolve promise with itself")):o.resolve(e,r)})}var r=e("immediate"),o=e("./handlers");t.exports=n},{"./handlers":8,immediate:19}],19:[function(e,t){"use strict";function n(){o=!0;for(var e,t,n=s.length;n;){for(t=s,s=[],e=-1;++e<n;)t[e]();n=s.length}o=!1}function r(e){1!==s.push(e)||o||i()}for(var o,i,u=[e("./nextTick"),e("./mutation.js"),e("./messageChannel"),e("./stateChange"),e("./timeout")],s=[],a=-1,c=u.length;++a<c;)if(u[a]&&u[a].test&&u[a].test()){i=u[a].install(n);break}t.exports=r},{"./messageChannel":20,"./mutation.js":21,"./nextTick":3,"./stateChange":22,"./timeout":23}],20:[function(e,t,n){var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};n.test=function(){return r.setImmediate?!1:"undefined"!=typeof r.MessageChannel},n.install=function(e){var t=new r.MessageChannel;return t.port1.onmessage=e,function(){t.port2.postMessage(0)}}},{}],21:[function(e,t,n){var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:{},o=r.MutationObserver||r.WebKitMutationObserver;n.test=function(){return o},n.install=function(e){var t=0,n=new o(e),i=r.document.createTextNode("");return n.observe(i,{characterData:!0}),function(){i.data=t=++t%2}}},{}],22:[function(e,t,n){var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};n.test=function(){return"document"in r&&"onreadystatechange"in r.document.createElement("script")},n.install=function(e){return function(){var t=r.document.createElement("script");return t.onreadystatechange=function(){e(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},r.document.documentElement.appendChild(t),e}}},{}],23:[function(e,t,n){"use strict";n.test=function(){return!0},n.install=function(e){return function(){setTimeout(e,0)}}},{}],24:[function(e,t,n){!function(){var e=function(t){var n=new e.Index;return n.pipeline.add(e.trimmer,e.stopWordFilter,e.stemmer),t&&t.call(n,n),n};e.version="0.5.5",e.utils={},e.utils.warn=function(e){return function(t){e.console&&console.warn&&console.warn(t)}}(this),e.EventEmitter=function(){this.events={}},e.EventEmitter.prototype.addListener=function(){var e=Array.prototype.slice.call(arguments),t=e.pop(),n=e;if("function"!=typeof t)throw new TypeError("last argument must be a function");n.forEach(function(e){this.hasHandler(e)||(this.events[e]=[]),this.events[e].push(t)},this)},e.EventEmitter.prototype.removeListener=function(e,t){if(this.hasHandler(e)){var n=this.events[e].indexOf(t);this.events[e].splice(n,1),this.events[e].length||delete this.events[e]}},e.EventEmitter.prototype.emit=function(e){if(this.hasHandler(e)){var t=Array.prototype.slice.call(arguments,1);this.events[e].forEach(function(e){e.apply(void 0,t)})}},e.EventEmitter.prototype.hasHandler=function(e){return e in this.events},e.tokenizer=function(e){if(!arguments.length||null==e||void 0==e)return[];if(Array.isArray(e))return e.map(function(e){return e.toLowerCase()});for(var t=e.toString().replace(/^\s+/,""),n=t.length-1;n>=0;n--)if(/\S/.test(t.charAt(n))){t=t.substring(0,n+1);break}return t.split(/(?:\s+|\-)/).filter(function(e){return!!e}).map(function(e){return e.toLowerCase()})},e.Pipeline=function(){this._stack=[]},e.Pipeline.registeredFunctions={},e.Pipeline.registerFunction=function(t,n){n in this.registeredFunctions&&e.utils.warn("Overwriting existing registered function: "+n),t.label=n,e.Pipeline.registeredFunctions[t.label]=t},e.Pipeline.warnIfFunctionNotRegistered=function(t){var n=t.label&&t.label in this.registeredFunctions;n||e.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",t)},e.Pipeline.load=function(t){var n=new e.Pipeline;return t.forEach(function(t){var r=e.Pipeline.registeredFunctions[t];if(!r)throw new Error("Cannot load un-registered function: "+t);n.add(r)}),n},e.Pipeline.prototype.add=function(){var t=Array.prototype.slice.call(arguments);t.forEach(function(t){e.Pipeline.warnIfFunctionNotRegistered(t),this._stack.push(t)},this)},e.Pipeline.prototype.after=function(t,n){e.Pipeline.warnIfFunctionNotRegistered(n);var r=this._stack.indexOf(t)+1;this._stack.splice(r,0,n)},e.Pipeline.prototype.before=function(t,n){e.Pipeline.warnIfFunctionNotRegistered(n);var r=this._stack.indexOf(t);this._stack.splice(r,0,n)},e.Pipeline.prototype.remove=function(e){var t=this._stack.indexOf(e);this._stack.splice(t,1)},e.Pipeline.prototype.run=function(e){for(var t=[],n=e.length,r=this._stack.length,o=0;n>o;o++){for(var i=e[o],u=0;r>u&&(i=this._stack[u](i,o,e),void 0!==i);u++);void 0!==i&&t.push(i)}return t},e.Pipeline.prototype.reset=function(){this._stack=[]},e.Pipeline.prototype.toJSON=function(){return this._stack.map(function(t){return e.Pipeline.warnIfFunctionNotRegistered(t),t.label})},e.Vector=function(){this._magnitude=null,this.list=void 0,this.length=0},e.Vector.Node=function(e,t,n){this.idx=e,this.val=t,this.next=n},e.Vector.prototype.insert=function(t,n){var r=this.list;if(!r)return this.list=new e.Vector.Node(t,n,r),this.length++;for(var o=r,i=r.next;void 0!=i;){if(t<i.idx)return o.next=new e.Vector.Node(t,n,i),this.length++;o=i,i=i.next}return o.next=new e.Vector.Node(t,n,i),this.length++},e.Vector.prototype.magnitude=function(){if(this._magniture)return this._magnitude;for(var e,t=this.list,n=0;t;)e=t.val,n+=e*e,t=t.next;return this._magnitude=Math.sqrt(n)},e.Vector.prototype.dot=function(e){for(var t=this.list,n=e.list,r=0;t&&n;)t.idx<n.idx?t=t.next:t.idx>n.idx?n=n.next:(r+=t.val*n.val,t=t.next,n=n.next);return r},e.Vector.prototype.similarity=function(e){return this.dot(e)/(this.magnitude()*e.magnitude())},e.SortedSet=function(){this.length=0,this.elements=[]},e.SortedSet.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},e.SortedSet.prototype.add=function(){Array.prototype.slice.call(arguments).forEach(function(e){~this.indexOf(e)||this.elements.splice(this.locationFor(e),0,e)},this),this.length=this.elements.length},e.SortedSet.prototype.toArray=function(){return this.elements.slice()},e.SortedSet.prototype.map=function(e,t){return this.elements.map(e,t)},e.SortedSet.prototype.forEach=function(e,t){return this.elements.forEach(e,t)},e.SortedSet.prototype.indexOf=function(e,t,n){var t=t||0,n=n||this.elements.length,r=n-t,o=t+Math.floor(r/2),i=this.elements[o];return 1>=r?i===e?o:-1:e>i?this.indexOf(e,o,n):i>e?this.indexOf(e,t,o):i===e?o:void 0},e.SortedSet.prototype.locationFor=function(e,t,n){var t=t||0,n=n||this.elements.length,r=n-t,o=t+Math.floor(r/2),i=this.elements[o];if(1>=r){if(i>e)return o;if(e>i)return o+1}return e>i?this.locationFor(e,o,n):i>e?this.locationFor(e,t,o):void 0},e.SortedSet.prototype.intersect=function(t){for(var n=new e.SortedSet,r=0,o=0,i=this.length,u=t.length,s=this.elements,a=t.elements;;){if(r>i-1||o>u-1)break;s[r]!==a[o]?s[r]<a[o]?r++:s[r]>a[o]&&o++:(n.add(s[r]),r++,o++)}return n},e.SortedSet.prototype.clone=function(){var t=new e.SortedSet;return t.elements=this.toArray(),t.length=t.elements.length,t},e.SortedSet.prototype.union=function(e){var t,n,r;return this.length>=e.length?(t=this,n=e):(t=e,n=this),r=t.clone(),r.add.apply(r,n.toArray()),r},e.SortedSet.prototype.toJSON=function(){return this.toArray()},e.Index=function(){this._fields=[],this._ref="id",this.pipeline=new e.Pipeline,this.documentStore=new e.Store,this.tokenStore=new e.TokenStore,this.corpusTokens=new e.SortedSet,this.eventEmitter=new e.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},e.Index.prototype.on=function(){var e=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,e)},e.Index.prototype.off=function(e,t){return this.eventEmitter.removeListener(e,t)},e.Index.load=function(t){t.version!==e.version&&e.utils.warn("version mismatch: current "+e.version+" importing "+t.version);var n=new this;return n._fields=t.fields,n._ref=t.ref,n.documentStore=e.Store.load(t.documentStore),n.tokenStore=e.TokenStore.load(t.tokenStore),n.corpusTokens=e.SortedSet.load(t.corpusTokens),n.pipeline=e.Pipeline.load(t.pipeline),n},e.Index.prototype.field=function(e,t){var t=t||{},n={name:e,boost:t.boost||1};return this._fields.push(n),this},e.Index.prototype.ref=function(e){return this._ref=e,this},e.Index.prototype.add=function(t,n){var r={},o=new e.SortedSet,i=t[this._ref],n=void 0===n?!0:n;this._fields.forEach(function(n){var i=this.pipeline.run(e.tokenizer(t[n.name]));r[n.name]=i,e.SortedSet.prototype.add.apply(o,i)},this),this.documentStore.set(i,o),e.SortedSet.prototype.add.apply(this.corpusTokens,o.toArray());for(var u=0;u<o.length;u++){var s=o.elements[u],a=this._fields.reduce(function(e,t){var n=r[t.name].length;if(!n)return e;var o=r[t.name].filter(function(e){return e===s}).length;return e+o/n*t.boost},0);this.tokenStore.add(s,{ref:i,tf:a})}n&&this.eventEmitter.emit("add",t,this)},e.Index.prototype.remove=function(e,t){var n=e[this._ref],t=void 0===t?!0:t;if(this.documentStore.has(n)){var r=this.documentStore.get(n);this.documentStore.remove(n),r.forEach(function(e){this.tokenStore.remove(e,n)},this),t&&this.eventEmitter.emit("remove",e,this)}},e.Index.prototype.update=function(e,t){var t=void 0===t?!0:t;this.remove(e,!1),this.add(e,!1),t&&this.eventEmitter.emit("update",e,this)},e.Index.prototype.idf=function(e){var t="@"+e;if(Object.prototype.hasOwnProperty.call(this._idfCache,t))return this._idfCache[t];var n=this.tokenStore.count(e),r=1;return n>0&&(r=1+Math.log(this.tokenStore.length/n)),this._idfCache[t]=r},e.Index.prototype.search=function(t){var n=this.pipeline.run(e.tokenizer(t)),r=new e.Vector,o=[],i=this._fields.reduce(function(e,t){return e+t.boost},0),u=n.some(function(e){return this.tokenStore.has(e)},this);if(!u)return[];n.forEach(function(t,n,u){var s=1/u.length*this._fields.length*i,a=this,c=this.tokenStore.expand(t).reduce(function(n,o){var i=a.corpusTokens.indexOf(o),u=a.idf(o),c=1,f=new e.SortedSet;if(o!==t){var l=Math.max(3,o.length-t.length);c=1/Math.log(l)}return i>-1&&r.insert(i,s*u*c),Object.keys(a.tokenStore.get(o)).forEach(function(e){f.add(e)}),n.union(f)},new e.SortedSet);o.push(c)},this);var s=o.reduce(function(e,t){return e.intersect(t)});return s.map(function(e){return{ref:e,score:r.similarity(this.documentVector(e))}},this).sort(function(e,t){return t.score-e.score})},e.Index.prototype.documentVector=function(t){for(var n=this.documentStore.get(t),r=n.length,o=new e.Vector,i=0;r>i;i++){var u=n.elements[i],s=this.tokenStore.get(u)[t].tf,a=this.idf(u);o.insert(this.corpusTokens.indexOf(u),s*a)}return o},e.Index.prototype.toJSON=function(){return{version:e.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),tokenStore:this.tokenStore.toJSON(),corpusTokens:this.corpusTokens.toJSON(),pipeline:this.pipeline.toJSON()}},e.Index.prototype.use=function(e){var t=Array.prototype.slice.call(arguments,1);t.unshift(this),e.apply(this,t)},e.Store=function(){this.store={},this.length=0},e.Store.load=function(t){var n=new this;return n.length=t.length,n.store=Object.keys(t.store).reduce(function(n,r){return n[r]=e.SortedSet.load(t.store[r]),n},{}),n},e.Store.prototype.set=function(e,t){this.store[e]=t,this.length=Object.keys(this.store).length},e.Store.prototype.get=function(e){return this.store[e]},e.Store.prototype.has=function(e){return e in this.store},e.Store.prototype.remove=function(e){this.has(e)&&(delete this.store[e],this.length--)},e.Store.prototype.toJSON=function(){return{store:this.store,length:this.length}},e.stemmer=function(){var e={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},t={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",r="[aeiouy]",o=n+"[^aeiouy]*",i=r+"[aeiou]*",u="^("+o+")?"+i+o,s="^("+o+")?"+i+o+"("+i+")?$",a="^("+o+")?"+i+o+i+o,c="^("+o+")?"+r;return function(n){var i,f,l,h,d,p,v;if(n.length<3)return n;if(l=n.substr(0,1),"y"==l&&(n=l.toUpperCase()+n.substr(1)),h=/^(.+?)(ss|i)es$/,d=/^(.+?)([^s])s$/,h.test(n)?n=n.replace(h,"$1$2"):d.test(n)&&(n=n.replace(d,"$1$2")),h=/^(.+?)eed$/,d=/^(.+?)(ed|ing)$/,h.test(n)){var y=h.exec(n);h=new RegExp(u),h.test(y[1])&&(h=/.$/,n=n.replace(h,""))}else if(d.test(n)){var y=d.exec(n);i=y[1],d=new RegExp(c),d.test(i)&&(n=i,d=/(at|bl|iz)$/,p=new RegExp("([^aeiouylsz])\\1$"),v=new RegExp("^"+o+r+"[^aeiouwxy]$"),d.test(n)?n+="e":p.test(n)?(h=/.$/,n=n.replace(h,"")):v.test(n)&&(n+="e"))}if(h=/^(.+?[^aeiou])y$/,h.test(n)){var y=h.exec(n);i=y[1],n=i+"i"}if(h=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,h.test(n)){var y=h.exec(n);i=y[1],f=y[2],h=new RegExp(u),h.test(i)&&(n=i+e[f])}if(h=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,h.test(n)){var y=h.exec(n);i=y[1],f=y[2],h=new RegExp(u),h.test(i)&&(n=i+t[f])}if(h=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,d=/^(.+?)(s|t)(ion)$/,h.test(n)){var y=h.exec(n);i=y[1],h=new RegExp(a),h.test(i)&&(n=i)}else if(d.test(n)){var y=d.exec(n);i=y[1]+y[2],d=new RegExp(a),d.test(i)&&(n=i)}if(h=/^(.+?)e$/,h.test(n)){var y=h.exec(n);i=y[1],h=new RegExp(a),d=new RegExp(s),p=new RegExp("^"+o+r+"[^aeiouwxy]$"),(h.test(i)||d.test(i)&&!p.test(i))&&(n=i)}return h=/ll$/,d=new RegExp(a),h.test(n)&&d.test(n)&&(h=/.$/,n=n.replace(h,"")),"y"==l&&(n=l.toLowerCase()+n.substr(1)),n}}(),e.Pipeline.registerFunction(e.stemmer,"stemmer"),e.stopWordFilter=function(t){return-1===e.stopWordFilter.stopWords.indexOf(t)?t:void 0},e.stopWordFilter.stopWords=new e.SortedSet,e.stopWordFilter.stopWords.length=119,e.stopWordFilter.stopWords.elements=["","a","able","about","across","after","all","almost","also","am","among","an","and","any","are","as","at","be","because","been","but","by","can","cannot","could","dear","did","do","does","either","else","ever","every","for","from","get","got","had","has","have","he","her","hers","him","his","how","however","i","if","in","into","is","it","its","just","least","let","like","likely","may","me","might","most","must","my","neither","no","nor","not","of","off","often","on","only","or","other","our","own","rather","said","say","says","she","should","since","so","some","than","that","the","their","them","then","there","these","they","this","tis","to","too","twas","us","wants","was","we","were","what","when","where","which","while","who","whom","why","will","with","would","yet","you","your"],e.Pipeline.registerFunction(e.stopWordFilter,"stopWordFilter"),e.trimmer=function(e){return e.replace(/^\W+/,"").replace(/\W+$/,"")},e.Pipeline.registerFunction(e.trimmer,"trimmer"),e.TokenStore=function(){this.root={docs:{}},this.length=0},e.TokenStore.load=function(e){var t=new this;return t.root=e.root,t.length=e.length,t},e.TokenStore.prototype.add=function(e,t,n){var n=n||this.root,r=e[0],o=e.slice(1);return r in n||(n[r]={docs:{}}),0===o.length?(n[r].docs[t.ref]=t,void(this.length+=1)):this.add(o,t,n[r])},e.TokenStore.prototype.has=function(e){if(!e)return!1;for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return!1;t=t[e[n]]}return!0},e.TokenStore.prototype.getNode=function(e){if(!e)return{};for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return{};t=t[e[n]]}return t},e.TokenStore.prototype.get=function(e,t){return this.getNode(e,t).docs||{}},e.TokenStore.prototype.count=function(e,t){return Object.keys(this.get(e,t)).length},e.TokenStore.prototype.remove=function(e,t){if(e){for(var n=this.root,r=0;r<e.length;r++){if(!(e[r]in n))return;n=n[e[r]]}delete n.docs[t]}},e.TokenStore.prototype.expand=function(e,t){var n=this.getNode(e),r=n.docs||{},t=t||[];return Object.keys(r).length&&t.push(e),Object.keys(n).forEach(function(n){"docs"!==n&&t.concat(this.expand(e+n,t))},this),t},e.TokenStore.prototype.toJSON=function(){return{root:this.root,length:this.length}},function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof n?t.exports=r():e.lunr=r()}(this,function(){return e})}()},{}],25:[function(e,t,n){!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof n?t.exports=r():e.md5=r()}(this,function(){function e(e,t){var u=e[0],s=e[1],a=e[2],c=e[3];u=n(u,s,a,c,t[0],7,-680876936),c=n(c,u,s,a,t[1],12,-389564586),a=n(a,c,u,s,t[2],17,606105819),s=n(s,a,c,u,t[3],22,-1044525330),u=n(u,s,a,c,t[4],7,-176418897),c=n(c,u,s,a,t[5],12,1200080426),a=n(a,c,u,s,t[6],17,-1473231341),s=n(s,a,c,u,t[7],22,-45705983),u=n(u,s,a,c,t[8],7,1770035416),c=n(c,u,s,a,t[9],12,-1958414417),a=n(a,c,u,s,t[10],17,-42063),s=n(s,a,c,u,t[11],22,-1990404162),u=n(u,s,a,c,t[12],7,1804603682),c=n(c,u,s,a,t[13],12,-40341101),a=n(a,c,u,s,t[14],17,-1502002290),s=n(s,a,c,u,t[15],22,1236535329),u=r(u,s,a,c,t[1],5,-165796510),c=r(c,u,s,a,t[6],9,-1069501632),a=r(a,c,u,s,t[11],14,643717713),s=r(s,a,c,u,t[0],20,-373897302),u=r(u,s,a,c,t[5],5,-701558691),c=r(c,u,s,a,t[10],9,38016083),a=r(a,c,u,s,t[15],14,-660478335),s=r(s,a,c,u,t[4],20,-405537848),u=r(u,s,a,c,t[9],5,568446438),c=r(c,u,s,a,t[14],9,-1019803690),a=r(a,c,u,s,t[3],14,-187363961),s=r(s,a,c,u,t[8],20,1163531501),u=r(u,s,a,c,t[13],5,-1444681467),c=r(c,u,s,a,t[2],9,-51403784),a=r(a,c,u,s,t[7],14,1735328473),s=r(s,a,c,u,t[12],20,-1926607734),u=o(u,s,a,c,t[5],4,-378558),c=o(c,u,s,a,t[8],11,-2022574463),a=o(a,c,u,s,t[11],16,1839030562),s=o(s,a,c,u,t[14],23,-35309556),u=o(u,s,a,c,t[1],4,-1530992060),c=o(c,u,s,a,t[4],11,1272893353),a=o(a,c,u,s,t[7],16,-155497632),s=o(s,a,c,u,t[10],23,-1094730640),u=o(u,s,a,c,t[13],4,681279174),c=o(c,u,s,a,t[0],11,-358537222),a=o(a,c,u,s,t[3],16,-722521979),s=o(s,a,c,u,t[6],23,76029189),u=o(u,s,a,c,t[9],4,-640364487),c=o(c,u,s,a,t[12],11,-421815835),a=o(a,c,u,s,t[15],16,530742520),s=o(s,a,c,u,t[2],23,-995338651),u=i(u,s,a,c,t[0],6,-198630844),c=i(c,u,s,a,t[7],10,1126891415),a=i(a,c,u,s,t[14],15,-1416354905),s=i(s,a,c,u,t[5],21,-57434055),u=i(u,s,a,c,t[12],6,1700485571),c=i(c,u,s,a,t[3],10,-1894986606),a=i(a,c,u,s,t[10],15,-1051523),s=i(s,a,c,u,t[1],21,-2054922799),u=i(u,s,a,c,t[8],6,1873313359),c=i(c,u,s,a,t[15],10,-30611744),a=i(a,c,u,s,t[6],15,-1560198380),s=i(s,a,c,u,t[13],21,1309151649),u=i(u,s,a,c,t[4],6,-145523070),c=i(c,u,s,a,t[11],10,-1120210379),a=i(a,c,u,s,t[2],15,718787259),s=i(s,a,c,u,t[9],21,-343485551),e[0]=l(u,e[0]),e[1]=l(s,e[1]),e[2]=l(a,e[2]),e[3]=l(c,e[3])}function t(e,t,n,r,o,i){return t=l(l(t,e),l(r,i)),l(t<<o|t>>>32-o,n)}function n(e,n,r,o,i,u,s){return t(n&r|~n&o,e,n,i,u,s)}function r(e,n,r,o,i,u,s){return t(n&o|r&~o,e,n,i,u,s)}function o(e,n,r,o,i,u,s){return t(n^r^o,e,n,i,u,s)}function i(e,n,r,o,i,u,s){return t(r^(n|~o),e,n,i,u,s)}function u(t){txt="";var n,r=t.length,o=[1732584193,-271733879,-1732584194,271733878];for(n=64;n<=t.length;n+=64)e(o,s(t.substring(n-64,n)));t=t.substring(n-64);var i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(n=0;n<t.length;n++)i[n>>2]|=t.charCodeAt(n)<<(n%4<<3);if(i[n>>2]|=128<<(n%4<<3),n>55)for(e(o,i),n=0;16>n;n++)i[n]=0;return i[14]=8*r,e(o,i),o}function s(e){var t,n=[];for(t=0;64>t;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}function a(e){for(var t="",n=0;4>n;n++)t+=h[e>>8*n+4&15]+h[e>>8*n&15];return t}function c(e){for(var t=0;t<e.length;t++)e[t]=a(e[t]);return e.join("")}function f(e){return c(u(e))}function l(e,t){return e+t&4294967295}function l(e,t){var n=(65535&e)+(65535&t),r=(e>>16)+(t>>16)+(n>>16);return r<<16|65535&n}var h="0123456789abcdef".split("");return"5d41402abc4b2a76b9719d911017c592"!=f("hello"),f})},{}],26:[function(e,t){"use strict";function n(e){return null===e?String(e):"object"==typeof e||"function"==typeof e?a[h.call(e)]||"object":typeof e}function r(e){return null!==e&&e===e.window}function o(e){if(!e||"object"!==n(e)||e.nodeType||r(e))return!1;try{if(e.constructor&&!d.call(e,"constructor")&&!d.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}var o;for(o in e);return void 0===o||d.call(e,o)}function i(e){return"function"===n(e)}function u(){for(var e=[],t=-1,n=arguments.length,r=new Array(n);++t<n;)r[t]=arguments[t];var o={};e.push({args:r,result:{container:o,key:"key"}});for(var i;i=e.pop();)s(e,i.args,i.result);return o.key}function s(e,t,n){var r,u,s,a,c,f,l,h=t[0]||{},d=1,v=t.length,y=!1,g=/\d+/;for("boolean"==typeof h&&(y=h,h=t[1]||{},d=2),"object"==typeof h||i(h)||(h={}),v===d&&(h=this,--d);v>d;d++)if(null!=(r=t[d])){l=p(r);for(u in r)if(!(u in Object.prototype)){if(l&&!g.test(u))continue;if(s=h[u],a=r[u],h===a)continue;y&&a&&(o(a)||(c=p(a)))?(c?(c=!1,f=s&&p(s)?s:[]):f=s&&o(s)?s:{},e.push({args:[y,f,a],result:{container:h,key:u}})):void 0!==a&&(p(r)&&i(a)||(h[u]=a))}}n.container[n.key]=h}for(var a={},c=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error"],f=0;f<c.length;f++){var l=c[f];a["[object "+l+"]"]=l.toLowerCase()}var h=a.toString,d=a.hasOwnProperty,p=Array.isArray||function(e){return"array"===n(e)};t.exports=u},{}],27:[function(e,t){"use strict";var n=e("./upsert"),r=e("./utils"),o=r.Promise;t.exports=function(e){var t=e.db,i=e.viewName,u=e.map,s=e.reduce,a=e.temporary,c=e.saveAs,f=u.toString()+(s&&s.toString())+"undefined"+(c||"");if(!a&&t._cachedViews){var l=t._cachedViews[f];if(l)return o.resolve(l)}return t.info().then(function(e){function l(){function e(e){e.views=e.views||{};var t=i;-1===t.indexOf("/")&&(t=i+"/"+i);var n=e.views[t]=e.views[t]||{};if(!n[d])return n[d]=!0,e}return n(t,"_local/mrviews",e)}function h(){return t.registerDependentDatabase(d).then(function(e){var n=e.db;n.auto_compaction=!0;var r={name:d,db:n,sourceDB:t,adapter:t.adapter,mapFun:u,reduceFun:s};return r.db.get("_local/lastSeq")["catch"](function(e){if(404!==e.status)throw e
}).then(function(e){return r.seq=e?e.seq:0,a||(t._cachedViews=t._cachedViews||{},t._cachedViews[f]=r,r.db.on("destroyed",function(){delete t._cachedViews[f]})),r})})}var d=e.db_name+"-";return d+=c?c:"mrview-"+(a?"temp":r.MD5(f)),o.resolve().then(function(){return i?l():o.resolve()}).then(h)})}},{"./upsert":34,"./utils":35}],28:[function(require,module,exports){"use strict";module.exports=function(func,emit,sum,log,isArray,toJSON){return eval("'use strict'; ("+func.replace(/;\s*$/,"")+");")}},{}],29:[function(e,t,n){function r(e){return-1===e.indexOf("/")?[e,e]:e.split("/")}function o(e,t,n){try{return{output:t.apply(null,n)}}catch(r){return e.emit("error",r),{error:r}}}function i(e,t){var n=j(e.key,t.key);return 0!==n?n:j(e.value,t.value)}function u(e,t,n){return n=n||0,"number"==typeof t?e.slice(n,t+n):n>0?e.slice(n):e}function s(e){var t=e.value,n=t&&"object"==typeof t&&t._id||e.id;return n}function a(e){var t=new Error("builtin "+e+" function requires map values to be numbers or number arrays");return t.name="invalid_value",t.status=500,t}function c(e){for(var t=0,n=0,r=e.length;r>n;n++){var o=e[n];if("number"!=typeof o){if(!Array.isArray(o))throw a("_sum");t="number"==typeof t?[t]:t;for(var i=0,u=o.length;u>i;i++){var s=o[i];if("number"!=typeof s)throw a("_sum");"undefined"==typeof t[i]?t.push(s):t[i]+=s}}else"number"==typeof t?t+=o:t[0]+=o}return t}function f(e,t,n,r){var o=t[e];"undefined"!=typeof o&&(r&&(o=encodeURIComponent(JSON.stringify(o))),n.push(e+"="+o))}function l(e,t){var n=e.descending?"endkey":"startkey",r=e.descending?"startkey":"endkey";if("undefined"!=typeof e[n]&&"undefined"!=typeof e[r]&&j(e[n],e[r])>0)throw new k("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(t.reduce&&e.reduce!==!1){if(e.include_docs)throw new k("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new k("Multi-key fetches for reduce views must use {group: true}")}if(e.group_level){if("number"!=typeof e.group_level)throw new k('Invalid value for integer: "'+e.group_level+'"');if(e.group_level<0)throw new k('Invalid value for positive integer: "'+e.group_level+'"')}}function h(e,t,n){var o,i=[],u="GET";if(f("reduce",n,i),f("include_docs",n,i),f("attachments",n,i),f("limit",n,i),f("descending",n,i),f("group",n,i),f("group_level",n,i),f("skip",n,i),f("stale",n,i),f("conflicts",n,i),f("startkey",n,i,!0),f("endkey",n,i,!0),f("inclusive_end",n,i),f("key",n,i,!0),i=i.join("&"),i=""===i?"":"?"+i,"undefined"!=typeof n.keys){var s=2e3,a="keys="+encodeURIComponent(JSON.stringify(n.keys));a.length+i.length+1<=s?i+=("?"===i[0]?"&":"?")+a:(u="POST","string"==typeof t?o=JSON.stringify({keys:n.keys}):t.keys=n.keys)}if("string"==typeof t){var c=r(t);return e.request({method:u,url:"_design/"+c[0]+"/_view/"+c[1]+i,body:o})}return o=o||{},Object.keys(t).forEach(function(e){o[e]=Array.isArray(t[e])?t[e]:t[e].toString()}),e.request({method:"POST",url:"_temp_view"+i,body:o})}function d(e){return function(t){if(404===t.status)return e;throw t}}function p(e,t,n){var r="_local/doc_"+e;return t.db.get(r)["catch"](d({_id:r,keys:[]})).then(function(r){return P.resolve().then(function(){return r.keys.length?t.db.allDocs({keys:r.keys,include_docs:!0}):{rows:[]}}).then(function(t){var o=t.rows.map(function(e){return e.doc}).filter(function(e){return e}),i=n[e],u={};o.forEach(function(e){if(u[e._id]=!0,e._deleted=!i[e._id],!e._deleted){var t=i[e._id];"value"in t&&(e.value=t.value)}});var s=Object.keys(i);return s.forEach(function(e){if(!u[e]){var t={_id:e},n=i[e];"value"in n&&(t.value=n.value),o.push(t)}}),r.keys=T.uniq(s.concat(r.keys)),o.splice(0,0,r),o})})}function v(e,t,n){var r="_local/lastSeq";return e.db.get(r)["catch"](d({_id:r,seq:0})).then(function(r){var o=Object.keys(t);return P.all(o.map(function(n){return p(n,e,t)})).then(function(t){var o=[];return t.forEach(function(e){o=o.concat(e)}),r.seq=n,o.push(r),e.db.bulkDocs({docs:o})})})}function y(e,t,n){0===n.group_level&&delete n.group_level;var r,i=n.group||n.group_level;r=L[e.reduceFun]?L[e.reduceFun]:N(e.reduceFun.toString(),null,c,x,Array.isArray,JSON.parse);var s=[],a=n.group_level;t.forEach(function(e){var t=s[s.length-1],n=i?e.key:null;return i&&Array.isArray(n)&&"number"==typeof a&&(n=n.length>a?n.slice(0,a):n),t&&0===j(t.key[0][0],n)?(t.key.push([n,e.id]),void t.value.push(e.value)):void s.push({key:[[n,e.id]],value:[e.value]})});for(var f=0,l=s.length;l>f;f++){var h=s[f],d=o(e.sourceDB,r,[h.key,h.value,!1]);h.value=d.error?null:d.output,h.key=h.key[0][0]}return{rows:u(s,n.limit,n.skip)}}function g(e){return e.request({method:"POST",url:"_view_cleanup"})}function m(e,t,n){l(n,t);var r={db:e,viewName:"temp_view/temp_view",map:t.map,reduce:t.reduce,temporary:!0};return q.add(function(){return I(r).then(function(e){function t(){return e.db.destroy()}return T.fin(D(e).then(function(){return $(e,n)}),t)})}),q.finish()}function w(e,t,n){function o(e){return"ok"===n.stale||"update_after"===n.stale?("update_after"===n.stale&&S.nextTick(function(){D(e)}),$(e,n)):D(e).then(function(){return $(e,n)})}if(n.saveAs){var i={db:e,saveAs:n.saveAs,map:t.map,reduce:t.reduce};return n.destroy?I(i).then(function(e){return e.db.destroy()}):(l(n,t),I(i).then(o))}var u=t,s=r(u),a=s[0],c=s[1];return e.get("_design/"+a).then(function(t){var r=t.views&&t.views[c];if(!r||"string"!=typeof r.map)throw new _("ddoc "+a+" has no view named "+c);l(n,r);var i={db:e,viewName:u,map:r.map,reduce:r.reduce};return I(i).then(o)})}function b(e,t,n){return"http"===e.type()?h(e,t,n):"string"==typeof t||n.saveAs?w(e,t,n):m(e,t,n)}function k(e){this.status=400,this.name="query_parse_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,k)}catch(t){}}function _(e){this.status=404,this.name="not_found",this.message=e,this.error=!0;try{Error.captureStackTrace(this,_)}catch(t){}}var x,S=e("__browserify_process"),E=e("pouchdb-collate"),A=e("./taskqueue"),j=E.collate,O=E.toIndexableString,F=E.normalizeKey,I=e("./create-view"),N=e("./evalfunc");x="undefined"!=typeof console&&"function"==typeof console.log?Function.prototype.bind.call(console.log,console):function(){};var T=e("./utils"),P=T.Promise,C=new A,q=new A,R=50,L={_sum:function(e,t){return c(t)},_count:function(e,t){return t.length},_stats:function(e,t){function n(e){for(var t=0,n=0,r=e.length;r>n;n++){var o=e[n];t+=o*o}return t}return{sum:c(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:n(t)}}},D=T.sequentialize(C,function(e){function t(e,t){var n={id:u._id,key:F(e)};"undefined"!=typeof t&&null!==t&&(n.value=F(t)),r.push(n)}function n(t,n){return function(){return v(e,t,n)}}var r,u,s;if("function"==typeof e.mapFun&&2===e.mapFun.length){var a=e.mapFun;s=function(e){return a(e,t)}}else s=N(e.mapFun.toString(),t,c,x,Array.isArray,JSON.parse);var f=e.seq||0,l=new A;return new P(function(t,a){function c(){l.finish().then(function(){e.seq=f,t()})}function h(){function t(e){a(e)}e.sourceDB.changes({conflicts:!0,include_docs:!0,since:f,limit:R}).on("complete",function(t){var a=t.results;if(!a.length)return c();for(var d={},p=0,v=a.length;v>p;p++){var y=a[p];if("_"!==y.doc._id[0]){r=[],u=y.doc,u._deleted||o(e.sourceDB,s,[u]),r.sort(i);for(var g,m={},w=0,b=r.length;b>w;w++){var k=r[w],_=[k.key,k.id];k.key===g&&_.push(w);var x=O(_);m[x]=k,g=k.key}d[y.doc._id]=m}f=y.seq}return l.add(n(d,f)),a.length<R?c():h()}).on("error",t)}h()})}),$=T.sequentialize(C,function(e,t){function n(t){return t.include_docs=!0,e.db.allDocs(t).then(function(e){return o=e.total_rows,e.rows.map(function(e){if("value"in e.doc&&"object"==typeof e.doc.value&&null!==e.doc.value){var t=Object.keys(e.doc.value).sort(),n=["id","key","value"];if(!(n>t||t>n))return e.doc.value}var r=E.parseIndexableString(e.doc._id);return{key:r[0],id:r[1],value:"value"in e.doc?e.doc.value:null}})})}function r(n){var r;if(r=i?y(e,n,t):{total_rows:o,offset:u,rows:n},t.include_docs){var a=T.uniq(n.map(s));return e.sourceDB.allDocs({keys:a,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments}).then(function(e){var t={};return e.rows.forEach(function(e){e.doc&&(t["$"+e.id]=e.doc)}),n.forEach(function(e){var n=s(e),r=t["$"+n];r&&(e.doc=r)}),r})}return r}var o,i=e.reduceFun&&t.reduce!==!1,u=t.skip||0;"undefined"==typeof t.keys||t.keys.length||(t.limit=0,delete t.keys);var a=function(e){return e.reduce(function(e,t){return e.concat(t)})};if("undefined"!=typeof t.keys){var c=t.keys,f=c.map(function(e){var t={startkey:O([e]),endkey:O([e,{}])};return n(t)});return P.all(f).then(a).then(r)}var l={descending:t.descending};if("undefined"!=typeof t.startkey&&(l.startkey=O(t.descending?[t.startkey,{}]:[t.startkey])),"undefined"!=typeof t.endkey){var h=t.inclusive_end!==!1;t.descending&&(h=!h),l.endkey=O(h?[t.endkey,{}]:[t.endkey])}if("undefined"!=typeof t.key){var d=O([t.key]),p=O([t.key,{}]);l.descending?(l.endkey=d,l.startkey=p):(l.startkey=d,l.endkey=p)}return i||("number"==typeof t.limit&&(l.limit=t.limit),l.skip=u),n(l).then(r)}),M=T.sequentialize(C,function(e){return e.get("_local/mrviews").then(function(t){var n={};Object.keys(t.views).forEach(function(e){var t=r(e),o="_design/"+t[0],i=t[1];n[o]=n[o]||{},n[o][i]=!0});var o={keys:Object.keys(n),include_docs:!0};return e.allDocs(o).then(function(r){var o={};r.rows.forEach(function(e){var r=e.key.substring(8);Object.keys(n[e.key]).forEach(function(n){var i=r+"/"+n;t.views[i]||(i=n);var u=Object.keys(t.views[i]),s=e.doc&&e.doc.views&&e.doc.views[n];u.forEach(function(e){o[e]=o[e]||s})})});var i=Object.keys(o).filter(function(e){return!o[e]}),u=i.map(function(t){return e.constructor.destroy(t,{adapter:e.adapter})});return P.all(u).then(function(){return{ok:!0}})})},d({ok:!0}))});n._search_viewCleanup=T.callbackify(function(){var e=this;return"http"===e.type()?g(e):M(e)}),n._search_query=function(e,t,n){"function"==typeof t&&(n=t,t={}),t=T.extend(!0,{},t),"function"==typeof e&&(e={map:e}),e.saveAs&&(t.saveAs=e.saveAs,delete e.saveAs);var r=this,o=P.resolve().then(function(){return b(r,e,t)});return T.promisedCallback(o,n),o},T.inherits(k,Error),T.inherits(_,Error)},{"./create-view":27,"./evalfunc":28,"./taskqueue":33,"./utils":35,__browserify_process:4,"pouchdb-collate":30}],30:[function(e,t,n){"use strict";function r(e){if(null!==e)switch(typeof e){case"boolean":return e?1:0;case"number":return f(e);case"string":return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var t=Array.isArray(e),r=t?e:Object.keys(e),o=-1,i=r.length,u="";if(t)for(;++o<i;)u+=n.toIndexableString(r[o]);else for(;++o<i;){var s=r[o];u+=n.toIndexableString(s)+n.toIndexableString(e[s])}return u}return""}function o(e,t){var n,r=t,o="1"===e[t];if(o)n=0,t++;else{var i="0"===e[t];t++;var u="",s=e.substring(t,t+h),a=parseInt(s,10)+l;for(i&&(a=-a),t+=h;;){var c=e[t];if("\x00"===c)break;u+=c,t++}u=u.split("."),n=1===u.length?parseInt(u,10):parseFloat(u[0]+"."+u[1]),i&&(n-=10),0!==a&&(n=parseFloat(n+"e"+a))}return{num:n,length:t-r}}function i(e,t){var n=e.pop();if(t.length){var r=t[t.length-1];n===r.element&&(t.pop(),r=t[t.length-1]);var o=r.element,i=r.index;if(Array.isArray(o))o.push(n);else if(i===e.length-2){var u=e.pop();o[u]=n}else e.push(n)}}function u(e,t){for(var r=Math.min(e.length,t.length),o=0;r>o;o++){var i=n.collate(e[o],t[o]);if(0!==i)return i}return e.length===t.length?0:e.length>t.length?1:-1}function s(e,t){return e===t?0:e>t?1:-1}function a(e,t){for(var r=Object.keys(e),o=Object.keys(t),i=Math.min(r.length,o.length),u=0;i>u;u++){var s=n.collate(r[u],o[u]);if(0!==s)return s;if(s=n.collate(e[r[u]],t[o[u]]),0!==s)return s}return r.length===o.length?0:r.length>o.length?1:-1}function c(e){var t=["boolean","number","string","object"],n=t.indexOf(typeof e);return~n?null===e?1:Array.isArray(e)?5:3>n?n+2:n+3:Array.isArray(e)?5:void 0}function f(e){if(0===e)return"1";var t=e.toExponential().split(/e\+?/),n=parseInt(t[1],10),r=0>e,o=r?"0":"2",i=(r?-n:n)-l,u=p.padLeft(i.toString(),"0",h);o+=d+u;var s=Math.abs(parseFloat(t[0]));r&&(s=10-s);var a=s.toFixed(20);return a=a.replace(/\.?0+$/,""),o+=d+a}var l=-324,h=3,d="",p=e("./utils");n.collate=function(e,t){if(e===t)return 0;e=n.normalizeKey(e),t=n.normalizeKey(t);var r=c(e),o=c(t);if(r-o!==0)return r-o;if(null===e)return 0;switch(typeof e){case"number":return e-t;case"boolean":return e===t?0:t>e?-1:1;case"string":return s(e,t)}return Array.isArray(e)?u(e,t):a(e,t)},n.normalizeKey=function(e){switch(typeof e){case"undefined":return null;case"number":return 1/0===e||e===-1/0||isNaN(e)?null:e;case"object":var t=e;if(Array.isArray(e)){var r=e.length;e=new Array(r);for(var o=0;r>o;o++)e[o]=n.normalizeKey(t[o])}else{if(e instanceof Date)return e.toJSON();if(null!==e){e={};for(var i in t)if(t.hasOwnProperty(i)){var u=t[i];"undefined"!=typeof u&&(e[i]=n.normalizeKey(u))}}}}return e},n.toIndexableString=function(e){var t="\x00";return e=n.normalizeKey(e),c(e)+d+r(e)+t},n.parseIndexableString=function(e){for(var t=[],n=[],r=0;;){var u=e[r++];if("\x00"!==u)switch(u){case"1":t.push(null);break;case"2":t.push("1"===e[r]),r++;break;case"3":var s=o(e,r);t.push(s.num),r+=s.length;break;case"4":for(var a="";;){var c=e[r];if("\x00"===c)break;a+=c,r++}a=a.replace(/\u0001\u0001/g,"\x00").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(a);break;case"5":var f={element:[],index:t.length};t.push(f.element),n.push(f);break;case"6":var l={element:{},index:t.length};t.push(l.element),n.push(l);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+u)}else{if(1===t.length)return t.pop();i(t,n)}}}},{"./utils":31}],31:[function(e,t,n){"use strict";function r(e,t,n){for(var r="",o=n-e.length;r.length<o;)r+=t;return r}n.padLeft=function(e,t,n){var o=r(e,t,n);return o+e},n.padRight=function(e,t,n){var o=r(e,t,n);return e+o},n.stringLexCompare=function(e,t){var n,r=e.length,o=t.length;for(n=0;r>n;n++){if(n===o)return 1;var i=e.charAt(n),u=t.charAt(n);if(i!==u)return u>i?-1:1}return o>r?-1:0},n.intToDecimalForm=function(e){var t=0>e,n="";do{var r=t?-Math.ceil(e%10):Math.floor(e%10);n=r+n,e=t?Math.ceil(e/10):Math.floor(e/10)}while(e);return t&&"0"!==n&&(n="-"+n),n}},{}],32:[function(e,t,n){!function(e){if("object"==typeof n)t.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var r;try{r=window}catch(o){r=self}r.SparkMD5=e()}}(function(){"use strict";var e=function(e,t){return e+t&4294967295},t=function(t,n,r,o,i,u){return n=e(e(n,t),e(o,u)),e(n<<i|n>>>32-i,r)},n=function(e,n,r,o,i,u,s){return t(n&r|~n&o,e,n,i,u,s)},r=function(e,n,r,o,i,u,s){return t(n&o|r&~o,e,n,i,u,s)},o=function(e,n,r,o,i,u,s){return t(n^r^o,e,n,i,u,s)},i=function(e,n,r,o,i,u,s){return t(r^(n|~o),e,n,i,u,s)},u=function(t,u){var s=t[0],a=t[1],c=t[2],f=t[3];s=n(s,a,c,f,u[0],7,-680876936),f=n(f,s,a,c,u[1],12,-389564586),c=n(c,f,s,a,u[2],17,606105819),a=n(a,c,f,s,u[3],22,-1044525330),s=n(s,a,c,f,u[4],7,-176418897),f=n(f,s,a,c,u[5],12,1200080426),c=n(c,f,s,a,u[6],17,-1473231341),a=n(a,c,f,s,u[7],22,-45705983),s=n(s,a,c,f,u[8],7,1770035416),f=n(f,s,a,c,u[9],12,-1958414417),c=n(c,f,s,a,u[10],17,-42063),a=n(a,c,f,s,u[11],22,-1990404162),s=n(s,a,c,f,u[12],7,1804603682),f=n(f,s,a,c,u[13],12,-40341101),c=n(c,f,s,a,u[14],17,-1502002290),a=n(a,c,f,s,u[15],22,1236535329),s=r(s,a,c,f,u[1],5,-165796510),f=r(f,s,a,c,u[6],9,-1069501632),c=r(c,f,s,a,u[11],14,643717713),a=r(a,c,f,s,u[0],20,-373897302),s=r(s,a,c,f,u[5],5,-701558691),f=r(f,s,a,c,u[10],9,38016083),c=r(c,f,s,a,u[15],14,-660478335),a=r(a,c,f,s,u[4],20,-405537848),s=r(s,a,c,f,u[9],5,568446438),f=r(f,s,a,c,u[14],9,-1019803690),c=r(c,f,s,a,u[3],14,-187363961),a=r(a,c,f,s,u[8],20,1163531501),s=r(s,a,c,f,u[13],5,-1444681467),f=r(f,s,a,c,u[2],9,-51403784),c=r(c,f,s,a,u[7],14,1735328473),a=r(a,c,f,s,u[12],20,-1926607734),s=o(s,a,c,f,u[5],4,-378558),f=o(f,s,a,c,u[8],11,-2022574463),c=o(c,f,s,a,u[11],16,1839030562),a=o(a,c,f,s,u[14],23,-35309556),s=o(s,a,c,f,u[1],4,-1530992060),f=o(f,s,a,c,u[4],11,1272893353),c=o(c,f,s,a,u[7],16,-155497632),a=o(a,c,f,s,u[10],23,-1094730640),s=o(s,a,c,f,u[13],4,681279174),f=o(f,s,a,c,u[0],11,-358537222),c=o(c,f,s,a,u[3],16,-722521979),a=o(a,c,f,s,u[6],23,76029189),s=o(s,a,c,f,u[9],4,-640364487),f=o(f,s,a,c,u[12],11,-421815835),c=o(c,f,s,a,u[15],16,530742520),a=o(a,c,f,s,u[2],23,-995338651),s=i(s,a,c,f,u[0],6,-198630844),f=i(f,s,a,c,u[7],10,1126891415),c=i(c,f,s,a,u[14],15,-1416354905),a=i(a,c,f,s,u[5],21,-57434055),s=i(s,a,c,f,u[12],6,1700485571),f=i(f,s,a,c,u[3],10,-1894986606),c=i(c,f,s,a,u[10],15,-1051523),a=i(a,c,f,s,u[1],21,-2054922799),s=i(s,a,c,f,u[8],6,1873313359),f=i(f,s,a,c,u[15],10,-30611744),c=i(c,f,s,a,u[6],15,-1560198380),a=i(a,c,f,s,u[13],21,1309151649),s=i(s,a,c,f,u[4],6,-145523070),f=i(f,s,a,c,u[11],10,-1120210379),c=i(c,f,s,a,u[2],15,718787259),a=i(a,c,f,s,u[9],21,-343485551),t[0]=e(s,t[0]),t[1]=e(a,t[1]),t[2]=e(c,t[2]),t[3]=e(f,t[3])},s=function(e){var t,n=[];for(t=0;64>t;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n},a=function(e){var t,n=[];for(t=0;64>t;t+=4)n[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return n},c=function(e){var t,n,r,o,i,a,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;c>=t;t+=64)u(f,s(e.substring(t-64,t)));for(e=e.substring(t-64),n=e.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;n>t;t+=1)r[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(u(f,r),t=0;16>t;t+=1)r[t]=0;return o=8*c,o=o.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(o[2],16),a=parseInt(o[1],16)||0,r[14]=i,r[15]=a,u(f,r),f},f=function(e){var t,n,r,o,i,s,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;c>=t;t+=64)u(f,a(e.subarray(t-64,t)));for(e=c>t-64?e.subarray(t-64):new Uint8Array(0),n=e.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;n>t;t+=1)r[t>>2]|=e[t]<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(u(f,r),t=0;16>t;t+=1)r[t]=0;return o=8*c,o=o.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(o[2],16),s=parseInt(o[1],16)||0,r[14]=i,r[15]=s,u(f,r),f},l=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],h=function(e){var t,n="";for(t=0;4>t;t+=1)n+=l[e>>8*t+4&15]+l[e>>8*t&15];return n},d=function(e){var t;for(t=0;t<e.length;t+=1)e[t]=h(e[t]);return e.join("")},p=function(e){return d(c(e))},v=function(){this.reset()};return"5d41402abc4b2a76b9719d911017c592"!==p("hello")&&(e=function(e,t){var n=(65535&e)+(65535&t),r=(e>>16)+(t>>16)+(n>>16);return r<<16|65535&n}),v.prototype.append=function(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),this.appendBinary(e),this},v.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,n=this._buff.length;for(t=64;n>=t;t+=64)u(this._state,s(this._buff.substring(t-64,t)));return this._buff=this._buff.substr(t-64),this},v.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;o>t;t+=1)i[t>>2]|=r.charCodeAt(t)<<(t%4<<3);return this._finish(i,o),n=e?this._state:d(this._state),this.reset(),n},v.prototype._finish=function(e,t){var n,r,o,i=t;if(e[i>>2]|=128<<(i%4<<3),i>55)for(u(this._state,e),i=0;16>i;i+=1)e[i]=0;n=8*this._length,n=n.toString(16).match(/(.*?)(.{0,8})$/),r=parseInt(n[2],16),o=parseInt(n[1],16)||0,e[14]=r,e[15]=o,u(this._state,e)},v.prototype.reset=function(){return this._buff="",this._length=0,this._state=[1732584193,-271733879,-1732584194,271733878],this},v.prototype.destroy=function(){delete this._state,delete this._buff,delete this._length},v.hash=function(e,t){/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e)));var n=c(e);return t?n:d(n)},v.hashBinary=function(e,t){var n=c(e);return t?n:d(n)},v.ArrayBuffer=function(){this.reset()},v.ArrayBuffer.prototype.append=function(e){var t,n=this._concatArrayBuffer(this._buff,e),r=n.length;for(this._length+=e.byteLength,t=64;r>=t;t+=64)u(this._state,a(n.subarray(t-64,t)));return this._buff=r>t-64?n.subarray(t-64):new Uint8Array(0),this},v.ArrayBuffer.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;o>t;t+=1)i[t>>2]|=r[t]<<(t%4<<3);return this._finish(i,o),n=e?this._state:d(this._state),this.reset(),n},v.ArrayBuffer.prototype._finish=v.prototype._finish,v.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._state=[1732584193,-271733879,-1732584194,271733878],this},v.ArrayBuffer.prototype.destroy=v.prototype.destroy,v.ArrayBuffer.prototype._concatArrayBuffer=function(e,t){var n=e.length,r=new Uint8Array(n+t.byteLength);return r.set(e),r.set(new Uint8Array(t),n),r},v.ArrayBuffer.hash=function(e,t){var n=f(new Uint8Array(e));return t?n:d(n)},v})},{}],33:[function(e,t){"use strict";function n(){this.promise=new r(function(e){e()})}var r=e("./utils").Promise;n.prototype.add=function(e){return this.promise=this.promise["catch"](function(){}).then(function(){return e()}),this.promise},n.prototype.finish=function(){return this.promise},t.exports=n},{"./utils":35}],34:[function(e,t){"use strict";function n(e,t,n){return new o(function(o,i){return t&&"object"==typeof t&&(t=t._id),"string"!=typeof t?i(new Error("doc id is required")):void e.get(t,function(u,s){if(u)return 404!==u.status?i(u):o(r(e,n({_id:t}),n));var a=n(s);return a?void o(r(e,a,n)):o(s)})})}function r(e,t,r){return e.put(t)["catch"](function(o){if(409!==o.status)throw o;return n(e,t,r)})}var o=e("./utils").Promise;t.exports=n},{"./utils":35}],35:[function(e,t,n){var r=e("__browserify_process"),o="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};n.Promise="function"==typeof o.Promise?o.Promise:e("lie"),n.inherits=e("inherits"),n.extend=e("pouchdb-extend");var i=e("argsarray");n.promisedCallback=function(e,t){return t&&e.then(function(e){r.nextTick(function(){t(null,e)})},function(e){r.nextTick(function(){t(e)})}),e},n.callbackify=function(e){return i(function(t){var r=t.pop(),o=e.apply(this,t);return"function"==typeof r&&n.promisedCallback(o,r),o})},n.fin=function(e,t){return e.then(function(e){var n=t();return"function"==typeof n.then?n.then(function(){return e}):e},function(e){var n=t();if("function"==typeof n.then)return n.then(function(){throw e});throw e})},n.sequentialize=function(e,t){return function(){var n=arguments,r=this;return e.add(function(){return t.apply(r,n)})}},n.uniq=function(e){for(var t={},n=0,r=e.length;r>n;n++)t["$"+e[n]]=!0;var o=Object.keys(t),i=new Array(o.length);for(n=0,r=o.length;r>n;n++)i[n]=o[n].substring(1);return i};var u=e("crypto"),s=e("spark-md5");n.MD5=function(e){return r.browser?s.hash(e):u.createHash("md5").update(e).digest("hex")}},{__browserify_process:4,argsarray:2,crypto:3,inherits:5,lie:9,"pouchdb-extend":26,"spark-md5":32}],36:[function(e,t){"use strict";function n(e,t){for(var n=1,r=e.length,o=e[0],i=e[0],u=1;r>u;++u)if(i=o,o=e[u],t(o,i)){if(u===n){n++;continue}e[n++]=o}return e.length=n,e}function r(e){for(var t=1,n=e.length,r=e[0],o=e[0],i=1;n>i;++i,o=r)if(o=r,r=e[i],r!==o){if(i===t){t++;continue}e[t++]=r}return e.length=t,e}function o(e,t,o){return 0===e.length?e:t?(o||e.sort(t),n(e,t)):(o||e.sort(),r(e))}t.exports=o},{}],37:[function(e,t,n){var r,o=e("__browserify_process"),i="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};r="undefined"!=typeof window&&window.PouchDB?window.PouchDB.utils.Promise:"function"==typeof i.Promise?i.Promise:e("lie"),n.once=function(e){var t=!1;return n.getArguments(function(n){if(t)throw console.trace(),new Error("once called more than once");t=!0,e.apply(this,n)})},n.getArguments=function(e){return function(){for(var t=arguments.length,n=new Array(t),r=-1;++r<t;)n[r]=arguments[r];return e.call(this,n)}},n.toPromise=function(e){return n.getArguments(function(t){var i,u=this,s="function"==typeof t[t.length-1]?t.pop():!1;s&&(i=function(e,t){o.nextTick(function(){s(e,t)})});var a=new r(function(r,o){try{var i=n.once(function(e,t){e?o(e):r(t)});t.push(i),e.apply(u,t)}catch(s){o(s)}});return i&&a.then(function(e){i(null,e)},i),a.cancel=function(){return this},a})},n.inherits=e("inherits"),n.Promise=r;var u=e("crypto"),s=e("md5-jkmyers");n.MD5=function(e){return o.browser?s(e):u.createHash("md5").update(e).digest("hex")},n.extend=e("pouchdb-extend")},{__browserify_process:4,crypto:3,inherits:5,lie:9,"md5-jkmyers":25,"pouchdb-extend":26}]},{},[1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment