Skip to content

Instantly share code, notes, and snippets.

@Darkle
Forked from nolanlawson/index.html
Last active December 18, 2015 05:46
Show Gist options
  • Save Darkle/9bcf54994859b53dc3da to your computer and use it in GitHub Desktop.
Save Darkle/9bcf54994859b53dc3da to your computer and use it in GitHub Desktop.
PouchDB Quick Search demo
<html>
<head>
<style>
#display{
max-width: 900px;
overflow: scroll;
}
</style>
</head>
<body>
<pre id="display"></pre>
<script src="//cdn.jsdelivr.net/pouchdb/5.1.0/pouchdb.min.js"></script>
<script src="pouchdb.quick-search.min.js"></script>
<script src="index.js"></script>
</body>
</html>
(function () {
function log(str) {
document.getElementById('display').innerHTML += str + '\n';
}
var testDB = new PouchDB('testDB');
var domainToSearchFor = 'wikipedia.org'
testDB.destroy('testDB').then(function () {
testDB = new PouchDB('testDB');
}).then(function () {
return testDB.bulkDocs([
{siteTitle : 'Google Search', domain: 'google.com', _id: 'doc1'},
{siteTitle : 'Yahoo Search', domain: 'yahoo.com', _id: 'doc2'},
{siteTitle : 'Bing Search', domain: 'bing.com', _id: 'doc3'},
{siteTitle : 'Baidu Search', domain: 'baidu.com', _id: 'doc4'},
{siteTitle : 'Hacker News', domain: 'ycombinator.com', _id: 'doc5'},
{siteTitle : 'Mozilla foo', domain: 'mozilla.org', _id: 'doc6'},
{siteTitle : 'Android foo', domain: 'android.com', _id: 'doc7'},
{siteTitle : 'Wikipedia foo', domain: 'wikipedia.org', _id: 'doc8'},
{siteTitle : 'Twitter foo', domain: 'twitter.com', _id: 'doc9'},
{siteTitle : 'Facebook foo', domain: 'facebook.com', _id: 'doc10'},
{siteTitle : 'Reddit foo', domain: 'reddit.com', _id: 'doc11'},
{siteTitle : 'The Verge foo', domain: 'theverge.com', _id: 'doc12'},
{siteTitle : 'Dropbox foo', domain: 'dropbox.com', _id: 'doc13'},
{siteTitle : 'Microsoft foo', domain: 'microsoft.com', _id: 'doc14'}
]);
}).then(function () {
return testDB.search({
fields: ['siteTitle'],
build: true
});
}).then(function(){
return testDB.search({
query: 'foo',
fields: ['siteTitle'],
filter: function(doc){
return doc.domain === domainToSearchFor
},
include_docs: true
});
}).then(function (res) {
log('result 1: ' + JSON.stringify(res));
domainToSearchFor = 'android.com'
return testDB.search({
query: 'foo',
fields: ['siteTitle'],
filter: function(doc){
return doc.domain === domainToSearchFor
},
include_docs: true
});
}).then(function (res) {
log('result 2: ' + 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 q=v(o(r,F));return q.length?(P.keys=q.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,{total_rows:0,rows:[]});var o=0,u={},f={};if(r.rows.forEach(function(e){var t=e.key.substring(1),n=e.value||0;if(t in f?f[t]++:f[t]=1,!(e.id in u))for(var r=u[e.id]=[],o=0;o<O.length;o++)r[o]={};var i=u[e.id][n];t in i?i[t]++:i[t]=1}),q.length>1&&Object.keys(u).forEach(function(e){var t={},n=u[e];Object.keys(n).forEach(function(e){Object.keys(n[e]).forEach(function(e){t[e]=!0})});var r=Object.keys(t).length,o=r/q.length;Math.floor(100*o)/100<i&&delete u[e]}),!Object.keys(u).length)return t(null,{total_rows:0,rows:[]});var l=Object.keys(u).map(function(e){return w+e}),d={saveAs:N,keys:l,stale:k};return n._search_query(T,d).then(function(e){var t={};e.rows.forEach(function(e){t[e.id]=e.value});var n=s(q,f,u,t,O);return n}).then(function(e){return o=e.length,"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,u):t}).then(function(e){t(null,{total_rows:o,rows:e})})})["catch"](t)):t(null,{total_rows:0,rows:[]})}),"undefined"!=typeof window&&window.PouchDB&&window.PouchDB.plugin(n)},{"./pouch-utils":34,lunr:19,"pouchdb-mapreduce-no-ddocs":26,uniq:33}],2:[function(e,t,n){"use strict";function r(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=r},{}],3:[function(e,t,n){},{}],4:[function(e,t,n){function r(){h=!0;for(var e,t,n=d.length;n;){for(t=d,d=[],e=-1;++e<n;)t[e]();n=d.length}h=!1}function o(e){1!==d.push(e)||h||i()}var i,u="undefined"!=typeof self?self:"undefined"!=typeof window?window:{},s=u.MutationObserver||u.WebKitMutationObserver;if(s){var a=0,c=new s(r),f=u.document.createTextNode("");c.observe(f,{characterData:!0}),i=function(){f.data=a=++a%2}}else if(u.setImmediate||"undefined"==typeof u.MessageChannel)i="document"in u&&"onreadystatechange"in u.document.createElement("script")?function(){var e=u.document.createElement("script");e.onreadystatechange=function(){r(),e.onreadystatechange=null,e.parentNode.removeChild(e),e=null},u.document.documentElement.appendChild(e)}:function(){setTimeout(r,0)};else{var l=new u.MessageChannel;l.port1.onmessage=r,i=function(){l.port2.postMessage(0)}}var h,d=[];t.exports=o},{}],5:[function(e,t,n){"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 n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},{}],6:[function(e,t,n){"use strict";function r(){}t.exports=r},{}],7:[function(e,t,n){"use strict";function r(e){function t(e,t){function o(e){c[t]=e,++f===n&!r&&(r=!0,a.resolve(h,c))}u(e).then(o,function(e){r||(r=!0,a.reject(h,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return i(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return u([]);for(var c=new Array(n),f=0,l=-1,h=new o(s);++l<n;)t(e[l],l);return h}var o=e("./promise"),i=e("./reject"),u=e("./resolve"),s=e("./INTERNAL"),a=e("./handlers");t.exports=r},{"./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,n){"use strict";function r(e){if(!(this instanceof r))return new r(e);if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=s.PENDING,this.queue=[],this.outcome=void 0,e!==i&&u.safely(this,e)}var o=e("./unwrap"),i=e("./INTERNAL"),u=e("./resolveThenable"),s=e("./states"),a=e("./queueItem");t.exports=r,r.prototype["catch"]=function(e){return this.then(null,e)},r.prototype.then=function(e,t){if("function"!=typeof e&&this.state===s.FULFILLED||"function"!=typeof t&&this.state===s.REJECTED)return this;var n=new r(i);if(this.state!==s.PENDING){var u=this.state===s.FULFILLED?e:t;o(n,u,this.outcome)}else this.queue.push(new a(n,e,t));return n}},{"./INTERNAL":6,"./queueItem":11,"./resolveThenable":15,"./states":16,"./unwrap":18}],11:[function(e,t,n){"use strict";function r(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 o=e("./handlers"),i=e("./unwrap");t.exports=r,r.prototype.callFulfilled=function(e){o.resolve(this.promise,e)},r.prototype.otherCallFulfilled=function(e){i(this.promise,this.onFulfilled,e)},r.prototype.callRejected=function(e){o.reject(this.promise,e)},r.prototype.otherCallRejected=function(e){i(this.promise,this.onRejected,e)}},{"./handlers":8,"./unwrap":18}],12:[function(e,t,n){"use strict";function r(e){function t(e){u(e).then(function(e){r||(r=!0,a.resolve(f,e))},function(e){r||(r=!0,a.reject(f,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return i(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return u([]);for(var c=-1,f=new o(s);++c<n;)t(e[c]);return f}var o=e("./promise"),i=e("./reject"),u=e("./resolve"),s=e("./INTERNAL"),a=e("./handlers");t.exports=r},{"./INTERNAL":6,"./handlers":8,"./promise":10,"./reject":13,"./resolve":14}],13:[function(e,t,n){"use strict";function r(e){var t=new o(i);return u.reject(t,e)}var o=e("./promise"),i=e("./INTERNAL"),u=e("./handlers");t.exports=r},{"./INTERNAL":6,"./handlers":8,"./promise":10}],14:[function(e,t,n){"use strict";function r(e){if(e)return e instanceof o?e:u.resolve(new o(i),e);var t=typeof e;switch(t){case"boolean":return s;case"undefined":return c;case"object":return a;case"number":return f;case"string":return l}}var o=e("./promise"),i=e("./INTERNAL"),u=e("./handlers");t.exports=r;var s=u.resolve(new o(i),!1),a=u.resolve(new o(i),null),c=u.resolve(new o(i),void 0),f=u.resolve(new o(i),0),l=u.resolve(new o(i),"")},{"./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,n){"use strict";function r(e,t){var n={};try{n.value=e(t),n.status="success"}catch(r){n.status="error",n.value=r}return n}t.exports=r},{}],18:[function(e,t,n){"use strict";function r(e,t,n){o(function(){var r;try{r=t(n)}catch(o){return i.reject(e,o)}r===e?i.reject(e,new TypeError("Cannot resolve promise with itself")):i.resolve(e,r)})}var o=e("immediate"),i=e("./handlers");t.exports=r},{"./handlers":8,immediate:4}],19:[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})}()},{}],20:[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})},{}],21:[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 e===1/0||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":22}],22:[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}},{}],23:[function(e,t,n){"use strict";function r(e){return null===e?String(e):"object"==typeof e||"function"==typeof e?c[d.call(e)]||"object":typeof e}function o(e){return null!==e&&e===e.window}function i(e){if(!e||"object"!==r(e)||e.nodeType||o(e))return!1;try{if(e.constructor&&!p.call(e,"constructor")&&!p.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}var n;for(n in e);return void 0===n||p.call(e,n)}function u(e){return"function"===r(e)}function s(){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();)a(e,i.args,i.result);return o.key}function a(e,t,n){var r,o,s,a,c,f,l,h=t[0]||{},d=1,p=t.length,y=!1,g=/\d+/;for("boolean"==typeof h&&(y=h,h=t[1]||{},d=2),"object"==typeof h||u(h)||(h={}),p===d&&(h=this,--d);p>d;d++)if(null!=(r=t[d])){l=v(r);for(o in r)if(!(o in Object.prototype)){if(l&&!g.test(o))continue;if(s=h[o],a=r[o],h===a)continue;y&&a&&(i(a)||(c=v(a)))?(c?(c=!1,f=s&&v(s)?s:[]):f=s&&i(s)?s:{},e.push({args:[y,f,a],result:{container:h,key:o}})):void 0!==a&&(v(r)&&u(a)||(h[o]=a))}}n.container[n.key]=h}for(var c={},f=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error"],l=0;l<f.length;l++){var h=f[l];c["[object "+h+"]"]=h.toLowerCase()}var d=c.toString,p=c.hasOwnProperty,v=Array.isArray||function(e){return"array"===r(e)};t.exports=s},{}],24:[function(e,t,n){"use strict";var r=e("./upsert"),o=e("./utils"),i=o.Promise;t.exports=function(e){var t=e.db,n=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 i.resolve(l)}return t.info().then(function(e){function l(){function e(e){e.views=e.views||{};var t=n;-1===t.indexOf("/")&&(t=n+"/"+n);var r=e.views[t]=e.views[t]||{};if(!r[d])return r[d]=!0,e}return r(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":o.MD5(f)),i.resolve().then(function(){return n?l():i.resolve()}).then(h)})}},{"./upsert":28,"./utils":29}],25:[function(require,module,exports){"use strict";module.exports=function(func,emit,sum,log,isArray,toJSON){return eval("'use strict'; ("+func.replace(/;\s*$/,"")+");")}},{}],26:[function(e,t,n){function r(e){return-1===e.indexOf("/")?[e,e]:e.split("/")}function o(e){return 1===e.length&&/^1-/.test(e[0].rev)}function i(e,t,n){try{return{output:t.apply(null,n)}}catch(r){return e.emit("error",r),{error:r}}}function u(e,t){var n=q(e.key,t.key);return 0!==n?n:q(e.value,t.value)}function s(e,t,n){return n=n||0,"number"==typeof t?e.slice(n,t+n):n>0?e.slice(n):e}function a(e){var t=e.value,n=t&&"object"==typeof t&&t._id||e.id;return n}function c(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 f(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 c("_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 c("_sum");"undefined"==typeof t[i]?t.push(s):t[i]+=s}}else"number"==typeof t?t+=o:t[0]+=o}return t}function l(e,t,n,r){var o=t[e];"undefined"!=typeof o&&(r&&(o=encodeURIComponent(JSON.stringify(o))),n.push(e+"="+o))}function h(e,t){var n=e.descending?"endkey":"startkey",r=e.descending?"startkey":"endkey";if("undefined"!=typeof e[n]&&"undefined"!=typeof e[r]&&q(e[n],e[r])>0)throw new O("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 O("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new O("Multi-key fetches for reduce views must use {group: true}")}if(e.group_level){if("number"!=typeof e.group_level)throw new O('Invalid value for integer: "'+e.group_level+'"');if(e.group_level<0)throw new O('Invalid value for positive integer: "'+e.group_level+'"')}}function d(e,t,n){var o,i=[],u="GET";if(l("reduce",n,i),l("include_docs",n,i),l("attachments",n,i),l("limit",n,i),l("descending",n,i),l("group",n,i),l("group_level",n,i),l("skip",n,i),l("stale",n,i),l("conflicts",n,i),l("startkey",n,i,!0),l("endkey",n,i,!0),l("inclusive_end",n,i),l("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){Array.isArray(t[e])?o[e]=t[e]:o[e]=t[e].toString()}),e.request({method:"POST",url:"_temp_view"+i,body:o})}function p(e){return function(t){if(404===t.status)return e;throw t}}function v(e,t,n){function r(){return o(l)?M.resolve(a):t.db.get(s)["catch"](p(a))}function i(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):M.resolve({rows:[]})}function u(e,t){for(var n=[],r={},o=0,i=t.rows.length;i>o;o++){var u=t.rows[o],s=u.doc;if(s&&(n.push(s),r[s._id]=!0,s._deleted=!f[s._id],!s._deleted)){var a=f[s._id];"value"in a&&(s.value=a.value)}}var c=Object.keys(f);return c.forEach(function(e){if(!r[e]){var t={_id:e},o=f[e];"value"in o&&(t.value=o.value),n.push(t)}}),e.keys=$.uniq(c.concat(e.keys)),n.push(e),n}var s="_local/doc_"+e,a={_id:s,keys:[]},c=n[e],f=c.indexableKeysToKeyValues,l=c.changes;return r().then(function(e){return i(e).then(function(t){return u(e,t)})})}function y(e,t,n){var r="_local/lastSeq";return e.db.get(r)["catch"](p({_id:r,seq:0})).then(function(r){var o=Object.keys(t);return M.all(o.map(function(n){return v(n,e,t)})).then(function(t){var o=$.flatten(t);return r.seq=n,o.push(r),e.db.bulkDocs({docs:o})})})}function g(e){var t="string"==typeof e?e:e.name,n=z[t];return n||(n=z[t]=new P),n}function m(e){return $.sequentialize(g(e),function(){return w(e)})()}function w(e){function t(e,t){var n={id:o._id,key:R(e)};"undefined"!=typeof t&&null!==t&&(n.value=R(t)),r.push(n)}function n(t,n){return function(){return y(e,t,n)}}var r,o,s;if("function"==typeof e.mapFun&&2===e.mapFun.length){var a=e.mapFun;s=function(e){return a(e,t)}}else s=L(e.mapFun.toString(),t,f,I,Array.isArray,JSON.parse);var c=e.seq||0,l=new P;return new M(function(t,a){function f(){l.finish().then(function(){e.seq=c,t()})}function h(){function t(e){a(e)}e.sourceDB.changes({conflicts:!0,include_docs:!0,style:"all_docs",since:c,limit:J}).on("complete",function(t){var a=t.results;if(!a.length)return f();for(var d={},p=0,v=a.length;v>p;p++){var y=a[p];if("_"!==y.doc._id[0]){r=[],o=y.doc,o._deleted||i(e.sourceDB,s,[o]),r.sort(u);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=C(_);m[x]=k,g=k.key}d[y.doc._id]={indexableKeysToKeyValues:m,changes:y.changes}}c=y.seq}return l.add(n(d,c)),a.length<J?f():h()}).on("error",t)}h()})}function b(e,t,n){0===n.group_level&&delete n.group_level;var r,o=n.group||n.group_level;r=V[e.reduceFun]?V[e.reduceFun]:L(e.reduceFun.toString(),null,f,I,Array.isArray,JSON.parse);var u=[],a=n.group_level;t.forEach(function(e){var t=u[u.length-1],n=o?e.key:null;return o&&Array.isArray(n)&&"number"==typeof a&&(n=n.length>a?n.slice(0,a):n),t&&0===q(t.key[0][0],n)?(t.key.push([n,e.id]),void t.value.push(e.value)):void u.push({key:[[n,e.id]],value:[e.value]})});for(var c=0,l=u.length;l>c;c++){var h=u[c],d=i(e.sourceDB,r,[h.key,h.value,!1]);h.value=d.error?null:d.output,h.key=h.key[0][0]}return{rows:s(u,n.limit,n.skip)}}function k(e,t){return $.sequentialize(g(e),function(){return _(e,t)})()}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=T.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?b(e,n,t):{total_rows:o,offset:u,rows:n},t.include_docs){var s=$.uniq(n.map(a));return e.sourceDB.allDocs({keys:s,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=a(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 s=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:C([e]),endkey:C([e,{}])};return n(t)});return M.all(f).then(s).then(r)}var l={descending:t.descending};if("undefined"!=typeof t.startkey&&(l.startkey=C(t.descending?[t.startkey,{}]:[t.startkey])),"undefined"!=typeof t.endkey){var h=t.inclusive_end!==!1;t.descending&&(h=!h),l.endkey=C(h?[t.endkey,{}]:[t.endkey])}if("undefined"!=typeof t.key){var d=C([t.key]),p=C([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)}function x(e){return e.request({method:"POST",url:"_view_cleanup"})}function S(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 $.sequentialize(g(t),function(){return e.constructor.destroy(t,e.__opts)})()});return M.all(u).then(function(){return{ok:!0}})})},p({ok:!0}))}function E(e,t,n){h(n,t);var r={db:e,viewName:"temp_view/temp_view",map:t.map,reduce:t.reduce,temporary:!0};return B.add(function(){return D(r).then(function(e){function t(){return e.db.destroy()}return $.fin(m(e).then(function(){return k(e,n)}),t)})}),B.finish()}function A(e,t,n){function o(e){return"ok"===n.stale||"update_after"===n.stale?("update_after"===n.stale&&N.nextTick(function(){m(e)}),k(e,n)):m(e).then(function(){return k(e,n)})}if(n.saveAs){var i={db:e,saveAs:n.saveAs,map:t.map,reduce:t.reduce};return n.destroy?D(i).then(function(e){return e.db.destroy()}):(h(n,t),D(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 F("ddoc "+a+" has no view named "+c);h(n,r);var i={db:e,viewName:u,map:r.map,reduce:r.reduce};return D(i).then(o)})}function j(e,t,n){return"http"===e.type()?d(e,t,n):"string"==typeof t||n.saveAs?A(e,t,n):E(e,t,n)}function O(e){this.status=400,this.name="query_parse_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,O)}catch(t){}}function F(e){this.status=404,this.name="not_found",this.message=e,this.error=!0;try{Error.captureStackTrace(this,F)}catch(t){}}var I,N=e("__browserify_process"),T=e("pouchdb-collate"),P=e("./taskqueue"),q=T.collate,C=T.toIndexableString,R=T.normalizeKey,D=e("./create-view"),L=e("./evalfunc");I="undefined"!=typeof console&&"function"==typeof console.log?Function.prototype.bind.call(console.log,console):function(){};var $=e("./utils"),M=$.Promise,z={},B=new P,J=50,V={_sum:function(e,t){return f(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:f(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:n(t)}}};n._search_viewCleanup=$.callbackify(function(){var e=this;return"http"===e.type()?x(e):S(e)}),n._search_query=function(e,t,n){"function"==typeof t&&(n=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=M.resolve().then(function(){return j(r,e,t)});return $.promisedCallback(o,n),o},$.inherits(O,Error),$.inherits(F,Error)},{"./create-view":24,"./evalfunc":25,"./taskqueue":27,"./utils":29,__browserify_process:31,"pouchdb-collate":21}],27:[function(e,t,n){"use strict";function r(){this.promise=new o(function(e){e()})}var o=e("./utils").Promise;r.prototype.add=function(e){return this.promise=this.promise["catch"](function(){}).then(function(){return e()}),this.promise},r.prototype.finish=function(){return this.promise},t.exports=r},{"./utils":29}],28:[function(e,t,n){"use strict";var r=e("pouchdb-upsert").upsert;t.exports=function(e,t,n){return r.apply(e,[t,n])}},{"pouchdb-upsert":30}],29:[function(e,t,n){var r=e("__browserify_process"),o="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};"function"==typeof o.Promise?n.Promise=o.Promise:n.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.flatten=function(e){for(var t=[],n=0,r=e.length;r>n;n++)t=t.concat(e[n]);return t},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:31,argsarray:2,crypto:3,inherits:5,lie:9,"pouchdb-extend":23,"spark-md5":32}],30:[function(e,t,n){function r(e,t,n){return new i(function(r,i){return"string"!=typeof t?i(new Error("doc id is required")):void e.get(t,function(u,s){if(u){if(404!==u.status)return i(u);s={}}var a=s._rev,c=n(s);return c?(c._id=t,c._rev=a,void r(o(e,c,n))):r({updated:!1,rev:a})})})}function o(e,t,n){return e.put(t).then(function(e){return{updated:!0,rev:e.rev}},function(o){if(409!==o.status)throw o;return r(e,t._id,n)})}var i,u="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};i="undefined"!=typeof window&&window.PouchDB?window.PouchDB.utils.Promise:"function"==typeof u.Promise?u.Promise:e("lie"),n.upsert=function(e,t,n){var o=this,i=r(o,e,t);return"function"!=typeof n?i:void i.then(function(e){n(null,e)},n)},n.putIfNotExists=function(e,t,n){var o=this;"string"!=typeof e&&(n=t,t=e,e=t._id);var i=function(e){return e._rev?!1:t},u=r(o,e,i);return"function"!=typeof n?u:void u.then(function(e){n(null,e)},n)},"undefined"!=typeof window&&window.PouchDB&&window.PouchDB.plugin(n)},{lie:9}],31:[function(e,t,n){var r=t.exports={};r.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)}}(),r.title="browser",r.browser=!0,r.env={},r.argv=[],r.binding=function(e){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(e){throw new Error("process.chdir is not supported")}},{}],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(e){"use strict";var t=function(e,t){return e+t&4294967295},n=function(e,n,r,o,i,u){return n=t(t(n,e),t(o,u)),t(n<<i|n>>>32-i,r)},r=function(e,t,r,o,i,u,s){return n(t&r|~t&o,e,t,i,u,s)},o=function(e,t,r,o,i,u,s){return n(t&o|r&~o,e,t,i,u,s)},i=function(e,t,r,o,i,u,s){return n(t^r^o,e,t,i,u,s)},u=function(e,t,r,o,i,u,s){return n(r^(t|~o),e,t,i,u,s)},s=function(e,n){var s=e[0],a=e[1],c=e[2],f=e[3];s=r(s,a,c,f,n[0],7,-680876936),f=r(f,s,a,c,n[1],12,-389564586),c=r(c,f,s,a,n[2],17,606105819),a=r(a,c,f,s,n[3],22,-1044525330),s=r(s,a,c,f,n[4],7,-176418897),f=r(f,s,a,c,n[5],12,1200080426),c=r(c,f,s,a,n[6],17,-1473231341),a=r(a,c,f,s,n[7],22,-45705983),s=r(s,a,c,f,n[8],7,1770035416),f=r(f,s,a,c,n[9],12,-1958414417),c=r(c,f,s,a,n[10],17,-42063),a=r(a,c,f,s,n[11],22,-1990404162),s=r(s,a,c,f,n[12],7,1804603682),f=r(f,s,a,c,n[13],12,-40341101),c=r(c,f,s,a,n[14],17,-1502002290),a=r(a,c,f,s,n[15],22,1236535329),s=o(s,a,c,f,n[1],5,-165796510),f=o(f,s,a,c,n[6],9,-1069501632),c=o(c,f,s,a,n[11],14,643717713),a=o(a,c,f,s,n[0],20,-373897302),s=o(s,a,c,f,n[5],5,-701558691),f=o(f,s,a,c,n[10],9,38016083),c=o(c,f,s,a,n[15],14,-660478335),a=o(a,c,f,s,n[4],20,-405537848),s=o(s,a,c,f,n[9],5,568446438),f=o(f,s,a,c,n[14],9,-1019803690),c=o(c,f,s,a,n[3],14,-187363961),a=o(a,c,f,s,n[8],20,1163531501),s=o(s,a,c,f,n[13],5,-1444681467),f=o(f,s,a,c,n[2],9,-51403784),c=o(c,f,s,a,n[7],14,1735328473),a=o(a,c,f,s,n[12],20,-1926607734),s=i(s,a,c,f,n[5],4,-378558),f=i(f,s,a,c,n[8],11,-2022574463),c=i(c,f,s,a,n[11],16,1839030562),a=i(a,c,f,s,n[14],23,-35309556),s=i(s,a,c,f,n[1],4,-1530992060),f=i(f,s,a,c,n[4],11,1272893353),c=i(c,f,s,a,n[7],16,-155497632),a=i(a,c,f,s,n[10],23,-1094730640),s=i(s,a,c,f,n[13],4,681279174),f=i(f,s,a,c,n[0],11,-358537222),c=i(c,f,s,a,n[3],16,-722521979),a=i(a,c,f,s,n[6],23,76029189),s=i(s,a,c,f,n[9],4,-640364487),f=i(f,s,a,c,n[12],11,-421815835),c=i(c,f,s,a,n[15],16,530742520),a=i(a,c,f,s,n[2],23,-995338651),s=u(s,a,c,f,n[0],6,-198630844),f=u(f,s,a,c,n[7],10,1126891415),c=u(c,f,s,a,n[14],15,-1416354905),a=u(a,c,f,s,n[5],21,-57434055),s=u(s,a,c,f,n[12],6,1700485571),f=u(f,s,a,c,n[3],10,-1894986606),c=u(c,f,s,a,n[10],15,-1051523),a=u(a,c,f,s,n[1],21,-2054922799),s=u(s,a,c,f,n[8],6,1873313359),f=u(f,s,a,c,n[15],10,-30611744),c=u(c,f,s,a,n[6],15,-1560198380),a=u(a,c,f,s,n[13],21,1309151649),s=u(s,a,c,f,n[4],6,-145523070),f=u(f,s,a,c,n[11],10,-1120210379),c=u(c,f,s,a,n[2],15,718787259),a=u(a,c,f,s,n[9],21,-343485551),e[0]=t(s,e[0]),e[1]=t(a,e[1]),e[2]=t(c,e[2]),e[3]=t(f,e[3])},a=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},c=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},f=function(e){var t,n,r,o,i,u,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;c>=t;t+=64)s(f,a(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(s(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),u=parseInt(o[1],16)||0,r[14]=i,r[15]=u,s(f,r),f},l=function(e){var t,n,r,o,i,u,a=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;a>=t;t+=64)s(f,c(e.subarray(t-64,t)));for(e=a>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(s(f,r),t=0;16>t;t+=1)r[t]=0;return o=8*a,o=o.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(o[2],16),u=parseInt(o[1],16)||0,r[14]=i,r[15]=u,s(f,r),f},h=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],d=function(e){var t,n="";for(t=0;4>t;t+=1)n+=h[e>>8*t+4&15]+h[e>>8*t&15];return n},p=function(e){var t;for(t=0;t<e.length;t+=1)e[t]=d(e[t]);return e.join("")},v=function(e){return p(f(e))},y=function(){this.reset()};return"5d41402abc4b2a76b9719d911017c592"!==v("hello")&&(t=function(e,t){var n=(65535&e)+(65535&t),r=(e>>16)+(t>>16)+(n>>16);return r<<16|65535&n}),y.prototype.append=function(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),this.appendBinary(e),this},y.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,n=this._buff.length;for(t=64;n>=t;t+=64)s(this._state,a(this._buff.substring(t-64,t)));return this._buff=this._buff.substr(t-64),this},y.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:p(this._state),this.reset(),n},y.prototype._finish=function(e,t){var n,r,o,i=t;if(e[i>>2]|=128<<(i%4<<3),i>55)for(s(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,s(this._state,e)},y.prototype.reset=function(){return this._buff="",this._length=0,this._state=[1732584193,-271733879,-1732584194,271733878],this},y.prototype.destroy=function(){delete this._state,delete this._buff,delete this._length},y.hash=function(e,t){/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e)));var n=f(e);return t?n:p(n)},y.hashBinary=function(e,t){var n=f(e);return t?n:p(n)},y.ArrayBuffer=function(){this.reset()},y.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)s(this._state,c(n.subarray(t-64,t)));return this._buff=r>t-64?n.subarray(t-64):new Uint8Array(0),this},y.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:p(this._state),this.reset(),n},y.ArrayBuffer.prototype._finish=y.prototype._finish,y.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._state=[1732584193,-271733879,-1732584194,271733878],this},y.ArrayBuffer.prototype.destroy=y.prototype.destroy,y.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},y.ArrayBuffer.hash=function(e,t){var n=l(new Uint8Array(e));return t?n:p(n)},y})},{}],33:[function(e,t,n){"use strict";function r(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 o(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 i(e,t,n){return 0===e.length?e:t?(n||e.sort(t),r(e,t)):(n||e.sort(),o(e))}t.exports=i},{}],34:[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:31,crypto:3,inherits:5,lie:9,"md5-jkmyers":20,"pouchdb-extend":23}]},{},[1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment