Socket
Socket
Sign inDemoInstall

nedb

Package Overview
Dependencies
4
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.10.6 to 0.10.7

4

browser-version/out/nedb.min.js

@@ -1,2 +0,2 @@

!function(t){if("function"==typeof bootstrap)bootstrap("nedb",t);else if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeNedb=t}else"undefined"!=typeof window?window.Nedb=t():global.Nedb=t()}(function(){var t;return function(t,e,n){function r(n,o){if(!e[n]){if(!t[n]){var u="function"==typeof require&&require;if(!o&&u)return u(n,!0);if(i)return i(n,!0);throw new Error("Cannot find module '"+n+"'")}var a=e[n]={exports:{}};t[n][0].call(a.exports,function(e){var i=t[n][1][e];return r(i?i:e)},a,a.exports)}return e[n].exports}for(var i="function"==typeof require&&require,o=0;o<n.length;o++)r(n[o]);return r}({1:[function(t,e,n){function r(t,e){if(t.indexOf)return t.indexOf(e);for(var n=0;n<t.length;n++)if(e===t[n])return n;return-1}var i=t("__browserify_process");i.EventEmitter||(i.EventEmitter=function(){});var o=n.EventEmitter=i.EventEmitter,u="function"==typeof Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},a=10;o.prototype.setMaxListeners=function(t){this._events||(this._events={}),this._events.maxListeners=t},o.prototype.emit=function(t){if("error"===t&&(!this._events||!this._events.error||u(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var e=this._events[t];if(!e)return!1;if("function"==typeof e){switch(arguments.length){case 1:e.call(this);break;case 2:e.call(this,arguments[1]);break;case 3:e.call(this,arguments[1],arguments[2]);break;default:var n=Array.prototype.slice.call(arguments,1);e.apply(this,n)}return!0}if(u(e)){for(var n=Array.prototype.slice.call(arguments,1),r=e.slice(),i=0,o=r.length;o>i;i++)r[i].apply(this,n);return!0}return!1},o.prototype.addListener=function(t,e){if("function"!=typeof e)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",t,e),this._events[t])if(u(this._events[t])){if(!this._events[t].warned){var n;n=void 0!==this._events.maxListeners?this._events.maxListeners:a,n&&n>0&&this._events[t].length>n&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),console.trace())}this._events[t].push(e)}else this._events[t]=[this._events[t],e];else this._events[t]=e;return this},o.prototype.on=o.prototype.addListener,o.prototype.once=function(t,e){var n=this;return n.on(t,function r(){n.removeListener(t,r),e.apply(this,arguments)}),this},o.prototype.removeListener=function(t,e){if("function"!=typeof e)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[t])return this;var n=this._events[t];if(u(n)){var i=r(n,e);if(0>i)return this;n.splice(i,1),0==n.length&&delete this._events[t]}else this._events[t]===e&&delete this._events[t];return this},o.prototype.removeAllListeners=function(t){return 0===arguments.length?(this._events={},this):(t&&this._events&&this._events[t]&&(this._events[t]=null),this)},o.prototype.listeners=function(t){return this._events||(this._events={}),this._events[t]||(this._events[t]=[]),u(this._events[t])||(this._events[t]=[this._events[t]]),this._events[t]},o.listenerCount=function(t,e){var n;return n=t._events&&t._events[e]?"function"==typeof t._events[e]?1:t._events[e].length:0}},{__browserify_process:3}],2:[function(t,e,n){function r(t){return Array.isArray(t)||"object"==typeof t&&"[object Array]"===Object.prototype.toString.call(t)}function i(t){"object"==typeof t&&"[object RegExp]"===Object.prototype.toString.call(t)}function o(t){return"object"==typeof t&&"[object Date]"===Object.prototype.toString.call(t)}t("events"),n.isArray=r,n.isDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)},n.isRegExp=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},n.print=function(){},n.puts=function(){},n.debug=function(){},n.inspect=function(t,e,s,c){function f(t,s){if(t&&"function"==typeof t.inspect&&t!==n&&(!t.constructor||t.constructor.prototype!==t))return t.inspect(s);switch(typeof t){case"undefined":return h("undefined","undefined");case"string":var c="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return h(c,"string");case"number":return h(""+t,"number");case"boolean":return h(""+t,"boolean")}if(null===t)return h("null","null");var p=u(t),y=e?a(t):p;if("function"==typeof t&&0===y.length){if(i(t))return h(""+t,"regexp");var d=t.name?": "+t.name:"";return h("[Function"+d+"]","special")}if(o(t)&&0===y.length)return h(t.toUTCString(),"date");var g,v,m;if(r(t)?(v="Array",m=["[","]"]):(v="Object",m=["{","}"]),"function"==typeof t){var b=t.name?": "+t.name:"";g=i(t)?" "+t:" [Function"+b+"]"}else g="";if(o(t)&&(g=" "+t.toUTCString()),0===y.length)return m[0]+g+m[1];if(0>s)return i(t)?h(""+t,"regexp"):h("[Object]","special");l.push(t);var w=y.map(function(e){var n,i;if(t.__lookupGetter__&&(t.__lookupGetter__(e)?i=t.__lookupSetter__(e)?h("[Getter/Setter]","special"):h("[Getter]","special"):t.__lookupSetter__(e)&&(i=h("[Setter]","special"))),p.indexOf(e)<0&&(n="["+e+"]"),i||(l.indexOf(t[e])<0?(i=null===s?f(t[e]):f(t[e],s-1),i.indexOf("\n")>-1&&(i=r(t)?i.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+i.split("\n").map(function(t){return" "+t}).join("\n"))):i=h("[Circular]","special")),"undefined"==typeof n){if("Array"===v&&e.match(/^\d+$/))return i;n=JSON.stringify(""+e),n.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(n=n.substr(1,n.length-2),n=h(n,"name")):(n=n.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),n=h(n,"string"))}return n+": "+i});l.pop();var k=0,x=w.reduce(function(t,e){return k++,e.indexOf("\n")>=0&&k++,t+e.length+1},0);return w=x>50?m[0]+(""===g?"":g+"\n ")+" "+w.join(",\n ")+" "+m[1]:m[0]+g+" "+w.join(", ")+" "+m[1]}var l=[],h=function(t,e){var n={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},r={special:"cyan",number:"blue","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[e];return r?"["+n[r][0]+"m"+t+"["+n[r][1]+"m":t};return c||(h=function(t){return t}),f(t,"undefined"==typeof s?2:s)},n.log=function(){},n.pump=null;var u=Object.keys||function(t){var e=[];for(var n in t)e.push(n);return e},a=Object.getOwnPropertyNames||function(t){var e=[];for(var n in t)Object.hasOwnProperty.call(t,n)&&e.push(n);return e},s=Object.create||function(t,e){var n;if(null===t)n={__proto__:null};else{if("object"!=typeof t)throw new TypeError("typeof prototype["+typeof t+"] != 'object'");var r=function(){};r.prototype=t,n=new r,n.__proto__=t}return"undefined"!=typeof e&&Object.defineProperties&&Object.defineProperties(n,e),n};n.inherits=function(t,e){t.super_=e,t.prototype=s(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})};var c=/%[sdj%]/g;n.format=function(t){if("string"!=typeof t){for(var e=[],r=0;r<arguments.length;r++)e.push(n.inspect(arguments[r]));return e.join(" ")}for(var r=1,i=arguments,o=i.length,u=String(t).replace(c,function(t){if("%%"===t)return"%";if(r>=o)return t;switch(t){case"%s":return String(i[r++]);case"%d":return Number(i[r++]);case"%j":return JSON.stringify(i[r++]);default:return t}}),a=i[r];o>r;a=i[++r])u+=null===a||"object"!=typeof a?" "+a:" "+n.inspect(a);return u}},{events:1}],3:[function(t,e){var n=e.exports={};n.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var n=[];return window.addEventListener("message",function(t){if(t.source===window&&"process-tick"===t.data&&(t.stopPropagation(),n.length>0)){var e=n.shift();e()}},!0),function(t){n.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,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")}},{}],4:[function(t,e){function n(t,e,n){this.db=t,this.query=e||{},n&&(this.execFn=n)}var r=t("./model");n.prototype.limit=function(t){return this._limit=t,this},n.prototype.skip=function(t){return this._skip=t,this},n.prototype.sort=function(t){return this._sort=t,this},n.prototype._exec=function(t){var e,n,i,o=this.db.getCandidates(this.query),u=[],a=0,s=0,c=this;try{for(e=0;e<o.length;e+=1)if(r.match(o[e],this.query))if(this._sort)u.push(o[e]);else if(this._skip&&this._skip>s)s+=1;else if(u.push(o[e]),a+=1,this._limit&&this._limit<=a)break}catch(f){return t(f)}if(this._sort){n=Object.keys(this._sort);var l=[];for(e=0;e<n.length;e++)i=n[e],l.push({key:i,direction:c._sort[i]});u.sort(function(t,e){var n,i,o;for(o=0;o<l.length;o++)if(n=l[o],i=n.direction*r.compareThings(r.getDotValue(t,n.key),r.getDotValue(e,n.key)),0!==i)return i;return 0});var h=this._limit||u.length,p=this._skip||0;u=u.slice(p,p+h)}return this.execFn?this.execFn(null,u,t):t(null,u)},n.prototype.exec=function(){this.db.executor.push({"this":this,fn:this._exec,arguments:arguments})},e.exports=n},{"./model":9}],5:[function(t,e){function n(t){for(var e,e,n=new Array(t),r=0;t>r;r++)0==(3&r)&&(e=4294967296*Math.random()),n[r]=255&e>>>((3&r)<<3);return n}function r(t){function e(t){return o[63&t>>18]+o[63&t>>12]+o[63&t>>6]+o[63&t]}var n,r,i,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=t.length%3,a="";for(i=0,r=t.length-u;r>i;i+=3)n=(t[i]<<16)+(t[i+1]<<8)+t[i+2],a+=e(n);switch(u){case 1:n=t[t.length-1],a+=o[n>>2],a+=o[63&n<<4],a+="==";break;case 2:n=(t[t.length-2]<<8)+t[t.length-1],a+=o[n>>10],a+=o[63&n>>4],a+=o[63&n<<2],a+="="}return a}function i(t){return r(n(Math.ceil(Math.max(8,2*t)))).replace(/[+\/]/g,"").slice(0,t)}e.exports.uid=i},{}],6:[function(t,e){function n(t){var e;"string"==typeof t?(e=t,this.inMemoryOnly=!1):(t=t||{},e=t.filename,this.inMemoryOnly=t.inMemoryOnly||!1,this.autoload=t.autoload||!1),e&&"string"==typeof e&&0!==e.length?this.filename=e:(this.filename=null,this.inMemoryOnly=!0),this.persistence=new f({db:this,nodeWebkitAppName:t.nodeWebkitAppName}),this.executor=new u,this.inMemoryOnly&&(this.executor.ready=!0),this.indexes={},this.indexes._id=new a({fieldName:"_id",unique:!0}),this.autoload&&this.loadDatabase(t.onload||function(t){if(t)throw t})}var r=t("./customUtils"),i=t("./model"),o=t("async"),u=t("./executor"),a=t("./indexes"),s=t("util"),c=t("underscore"),f=t("./persistence"),l=t("./cursor");n.prototype.loadDatabase=function(){this.executor.push({"this":this.persistence,fn:this.persistence.loadDatabase,arguments:arguments},!0)},n.prototype.getAllData=function(){return this.indexes._id.getAll()},n.prototype.resetIndexes=function(t){var e=this;Object.keys(this.indexes).forEach(function(n){e.indexes[n].reset(t)})},n.prototype.ensureIndex=function(t,e){var n=e||function(){};if(t=t||{},!t.fieldName)return n({missingFieldName:!0});if(this.indexes[t.fieldName])return n(null);this.indexes[t.fieldName]=new a(t);try{this.indexes[t.fieldName].insert(this.getAllData())}catch(r){return delete this.indexes[t.fieldName],n(r)}this.persistence.persistNewState([{$$indexCreated:t}],function(t){return t?n(t):n(null)})},n.prototype.removeIndex=function(t,e){var n=e||function(){};delete this.indexes[t],this.persistence.persistNewState([{$$indexRemoved:t}],function(t){return t?n(t):n(null)})},n.prototype.addToIndexes=function(t){var e,n,r,i=Object.keys(this.indexes);for(e=0;e<i.length;e+=1)try{this.indexes[i[e]].insert(t)}catch(o){n=e,r=o;break}if(r){for(e=0;n>e;e+=1)this.indexes[i[e]].remove(t);throw r}},n.prototype.removeFromIndexes=function(t){var e=this;Object.keys(this.indexes).forEach(function(n){e.indexes[n].remove(t)})},n.prototype.updateIndexes=function(t,e){var n,r,i,o=Object.keys(this.indexes);for(n=0;n<o.length;n+=1)try{this.indexes[o[n]].update(t,e)}catch(u){r=n,i=u;break}if(i){for(n=0;r>n;n+=1)this.indexes[o[n]].revertUpdate(t,e);throw i}},n.prototype.getCandidates=function(t){var e,n=Object.keys(this.indexes);return e=[],Object.keys(t).forEach(function(n){("string"==typeof t[n]||"number"==typeof t[n]||"boolean"==typeof t[n]||s.isDate(t[n])||null===t[n])&&e.push(n)}),e=c.intersection(e,n),e.length>0?this.indexes[e[0]].getMatching(t[e[0]]):(e=[],Object.keys(t).forEach(function(n){t[n]&&t[n].hasOwnProperty("$in")&&e.push(n)}),e=c.intersection(e,n),e.length>0?this.indexes[e[0]].getMatching(t[e[0]].$in):(e=[],Object.keys(t).forEach(function(n){t[n]&&(t[n].hasOwnProperty("$lt")||t[n].hasOwnProperty("$lte")||t[n].hasOwnProperty("$gt")||t[n].hasOwnProperty("$gte"))&&e.push(n)}),e=c.intersection(e,n),e.length>0?this.indexes[e[0]].getBetweenBounds(t[e[0]]):this.getAllData()))},n.prototype._insert=function(t,e){var n=e||function(){};try{this._insertInCache(t)}catch(r){return n(r)}this.persistence.persistNewState(s.isArray(t)?t:[t],function(e){return e?n(e):n(null,t)})},n.prototype.prepareDocumentForInsertion=function(t){var e,n=this;return s.isArray(t)?(e=[],t.forEach(function(t){e.push(n.prepareDocumentForInsertion(t))})):(t._id=t._id||r.uid(16),e=i.deepCopy(t),i.checkObject(e)),e},n.prototype._insertInCache=function(t){s.isArray(t)?this._insertMultipleDocsInCache(t):this.addToIndexes(this.prepareDocumentForInsertion(t))},n.prototype._insertMultipleDocsInCache=function(t){var e,n,r,i=this.prepareDocumentForInsertion(t);for(e=0;e<i.length;e+=1)try{this.addToIndexes(i[e])}catch(o){r=o,n=e;break}if(r){for(e=0;n>e;e+=1)this.removeFromIndexes(i[e]);throw r}},n.prototype.insert=function(){this.executor.push({"this":this,fn:this._insert,arguments:arguments})},n.prototype.count=function(t,e){var n=new l(this,t,function(t,e,n){return t?n(t):n(null,e.length)});return"function"!=typeof e?n:(n.exec(e),void 0)},n.prototype.find=function(t,e){var n=new l(this,t,function(t,e,n){var r,o=[];if(t)return n(t);for(r=0;r<e.length;r+=1)o.push(i.deepCopy(e[r]));return n(null,o)});return"function"!=typeof e?n:(n.exec(e),void 0)},n.prototype.findOne=function(t,e){var n=new l(this,t,function(t,e,n){return t?n(t):1===e.length?n(null,i.deepCopy(e[0])):n(null,null)});return n.limit(1),"function"!=typeof e?n:(n.exec(e),void 0)},n.prototype._update=function(t,e,n,r){var u,a,s,f,h=this,p=0;"function"==typeof n&&(r=n,n={}),u=r||function(){},a=void 0!==n.multi?n.multi:!1,s=void 0!==n.upsert?n.upsert:!1,o.waterfall([function(n){if(!s)return n();var r=new l(h,t);r.limit(1)._exec(function(r,o){return r?u(r):1===o.length?n():h._insert(i.modify(t,e),function(t,e){return t?u(t):u(null,1,e)})})},function(){var n,r=h.getCandidates(t),o=[];try{for(f=0;f<r.length;f+=1)i.match(r[f],t)&&(a||0===p)&&(p+=1,n=i.modify(r[f],e),o.push({oldDoc:r[f],newDoc:n}))}catch(s){return u(s)}try{h.updateIndexes(o)}catch(s){return u(s)}h.persistence.persistNewState(c.pluck(o,"newDoc"),function(t){return t?u(t):u(null,p)})}])},n.prototype.update=function(){this.executor.push({"this":this,fn:this._update,arguments:arguments})},n.prototype._remove=function(t,e,n){var r,o,u=this,a=0,s=[],c=this.getCandidates(t);"function"==typeof e&&(n=e,e={}),r=n||function(){},o=void 0!==e.multi?e.multi:!1;try{c.forEach(function(e){i.match(e,t)&&(o||0===a)&&(a+=1,s.push({$$deleted:!0,_id:e._id}),u.removeFromIndexes(e))})}catch(f){return r(f)}u.persistence.persistNewState(s,function(t){return t?r(t):r(null,a)})},n.prototype.remove=function(){this.executor.push({"this":this,fn:this._remove,arguments:arguments})},e.exports=n},{"./cursor":4,"./customUtils":5,"./executor":7,"./indexes":8,"./model":9,"./persistence":10,async:11,underscore:16,util:2}],7:[function(t,e){function n(){this.buffer=[],this.ready=!1,this.queue=i.queue(function(t,e){var n,i,o=t.arguments[t.arguments.length-1],u=[];for(i=0;i<t.arguments.length;i+=1)u.push(t.arguments[i]);"function"==typeof o?(n=function(){r.nextTick(e),o.apply(null,arguments)},u[u.length-1]=n):(n=function(){e()},u.push(n)),t.fn.apply(t.this,u)},1)}var r=t("__browserify_process"),i=t("async");n.prototype.push=function(t,e){this.ready||e?this.queue.push(t):this.buffer.push(t)},n.prototype.processBuffer=function(){var t;for(this.ready=!0,t=0;t<this.buffer.length;t+=1)this.queue.push(this.buffer[t]);this.buffer=[]},e.exports=n},{__browserify_process:3,async:11}],8:[function(t,e){function n(t,e){return t===e}function r(t){return null===t?"$null":"string"==typeof t?"$string"+t:"boolean"==typeof t?"$boolean"+t:"number"==typeof t?"$number"+t:c.isArray(t)?"$date"+t.getTime():t}function i(t){this.fieldName=t.fieldName,this.unique=t.unique||!1,this.sparse=t.sparse||!1,this.treeOptions={unique:this.unique,compareKeys:a.compareThings,checkValueEquality:n},this.reset()}function o(t,e){var n;for(n=0;n<e.length;n+=1)t.push(e[n])}var u=t("binary-search-tree").AVLTree,a=t("./model"),s=t("underscore"),c=t("util");i.prototype.reset=function(t){this.tree=new u(this.treeOptions),t&&this.insert(t)},i.prototype.insert=function(t){var e,n,i,o,u;if(c.isArray(t))return this.insertMultipleDocs(t),void 0;if(e=a.getDotValue(t,this.fieldName),void 0!==e||!this.sparse)if(c.isArray(e)){for(n=s.uniq(e,r),i=0;i<n.length;i+=1)try{this.tree.insert(n[i],t)}catch(f){u=f,o=i;break}if(u){for(i=0;o>i;i+=1)this.tree.delete(n[i],t);throw u}}else this.tree.insert(e,t)},i.prototype.insertMultipleDocs=function(t){var e,n,r;for(e=0;e<t.length;e+=1)try{this.insert(t[e])}catch(i){n=i,r=e;break}if(n){for(e=0;r>e;e+=1)this.remove(t[e]);throw n}},i.prototype.remove=function(t){var e,n=this;return c.isArray(t)?(t.forEach(function(t){n.remove(t)}),void 0):(e=a.getDotValue(t,this.fieldName),void 0===e&&this.sparse||(c.isArray(e)?s.uniq(e,r).forEach(function(e){n.tree.delete(e,t)}):this.tree.delete(e,t)),void 0)},i.prototype.update=function(t,e){if(c.isArray(t))return this.updateMultipleDocs(t),void 0;this.remove(t);try{this.insert(e)}catch(n){throw this.insert(t),n}},i.prototype.updateMultipleDocs=function(t){var e,n,r;for(e=0;e<t.length;e+=1)this.remove(t[e].oldDoc);for(e=0;e<t.length;e+=1)try{this.insert(t[e].newDoc)}catch(i){r=i,n=e;break}if(r){for(e=0;n>e;e+=1)this.remove(t[e].newDoc);for(e=0;e<t.length;e+=1)this.insert(t[e].oldDoc);throw r}},i.prototype.revertUpdate=function(t,e){var n=[];c.isArray(t)?(t.forEach(function(t){n.push({oldDoc:t.newDoc,newDoc:t.oldDoc})}),this.update(n)):this.update(e,t)},i.prototype.getMatching=function(t){var e,n=this;return c.isArray(t)?(e=[],t.forEach(function(t){o(e,n.getMatching(t))}),e):this.tree.search(t)},i.prototype.getBetweenBounds=function(t){return this.tree.betweenBounds(t)},i.prototype.getAll=function(){var t=[];return this.tree.executeOnEveryNode(function(e){var n;for(n=0;n<e.data.length;n+=1)t.push(e.data[n])}),t},e.exports=i},{"./model":9,"binary-search-tree":12,underscore:16,util:2}],9:[function(t,e){function n(t,e){if(!("$"!==t[0]||"$$date"===t&&"number"==typeof e||"$$deleted"===t&&e===!0||"$$indexCreated"===t||"$$indexRemoved"===t))throw"Field names cannot begin with the $ character";if(-1!==t.indexOf("."))throw"Field names cannot contain a ."}function r(t){w.isArray(t)&&t.forEach(function(t){r(t)}),"object"==typeof t&&null!==t&&Object.keys(t).forEach(function(e){n(e,t[e]),r(t[e])})}function i(t){var e;return Date.prototype.toJSON=m,e=JSON.stringify(t,function(t,e){return n(t,e),void 0===typeof e?null:"string"==typeof e||"number"==typeof e||"boolean"==typeof e||null===e?e:e}),Date.prototype.toJSON=b,e}function o(t){return JSON.parse(t,function(t,e){return"$$date"===t?new Date(e):"string"==typeof e||"number"==typeof e||"boolean"==typeof e||null===e?e:e&&e.$$date?e.$$date:e})}function u(t){var e;return"boolean"==typeof t||"number"==typeof t||"string"==typeof t||null===t||w.isDate(t)?t:w.isArray(t)?(e=[],t.forEach(function(t){e.push(t)}),e):"object"==typeof t?(e={},Object.keys(t).forEach(function(n){e[n]=u(t[n])}),e):void 0}function a(t){return"boolean"==typeof t||"number"==typeof t||"string"==typeof t||null===t||w.isDate(t)||w.isArray(t)}function s(t,e){return e>t?-1:t>e?1:0}function c(t,e){var n,r;for(n=0;n<Math.min(t.length,e.length);n+=1)if(r=f(t[n],e[n]),0!==r)return r;return s(t.length,e.length)}function f(t,e){var n,r,i,o;if(void 0===t)return void 0===e?0:-1;if(void 0===e)return void 0===t?0:1;if(null===t)return null===e?0:-1;if(null===e)return null===t?0:1;if("number"==typeof t)return"number"==typeof e?s(t,e):-1;if("number"==typeof e)return"number"==typeof t?s(t,e):1;if("string"==typeof t)return"string"==typeof e?s(t,e):-1;if("string"==typeof e)return"string"==typeof t?s(t,e):1;if("boolean"==typeof t)return"boolean"==typeof e?s(t,e):-1;if("boolean"==typeof e)return"boolean"==typeof t?s(t,e):1;if(w.isDate(t))return w.isDate(e)?s(t.getTime(),e.getTime()):-1;if(w.isDate(e))return w.isDate(t)?s(t.getTime(),e.getTime()):1;if(w.isArray(t))return w.isArray(e)?c(t,e):-1;if(w.isArray(e))return w.isArray(t)?c(t,e):1;for(n=Object.keys(t).sort(),r=Object.keys(e).sort(),o=0;o<Math.min(n.length,r.length);o+=1)if(i=f(t[n[o]],e[r[o]]),0!==i)return i;return s(n.length,r.length)}function l(t){return function(e,n,r){var i="string"==typeof n?n.split("."):n;1===i.length?_[t](e,n,r):(e[i[0]]=e[i[0]]||{},x[t](e[i[0]],i.slice(1),r))}}function h(t,e){var n,i,o=Object.keys(e),a=k.map(o,function(t){return t[0]}),s=k.filter(a,function(t){return"$"===t});if(-1!==o.indexOf("_id")&&e._id!==t._id)throw"You cannot change a document's _id";if(0!==s.length&&s.length!==a.length)throw"You cannot mix modifiers and normal fields";if(0===s.length?(n=u(e),n._id=t._id):(i=k.uniq(o),n=u(t),i.forEach(function(t){var r;if(!x[t])throw"Unknown modifier "+t;try{r=Object.keys(e[t])}catch(i){throw"Modifier "+t+"'s argument must be an object"}r.forEach(function(r){x[t](n,r,e[t][r])})})),r(n),t._id!==n._id)throw"You can't change a document's _id";return n}function p(t,e){var n,r,i="string"==typeof e?e.split("."):e;if(!t)return void 0;if(0===i.length)return t;if(1===i.length)return t[i[0]];if(w.isArray(t[i[0]])){if(n=parseInt(i[1],10),"number"==typeof n&&!isNaN(n))return p(t[i[0]][n],i.slice(2));for(r=new Array,n=0;n<t[i[0]].length;n+=1)r.push(p(t[i[0]][n],i.slice(1)));return r}return p(t[i[0]],i.slice(1))}function y(t,e){var n,r,i;if(null===t||"string"==typeof t||"boolean"==typeof t||"number"==typeof t||null===e||"string"==typeof e||"boolean"==typeof e||"number"==typeof e)return t===e;if(w.isDate(t)||w.isDate(e))return w.isDate(t)&&w.isDate(e)&&t.getTime()===e.getTime();if(w.isArray(t)||w.isArray(e)||void 0===t||void 0===e)return!1;try{n=Object.keys(t),r=Object.keys(e)}catch(o){return!1}if(n.length!==r.length)return!1;for(i=0;i<n.length;i+=1){if(-1===r.indexOf(n[i]))return!1;if(!y(t[n[i]],e[n[i]]))return!1}return!0}function d(t,e){return"string"==typeof t||"number"==typeof t||w.isDate(t)||"string"==typeof e||"number"==typeof e||w.isDate(e)?typeof t!=typeof e?!1:!0:!1}function g(t,e){var n,r,i,o;if(a(t)||a(e))return v({needAKey:t},"needAKey",e);for(n=Object.keys(e),o=0;o<n.length;o+=1)if(r=n[o],i=e[r],"$"===r[0]){if(!A[r])throw"Unknown logical operator "+r;if(!A[r](t,i))return!1}else if(!v(t,r,i))return!1;return!0}function v(t,e,n,r){var i,o,u,a,s=p(t,e);if(w.isArray(s)&&!r){if(null!==n&&"object"==typeof n&&!w.isRegExp(n))for(o=Object.keys(n),i=0;i<o.length;i+=1)if($[o[i]])return v(t,e,n,!0);for(i=0;i<s.length;i+=1)if(v({k:s[i]},"k",n))return!0;return!1}if(null!==n&&"object"==typeof n&&!w.isRegExp(n)){if(o=Object.keys(n),u=k.map(o,function(t){return t[0]}),a=k.filter(u,function(t){return"$"===t}),0!==a.length&&a.length!==u.length)throw"You cannot mix operators and normal fields";if(a.length>0){for(i=0;i<o.length;i+=1){if(!O[o[i]])throw"Unknown comparison function "+o[i];if(!O[o[i]](s,n[o[i]]))return!1}return!0}}return w.isRegExp(n)?O.$regex(s,n):y(s,n)?!0:!1}var m=function(){return{$$date:this.getTime()}},b=Date.prototype.toJSON,w=t("util"),k=t("underscore"),x={},_={},O={},A={},$={};_.$set=function(t,e,n){t[e]=n},_.$unset=function(t,e){delete t[e]},_.$push=function(t,e,n){if(t.hasOwnProperty(e)||(t[e]=[]),!w.isArray(t[e]))throw"Can't $push an element on non-array values";if(null!==n&&"object"==typeof n&&n.$each){if(Object.keys(n).length>1)throw"Can't use another field in conjunction with $each";if(!w.isArray(n.$each))throw"$each requires an array value";n.$each.forEach(function(n){t[e].push(n)})}else t[e].push(n)},_.$addToSet=function(t,e,n){var r=!0;if(t.hasOwnProperty(e)||(t[e]=[]),!w.isArray(t[e]))throw"Can't $addToSet an element on non-array values";if(null!==n&&"object"==typeof n&&n.$each){if(Object.keys(n).length>1)throw"Can't use another field in conjunction with $each";if(!w.isArray(n.$each))throw"$each requires an array value";n.$each.forEach(function(n){_.$addToSet(t,e,n)})}else t[e].forEach(function(t){0===f(t,n)&&(r=!1)}),r&&t[e].push(n)},_.$pop=function(t,e,n){if(!w.isArray(t[e]))throw"Can't $pop an element from non-array values";if("number"!=typeof n)throw n+" isn't an integer, can't use it with $pop";0!==n&&(t[e]=n>0?t[e].slice(0,t[e].length-1):t[e].slice(1))},_.$pull=function(t,e,n){var r,i;if(!w.isArray(t[e]))throw"Can't $pull an element from non-array values";for(r=t[e],i=r.length-1;i>=0;i-=1)g(r[i],n)&&r.splice(i,1)},_.$inc=function(t,e,n){if("number"!=typeof n)throw n+" must be a number";if("number"!=typeof t[e]){if(k.has(t,e))throw"Don't use the $inc modifier on non-number fields";t[e]=n}else t[e]+=n},Object.keys(_).forEach(function(t){x[t]=l(t)}),O.$lt=function(t,e){return d(t,e)&&e>t},O.$lte=function(t,e){return d(t,e)&&e>=t},O.$gt=function(t,e){return d(t,e)&&t>e},O.$gte=function(t,e){return d(t,e)&&t>=e},O.$ne=function(t,e){return t?!y(t,e):!0},O.$in=function(t,e){var n;if(!w.isArray(e))throw"$in operator called with a non-array";for(n=0;n<e.length;n+=1)if(y(t,e[n]))return!0;return!1},O.$nin=function(t,e){if(!w.isArray(e))throw"$nin operator called with a non-array";return!O.$in(t,e)},O.$regex=function(t,e){if(!w.isRegExp(e))throw"$regex operator called with non regular expression";return"string"!=typeof t?!1:e.test(t)},O.$exists=function(t,e){return e=e||""===e?!0:!1,void 0===t?!e:e},O.$size=function(t,e){if(!w.isArray(t))return!1;if(0!==e%1)throw"$size operator called without an integer";return t.length==e},$.$size=!0,A.$or=function(t,e){var n;if(!w.isArray(e))throw"$or operator used without an array";for(n=0;n<e.length;n+=1)if(g(t,e[n]))return!0;return!1},A.$and=function(t,e){var n;if(!w.isArray(e))throw"$and operator used without an array";for(n=0;n<e.length;n+=1)if(!g(t,e[n]))return!1;return!0},A.$not=function(t,e){return!g(t,e)},A.$where=function(t,e){var n;if(!k.isFunction(e))throw"$where operator used without a function";if(n=e.call(t),!k.isBoolean(n))throw"$where function must return boolean";return n},e.exports.serialize=i,e.exports.deserialize=o,e.exports.deepCopy=u,e.exports.checkObject=r,e.exports.isPrimitiveType=a,e.exports.modify=h,e.exports.getDotValue=p,e.exports.match=g,e.exports.areThingsEqual=y,e.exports.compareThings=f},{underscore:16,util:2}],10:[function(t,e){function n(t){this.db=t.db,this.db.inMemoryOnly=!0,this.db.filename=null,this.inMemoryOnly=!0}n.prototype.persistNewState=function(t,e){return e?e():void 0},n.prototype.loadDatabase=function(t){return t?t():void 0},e.exports=n},{}],11:[function(e,n){var r=e("__browserify_process");!function(){function e(t){var e=!1;return function(){if(e)throw new Error("Callback was already called.");e=!0,t.apply(i,arguments)}}var i,o,u={};i=this,null!=i&&(o=i.async),u.noConflict=function(){return i.async=o,u};var a=function(t,e){if(t.forEach)return t.forEach(e);for(var n=0;n<t.length;n+=1)e(t[n],n,t)},s=function(t,e){if(t.map)return t.map(e);var n=[];return a(t,function(t,r,i){n.push(e(t,r,i))}),n},c=function(t,e,n){return t.reduce?t.reduce(e,n):(a(t,function(t,r,i){n=e(n,t,r,i)}),n)},f=function(t){if(Object.keys)return Object.keys(t);var e=[];for(var n in t)t.hasOwnProperty(n)&&e.push(n);return e};"undefined"!=typeof r&&r.nextTick?(u.nextTick=r.nextTick,u.setImmediate="undefined"!=typeof setImmediate?function(t){setImmediate(t)}:u.nextTick):"function"==typeof setImmediate?(u.nextTick=function(t){setImmediate(t)},u.setImmediate=u.nextTick):(u.nextTick=function(t){setTimeout(t,0)},u.setImmediate=u.nextTick),u.each=function(t,n,r){if(r=r||function(){},!t.length)return r();var i=0;a(t,function(o){n(o,e(function(e){e?(r(e),r=function(){}):(i+=1,i>=t.length&&r(null))}))})},u.forEach=u.each,u.eachSeries=function(t,e,n){if(n=n||function(){},!t.length)return n();var r=0,i=function(){e(t[r],function(e){e?(n(e),n=function(){}):(r+=1,r>=t.length?n(null):i())})};i()},u.forEachSeries=u.eachSeries,u.eachLimit=function(t,e,n,r){var i=l(e);i.apply(null,[t,n,r])},u.forEachLimit=u.eachLimit;var l=function(t){return function(e,n,r){if(r=r||function(){},!e.length||0>=t)return r();var i=0,o=0,u=0;!function a(){if(i>=e.length)return r();for(;t>u&&o<e.length;)o+=1,u+=1,n(e[o-1],function(t){t?(r(t),r=function(){}):(i+=1,u-=1,i>=e.length?r():a())})}()}},h=function(t){return function(){var e=Array.prototype.slice.call(arguments);return t.apply(null,[u.each].concat(e))}},p=function(t,e){return function(){var n=Array.prototype.slice.call(arguments);return e.apply(null,[l(t)].concat(n))}},y=function(t){return function(){var e=Array.prototype.slice.call(arguments);return t.apply(null,[u.eachSeries].concat(e))}},d=function(t,e,n,r){var i=[];e=s(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n,r){i[t.index]=r,e(n)})},function(t){r(t,i)})};u.map=h(d),u.mapSeries=y(d),u.mapLimit=function(t,e,n,r){return g(e)(t,n,r)};var g=function(t){return p(t,d)};u.reduce=function(t,e,n,r){u.eachSeries(t,function(t,r){n(e,t,function(t,n){e=n,r(t)})},function(t){r(t,e)})},u.inject=u.reduce,u.foldl=u.reduce,u.reduceRight=function(t,e,n,r){var i=s(t,function(t){return t}).reverse();u.reduce(i,e,n,r)},u.foldr=u.reduceRight;var v=function(t,e,n,r){var i=[];e=s(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n){n&&i.push(t),e()})},function(){r(s(i.sort(function(t,e){return t.index-e.index}),function(t){return t.value}))})};u.filter=h(v),u.filterSeries=y(v),u.select=u.filter,u.selectSeries=u.filterSeries;var m=function(t,e,n,r){var i=[];e=s(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n){n||i.push(t),e()})},function(){r(s(i.sort(function(t,e){return t.index-e.index}),function(t){return t.value}))})};u.reject=h(m),u.rejectSeries=y(m);var b=function(t,e,n,r){t(e,function(t,e){n(t,function(n){n?(r(t),r=function(){}):e()})},function(){r()})};u.detect=h(b),u.detectSeries=y(b),u.some=function(t,e,n){u.each(t,function(t,r){e(t,function(t){t&&(n(!0),n=function(){}),r()})},function(){n(!1)})},u.any=u.some,u.every=function(t,e,n){u.each(t,function(t,r){e(t,function(t){t||(n(!1),n=function(){}),r()})},function(){n(!0)})},u.all=u.every,u.sortBy=function(t,e,n){u.map(t,function(t,n){e(t,function(e,r){e?n(e):n(null,{value:t,criteria:r})})},function(t,e){if(t)return n(t);var r=function(t,e){var n=t.criteria,r=e.criteria;return r>n?-1:n>r?1:0};n(null,s(e.sort(r),function(t){return t.value}))})},u.auto=function(t,e){e=e||function(){};var n=f(t);if(!n.length)return e(null);var r={},i=[],o=function(t){i.unshift(t)},s=function(t){for(var e=0;e<i.length;e+=1)if(i[e]===t)return i.splice(e,1),void 0},l=function(){a(i.slice(0),function(t){t()})};o(function(){f(r).length===n.length&&(e(null,r),e=function(){})}),a(n,function(n){var i=t[n]instanceof Function?[t[n]]:t[n],h=function(t){var i=Array.prototype.slice.call(arguments,1);if(i.length<=1&&(i=i[0]),t){var o={};a(f(r),function(t){o[t]=r[t]}),o[n]=i,e(t,o),e=function(){}}else r[n]=i,u.setImmediate(l)},p=i.slice(0,Math.abs(i.length-1))||[],y=function(){return c(p,function(t,e){return t&&r.hasOwnProperty(e)},!0)&&!r.hasOwnProperty(n)};if(y())i[i.length-1](h,r);else{var d=function(){y()&&(s(d),i[i.length-1](h,r))};o(d)
}})},u.waterfall=function(t,e){if(e=e||function(){},t.constructor!==Array){var n=new Error("First argument to waterfall must be an array of functions");return e(n)}if(!t.length)return e();var r=function(t){return function(n){if(n)e.apply(null,arguments),e=function(){};else{var i=Array.prototype.slice.call(arguments,1),o=t.next();o?i.push(r(o)):i.push(e),u.setImmediate(function(){t.apply(null,i)})}}};r(u.iterator(t))()};var w=function(t,e,n){if(n=n||function(){},e.constructor===Array)t.map(e,function(t,e){t&&t(function(t){var n=Array.prototype.slice.call(arguments,1);n.length<=1&&(n=n[0]),e.call(null,t,n)})},n);else{var r={};t.each(f(e),function(t,n){e[t](function(e){var i=Array.prototype.slice.call(arguments,1);i.length<=1&&(i=i[0]),r[t]=i,n(e)})},function(t){n(t,r)})}};u.parallel=function(t,e){w({map:u.map,each:u.each},t,e)},u.parallelLimit=function(t,e,n){w({map:g(e),each:l(e)},t,n)},u.series=function(t,e){if(e=e||function(){},t.constructor===Array)u.mapSeries(t,function(t,e){t&&t(function(t){var n=Array.prototype.slice.call(arguments,1);n.length<=1&&(n=n[0]),e.call(null,t,n)})},e);else{var n={};u.eachSeries(f(t),function(e,r){t[e](function(t){var i=Array.prototype.slice.call(arguments,1);i.length<=1&&(i=i[0]),n[e]=i,r(t)})},function(t){e(t,n)})}},u.iterator=function(t){var e=function(n){var r=function(){return t.length&&t[n].apply(null,arguments),r.next()};return r.next=function(){return n<t.length-1?e(n+1):null},r};return e(0)},u.apply=function(t){var e=Array.prototype.slice.call(arguments,1);return function(){return t.apply(null,e.concat(Array.prototype.slice.call(arguments)))}};var k=function(t,e,n,r){var i=[];t(e,function(t,e){n(t,function(t,n){i=i.concat(n||[]),e(t)})},function(t){r(t,i)})};u.concat=h(k),u.concatSeries=y(k),u.whilst=function(t,e,n){t()?e(function(r){return r?n(r):(u.whilst(t,e,n),void 0)}):n()},u.doWhilst=function(t,e,n){t(function(r){return r?n(r):(e()?u.doWhilst(t,e,n):n(),void 0)})},u.until=function(t,e,n){t()?n():e(function(r){return r?n(r):(u.until(t,e,n),void 0)})},u.doUntil=function(t,e,n){t(function(r){return r?n(r):(e()?n():u.doUntil(t,e,n),void 0)})},u.queue=function(t,n){function r(t,e,r,i){e.constructor!==Array&&(e=[e]),a(e,function(e){var o={data:e,callback:"function"==typeof i?i:null};r?t.tasks.unshift(o):t.tasks.push(o),t.saturated&&t.tasks.length===n&&t.saturated(),u.setImmediate(t.process)})}void 0===n&&(n=1);var i=0,o={tasks:[],concurrency:n,saturated:null,empty:null,drain:null,push:function(t,e){r(o,t,!1,e)},unshift:function(t,e){r(o,t,!0,e)},process:function(){if(i<o.concurrency&&o.tasks.length){var n=o.tasks.shift();o.empty&&0===o.tasks.length&&o.empty(),i+=1;var r=function(){i-=1,n.callback&&n.callback.apply(n,arguments),o.drain&&0===o.tasks.length+i&&o.drain(),o.process()},u=e(r);t(n.data,u)}},length:function(){return o.tasks.length},running:function(){return i}};return o},u.cargo=function(t,e){var n=!1,r=[],i={tasks:r,payload:e,saturated:null,empty:null,drain:null,push:function(t,n){t.constructor!==Array&&(t=[t]),a(t,function(t){r.push({data:t,callback:"function"==typeof n?n:null}),i.saturated&&r.length===e&&i.saturated()}),u.setImmediate(i.process)},process:function o(){if(!n){if(0===r.length)return i.drain&&i.drain(),void 0;var u="number"==typeof e?r.splice(0,e):r.splice(0),c=s(u,function(t){return t.data});i.empty&&i.empty(),n=!0,t(c,function(){n=!1;var t=arguments;a(u,function(e){e.callback&&e.callback.apply(null,t)}),o()})}},length:function(){return r.length},running:function(){return n}};return i};var x=function(t){return function(e){var n=Array.prototype.slice.call(arguments,1);e.apply(null,n.concat([function(e){var n=Array.prototype.slice.call(arguments,1);"undefined"!=typeof console&&(e?console.error&&console.error(e):console[t]&&a(n,function(e){console[t](e)}))}]))}};u.log=x("log"),u.dir=x("dir"),u.memoize=function(t,e){var n={},r={};e=e||function(t){return t};var i=function(){var i=Array.prototype.slice.call(arguments),o=i.pop(),u=e.apply(null,i);u in n?o.apply(null,n[u]):u in r?r[u].push(o):(r[u]=[o],t.apply(null,i.concat([function(){n[u]=arguments;var t=r[u];delete r[u];for(var e=0,i=t.length;i>e;e++)t[e].apply(null,arguments)}])))};return i.memo=n,i.unmemoized=t,i},u.unmemoize=function(t){return function(){return(t.unmemoized||t).apply(null,arguments)}},u.times=function(t,e,n){for(var r=[],i=0;t>i;i++)r.push(i);return u.map(r,e,n)},u.timesSeries=function(t,e,n){for(var r=[],i=0;t>i;i++)r.push(i);return u.mapSeries(r,e,n)},u.compose=function(){var t=Array.prototype.reverse.call(arguments);return function(){var e=this,n=Array.prototype.slice.call(arguments),r=n.pop();u.reduce(t,n,function(t,n,r){n.apply(e,t.concat([function(){var t=arguments[0],e=Array.prototype.slice.call(arguments,1);r(t,e)}]))},function(t,n){r.apply(e,[t].concat(n))})}};var _=function(t,e){var n=function(){var n=this,r=Array.prototype.slice.call(arguments),i=r.pop();return t(e,function(t,e){t.apply(n,r.concat([e]))},i)};if(arguments.length>2){var r=Array.prototype.slice.call(arguments,2);return n.apply(this,r)}return n};u.applyEach=h(_),u.applyEachSeries=y(_),u.forever=function(t,e){function n(r){if(r){if(e)return e(r);throw r}t(n)}n()},"undefined"!=typeof t&&t.amd?t([],function(){return u}):"undefined"!=typeof n&&n.exports?n.exports=u:i.async=u}()},{__browserify_process:3}],12:[function(t,e){e.exports.BinarySearchTree=t("./lib/bst"),e.exports.AVLTree=t("./lib/avltree")},{"./lib/avltree":13,"./lib/bst":14}],13:[function(t,e){function n(t){this.tree=new r(t)}function r(t){t=t||{},this.left=null,this.right=null,this.parent=void 0!==t.parent?t.parent:null,t.hasOwnProperty("key")&&(this.key=t.key),this.data=t.hasOwnProperty("value")?[t.value]:[],this.unique=t.unique||!1,this.compareKeys=t.compareKeys||o.defaultCompareKeysFunction,this.checkValueEquality=t.checkValueEquality||o.defaultCheckValueEquality}var i=t("./bst"),o=t("./customUtils"),u=t("util");t("underscore"),u.inherits(r,i),n._AVLTree=r,r.prototype.checkHeightCorrect=function(){var t,e;if(this.hasOwnProperty("key")){if(this.left&&void 0===this.left.height)throw"Undefined height for node "+this.left.key;if(this.right&&void 0===this.right.height)throw"Undefined height for node "+this.right.key;if(void 0===this.height)throw"Undefined height for node "+this.key;if(t=this.left?this.left.height:0,e=this.right?this.right.height:0,this.height!==1+Math.max(t,e))throw"Height constraint failed for node "+this.key;this.left&&this.left.checkHeightCorrect(),this.right&&this.right.checkHeightCorrect()}},r.prototype.balanceFactor=function(){var t=this.left?this.left.height:0,e=this.right?this.right.height:0;return t-e},r.prototype.checkBalanceFactors=function(){if(Math.abs(this.balanceFactor())>1)throw"Tree is unbalanced at node "+this.key;this.left&&this.left.checkBalanceFactors(),this.right&&this.right.checkBalanceFactors()},r.prototype.checkIsAVLT=function(){r.super_.prototype.checkIsBST.call(this),this.checkHeightCorrect(),this.checkBalanceFactors()},n.prototype.checkIsAVLT=function(){this.tree.checkIsAVLT()},r.prototype.rightRotation=function(){var t,e,n,r,i=this,o=this.left;return o?(t=o.right,i.parent?(o.parent=i.parent,i.parent.left===i?i.parent.left=o:i.parent.right=o):o.parent=null,o.right=i,i.parent=o,i.left=t,t&&(t.parent=i),e=o.left?o.left.height:0,n=t?t.height:0,r=i.right?i.right.height:0,i.height=Math.max(n,r)+1,o.height=Math.max(e,i.height)+1,o):this},r.prototype.leftRotation=function(){var t,e,n,r,i=this,o=this.right;return o?(t=o.left,i.parent?(o.parent=i.parent,i.parent.left===i?i.parent.left=o:i.parent.right=o):o.parent=null,o.left=i,i.parent=o,i.right=t,t&&(t.parent=i),e=i.left?i.left.height:0,n=t?t.height:0,r=o.right?o.right.height:0,i.height=Math.max(e,n)+1,o.height=Math.max(r,i.height)+1,o):this},r.prototype.rightTooSmall=function(){return this.balanceFactor()<=1?this:(this.left.balanceFactor()<0&&this.left.leftRotation(),this.rightRotation())},r.prototype.leftTooSmall=function(){return this.balanceFactor()>=-1?this:(this.right.balanceFactor()>0&&this.right.rightRotation(),this.leftRotation())},r.prototype.rebalanceAlongPath=function(t){var e,n,r=this;if(!this.hasOwnProperty("key"))return delete this.height,this;for(n=t.length-1;n>=0;n-=1)t[n].height=1+Math.max(t[n].left?t[n].left.height:0,t[n].right?t[n].right.height:0),t[n].balanceFactor()>1&&(e=t[n].rightTooSmall(),0===n&&(r=e)),t[n].balanceFactor()<-1&&(e=t[n].leftTooSmall(),0===n&&(r=e));return r},r.prototype.insert=function(t,e){var n=[],r=this;if(!this.hasOwnProperty("key"))return this.key=t,this.data.push(e),this.height=1,this;for(;;){if(0===r.compareKeys(r.key,t)){if(r.unique)throw{message:"Can't insert key "+t+", it violates the unique constraint",key:t,errorType:"uniqueViolated"};return r.data.push(e),this}if(n.push(r),r.compareKeys(t,r.key)<0){if(!r.left){n.push(r.createLeftChild({key:t,value:e}));break}r=r.left}else{if(!r.right){n.push(r.createRightChild({key:t,value:e}));break}r=r.right}}return this.rebalanceAlongPath(n)},n.prototype.insert=function(t,e){var n=this.tree.insert(t,e);n&&(this.tree=n)},r.prototype.delete=function(t,e){var n,r=[],i=this,o=[];if(!this.hasOwnProperty("key"))return this;for(;;){if(0===i.compareKeys(t,i.key))break;if(o.push(i),i.compareKeys(t,i.key)<0){if(!i.left)return this;i=i.left}else{if(!i.right)return this;i=i.right}}if(i.data.length>1&&e)return i.data.forEach(function(t){i.checkValueEquality(t,e)||r.push(t)}),i.data=r,this;if(!i.left&&!i.right)return i===this?(delete i.key,i.data=[],delete i.height,this):(i.parent.left===i?i.parent.left=null:i.parent.right=null,this.rebalanceAlongPath(o));if(!i.left||!i.right)return n=i.left?i.left:i.right,i===this?(n.parent=null,n):(i.parent.left===i?(i.parent.left=n,n.parent=i.parent):(i.parent.right=n,n.parent=i.parent),this.rebalanceAlongPath(o));if(o.push(i),n=i.left,!n.right)return i.key=n.key,i.data=n.data,i.left=n.left,n.left&&(n.left.parent=i),this.rebalanceAlongPath(o);for(;;){if(!n.right)break;o.push(n),n=n.right}return i.key=n.key,i.data=n.data,n.parent.right=n.left,n.left&&(n.left.parent=n.parent),this.rebalanceAlongPath(o)},n.prototype.delete=function(t,e){var n=this.tree.delete(t,e);n&&(this.tree=n)},["getNumberOfKeys","search","betweenBounds","prettyPrint","executeOnEveryNode"].forEach(function(t){n.prototype[t]=function(){return this.tree[t].apply(this.tree,arguments)}}),e.exports=n},{"./bst":14,"./customUtils":15,underscore:16,util:2}],14:[function(t,e){function n(t){t=t||{},this.left=null,this.right=null,this.parent=void 0!==t.parent?t.parent:null,t.hasOwnProperty("key")&&(this.key=t.key),this.data=t.hasOwnProperty("value")?[t.value]:[],this.unique=t.unique||!1,this.compareKeys=t.compareKeys||i.defaultCompareKeysFunction,this.checkValueEquality=t.checkValueEquality||i.defaultCheckValueEquality}function r(t,e){var n;for(n=0;n<e.length;n+=1)t.push(e[n])}var i=t("./customUtils");n.prototype.getMaxKeyDescendant=function(){return this.right?this.right.getMaxKeyDescendant():this},n.prototype.getMaxKey=function(){return this.getMaxKeyDescendant().key},n.prototype.getMinKeyDescendant=function(){return this.left?this.left.getMinKeyDescendant():this},n.prototype.getMinKey=function(){return this.getMinKeyDescendant().key},n.prototype.checkAllNodesFullfillCondition=function(t){this.hasOwnProperty("key")&&(t(this.key,this.data),this.left&&this.left.checkAllNodesFullfillCondition(t),this.right&&this.right.checkAllNodesFullfillCondition(t))},n.prototype.checkNodeOrdering=function(){var t=this;this.hasOwnProperty("key")&&(this.left&&(this.left.checkAllNodesFullfillCondition(function(e){if(t.compareKeys(e,t.key)>=0)throw"Tree with root "+t.key+" is not a binary search tree"}),this.left.checkNodeOrdering()),this.right&&(this.right.checkAllNodesFullfillCondition(function(e){if(t.compareKeys(e,t.key)<=0)throw"Tree with root "+t.key+" is not a binary search tree"}),this.right.checkNodeOrdering()))},n.prototype.checkInternalPointers=function(){if(this.left){if(this.left.parent!==this)throw"Parent pointer broken for key "+this.key;this.left.checkInternalPointers()}if(this.right){if(this.right.parent!==this)throw"Parent pointer broken for key "+this.key;this.right.checkInternalPointers()}},n.prototype.checkIsBST=function(){if(this.checkNodeOrdering(),this.checkInternalPointers(),this.parent)throw"The root shouldn't have a parent"},n.prototype.getNumberOfKeys=function(){var t;return this.hasOwnProperty("key")?(t=1,this.left&&(t+=this.left.getNumberOfKeys()),this.right&&(t+=this.right.getNumberOfKeys()),t):0},n.prototype.createSimilar=function(t){return t=t||{},t.unique=this.unique,t.compareKeys=this.compareKeys,t.checkValueEquality=this.checkValueEquality,new this.constructor(t)},n.prototype.createLeftChild=function(t){var e=this.createSimilar(t);return e.parent=this,this.left=e,e},n.prototype.createRightChild=function(t){var e=this.createSimilar(t);return e.parent=this,this.right=e,e},n.prototype.insert=function(t,e){if(!this.hasOwnProperty("key"))return this.key=t,this.data.push(e),void 0;if(0===this.compareKeys(this.key,t)){if(this.unique)throw{message:"Can't insert key "+t+", it violates the unique constraint",key:t,errorType:"uniqueViolated"};return this.data.push(e),void 0}this.compareKeys(t,this.key)<0?this.left?this.left.insert(t,e):this.createLeftChild({key:t,value:e}):this.right?this.right.insert(t,e):this.createRightChild({key:t,value:e})},n.prototype.search=function(t){return this.hasOwnProperty("key")?0===this.compareKeys(this.key,t)?this.data:this.compareKeys(t,this.key)<0?this.left?this.left.search(t):[]:this.right?this.right.search(t):[]:[]},n.prototype.getLowerBoundMatcher=function(t){var e=this;return t.hasOwnProperty("$gt")||t.hasOwnProperty("$gte")?t.hasOwnProperty("$gt")&&t.hasOwnProperty("$gte")?0===e.compareKeys(t.$gte,t.$gt)?function(n){return e.compareKeys(n,t.$gt)>0}:e.compareKeys(t.$gte,t.$gt)>0?function(n){return e.compareKeys(n,t.$gte)>=0}:function(n){return e.compareKeys(n,t.$gt)>0}:t.hasOwnProperty("$gt")?function(n){return e.compareKeys(n,t.$gt)>0}:function(n){return e.compareKeys(n,t.$gte)>=0}:function(){return!0}},n.prototype.getUpperBoundMatcher=function(t){var e=this;return t.hasOwnProperty("$lt")||t.hasOwnProperty("$lte")?t.hasOwnProperty("$lt")&&t.hasOwnProperty("$lte")?0===e.compareKeys(t.$lte,t.$lt)?function(n){return e.compareKeys(n,t.$lt)<0}:e.compareKeys(t.$lte,t.$lt)<0?function(n){return e.compareKeys(n,t.$lte)<=0}:function(n){return e.compareKeys(n,t.$lt)<0}:t.hasOwnProperty("$lt")?function(n){return e.compareKeys(n,t.$lt)<0}:function(n){return e.compareKeys(n,t.$lte)<=0}:function(){return!0}},n.prototype.betweenBounds=function(t,e,n){var i=[];return this.hasOwnProperty("key")?(e=e||this.getLowerBoundMatcher(t),n=n||this.getUpperBoundMatcher(t),e(this.key)&&this.left&&r(i,this.left.betweenBounds(t,e,n)),e(this.key)&&n(this.key)&&r(i,this.data),n(this.key)&&this.right&&r(i,this.right.betweenBounds(t,e,n)),i):[]},n.prototype.deleteIfLeaf=function(){return this.left||this.right?!1:this.parent?(this.parent.left===this?this.parent.left=null:this.parent.right=null,!0):(delete this.key,this.data=[],!0)},n.prototype.deleteIfOnlyOneChild=function(){var t;return this.left&&!this.right&&(t=this.left),!this.left&&this.right&&(t=this.right),t?this.parent?(this.parent.left===this?(this.parent.left=t,t.parent=this.parent):(this.parent.right=t,t.parent=this.parent),!0):(this.key=t.key,this.data=t.data,this.left=null,t.left&&(this.left=t.left,t.left.parent=this),this.right=null,t.right&&(this.right=t.right,t.right.parent=this),!0):!1},n.prototype.delete=function(t,e){var n,r=[],i=this;if(this.hasOwnProperty("key")){if(this.compareKeys(t,this.key)<0)return this.left&&this.left.delete(t,e),void 0;if(this.compareKeys(t,this.key)>0)return this.right&&this.right.delete(t,e),void 0;if(0!==!this.compareKeys(t,this.key))return this.data.length>1&&e?(this.data.forEach(function(t){i.checkValueEquality(t,e)||r.push(t)}),i.data=r,void 0):(this.deleteIfLeaf()||this.deleteIfOnlyOneChild()||(Math.random()>=.5?(n=this.left.getMaxKeyDescendant(),this.key=n.key,this.data=n.data,this===n.parent?(this.left=n.left,n.left&&(n.left.parent=n.parent)):(n.parent.right=n.left,n.left&&(n.left.parent=n.parent))):(n=this.right.getMinKeyDescendant(),this.key=n.key,this.data=n.data,this===n.parent?(this.right=n.right,n.right&&(n.right.parent=n.parent)):(n.parent.left=n.right,n.right&&(n.right.parent=n.parent)))),void 0)}},n.prototype.executeOnEveryNode=function(t){this.left&&this.left.executeOnEveryNode(t),t(this),this.right&&this.right.executeOnEveryNode(t)},n.prototype.prettyPrint=function(t,e){e=e||"",console.log(e+"* "+this.key),t&&console.log(e+"* "+this.data),(this.left||this.right)&&(this.left?this.left.prettyPrint(t,e+" "):console.log(e+" *"),this.right?this.right.prettyPrint(t,e+" "):console.log(e+" *"))},e.exports=n},{"./customUtils":15}],15:[function(t,e){function n(t){var e,r;return 0===t?[]:1===t?[0]:(e=n(t-1),r=Math.floor(Math.random()*t),e.splice(r,0,t-1),e)}function r(t,e){if(e>t)return-1;if(t>e)return 1;if(t===e)return 0;throw{message:"Couldn't compare elements",a:t,b:e}}function i(t,e){return t===e}e.exports.getRandomArray=n,e.exports.defaultCompareKeysFunction=r,e.exports.defaultCheckValueEquality=i},{}],16:[function(t,e,n){!function(){var t=this,r=t._,i={},o=Array.prototype,u=Object.prototype,a=Function.prototype,s=o.push,c=o.slice,f=o.concat,l=u.toString,h=u.hasOwnProperty,p=o.forEach,y=o.map,d=o.reduce,g=o.reduceRight,v=o.filter,m=o.every,b=o.some,w=o.indexOf,k=o.lastIndexOf,x=Array.isArray,_=Object.keys,O=a.bind,A=function(t){return t instanceof A?t:this instanceof A?(this._wrapped=t,void 0):new A(t)};"undefined"!=typeof n?("undefined"!=typeof e&&e.exports&&(n=e.exports=A),n._=A):t._=A,A.VERSION="1.4.4";var $=A.each=A.forEach=function(t,e,n){if(null!=t)if(p&&t.forEach===p)t.forEach(e,n);else if(t.length===+t.length){for(var r=0,o=t.length;o>r;r++)if(e.call(n,t[r],r,t)===i)return}else for(var u in t)if(A.has(t,u)&&e.call(n,t[u],u,t)===i)return};A.map=A.collect=function(t,e,n){var r=[];return null==t?r:y&&t.map===y?t.map(e,n):($(t,function(t,i,o){r[r.length]=e.call(n,t,i,o)}),r)};var j="Reduce of empty array with no initial value";A.reduce=A.foldl=A.inject=function(t,e,n,r){var i=arguments.length>2;if(null==t&&(t=[]),d&&t.reduce===d)return r&&(e=A.bind(e,r)),i?t.reduce(e,n):t.reduce(e);if($(t,function(t,o,u){i?n=e.call(r,n,t,o,u):(n=t,i=!0)}),!i)throw new TypeError(j);return n},A.reduceRight=A.foldr=function(t,e,n,r){var i=arguments.length>2;if(null==t&&(t=[]),g&&t.reduceRight===g)return r&&(e=A.bind(e,r)),i?t.reduceRight(e,n):t.reduceRight(e);var o=t.length;if(o!==+o){var u=A.keys(t);o=u.length}if($(t,function(a,s,c){s=u?u[--o]:--o,i?n=e.call(r,n,t[s],s,c):(n=t[s],i=!0)}),!i)throw new TypeError(j);return n},A.find=A.detect=function(t,e,n){var r;return E(t,function(t,i,o){return e.call(n,t,i,o)?(r=t,!0):void 0}),r},A.filter=A.select=function(t,e,n){var r=[];return null==t?r:v&&t.filter===v?t.filter(e,n):($(t,function(t,i,o){e.call(n,t,i,o)&&(r[r.length]=t)}),r)},A.reject=function(t,e,n){return A.filter(t,function(t,r,i){return!e.call(n,t,r,i)},n)},A.every=A.all=function(t,e,n){e||(e=A.identity);var r=!0;return null==t?r:m&&t.every===m?t.every(e,n):($(t,function(t,o,u){return(r=r&&e.call(n,t,o,u))?void 0:i}),!!r)};var E=A.some=A.any=function(t,e,n){e||(e=A.identity);var r=!1;return null==t?r:b&&t.some===b?t.some(e,n):($(t,function(t,o,u){return r||(r=e.call(n,t,o,u))?i:void 0}),!!r)};A.contains=A.include=function(t,e){return null==t?!1:w&&t.indexOf===w?-1!=t.indexOf(e):E(t,function(t){return t===e})},A.invoke=function(t,e){var n=c.call(arguments,2),r=A.isFunction(e);return A.map(t,function(t){return(r?e:t[e]).apply(t,n)})},A.pluck=function(t,e){return A.map(t,function(t){return t[e]})},A.where=function(t,e,n){return A.isEmpty(e)?n?null:[]:A[n?"find":"filter"](t,function(t){for(var n in e)if(e[n]!==t[n])return!1;return!0})},A.findWhere=function(t,e){return A.where(t,e,!0)},A.max=function(t,e,n){if(!e&&A.isArray(t)&&t[0]===+t[0]&&t.length<65535)return Math.max.apply(Math,t);if(!e&&A.isEmpty(t))return-1/0;var r={computed:-1/0,value:-1/0};return $(t,function(t,i,o){var u=e?e.call(n,t,i,o):t;u>=r.computed&&(r={value:t,computed:u})}),r.value},A.min=function(t,e,n){if(!e&&A.isArray(t)&&t[0]===+t[0]&&t.length<65535)return Math.min.apply(Math,t);if(!e&&A.isEmpty(t))return 1/0;var r={computed:1/0,value:1/0};return $(t,function(t,i,o){var u=e?e.call(n,t,i,o):t;u<r.computed&&(r={value:t,computed:u})}),r.value},A.shuffle=function(t){var e,n=0,r=[];return $(t,function(t){e=A.random(n++),r[n-1]=r[e],r[e]=t}),r};var S=function(t){return A.isFunction(t)?t:function(e){return e[t]}};A.sortBy=function(t,e,n){var r=S(e);return A.pluck(A.map(t,function(t,e,i){return{value:t,index:e,criteria:r.call(n,t,e,i)}}).sort(function(t,e){var n=t.criteria,r=e.criteria;if(n!==r){if(n>r||void 0===n)return 1;if(r>n||void 0===r)return-1}return t.index<e.index?-1:1}),"value")};var D=function(t,e,n,r){var i={},o=S(e||A.identity);return $(t,function(e,u){var a=o.call(n,e,u,t);r(i,a,e)}),i};A.groupBy=function(t,e,n){return D(t,e,n,function(t,e,n){(A.has(t,e)?t[e]:t[e]=[]).push(n)})},A.countBy=function(t,e,n){return D(t,e,n,function(t,e){A.has(t,e)||(t[e]=0),t[e]++})},A.sortedIndex=function(t,e,n,r){n=null==n?A.identity:S(n);for(var i=n.call(r,e),o=0,u=t.length;u>o;){var a=o+u>>>1;n.call(r,t[a])<i?o=a+1:u=a}return o},A.toArray=function(t){return t?A.isArray(t)?c.call(t):t.length===+t.length?A.map(t,A.identity):A.values(t):[]},A.size=function(t){return null==t?0:t.length===+t.length?t.length:A.keys(t).length},A.first=A.head=A.take=function(t,e,n){return null==t?void 0:null==e||n?t[0]:c.call(t,0,e)},A.initial=function(t,e,n){return c.call(t,0,t.length-(null==e||n?1:e))},A.last=function(t,e,n){return null==t?void 0:null==e||n?t[t.length-1]:c.call(t,Math.max(t.length-e,0))},A.rest=A.tail=A.drop=function(t,e,n){return c.call(t,null==e||n?1:e)},A.compact=function(t){return A.filter(t,A.identity)};var M=function(t,e,n){return $(t,function(t){A.isArray(t)?e?s.apply(n,t):M(t,e,n):n.push(t)}),n};A.flatten=function(t,e){return M(t,e,[])},A.without=function(t){return A.difference(t,c.call(arguments,1))},A.uniq=A.unique=function(t,e,n,r){A.isFunction(e)&&(r=n,n=e,e=!1);var i=n?A.map(t,n,r):t,o=[],u=[];return $(i,function(n,r){(e?r&&u[u.length-1]===n:A.contains(u,n))||(u.push(n),o.push(t[r]))}),o},A.union=function(){return A.uniq(f.apply(o,arguments))},A.intersection=function(t){var e=c.call(arguments,1);return A.filter(A.uniq(t),function(t){return A.every(e,function(e){return A.indexOf(e,t)>=0})})},A.difference=function(t){var e=f.apply(o,c.call(arguments,1));return A.filter(t,function(t){return!A.contains(e,t)})},A.zip=function(){for(var t=c.call(arguments),e=A.max(A.pluck(t,"length")),n=new Array(e),r=0;e>r;r++)n[r]=A.pluck(t,""+r);return n},A.object=function(t,e){if(null==t)return{};for(var n={},r=0,i=t.length;i>r;r++)e?n[t[r]]=e[r]:n[t[r][0]]=t[r][1];return n},A.indexOf=function(t,e,n){if(null==t)return-1;var r=0,i=t.length;if(n){if("number"!=typeof n)return r=A.sortedIndex(t,e),t[r]===e?r:-1;r=0>n?Math.max(0,i+n):n}if(w&&t.indexOf===w)return t.indexOf(e,n);for(;i>r;r++)if(t[r]===e)return r;return-1},A.lastIndexOf=function(t,e,n){if(null==t)return-1;var r=null!=n;if(k&&t.lastIndexOf===k)return r?t.lastIndexOf(e,n):t.lastIndexOf(e);for(var i=r?n:t.length;i--;)if(t[i]===e)return i;return-1},A.range=function(t,e,n){arguments.length<=1&&(e=t||0,t=0),n=arguments[2]||1;for(var r=Math.max(Math.ceil((e-t)/n),0),i=0,o=new Array(r);r>i;)o[i++]=t,t+=n;return o},A.bind=function(t,e){if(t.bind===O&&O)return O.apply(t,c.call(arguments,1));var n=c.call(arguments,2);return function(){return t.apply(e,n.concat(c.call(arguments)))}},A.partial=function(t){var e=c.call(arguments,1);return function(){return t.apply(this,e.concat(c.call(arguments)))}},A.bindAll=function(t){var e=c.call(arguments,1);return 0===e.length&&(e=A.functions(t)),$(e,function(e){t[e]=A.bind(t[e],t)}),t},A.memoize=function(t,e){var n={};return e||(e=A.identity),function(){var r=e.apply(this,arguments);return A.has(n,r)?n[r]:n[r]=t.apply(this,arguments)}},A.delay=function(t,e){var n=c.call(arguments,2);return setTimeout(function(){return t.apply(null,n)},e)},A.defer=function(t){return A.delay.apply(A,[t,1].concat(c.call(arguments,1)))},A.throttle=function(t,e){var n,r,i,o,u=0,a=function(){u=new Date,i=null,o=t.apply(n,r)};return function(){var s=new Date,c=e-(s-u);return n=this,r=arguments,0>=c?(clearTimeout(i),i=null,u=s,o=t.apply(n,r)):i||(i=setTimeout(a,c)),o}},A.debounce=function(t,e,n){var r,i;return function(){var o=this,u=arguments,a=function(){r=null,n||(i=t.apply(o,u))},s=n&&!r;return clearTimeout(r),r=setTimeout(a,e),s&&(i=t.apply(o,u)),i}},A.once=function(t){var e,n=!1;return function(){return n?e:(n=!0,e=t.apply(this,arguments),t=null,e)}},A.wrap=function(t,e){return function(){var n=[t];return s.apply(n,arguments),e.apply(this,n)}},A.compose=function(){var t=arguments;return function(){for(var e=arguments,n=t.length-1;n>=0;n--)e=[t[n].apply(this,e)];return e[0]}},A.after=function(t,e){return 0>=t?e():function(){return--t<1?e.apply(this,arguments):void 0}},A.keys=_||function(t){if(t!==Object(t))throw new TypeError("Invalid object");var e=[];for(var n in t)A.has(t,n)&&(e[e.length]=n);return e},A.values=function(t){var e=[];for(var n in t)A.has(t,n)&&e.push(t[n]);return e},A.pairs=function(t){var e=[];for(var n in t)A.has(t,n)&&e.push([n,t[n]]);return e},A.invert=function(t){var e={};for(var n in t)A.has(t,n)&&(e[t[n]]=n);return e},A.functions=A.methods=function(t){var e=[];for(var n in t)A.isFunction(t[n])&&e.push(n);return e.sort()},A.extend=function(t){return $(c.call(arguments,1),function(e){if(e)for(var n in e)t[n]=e[n]}),t},A.pick=function(t){var e={},n=f.apply(o,c.call(arguments,1));return $(n,function(n){n in t&&(e[n]=t[n])}),e},A.omit=function(t){var e={},n=f.apply(o,c.call(arguments,1));for(var r in t)A.contains(n,r)||(e[r]=t[r]);return e},A.defaults=function(t){return $(c.call(arguments,1),function(e){if(e)for(var n in e)null==t[n]&&(t[n]=e[n])}),t},A.clone=function(t){return A.isObject(t)?A.isArray(t)?t.slice():A.extend({},t):t},A.tap=function(t,e){return e(t),t};var T=function(t,e,n,r){if(t===e)return 0!==t||1/t==1/e;if(null==t||null==e)return t===e;t instanceof A&&(t=t._wrapped),e instanceof A&&(e=e._wrapped);var i=l.call(t);if(i!=l.call(e))return!1;switch(i){case"[object String]":return t==String(e);case"[object Number]":return t!=+t?e!=+e:0==t?1/t==1/e:t==+e;case"[object Date]":case"[object Boolean]":return+t==+e;case"[object RegExp]":return t.source==e.source&&t.global==e.global&&t.multiline==e.multiline&&t.ignoreCase==e.ignoreCase}if("object"!=typeof t||"object"!=typeof e)return!1;for(var o=n.length;o--;)if(n[o]==t)return r[o]==e;n.push(t),r.push(e);var u=0,a=!0;if("[object Array]"==i){if(u=t.length,a=u==e.length)for(;u--&&(a=T(t[u],e[u],n,r)););}else{var s=t.constructor,c=e.constructor;if(s!==c&&!(A.isFunction(s)&&s instanceof s&&A.isFunction(c)&&c instanceof c))return!1;for(var f in t)if(A.has(t,f)&&(u++,!(a=A.has(e,f)&&T(t[f],e[f],n,r))))break;if(a){for(f in e)if(A.has(e,f)&&!u--)break;a=!u}}return n.pop(),r.pop(),a};A.isEqual=function(t,e){return T(t,e,[],[])},A.isEmpty=function(t){if(null==t)return!0;if(A.isArray(t)||A.isString(t))return 0===t.length;for(var e in t)if(A.has(t,e))return!1;return!0},A.isElement=function(t){return!(!t||1!==t.nodeType)},A.isArray=x||function(t){return"[object Array]"==l.call(t)},A.isObject=function(t){return t===Object(t)},$(["Arguments","Function","String","Number","Date","RegExp"],function(t){A["is"+t]=function(e){return l.call(e)=="[object "+t+"]"}}),A.isArguments(arguments)||(A.isArguments=function(t){return!(!t||!A.has(t,"callee"))}),"function"!=typeof/./&&(A.isFunction=function(t){return"function"==typeof t}),A.isFinite=function(t){return isFinite(t)&&!isNaN(parseFloat(t))},A.isNaN=function(t){return A.isNumber(t)&&t!=+t},A.isBoolean=function(t){return t===!0||t===!1||"[object Boolean]"==l.call(t)},A.isNull=function(t){return null===t},A.isUndefined=function(t){return void 0===t},A.has=function(t,e){return h.call(t,e)},A.noConflict=function(){return t._=r,this},A.identity=function(t){return t},A.times=function(t,e,n){for(var r=Array(t),i=0;t>i;i++)r[i]=e.call(n,i);return r},A.random=function(t,e){return null==e&&(e=t,t=0),t+Math.floor(Math.random()*(e-t+1))};var N={escape:{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;"}};N.unescape=A.invert(N.escape);var P={escape:new RegExp("["+A.keys(N.escape).join("")+"]","g"),unescape:new RegExp("("+A.keys(N.unescape).join("|")+")","g")};A.each(["escape","unescape"],function(t){A[t]=function(e){return null==e?"":(""+e).replace(P[t],function(e){return N[t][e]})}}),A.result=function(t,e){if(null==t)return null;var n=t[e];return A.isFunction(n)?n.call(t):n},A.mixin=function(t){$(A.functions(t),function(e){var n=A[e]=t[e];A.prototype[e]=function(){var t=[this._wrapped];return s.apply(t,arguments),K.call(this,n.apply(A,t))}})};var C=0;A.uniqueId=function(t){var e=++C+"";return t?t+e:e},A.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var I=/(.)^/,F={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},q=/\\|'|\r|\n|\t|\u2028|\u2029/g;A.template=function(t,e,n){var r;n=A.defaults({},n,A.templateSettings);var i=new RegExp([(n.escape||I).source,(n.interpolate||I).source,(n.evaluate||I).source].join("|")+"|$","g"),o=0,u="__p+='";t.replace(i,function(e,n,r,i,a){return u+=t.slice(o,a).replace(q,function(t){return"\\"+F[t]}),n&&(u+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'"),r&&(u+="'+\n((__t=("+r+"))==null?'':__t)+\n'"),i&&(u+="';\n"+i+"\n__p+='"),o=a+e.length,e}),u+="';\n",n.variable||(u="with(obj||{}){\n"+u+"}\n"),u="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+u+"return __p;\n";try{r=new Function(n.variable||"obj","_",u)}catch(a){throw a.source=u,a}if(e)return r(e,A);var s=function(t){return r.call(this,t,A)};return s.source="function("+(n.variable||"obj")+"){\n"+u+"}",s},A.chain=function(t){return A(t).chain()};var K=function(t){return this._chain?A(t).chain():t};A.mixin(A),$(["pop","push","reverse","shift","sort","splice","unshift"],function(t){var e=o[t];A.prototype[t]=function(){var n=this._wrapped;return e.apply(n,arguments),"shift"!=t&&"splice"!=t||0!==n.length||delete n[0],K.call(this,n)}}),$(["concat","join","slice"],function(t){var e=o[t];A.prototype[t]=function(){return K.call(this,e.apply(this._wrapped,arguments))}}),A.extend(A.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this)},{}]},{},[6])(6)});
!function(t){if("function"==typeof bootstrap)bootstrap("nedb",t);else if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeNedb=t}else"undefined"!=typeof window?window.Nedb=t():global.Nedb=t()}(function(){var t;return function(t,e,n){function r(n,o){if(!e[n]){if(!t[n]){var u="function"==typeof require&&require;if(!o&&u)return u(n,!0);if(i)return i(n,!0);throw new Error("Cannot find module '"+n+"'")}var a=e[n]={exports:{}};t[n][0].call(a.exports,function(e){var i=t[n][1][e];return r(i?i:e)},a,a.exports)}return e[n].exports}for(var i="function"==typeof require&&require,o=0;o<n.length;o++)r(n[o]);return r}({1:[function(t,e,n){function r(t,e){if(t.indexOf)return t.indexOf(e);for(var n=0;n<t.length;n++)if(e===t[n])return n;return-1}var i=t("__browserify_process");i.EventEmitter||(i.EventEmitter=function(){});var o=n.EventEmitter=i.EventEmitter,u="function"==typeof Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},a=10;o.prototype.setMaxListeners=function(t){this._events||(this._events={}),this._events.maxListeners=t},o.prototype.emit=function(t){if("error"===t&&(!this._events||!this._events.error||u(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var e=this._events[t];if(!e)return!1;if("function"==typeof e){switch(arguments.length){case 1:e.call(this);break;case 2:e.call(this,arguments[1]);break;case 3:e.call(this,arguments[1],arguments[2]);break;default:var n=Array.prototype.slice.call(arguments,1);e.apply(this,n)}return!0}if(u(e)){for(var n=Array.prototype.slice.call(arguments,1),r=e.slice(),i=0,o=r.length;o>i;i++)r[i].apply(this,n);return!0}return!1},o.prototype.addListener=function(t,e){if("function"!=typeof e)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",t,e),this._events[t])if(u(this._events[t])){if(!this._events[t].warned){var n;n=void 0!==this._events.maxListeners?this._events.maxListeners:a,n&&n>0&&this._events[t].length>n&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),console.trace())}this._events[t].push(e)}else this._events[t]=[this._events[t],e];else this._events[t]=e;return this},o.prototype.on=o.prototype.addListener,o.prototype.once=function(t,e){var n=this;return n.on(t,function r(){n.removeListener(t,r),e.apply(this,arguments)}),this},o.prototype.removeListener=function(t,e){if("function"!=typeof e)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[t])return this;var n=this._events[t];if(u(n)){var i=r(n,e);if(0>i)return this;n.splice(i,1),0==n.length&&delete this._events[t]}else this._events[t]===e&&delete this._events[t];return this},o.prototype.removeAllListeners=function(t){return 0===arguments.length?(this._events={},this):(t&&this._events&&this._events[t]&&(this._events[t]=null),this)},o.prototype.listeners=function(t){return this._events||(this._events={}),this._events[t]||(this._events[t]=[]),u(this._events[t])||(this._events[t]=[this._events[t]]),this._events[t]},o.listenerCount=function(t,e){var n;return n=t._events&&t._events[e]?"function"==typeof t._events[e]?1:t._events[e].length:0}},{__browserify_process:3}],2:[function(t,e,n){function r(t){return Array.isArray(t)||"object"==typeof t&&"[object Array]"===Object.prototype.toString.call(t)}function i(t){"object"==typeof t&&"[object RegExp]"===Object.prototype.toString.call(t)}function o(t){return"object"==typeof t&&"[object Date]"===Object.prototype.toString.call(t)}t("events"),n.isArray=r,n.isDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)},n.isRegExp=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},n.print=function(){},n.puts=function(){},n.debug=function(){},n.inspect=function(t,e,s,c){function f(t,s){if(t&&"function"==typeof t.inspect&&t!==n&&(!t.constructor||t.constructor.prototype!==t))return t.inspect(s);switch(typeof t){case"undefined":return h("undefined","undefined");case"string":var c="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return h(c,"string");case"number":return h(""+t,"number");case"boolean":return h(""+t,"boolean")}if(null===t)return h("null","null");var p=u(t),y=e?a(t):p;if("function"==typeof t&&0===y.length){if(i(t))return h(""+t,"regexp");var d=t.name?": "+t.name:"";return h("[Function"+d+"]","special")}if(o(t)&&0===y.length)return h(t.toUTCString(),"date");var g,v,m;if(r(t)?(v="Array",m=["[","]"]):(v="Object",m=["{","}"]),"function"==typeof t){var b=t.name?": "+t.name:"";g=i(t)?" "+t:" [Function"+b+"]"}else g="";if(o(t)&&(g=" "+t.toUTCString()),0===y.length)return m[0]+g+m[1];if(0>s)return i(t)?h(""+t,"regexp"):h("[Object]","special");l.push(t);var w=y.map(function(e){var n,i;if(t.__lookupGetter__&&(t.__lookupGetter__(e)?i=t.__lookupSetter__(e)?h("[Getter/Setter]","special"):h("[Getter]","special"):t.__lookupSetter__(e)&&(i=h("[Setter]","special"))),p.indexOf(e)<0&&(n="["+e+"]"),i||(l.indexOf(t[e])<0?(i=null===s?f(t[e]):f(t[e],s-1),i.indexOf("\n")>-1&&(i=r(t)?i.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+i.split("\n").map(function(t){return" "+t}).join("\n"))):i=h("[Circular]","special")),"undefined"==typeof n){if("Array"===v&&e.match(/^\d+$/))return i;n=JSON.stringify(""+e),n.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(n=n.substr(1,n.length-2),n=h(n,"name")):(n=n.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),n=h(n,"string"))}return n+": "+i});l.pop();var k=0,x=w.reduce(function(t,e){return k++,e.indexOf("\n")>=0&&k++,t+e.length+1},0);return w=x>50?m[0]+(""===g?"":g+"\n ")+" "+w.join(",\n ")+" "+m[1]:m[0]+g+" "+w.join(", ")+" "+m[1]}var l=[],h=function(t,e){var n={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},r={special:"cyan",number:"blue","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[e];return r?"["+n[r][0]+"m"+t+"["+n[r][1]+"m":t};return c||(h=function(t){return t}),f(t,"undefined"==typeof s?2:s)},n.log=function(){},n.pump=null;var u=Object.keys||function(t){var e=[];for(var n in t)e.push(n);return e},a=Object.getOwnPropertyNames||function(t){var e=[];for(var n in t)Object.hasOwnProperty.call(t,n)&&e.push(n);return e},s=Object.create||function(t,e){var n;if(null===t)n={__proto__:null};else{if("object"!=typeof t)throw new TypeError("typeof prototype["+typeof t+"] != 'object'");var r=function(){};r.prototype=t,n=new r,n.__proto__=t}return"undefined"!=typeof e&&Object.defineProperties&&Object.defineProperties(n,e),n};n.inherits=function(t,e){t.super_=e,t.prototype=s(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})};var c=/%[sdj%]/g;n.format=function(t){if("string"!=typeof t){for(var e=[],r=0;r<arguments.length;r++)e.push(n.inspect(arguments[r]));return e.join(" ")}for(var r=1,i=arguments,o=i.length,u=String(t).replace(c,function(t){if("%%"===t)return"%";if(r>=o)return t;switch(t){case"%s":return String(i[r++]);case"%d":return Number(i[r++]);case"%j":return JSON.stringify(i[r++]);default:return t}}),a=i[r];o>r;a=i[++r])u+=null===a||"object"!=typeof a?" "+a:" "+n.inspect(a);return u}},{events:1}],3:[function(t,e){var n=e.exports={};n.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var n=[];return window.addEventListener("message",function(t){if(t.source===window&&"process-tick"===t.data&&(t.stopPropagation(),n.length>0)){var e=n.shift();e()}},!0),function(t){n.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,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")}},{}],4:[function(t,e){function n(t,e,n){this.db=t,this.query=e||{},n&&(this.execFn=n)}var r=t("./model");n.prototype.limit=function(t){return this._limit=t,this},n.prototype.skip=function(t){return this._skip=t,this},n.prototype.sort=function(t){return this._sort=t,this},n.prototype._exec=function(t){var e,n,i,o=this.db.getCandidates(this.query),u=[],a=0,s=0,c=this;try{for(e=0;e<o.length;e+=1)if(r.match(o[e],this.query))if(this._sort)u.push(o[e]);else if(this._skip&&this._skip>s)s+=1;else if(u.push(o[e]),a+=1,this._limit&&this._limit<=a)break}catch(f){return t(f)}if(this._sort){n=Object.keys(this._sort);var l=[];for(e=0;e<n.length;e++)i=n[e],l.push({key:i,direction:c._sort[i]});u.sort(function(t,e){var n,i,o;for(o=0;o<l.length;o++)if(n=l[o],i=n.direction*r.compareThings(r.getDotValue(t,n.key),r.getDotValue(e,n.key)),0!==i)return i;return 0});var h=this._limit||u.length,p=this._skip||0;u=u.slice(p,p+h)}return this.execFn?this.execFn(null,u,t):t(null,u)},n.prototype.exec=function(){this.db.executor.push({"this":this,fn:this._exec,arguments:arguments})},e.exports=n},{"./model":9}],5:[function(t,e){function n(t){for(var e,e,n=new Array(t),r=0;t>r;r++)0==(3&r)&&(e=4294967296*Math.random()),n[r]=255&e>>>((3&r)<<3);return n}function r(t){function e(t){return o[63&t>>18]+o[63&t>>12]+o[63&t>>6]+o[63&t]}var n,r,i,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=t.length%3,a="";for(i=0,r=t.length-u;r>i;i+=3)n=(t[i]<<16)+(t[i+1]<<8)+t[i+2],a+=e(n);switch(u){case 1:n=t[t.length-1],a+=o[n>>2],a+=o[63&n<<4],a+="==";break;case 2:n=(t[t.length-2]<<8)+t[t.length-1],a+=o[n>>10],a+=o[63&n>>4],a+=o[63&n<<2],a+="="}return a}function i(t){return r(n(Math.ceil(Math.max(8,2*t)))).replace(/[+\/]/g,"").slice(0,t)}e.exports.uid=i},{}],6:[function(t,e){function n(t){var e;"string"==typeof t?(e=t,this.inMemoryOnly=!1):(t=t||{},e=t.filename,this.inMemoryOnly=t.inMemoryOnly||!1,this.autoload=t.autoload||!1),e&&"string"==typeof e&&0!==e.length?this.filename=e:(this.filename=null,this.inMemoryOnly=!0),this.persistence=new f({db:this,nodeWebkitAppName:t.nodeWebkitAppName}),this.executor=new u,this.inMemoryOnly&&(this.executor.ready=!0),this.indexes={},this.indexes._id=new a({fieldName:"_id",unique:!0}),this.autoload&&this.loadDatabase(t.onload||function(t){if(t)throw t})}var r=t("./customUtils"),i=t("./model"),o=t("async"),u=t("./executor"),a=t("./indexes"),s=t("util"),c=t("underscore"),f=t("./persistence"),l=t("./cursor");n.prototype.loadDatabase=function(){this.executor.push({"this":this.persistence,fn:this.persistence.loadDatabase,arguments:arguments},!0)},n.prototype.getAllData=function(){return this.indexes._id.getAll()},n.prototype.resetIndexes=function(t){var e=this;Object.keys(this.indexes).forEach(function(n){e.indexes[n].reset(t)})},n.prototype.ensureIndex=function(t,e){var n=e||function(){};if(t=t||{},!t.fieldName)return n({missingFieldName:!0});if(this.indexes[t.fieldName])return n(null);this.indexes[t.fieldName]=new a(t);try{this.indexes[t.fieldName].insert(this.getAllData())}catch(r){return delete this.indexes[t.fieldName],n(r)}this.persistence.persistNewState([{$$indexCreated:t}],function(t){return t?n(t):n(null)})},n.prototype.removeIndex=function(t,e){var n=e||function(){};delete this.indexes[t],this.persistence.persistNewState([{$$indexRemoved:t}],function(t){return t?n(t):n(null)})},n.prototype.addToIndexes=function(t){var e,n,r,i=Object.keys(this.indexes);for(e=0;e<i.length;e+=1)try{this.indexes[i[e]].insert(t)}catch(o){n=e,r=o;break}if(r){for(e=0;n>e;e+=1)this.indexes[i[e]].remove(t);throw r}},n.prototype.removeFromIndexes=function(t){var e=this;Object.keys(this.indexes).forEach(function(n){e.indexes[n].remove(t)})},n.prototype.updateIndexes=function(t,e){var n,r,i,o=Object.keys(this.indexes);for(n=0;n<o.length;n+=1)try{this.indexes[o[n]].update(t,e)}catch(u){r=n,i=u;break}if(i){for(n=0;r>n;n+=1)this.indexes[o[n]].revertUpdate(t,e);throw i}},n.prototype.getCandidates=function(t){var e,n=Object.keys(this.indexes);return e=[],Object.keys(t).forEach(function(n){("string"==typeof t[n]||"number"==typeof t[n]||"boolean"==typeof t[n]||s.isDate(t[n])||null===t[n])&&e.push(n)}),e=c.intersection(e,n),e.length>0?this.indexes[e[0]].getMatching(t[e[0]]):(e=[],Object.keys(t).forEach(function(n){t[n]&&t[n].hasOwnProperty("$in")&&e.push(n)}),e=c.intersection(e,n),e.length>0?this.indexes[e[0]].getMatching(t[e[0]].$in):(e=[],Object.keys(t).forEach(function(n){t[n]&&(t[n].hasOwnProperty("$lt")||t[n].hasOwnProperty("$lte")||t[n].hasOwnProperty("$gt")||t[n].hasOwnProperty("$gte"))&&e.push(n)}),e=c.intersection(e,n),e.length>0?this.indexes[e[0]].getBetweenBounds(t[e[0]]):this.getAllData()))},n.prototype._insert=function(t,e){var n=e||function(){};try{this._insertInCache(t)}catch(r){return n(r)}this.persistence.persistNewState(s.isArray(t)?t:[t],function(e){return e?n(e):n(null,t)})},n.prototype.prepareDocumentForInsertion=function(t){var e,n=this;return s.isArray(t)?(e=[],t.forEach(function(t){e.push(n.prepareDocumentForInsertion(t))})):(t._id=t._id||r.uid(16),e=i.deepCopy(t),i.checkObject(e)),e},n.prototype._insertInCache=function(t){s.isArray(t)?this._insertMultipleDocsInCache(t):this.addToIndexes(this.prepareDocumentForInsertion(t))},n.prototype._insertMultipleDocsInCache=function(t){var e,n,r,i=this.prepareDocumentForInsertion(t);for(e=0;e<i.length;e+=1)try{this.addToIndexes(i[e])}catch(o){r=o,n=e;break}if(r){for(e=0;n>e;e+=1)this.removeFromIndexes(i[e]);throw r}},n.prototype.insert=function(){this.executor.push({"this":this,fn:this._insert,arguments:arguments})},n.prototype.count=function(t,e){var n=new l(this,t,function(t,e,n){return t?n(t):n(null,e.length)});return"function"!=typeof e?n:(n.exec(e),void 0)},n.prototype.find=function(t,e){var n=new l(this,t,function(t,e,n){var r,o=[];if(t)return n(t);for(r=0;r<e.length;r+=1)o.push(i.deepCopy(e[r]));return n(null,o)});return"function"!=typeof e?n:(n.exec(e),void 0)},n.prototype.findOne=function(t,e){var n=new l(this,t,function(t,e,n){return t?n(t):1===e.length?n(null,i.deepCopy(e[0])):n(null,null)});return n.limit(1),"function"!=typeof e?n:(n.exec(e),void 0)},n.prototype._update=function(t,e,n,r){var u,a,s,f,h=this,p=0;"function"==typeof n&&(r=n,n={}),u=r||function(){},a=void 0!==n.multi?n.multi:!1,s=void 0!==n.upsert?n.upsert:!1,o.waterfall([function(n){if(!s)return n();var r=new l(h,t);r.limit(1)._exec(function(r,o){return r?u(r):1===o.length?n():h._insert(i.modify(t,e),function(t,e){return t?u(t):u(null,1,e)})})},function(){var n,r=h.getCandidates(t),o=[];try{for(f=0;f<r.length;f+=1)i.match(r[f],t)&&(a||0===p)&&(p+=1,n=i.modify(r[f],e),o.push({oldDoc:r[f],newDoc:n}))}catch(s){return u(s)}try{h.updateIndexes(o)}catch(s){return u(s)}h.persistence.persistNewState(c.pluck(o,"newDoc"),function(t){return t?u(t):u(null,p)})}])},n.prototype.update=function(){this.executor.push({"this":this,fn:this._update,arguments:arguments})},n.prototype._remove=function(t,e,n){var r,o,u=this,a=0,s=[],c=this.getCandidates(t);"function"==typeof e&&(n=e,e={}),r=n||function(){},o=void 0!==e.multi?e.multi:!1;try{c.forEach(function(e){i.match(e,t)&&(o||0===a)&&(a+=1,s.push({$$deleted:!0,_id:e._id}),u.removeFromIndexes(e))})}catch(f){return r(f)}u.persistence.persistNewState(s,function(t){return t?r(t):r(null,a)})},n.prototype.remove=function(){this.executor.push({"this":this,fn:this._remove,arguments:arguments})},e.exports=n},{"./cursor":4,"./customUtils":5,"./executor":7,"./indexes":8,"./model":9,"./persistence":10,async:11,underscore:16,util:2}],7:[function(t,e){function n(){this.buffer=[],this.ready=!1,this.queue=i.queue(function(t,e){var n,i,o=t.arguments[t.arguments.length-1],u=[];for(i=0;i<t.arguments.length;i+=1)u.push(t.arguments[i]);"function"==typeof o?(n=function(){r.nextTick(e),o.apply(null,arguments)},u[u.length-1]=n):(n=function(){e()},u.push(n)),t.fn.apply(t.this,u)},1)}var r=t("__browserify_process"),i=t("async");n.prototype.push=function(t,e){this.ready||e?this.queue.push(t):this.buffer.push(t)},n.prototype.processBuffer=function(){var t;for(this.ready=!0,t=0;t<this.buffer.length;t+=1)this.queue.push(this.buffer[t]);this.buffer=[]},e.exports=n},{__browserify_process:3,async:11}],8:[function(t,e){function n(t,e){return t===e}function r(t){return null===t?"$null":"string"==typeof t?"$string"+t:"boolean"==typeof t?"$boolean"+t:"number"==typeof t?"$number"+t:c.isArray(t)?"$date"+t.getTime():t}function i(t){this.fieldName=t.fieldName,this.unique=t.unique||!1,this.sparse=t.sparse||!1,this.treeOptions={unique:this.unique,compareKeys:a.compareThings,checkValueEquality:n},this.reset()}function o(t,e){var n;for(n=0;n<e.length;n+=1)t.push(e[n])}var u=t("binary-search-tree").AVLTree,a=t("./model"),s=t("underscore"),c=t("util");i.prototype.reset=function(t){this.tree=new u(this.treeOptions),t&&this.insert(t)},i.prototype.insert=function(t){var e,n,i,o,u;if(c.isArray(t))return this.insertMultipleDocs(t),void 0;if(e=a.getDotValue(t,this.fieldName),void 0!==e||!this.sparse)if(c.isArray(e)){for(n=s.uniq(e,r),i=0;i<n.length;i+=1)try{this.tree.insert(n[i],t)}catch(f){u=f,o=i;break}if(u){for(i=0;o>i;i+=1)this.tree.delete(n[i],t);throw u}}else this.tree.insert(e,t)},i.prototype.insertMultipleDocs=function(t){var e,n,r;for(e=0;e<t.length;e+=1)try{this.insert(t[e])}catch(i){n=i,r=e;break}if(n){for(e=0;r>e;e+=1)this.remove(t[e]);throw n}},i.prototype.remove=function(t){var e,n=this;return c.isArray(t)?(t.forEach(function(t){n.remove(t)}),void 0):(e=a.getDotValue(t,this.fieldName),void 0===e&&this.sparse||(c.isArray(e)?s.uniq(e,r).forEach(function(e){n.tree.delete(e,t)}):this.tree.delete(e,t)),void 0)},i.prototype.update=function(t,e){if(c.isArray(t))return this.updateMultipleDocs(t),void 0;this.remove(t);try{this.insert(e)}catch(n){throw this.insert(t),n}},i.prototype.updateMultipleDocs=function(t){var e,n,r;for(e=0;e<t.length;e+=1)this.remove(t[e].oldDoc);for(e=0;e<t.length;e+=1)try{this.insert(t[e].newDoc)}catch(i){r=i,n=e;break}if(r){for(e=0;n>e;e+=1)this.remove(t[e].newDoc);for(e=0;e<t.length;e+=1)this.insert(t[e].oldDoc);throw r}},i.prototype.revertUpdate=function(t,e){var n=[];c.isArray(t)?(t.forEach(function(t){n.push({oldDoc:t.newDoc,newDoc:t.oldDoc})}),this.update(n)):this.update(e,t)},i.prototype.getMatching=function(t){var e,n=this;return c.isArray(t)?(e=[],t.forEach(function(t){o(e,n.getMatching(t))}),e):this.tree.search(t)},i.prototype.getBetweenBounds=function(t){return this.tree.betweenBounds(t)},i.prototype.getAll=function(){var t=[];return this.tree.executeOnEveryNode(function(e){var n;for(n=0;n<e.data.length;n+=1)t.push(e.data[n])}),t},e.exports=i},{"./model":9,"binary-search-tree":12,underscore:16,util:2}],9:[function(t,e){function n(t,e){if(!("$"!==t[0]||"$$date"===t&&"number"==typeof e||"$$deleted"===t&&e===!0||"$$indexCreated"===t||"$$indexRemoved"===t))throw"Field names cannot begin with the $ character";if(-1!==t.indexOf("."))throw"Field names cannot contain a ."}function r(t){m.isArray(t)&&t.forEach(function(t){r(t)}),"object"==typeof t&&null!==t&&Object.keys(t).forEach(function(e){n(e,t[e]),r(t[e])})}function i(t){var e;return e=JSON.stringify(t,function(t,e){return n(t,e),void 0===e?void 0:null===e?null:"function"==typeof this[t].getTime?{$$date:this[t].getTime()}:e})}function o(t){return JSON.parse(t,function(t,e){return"$$date"===t?new Date(e):"string"==typeof e||"number"==typeof e||"boolean"==typeof e||null===e?e:e&&e.$$date?e.$$date:e})}function u(t){var e;return"boolean"==typeof t||"number"==typeof t||"string"==typeof t||null===t||m.isDate(t)?t:m.isArray(t)?(e=[],t.forEach(function(t){e.push(t)}),e):"object"==typeof t?(e={},Object.keys(t).forEach(function(n){e[n]=u(t[n])}),e):void 0}function a(t){return"boolean"==typeof t||"number"==typeof t||"string"==typeof t||null===t||m.isDate(t)||m.isArray(t)}function s(t,e){return e>t?-1:t>e?1:0}function c(t,e){var n,r;for(n=0;n<Math.min(t.length,e.length);n+=1)if(r=f(t[n],e[n]),0!==r)return r;return s(t.length,e.length)}function f(t,e){var n,r,i,o;if(void 0===t)return void 0===e?0:-1;if(void 0===e)return void 0===t?0:1;if(null===t)return null===e?0:-1;if(null===e)return null===t?0:1;if("number"==typeof t)return"number"==typeof e?s(t,e):-1;if("number"==typeof e)return"number"==typeof t?s(t,e):1;if("string"==typeof t)return"string"==typeof e?s(t,e):-1;if("string"==typeof e)return"string"==typeof t?s(t,e):1;if("boolean"==typeof t)return"boolean"==typeof e?s(t,e):-1;if("boolean"==typeof e)return"boolean"==typeof t?s(t,e):1;if(m.isDate(t))return m.isDate(e)?s(t.getTime(),e.getTime()):-1;if(m.isDate(e))return m.isDate(t)?s(t.getTime(),e.getTime()):1;if(m.isArray(t))return m.isArray(e)?c(t,e):-1;if(m.isArray(e))return m.isArray(t)?c(t,e):1;for(n=Object.keys(t).sort(),r=Object.keys(e).sort(),o=0;o<Math.min(n.length,r.length);o+=1)if(i=f(t[n[o]],e[r[o]]),0!==i)return i;return s(n.length,r.length)}function l(t){return function(e,n,r){var i="string"==typeof n?n.split("."):n;1===i.length?k[t](e,n,r):(e[i[0]]=e[i[0]]||{},w[t](e[i[0]],i.slice(1),r))}}function h(t,e){var n,i,o=Object.keys(e),a=b.map(o,function(t){return t[0]}),s=b.filter(a,function(t){return"$"===t});if(-1!==o.indexOf("_id")&&e._id!==t._id)throw"You cannot change a document's _id";if(0!==s.length&&s.length!==a.length)throw"You cannot mix modifiers and normal fields";if(0===s.length?(n=u(e),n._id=t._id):(i=b.uniq(o),n=u(t),i.forEach(function(t){var r;if(!w[t])throw"Unknown modifier "+t;try{r=Object.keys(e[t])}catch(i){throw"Modifier "+t+"'s argument must be an object"}r.forEach(function(r){w[t](n,r,e[t][r])})})),r(n),t._id!==n._id)throw"You can't change a document's _id";return n}function p(t,e){var n,r,i="string"==typeof e?e.split("."):e;if(!t)return void 0;if(0===i.length)return t;if(1===i.length)return t[i[0]];if(m.isArray(t[i[0]])){if(n=parseInt(i[1],10),"number"==typeof n&&!isNaN(n))return p(t[i[0]][n],i.slice(2));for(r=new Array,n=0;n<t[i[0]].length;n+=1)r.push(p(t[i[0]][n],i.slice(1)));return r}return p(t[i[0]],i.slice(1))}function y(t,e){var n,r,i;if(null===t||"string"==typeof t||"boolean"==typeof t||"number"==typeof t||null===e||"string"==typeof e||"boolean"==typeof e||"number"==typeof e)return t===e;if(m.isDate(t)||m.isDate(e))return m.isDate(t)&&m.isDate(e)&&t.getTime()===e.getTime();if(m.isArray(t)||m.isArray(e)||void 0===t||void 0===e)return!1;try{n=Object.keys(t),r=Object.keys(e)}catch(o){return!1}if(n.length!==r.length)return!1;for(i=0;i<n.length;i+=1){if(-1===r.indexOf(n[i]))return!1;if(!y(t[n[i]],e[n[i]]))return!1}return!0}function d(t,e){return"string"==typeof t||"number"==typeof t||m.isDate(t)||"string"==typeof e||"number"==typeof e||m.isDate(e)?typeof t!=typeof e?!1:!0:!1}function g(t,e){var n,r,i,o;if(a(t)||a(e))return v({needAKey:t},"needAKey",e);for(n=Object.keys(e),o=0;o<n.length;o+=1)if(r=n[o],i=e[r],"$"===r[0]){if(!_[r])throw"Unknown logical operator "+r;if(!_[r](t,i))return!1}else if(!v(t,r,i))return!1;return!0}function v(t,e,n,r){var i,o,u,a,s=p(t,e);if(m.isArray(s)&&!r){if(null!==n&&"object"==typeof n&&!m.isRegExp(n))for(o=Object.keys(n),i=0;i<o.length;i+=1)if(O[o[i]])return v(t,e,n,!0);for(i=0;i<s.length;i+=1)if(v({k:s[i]},"k",n))return!0;return!1}if(null!==n&&"object"==typeof n&&!m.isRegExp(n)){if(o=Object.keys(n),u=b.map(o,function(t){return t[0]}),a=b.filter(u,function(t){return"$"===t}),0!==a.length&&a.length!==u.length)throw"You cannot mix operators and normal fields";if(a.length>0){for(i=0;i<o.length;i+=1){if(!x[o[i]])throw"Unknown comparison function "+o[i];if(!x[o[i]](s,n[o[i]]))return!1}return!0}}return m.isRegExp(n)?x.$regex(s,n):y(s,n)?!0:!1}var m=t("util"),b=t("underscore"),w={},k={},x={},_={},O={};k.$set=function(t,e,n){t[e]=n},k.$unset=function(t,e){delete t[e]},k.$push=function(t,e,n){if(t.hasOwnProperty(e)||(t[e]=[]),!m.isArray(t[e]))throw"Can't $push an element on non-array values";if(null!==n&&"object"==typeof n&&n.$each){if(Object.keys(n).length>1)throw"Can't use another field in conjunction with $each";if(!m.isArray(n.$each))throw"$each requires an array value";n.$each.forEach(function(n){t[e].push(n)})}else t[e].push(n)},k.$addToSet=function(t,e,n){var r=!0;if(t.hasOwnProperty(e)||(t[e]=[]),!m.isArray(t[e]))throw"Can't $addToSet an element on non-array values";if(null!==n&&"object"==typeof n&&n.$each){if(Object.keys(n).length>1)throw"Can't use another field in conjunction with $each";if(!m.isArray(n.$each))throw"$each requires an array value";n.$each.forEach(function(n){k.$addToSet(t,e,n)})}else t[e].forEach(function(t){0===f(t,n)&&(r=!1)}),r&&t[e].push(n)},k.$pop=function(t,e,n){if(!m.isArray(t[e]))throw"Can't $pop an element from non-array values";if("number"!=typeof n)throw n+" isn't an integer, can't use it with $pop";0!==n&&(t[e]=n>0?t[e].slice(0,t[e].length-1):t[e].slice(1))},k.$pull=function(t,e,n){var r,i;if(!m.isArray(t[e]))throw"Can't $pull an element from non-array values";for(r=t[e],i=r.length-1;i>=0;i-=1)g(r[i],n)&&r.splice(i,1)},k.$inc=function(t,e,n){if("number"!=typeof n)throw n+" must be a number";if("number"!=typeof t[e]){if(b.has(t,e))throw"Don't use the $inc modifier on non-number fields";t[e]=n}else t[e]+=n},Object.keys(k).forEach(function(t){w[t]=l(t)}),x.$lt=function(t,e){return d(t,e)&&e>t},x.$lte=function(t,e){return d(t,e)&&e>=t},x.$gt=function(t,e){return d(t,e)&&t>e},x.$gte=function(t,e){return d(t,e)&&t>=e},x.$ne=function(t,e){return t?!y(t,e):!0},x.$in=function(t,e){var n;if(!m.isArray(e))throw"$in operator called with a non-array";for(n=0;n<e.length;n+=1)if(y(t,e[n]))return!0;return!1},x.$nin=function(t,e){if(!m.isArray(e))throw"$nin operator called with a non-array";return!x.$in(t,e)},x.$regex=function(t,e){if(!m.isRegExp(e))throw"$regex operator called with non regular expression";return"string"!=typeof t?!1:e.test(t)},x.$exists=function(t,e){return e=e||""===e?!0:!1,void 0===t?!e:e},x.$size=function(t,e){if(!m.isArray(t))return!1;if(0!==e%1)throw"$size operator called without an integer";return t.length==e},O.$size=!0,_.$or=function(t,e){var n;if(!m.isArray(e))throw"$or operator used without an array";for(n=0;n<e.length;n+=1)if(g(t,e[n]))return!0;return!1},_.$and=function(t,e){var n;if(!m.isArray(e))throw"$and operator used without an array";for(n=0;n<e.length;n+=1)if(!g(t,e[n]))return!1;return!0},_.$not=function(t,e){return!g(t,e)},_.$where=function(t,e){var n;if(!b.isFunction(e))throw"$where operator used without a function";if(n=e.call(t),!b.isBoolean(n))throw"$where function must return boolean";return n},e.exports.serialize=i,e.exports.deserialize=o,e.exports.deepCopy=u,e.exports.checkObject=r,e.exports.isPrimitiveType=a,e.exports.modify=h,e.exports.getDotValue=p,e.exports.match=g,e.exports.areThingsEqual=y,e.exports.compareThings=f},{underscore:16,util:2}],10:[function(t,e){function n(t){this.db=t.db,this.db.inMemoryOnly=!0,this.db.filename=null,this.inMemoryOnly=!0}n.prototype.persistNewState=function(t,e){return e?e():void 0},n.prototype.loadDatabase=function(t){return t?t():void 0},e.exports=n},{}],11:[function(e,n){var r=e("__browserify_process");!function(){function e(t){var e=!1;return function(){if(e)throw new Error("Callback was already called.");e=!0,t.apply(i,arguments)}}var i,o,u={};i=this,null!=i&&(o=i.async),u.noConflict=function(){return i.async=o,u};var a=function(t,e){if(t.forEach)return t.forEach(e);for(var n=0;n<t.length;n+=1)e(t[n],n,t)},s=function(t,e){if(t.map)return t.map(e);var n=[];return a(t,function(t,r,i){n.push(e(t,r,i))}),n},c=function(t,e,n){return t.reduce?t.reduce(e,n):(a(t,function(t,r,i){n=e(n,t,r,i)}),n)},f=function(t){if(Object.keys)return Object.keys(t);var e=[];for(var n in t)t.hasOwnProperty(n)&&e.push(n);return e};"undefined"!=typeof r&&r.nextTick?(u.nextTick=r.nextTick,u.setImmediate="undefined"!=typeof setImmediate?function(t){setImmediate(t)}:u.nextTick):"function"==typeof setImmediate?(u.nextTick=function(t){setImmediate(t)},u.setImmediate=u.nextTick):(u.nextTick=function(t){setTimeout(t,0)},u.setImmediate=u.nextTick),u.each=function(t,n,r){if(r=r||function(){},!t.length)return r();var i=0;a(t,function(o){n(o,e(function(e){e?(r(e),r=function(){}):(i+=1,i>=t.length&&r(null))}))})},u.forEach=u.each,u.eachSeries=function(t,e,n){if(n=n||function(){},!t.length)return n();var r=0,i=function(){e(t[r],function(e){e?(n(e),n=function(){}):(r+=1,r>=t.length?n(null):i())})};i()},u.forEachSeries=u.eachSeries,u.eachLimit=function(t,e,n,r){var i=l(e);i.apply(null,[t,n,r])},u.forEachLimit=u.eachLimit;var l=function(t){return function(e,n,r){if(r=r||function(){},!e.length||0>=t)return r();var i=0,o=0,u=0;!function a(){if(i>=e.length)return r();for(;t>u&&o<e.length;)o+=1,u+=1,n(e[o-1],function(t){t?(r(t),r=function(){}):(i+=1,u-=1,i>=e.length?r():a())})}()}},h=function(t){return function(){var e=Array.prototype.slice.call(arguments);return t.apply(null,[u.each].concat(e))}},p=function(t,e){return function(){var n=Array.prototype.slice.call(arguments);return e.apply(null,[l(t)].concat(n))}},y=function(t){return function(){var e=Array.prototype.slice.call(arguments);return t.apply(null,[u.eachSeries].concat(e))}},d=function(t,e,n,r){var i=[];e=s(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n,r){i[t.index]=r,e(n)})},function(t){r(t,i)})};u.map=h(d),u.mapSeries=y(d),u.mapLimit=function(t,e,n,r){return g(e)(t,n,r)};var g=function(t){return p(t,d)};u.reduce=function(t,e,n,r){u.eachSeries(t,function(t,r){n(e,t,function(t,n){e=n,r(t)})},function(t){r(t,e)})},u.inject=u.reduce,u.foldl=u.reduce,u.reduceRight=function(t,e,n,r){var i=s(t,function(t){return t}).reverse();u.reduce(i,e,n,r)},u.foldr=u.reduceRight;var v=function(t,e,n,r){var i=[];e=s(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n){n&&i.push(t),e()})},function(){r(s(i.sort(function(t,e){return t.index-e.index}),function(t){return t.value}))})};u.filter=h(v),u.filterSeries=y(v),u.select=u.filter,u.selectSeries=u.filterSeries;var m=function(t,e,n,r){var i=[];e=s(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n){n||i.push(t),e()})},function(){r(s(i.sort(function(t,e){return t.index-e.index}),function(t){return t.value}))})};u.reject=h(m),u.rejectSeries=y(m);var b=function(t,e,n,r){t(e,function(t,e){n(t,function(n){n?(r(t),r=function(){}):e()})},function(){r()})};u.detect=h(b),u.detectSeries=y(b),u.some=function(t,e,n){u.each(t,function(t,r){e(t,function(t){t&&(n(!0),n=function(){}),r()})},function(){n(!1)})},u.any=u.some,u.every=function(t,e,n){u.each(t,function(t,r){e(t,function(t){t||(n(!1),n=function(){}),r()})},function(){n(!0)})},u.all=u.every,u.sortBy=function(t,e,n){u.map(t,function(t,n){e(t,function(e,r){e?n(e):n(null,{value:t,criteria:r})})},function(t,e){if(t)return n(t);var r=function(t,e){var n=t.criteria,r=e.criteria;return r>n?-1:n>r?1:0};n(null,s(e.sort(r),function(t){return t.value}))})},u.auto=function(t,e){e=e||function(){};var n=f(t);if(!n.length)return e(null);var r={},i=[],o=function(t){i.unshift(t)},s=function(t){for(var e=0;e<i.length;e+=1)if(i[e]===t)return i.splice(e,1),void 0},l=function(){a(i.slice(0),function(t){t()})};o(function(){f(r).length===n.length&&(e(null,r),e=function(){})}),a(n,function(n){var i=t[n]instanceof Function?[t[n]]:t[n],h=function(t){var i=Array.prototype.slice.call(arguments,1);if(i.length<=1&&(i=i[0]),t){var o={};a(f(r),function(t){o[t]=r[t]}),o[n]=i,e(t,o),e=function(){}}else r[n]=i,u.setImmediate(l)},p=i.slice(0,Math.abs(i.length-1))||[],y=function(){return c(p,function(t,e){return t&&r.hasOwnProperty(e)},!0)&&!r.hasOwnProperty(n)};if(y())i[i.length-1](h,r);else{var d=function(){y()&&(s(d),i[i.length-1](h,r))};o(d)}})},u.waterfall=function(t,e){if(e=e||function(){},t.constructor!==Array){var n=new Error("First argument to waterfall must be an array of functions");
return e(n)}if(!t.length)return e();var r=function(t){return function(n){if(n)e.apply(null,arguments),e=function(){};else{var i=Array.prototype.slice.call(arguments,1),o=t.next();o?i.push(r(o)):i.push(e),u.setImmediate(function(){t.apply(null,i)})}}};r(u.iterator(t))()};var w=function(t,e,n){if(n=n||function(){},e.constructor===Array)t.map(e,function(t,e){t&&t(function(t){var n=Array.prototype.slice.call(arguments,1);n.length<=1&&(n=n[0]),e.call(null,t,n)})},n);else{var r={};t.each(f(e),function(t,n){e[t](function(e){var i=Array.prototype.slice.call(arguments,1);i.length<=1&&(i=i[0]),r[t]=i,n(e)})},function(t){n(t,r)})}};u.parallel=function(t,e){w({map:u.map,each:u.each},t,e)},u.parallelLimit=function(t,e,n){w({map:g(e),each:l(e)},t,n)},u.series=function(t,e){if(e=e||function(){},t.constructor===Array)u.mapSeries(t,function(t,e){t&&t(function(t){var n=Array.prototype.slice.call(arguments,1);n.length<=1&&(n=n[0]),e.call(null,t,n)})},e);else{var n={};u.eachSeries(f(t),function(e,r){t[e](function(t){var i=Array.prototype.slice.call(arguments,1);i.length<=1&&(i=i[0]),n[e]=i,r(t)})},function(t){e(t,n)})}},u.iterator=function(t){var e=function(n){var r=function(){return t.length&&t[n].apply(null,arguments),r.next()};return r.next=function(){return n<t.length-1?e(n+1):null},r};return e(0)},u.apply=function(t){var e=Array.prototype.slice.call(arguments,1);return function(){return t.apply(null,e.concat(Array.prototype.slice.call(arguments)))}};var k=function(t,e,n,r){var i=[];t(e,function(t,e){n(t,function(t,n){i=i.concat(n||[]),e(t)})},function(t){r(t,i)})};u.concat=h(k),u.concatSeries=y(k),u.whilst=function(t,e,n){t()?e(function(r){return r?n(r):(u.whilst(t,e,n),void 0)}):n()},u.doWhilst=function(t,e,n){t(function(r){return r?n(r):(e()?u.doWhilst(t,e,n):n(),void 0)})},u.until=function(t,e,n){t()?n():e(function(r){return r?n(r):(u.until(t,e,n),void 0)})},u.doUntil=function(t,e,n){t(function(r){return r?n(r):(e()?n():u.doUntil(t,e,n),void 0)})},u.queue=function(t,n){function r(t,e,r,i){e.constructor!==Array&&(e=[e]),a(e,function(e){var o={data:e,callback:"function"==typeof i?i:null};r?t.tasks.unshift(o):t.tasks.push(o),t.saturated&&t.tasks.length===n&&t.saturated(),u.setImmediate(t.process)})}void 0===n&&(n=1);var i=0,o={tasks:[],concurrency:n,saturated:null,empty:null,drain:null,push:function(t,e){r(o,t,!1,e)},unshift:function(t,e){r(o,t,!0,e)},process:function(){if(i<o.concurrency&&o.tasks.length){var n=o.tasks.shift();o.empty&&0===o.tasks.length&&o.empty(),i+=1;var r=function(){i-=1,n.callback&&n.callback.apply(n,arguments),o.drain&&0===o.tasks.length+i&&o.drain(),o.process()},u=e(r);t(n.data,u)}},length:function(){return o.tasks.length},running:function(){return i}};return o},u.cargo=function(t,e){var n=!1,r=[],i={tasks:r,payload:e,saturated:null,empty:null,drain:null,push:function(t,n){t.constructor!==Array&&(t=[t]),a(t,function(t){r.push({data:t,callback:"function"==typeof n?n:null}),i.saturated&&r.length===e&&i.saturated()}),u.setImmediate(i.process)},process:function o(){if(!n){if(0===r.length)return i.drain&&i.drain(),void 0;var u="number"==typeof e?r.splice(0,e):r.splice(0),c=s(u,function(t){return t.data});i.empty&&i.empty(),n=!0,t(c,function(){n=!1;var t=arguments;a(u,function(e){e.callback&&e.callback.apply(null,t)}),o()})}},length:function(){return r.length},running:function(){return n}};return i};var x=function(t){return function(e){var n=Array.prototype.slice.call(arguments,1);e.apply(null,n.concat([function(e){var n=Array.prototype.slice.call(arguments,1);"undefined"!=typeof console&&(e?console.error&&console.error(e):console[t]&&a(n,function(e){console[t](e)}))}]))}};u.log=x("log"),u.dir=x("dir"),u.memoize=function(t,e){var n={},r={};e=e||function(t){return t};var i=function(){var i=Array.prototype.slice.call(arguments),o=i.pop(),u=e.apply(null,i);u in n?o.apply(null,n[u]):u in r?r[u].push(o):(r[u]=[o],t.apply(null,i.concat([function(){n[u]=arguments;var t=r[u];delete r[u];for(var e=0,i=t.length;i>e;e++)t[e].apply(null,arguments)}])))};return i.memo=n,i.unmemoized=t,i},u.unmemoize=function(t){return function(){return(t.unmemoized||t).apply(null,arguments)}},u.times=function(t,e,n){for(var r=[],i=0;t>i;i++)r.push(i);return u.map(r,e,n)},u.timesSeries=function(t,e,n){for(var r=[],i=0;t>i;i++)r.push(i);return u.mapSeries(r,e,n)},u.compose=function(){var t=Array.prototype.reverse.call(arguments);return function(){var e=this,n=Array.prototype.slice.call(arguments),r=n.pop();u.reduce(t,n,function(t,n,r){n.apply(e,t.concat([function(){var t=arguments[0],e=Array.prototype.slice.call(arguments,1);r(t,e)}]))},function(t,n){r.apply(e,[t].concat(n))})}};var _=function(t,e){var n=function(){var n=this,r=Array.prototype.slice.call(arguments),i=r.pop();return t(e,function(t,e){t.apply(n,r.concat([e]))},i)};if(arguments.length>2){var r=Array.prototype.slice.call(arguments,2);return n.apply(this,r)}return n};u.applyEach=h(_),u.applyEachSeries=y(_),u.forever=function(t,e){function n(r){if(r){if(e)return e(r);throw r}t(n)}n()},"undefined"!=typeof t&&t.amd?t([],function(){return u}):"undefined"!=typeof n&&n.exports?n.exports=u:i.async=u}()},{__browserify_process:3}],12:[function(t,e){e.exports.BinarySearchTree=t("./lib/bst"),e.exports.AVLTree=t("./lib/avltree")},{"./lib/avltree":13,"./lib/bst":14}],13:[function(t,e){function n(t){this.tree=new r(t)}function r(t){t=t||{},this.left=null,this.right=null,this.parent=void 0!==t.parent?t.parent:null,t.hasOwnProperty("key")&&(this.key=t.key),this.data=t.hasOwnProperty("value")?[t.value]:[],this.unique=t.unique||!1,this.compareKeys=t.compareKeys||o.defaultCompareKeysFunction,this.checkValueEquality=t.checkValueEquality||o.defaultCheckValueEquality}var i=t("./bst"),o=t("./customUtils"),u=t("util");t("underscore"),u.inherits(r,i),n._AVLTree=r,r.prototype.checkHeightCorrect=function(){var t,e;if(this.hasOwnProperty("key")){if(this.left&&void 0===this.left.height)throw"Undefined height for node "+this.left.key;if(this.right&&void 0===this.right.height)throw"Undefined height for node "+this.right.key;if(void 0===this.height)throw"Undefined height for node "+this.key;if(t=this.left?this.left.height:0,e=this.right?this.right.height:0,this.height!==1+Math.max(t,e))throw"Height constraint failed for node "+this.key;this.left&&this.left.checkHeightCorrect(),this.right&&this.right.checkHeightCorrect()}},r.prototype.balanceFactor=function(){var t=this.left?this.left.height:0,e=this.right?this.right.height:0;return t-e},r.prototype.checkBalanceFactors=function(){if(Math.abs(this.balanceFactor())>1)throw"Tree is unbalanced at node "+this.key;this.left&&this.left.checkBalanceFactors(),this.right&&this.right.checkBalanceFactors()},r.prototype.checkIsAVLT=function(){r.super_.prototype.checkIsBST.call(this),this.checkHeightCorrect(),this.checkBalanceFactors()},n.prototype.checkIsAVLT=function(){this.tree.checkIsAVLT()},r.prototype.rightRotation=function(){var t,e,n,r,i=this,o=this.left;return o?(t=o.right,i.parent?(o.parent=i.parent,i.parent.left===i?i.parent.left=o:i.parent.right=o):o.parent=null,o.right=i,i.parent=o,i.left=t,t&&(t.parent=i),e=o.left?o.left.height:0,n=t?t.height:0,r=i.right?i.right.height:0,i.height=Math.max(n,r)+1,o.height=Math.max(e,i.height)+1,o):this},r.prototype.leftRotation=function(){var t,e,n,r,i=this,o=this.right;return o?(t=o.left,i.parent?(o.parent=i.parent,i.parent.left===i?i.parent.left=o:i.parent.right=o):o.parent=null,o.left=i,i.parent=o,i.right=t,t&&(t.parent=i),e=i.left?i.left.height:0,n=t?t.height:0,r=o.right?o.right.height:0,i.height=Math.max(e,n)+1,o.height=Math.max(r,i.height)+1,o):this},r.prototype.rightTooSmall=function(){return this.balanceFactor()<=1?this:(this.left.balanceFactor()<0&&this.left.leftRotation(),this.rightRotation())},r.prototype.leftTooSmall=function(){return this.balanceFactor()>=-1?this:(this.right.balanceFactor()>0&&this.right.rightRotation(),this.leftRotation())},r.prototype.rebalanceAlongPath=function(t){var e,n,r=this;if(!this.hasOwnProperty("key"))return delete this.height,this;for(n=t.length-1;n>=0;n-=1)t[n].height=1+Math.max(t[n].left?t[n].left.height:0,t[n].right?t[n].right.height:0),t[n].balanceFactor()>1&&(e=t[n].rightTooSmall(),0===n&&(r=e)),t[n].balanceFactor()<-1&&(e=t[n].leftTooSmall(),0===n&&(r=e));return r},r.prototype.insert=function(t,e){var n=[],r=this;if(!this.hasOwnProperty("key"))return this.key=t,this.data.push(e),this.height=1,this;for(;;){if(0===r.compareKeys(r.key,t)){if(r.unique)throw{message:"Can't insert key "+t+", it violates the unique constraint",key:t,errorType:"uniqueViolated"};return r.data.push(e),this}if(n.push(r),r.compareKeys(t,r.key)<0){if(!r.left){n.push(r.createLeftChild({key:t,value:e}));break}r=r.left}else{if(!r.right){n.push(r.createRightChild({key:t,value:e}));break}r=r.right}}return this.rebalanceAlongPath(n)},n.prototype.insert=function(t,e){var n=this.tree.insert(t,e);n&&(this.tree=n)},r.prototype.delete=function(t,e){var n,r=[],i=this,o=[];if(!this.hasOwnProperty("key"))return this;for(;;){if(0===i.compareKeys(t,i.key))break;if(o.push(i),i.compareKeys(t,i.key)<0){if(!i.left)return this;i=i.left}else{if(!i.right)return this;i=i.right}}if(i.data.length>1&&e)return i.data.forEach(function(t){i.checkValueEquality(t,e)||r.push(t)}),i.data=r,this;if(!i.left&&!i.right)return i===this?(delete i.key,i.data=[],delete i.height,this):(i.parent.left===i?i.parent.left=null:i.parent.right=null,this.rebalanceAlongPath(o));if(!i.left||!i.right)return n=i.left?i.left:i.right,i===this?(n.parent=null,n):(i.parent.left===i?(i.parent.left=n,n.parent=i.parent):(i.parent.right=n,n.parent=i.parent),this.rebalanceAlongPath(o));if(o.push(i),n=i.left,!n.right)return i.key=n.key,i.data=n.data,i.left=n.left,n.left&&(n.left.parent=i),this.rebalanceAlongPath(o);for(;;){if(!n.right)break;o.push(n),n=n.right}return i.key=n.key,i.data=n.data,n.parent.right=n.left,n.left&&(n.left.parent=n.parent),this.rebalanceAlongPath(o)},n.prototype.delete=function(t,e){var n=this.tree.delete(t,e);n&&(this.tree=n)},["getNumberOfKeys","search","betweenBounds","prettyPrint","executeOnEveryNode"].forEach(function(t){n.prototype[t]=function(){return this.tree[t].apply(this.tree,arguments)}}),e.exports=n},{"./bst":14,"./customUtils":15,underscore:16,util:2}],14:[function(t,e){function n(t){t=t||{},this.left=null,this.right=null,this.parent=void 0!==t.parent?t.parent:null,t.hasOwnProperty("key")&&(this.key=t.key),this.data=t.hasOwnProperty("value")?[t.value]:[],this.unique=t.unique||!1,this.compareKeys=t.compareKeys||i.defaultCompareKeysFunction,this.checkValueEquality=t.checkValueEquality||i.defaultCheckValueEquality}function r(t,e){var n;for(n=0;n<e.length;n+=1)t.push(e[n])}var i=t("./customUtils");n.prototype.getMaxKeyDescendant=function(){return this.right?this.right.getMaxKeyDescendant():this},n.prototype.getMaxKey=function(){return this.getMaxKeyDescendant().key},n.prototype.getMinKeyDescendant=function(){return this.left?this.left.getMinKeyDescendant():this},n.prototype.getMinKey=function(){return this.getMinKeyDescendant().key},n.prototype.checkAllNodesFullfillCondition=function(t){this.hasOwnProperty("key")&&(t(this.key,this.data),this.left&&this.left.checkAllNodesFullfillCondition(t),this.right&&this.right.checkAllNodesFullfillCondition(t))},n.prototype.checkNodeOrdering=function(){var t=this;this.hasOwnProperty("key")&&(this.left&&(this.left.checkAllNodesFullfillCondition(function(e){if(t.compareKeys(e,t.key)>=0)throw"Tree with root "+t.key+" is not a binary search tree"}),this.left.checkNodeOrdering()),this.right&&(this.right.checkAllNodesFullfillCondition(function(e){if(t.compareKeys(e,t.key)<=0)throw"Tree with root "+t.key+" is not a binary search tree"}),this.right.checkNodeOrdering()))},n.prototype.checkInternalPointers=function(){if(this.left){if(this.left.parent!==this)throw"Parent pointer broken for key "+this.key;this.left.checkInternalPointers()}if(this.right){if(this.right.parent!==this)throw"Parent pointer broken for key "+this.key;this.right.checkInternalPointers()}},n.prototype.checkIsBST=function(){if(this.checkNodeOrdering(),this.checkInternalPointers(),this.parent)throw"The root shouldn't have a parent"},n.prototype.getNumberOfKeys=function(){var t;return this.hasOwnProperty("key")?(t=1,this.left&&(t+=this.left.getNumberOfKeys()),this.right&&(t+=this.right.getNumberOfKeys()),t):0},n.prototype.createSimilar=function(t){return t=t||{},t.unique=this.unique,t.compareKeys=this.compareKeys,t.checkValueEquality=this.checkValueEquality,new this.constructor(t)},n.prototype.createLeftChild=function(t){var e=this.createSimilar(t);return e.parent=this,this.left=e,e},n.prototype.createRightChild=function(t){var e=this.createSimilar(t);return e.parent=this,this.right=e,e},n.prototype.insert=function(t,e){if(!this.hasOwnProperty("key"))return this.key=t,this.data.push(e),void 0;if(0===this.compareKeys(this.key,t)){if(this.unique)throw{message:"Can't insert key "+t+", it violates the unique constraint",key:t,errorType:"uniqueViolated"};return this.data.push(e),void 0}this.compareKeys(t,this.key)<0?this.left?this.left.insert(t,e):this.createLeftChild({key:t,value:e}):this.right?this.right.insert(t,e):this.createRightChild({key:t,value:e})},n.prototype.search=function(t){return this.hasOwnProperty("key")?0===this.compareKeys(this.key,t)?this.data:this.compareKeys(t,this.key)<0?this.left?this.left.search(t):[]:this.right?this.right.search(t):[]:[]},n.prototype.getLowerBoundMatcher=function(t){var e=this;return t.hasOwnProperty("$gt")||t.hasOwnProperty("$gte")?t.hasOwnProperty("$gt")&&t.hasOwnProperty("$gte")?0===e.compareKeys(t.$gte,t.$gt)?function(n){return e.compareKeys(n,t.$gt)>0}:e.compareKeys(t.$gte,t.$gt)>0?function(n){return e.compareKeys(n,t.$gte)>=0}:function(n){return e.compareKeys(n,t.$gt)>0}:t.hasOwnProperty("$gt")?function(n){return e.compareKeys(n,t.$gt)>0}:function(n){return e.compareKeys(n,t.$gte)>=0}:function(){return!0}},n.prototype.getUpperBoundMatcher=function(t){var e=this;return t.hasOwnProperty("$lt")||t.hasOwnProperty("$lte")?t.hasOwnProperty("$lt")&&t.hasOwnProperty("$lte")?0===e.compareKeys(t.$lte,t.$lt)?function(n){return e.compareKeys(n,t.$lt)<0}:e.compareKeys(t.$lte,t.$lt)<0?function(n){return e.compareKeys(n,t.$lte)<=0}:function(n){return e.compareKeys(n,t.$lt)<0}:t.hasOwnProperty("$lt")?function(n){return e.compareKeys(n,t.$lt)<0}:function(n){return e.compareKeys(n,t.$lte)<=0}:function(){return!0}},n.prototype.betweenBounds=function(t,e,n){var i=[];return this.hasOwnProperty("key")?(e=e||this.getLowerBoundMatcher(t),n=n||this.getUpperBoundMatcher(t),e(this.key)&&this.left&&r(i,this.left.betweenBounds(t,e,n)),e(this.key)&&n(this.key)&&r(i,this.data),n(this.key)&&this.right&&r(i,this.right.betweenBounds(t,e,n)),i):[]},n.prototype.deleteIfLeaf=function(){return this.left||this.right?!1:this.parent?(this.parent.left===this?this.parent.left=null:this.parent.right=null,!0):(delete this.key,this.data=[],!0)},n.prototype.deleteIfOnlyOneChild=function(){var t;return this.left&&!this.right&&(t=this.left),!this.left&&this.right&&(t=this.right),t?this.parent?(this.parent.left===this?(this.parent.left=t,t.parent=this.parent):(this.parent.right=t,t.parent=this.parent),!0):(this.key=t.key,this.data=t.data,this.left=null,t.left&&(this.left=t.left,t.left.parent=this),this.right=null,t.right&&(this.right=t.right,t.right.parent=this),!0):!1},n.prototype.delete=function(t,e){var n,r=[],i=this;if(this.hasOwnProperty("key")){if(this.compareKeys(t,this.key)<0)return this.left&&this.left.delete(t,e),void 0;if(this.compareKeys(t,this.key)>0)return this.right&&this.right.delete(t,e),void 0;if(0!==!this.compareKeys(t,this.key))return this.data.length>1&&e?(this.data.forEach(function(t){i.checkValueEquality(t,e)||r.push(t)}),i.data=r,void 0):(this.deleteIfLeaf()||this.deleteIfOnlyOneChild()||(Math.random()>=.5?(n=this.left.getMaxKeyDescendant(),this.key=n.key,this.data=n.data,this===n.parent?(this.left=n.left,n.left&&(n.left.parent=n.parent)):(n.parent.right=n.left,n.left&&(n.left.parent=n.parent))):(n=this.right.getMinKeyDescendant(),this.key=n.key,this.data=n.data,this===n.parent?(this.right=n.right,n.right&&(n.right.parent=n.parent)):(n.parent.left=n.right,n.right&&(n.right.parent=n.parent)))),void 0)}},n.prototype.executeOnEveryNode=function(t){this.left&&this.left.executeOnEveryNode(t),t(this),this.right&&this.right.executeOnEveryNode(t)},n.prototype.prettyPrint=function(t,e){e=e||"",console.log(e+"* "+this.key),t&&console.log(e+"* "+this.data),(this.left||this.right)&&(this.left?this.left.prettyPrint(t,e+" "):console.log(e+" *"),this.right?this.right.prettyPrint(t,e+" "):console.log(e+" *"))},e.exports=n},{"./customUtils":15}],15:[function(t,e){function n(t){var e,r;return 0===t?[]:1===t?[0]:(e=n(t-1),r=Math.floor(Math.random()*t),e.splice(r,0,t-1),e)}function r(t,e){if(e>t)return-1;if(t>e)return 1;if(t===e)return 0;throw{message:"Couldn't compare elements",a:t,b:e}}function i(t,e){return t===e}e.exports.getRandomArray=n,e.exports.defaultCompareKeysFunction=r,e.exports.defaultCheckValueEquality=i},{}],16:[function(t,e,n){!function(){var t=this,r=t._,i={},o=Array.prototype,u=Object.prototype,a=Function.prototype,s=o.push,c=o.slice,f=o.concat,l=u.toString,h=u.hasOwnProperty,p=o.forEach,y=o.map,d=o.reduce,g=o.reduceRight,v=o.filter,m=o.every,b=o.some,w=o.indexOf,k=o.lastIndexOf,x=Array.isArray,_=Object.keys,O=a.bind,A=function(t){return t instanceof A?t:this instanceof A?(this._wrapped=t,void 0):new A(t)};"undefined"!=typeof n?("undefined"!=typeof e&&e.exports&&(n=e.exports=A),n._=A):t._=A,A.VERSION="1.4.4";var $=A.each=A.forEach=function(t,e,n){if(null!=t)if(p&&t.forEach===p)t.forEach(e,n);else if(t.length===+t.length){for(var r=0,o=t.length;o>r;r++)if(e.call(n,t[r],r,t)===i)return}else for(var u in t)if(A.has(t,u)&&e.call(n,t[u],u,t)===i)return};A.map=A.collect=function(t,e,n){var r=[];return null==t?r:y&&t.map===y?t.map(e,n):($(t,function(t,i,o){r[r.length]=e.call(n,t,i,o)}),r)};var j="Reduce of empty array with no initial value";A.reduce=A.foldl=A.inject=function(t,e,n,r){var i=arguments.length>2;if(null==t&&(t=[]),d&&t.reduce===d)return r&&(e=A.bind(e,r)),i?t.reduce(e,n):t.reduce(e);if($(t,function(t,o,u){i?n=e.call(r,n,t,o,u):(n=t,i=!0)}),!i)throw new TypeError(j);return n},A.reduceRight=A.foldr=function(t,e,n,r){var i=arguments.length>2;if(null==t&&(t=[]),g&&t.reduceRight===g)return r&&(e=A.bind(e,r)),i?t.reduceRight(e,n):t.reduceRight(e);var o=t.length;if(o!==+o){var u=A.keys(t);o=u.length}if($(t,function(a,s,c){s=u?u[--o]:--o,i?n=e.call(r,n,t[s],s,c):(n=t[s],i=!0)}),!i)throw new TypeError(j);return n},A.find=A.detect=function(t,e,n){var r;return E(t,function(t,i,o){return e.call(n,t,i,o)?(r=t,!0):void 0}),r},A.filter=A.select=function(t,e,n){var r=[];return null==t?r:v&&t.filter===v?t.filter(e,n):($(t,function(t,i,o){e.call(n,t,i,o)&&(r[r.length]=t)}),r)},A.reject=function(t,e,n){return A.filter(t,function(t,r,i){return!e.call(n,t,r,i)},n)},A.every=A.all=function(t,e,n){e||(e=A.identity);var r=!0;return null==t?r:m&&t.every===m?t.every(e,n):($(t,function(t,o,u){return(r=r&&e.call(n,t,o,u))?void 0:i}),!!r)};var E=A.some=A.any=function(t,e,n){e||(e=A.identity);var r=!1;return null==t?r:b&&t.some===b?t.some(e,n):($(t,function(t,o,u){return r||(r=e.call(n,t,o,u))?i:void 0}),!!r)};A.contains=A.include=function(t,e){return null==t?!1:w&&t.indexOf===w?-1!=t.indexOf(e):E(t,function(t){return t===e})},A.invoke=function(t,e){var n=c.call(arguments,2),r=A.isFunction(e);return A.map(t,function(t){return(r?e:t[e]).apply(t,n)})},A.pluck=function(t,e){return A.map(t,function(t){return t[e]})},A.where=function(t,e,n){return A.isEmpty(e)?n?null:[]:A[n?"find":"filter"](t,function(t){for(var n in e)if(e[n]!==t[n])return!1;return!0})},A.findWhere=function(t,e){return A.where(t,e,!0)},A.max=function(t,e,n){if(!e&&A.isArray(t)&&t[0]===+t[0]&&t.length<65535)return Math.max.apply(Math,t);if(!e&&A.isEmpty(t))return-1/0;var r={computed:-1/0,value:-1/0};return $(t,function(t,i,o){var u=e?e.call(n,t,i,o):t;u>=r.computed&&(r={value:t,computed:u})}),r.value},A.min=function(t,e,n){if(!e&&A.isArray(t)&&t[0]===+t[0]&&t.length<65535)return Math.min.apply(Math,t);if(!e&&A.isEmpty(t))return 1/0;var r={computed:1/0,value:1/0};return $(t,function(t,i,o){var u=e?e.call(n,t,i,o):t;u<r.computed&&(r={value:t,computed:u})}),r.value},A.shuffle=function(t){var e,n=0,r=[];return $(t,function(t){e=A.random(n++),r[n-1]=r[e],r[e]=t}),r};var S=function(t){return A.isFunction(t)?t:function(e){return e[t]}};A.sortBy=function(t,e,n){var r=S(e);return A.pluck(A.map(t,function(t,e,i){return{value:t,index:e,criteria:r.call(n,t,e,i)}}).sort(function(t,e){var n=t.criteria,r=e.criteria;if(n!==r){if(n>r||void 0===n)return 1;if(r>n||void 0===r)return-1}return t.index<e.index?-1:1}),"value")};var D=function(t,e,n,r){var i={},o=S(e||A.identity);return $(t,function(e,u){var a=o.call(n,e,u,t);r(i,a,e)}),i};A.groupBy=function(t,e,n){return D(t,e,n,function(t,e,n){(A.has(t,e)?t[e]:t[e]=[]).push(n)})},A.countBy=function(t,e,n){return D(t,e,n,function(t,e){A.has(t,e)||(t[e]=0),t[e]++})},A.sortedIndex=function(t,e,n,r){n=null==n?A.identity:S(n);for(var i=n.call(r,e),o=0,u=t.length;u>o;){var a=o+u>>>1;n.call(r,t[a])<i?o=a+1:u=a}return o},A.toArray=function(t){return t?A.isArray(t)?c.call(t):t.length===+t.length?A.map(t,A.identity):A.values(t):[]},A.size=function(t){return null==t?0:t.length===+t.length?t.length:A.keys(t).length},A.first=A.head=A.take=function(t,e,n){return null==t?void 0:null==e||n?t[0]:c.call(t,0,e)},A.initial=function(t,e,n){return c.call(t,0,t.length-(null==e||n?1:e))},A.last=function(t,e,n){return null==t?void 0:null==e||n?t[t.length-1]:c.call(t,Math.max(t.length-e,0))},A.rest=A.tail=A.drop=function(t,e,n){return c.call(t,null==e||n?1:e)},A.compact=function(t){return A.filter(t,A.identity)};var T=function(t,e,n){return $(t,function(t){A.isArray(t)?e?s.apply(n,t):T(t,e,n):n.push(t)}),n};A.flatten=function(t,e){return T(t,e,[])},A.without=function(t){return A.difference(t,c.call(arguments,1))},A.uniq=A.unique=function(t,e,n,r){A.isFunction(e)&&(r=n,n=e,e=!1);var i=n?A.map(t,n,r):t,o=[],u=[];return $(i,function(n,r){(e?r&&u[u.length-1]===n:A.contains(u,n))||(u.push(n),o.push(t[r]))}),o},A.union=function(){return A.uniq(f.apply(o,arguments))},A.intersection=function(t){var e=c.call(arguments,1);return A.filter(A.uniq(t),function(t){return A.every(e,function(e){return A.indexOf(e,t)>=0})})},A.difference=function(t){var e=f.apply(o,c.call(arguments,1));return A.filter(t,function(t){return!A.contains(e,t)})},A.zip=function(){for(var t=c.call(arguments),e=A.max(A.pluck(t,"length")),n=new Array(e),r=0;e>r;r++)n[r]=A.pluck(t,""+r);return n},A.object=function(t,e){if(null==t)return{};for(var n={},r=0,i=t.length;i>r;r++)e?n[t[r]]=e[r]:n[t[r][0]]=t[r][1];return n},A.indexOf=function(t,e,n){if(null==t)return-1;var r=0,i=t.length;if(n){if("number"!=typeof n)return r=A.sortedIndex(t,e),t[r]===e?r:-1;r=0>n?Math.max(0,i+n):n}if(w&&t.indexOf===w)return t.indexOf(e,n);for(;i>r;r++)if(t[r]===e)return r;return-1},A.lastIndexOf=function(t,e,n){if(null==t)return-1;var r=null!=n;if(k&&t.lastIndexOf===k)return r?t.lastIndexOf(e,n):t.lastIndexOf(e);for(var i=r?n:t.length;i--;)if(t[i]===e)return i;return-1},A.range=function(t,e,n){arguments.length<=1&&(e=t||0,t=0),n=arguments[2]||1;for(var r=Math.max(Math.ceil((e-t)/n),0),i=0,o=new Array(r);r>i;)o[i++]=t,t+=n;return o},A.bind=function(t,e){if(t.bind===O&&O)return O.apply(t,c.call(arguments,1));var n=c.call(arguments,2);return function(){return t.apply(e,n.concat(c.call(arguments)))}},A.partial=function(t){var e=c.call(arguments,1);return function(){return t.apply(this,e.concat(c.call(arguments)))}},A.bindAll=function(t){var e=c.call(arguments,1);return 0===e.length&&(e=A.functions(t)),$(e,function(e){t[e]=A.bind(t[e],t)}),t},A.memoize=function(t,e){var n={};return e||(e=A.identity),function(){var r=e.apply(this,arguments);return A.has(n,r)?n[r]:n[r]=t.apply(this,arguments)}},A.delay=function(t,e){var n=c.call(arguments,2);return setTimeout(function(){return t.apply(null,n)},e)},A.defer=function(t){return A.delay.apply(A,[t,1].concat(c.call(arguments,1)))},A.throttle=function(t,e){var n,r,i,o,u=0,a=function(){u=new Date,i=null,o=t.apply(n,r)};return function(){var s=new Date,c=e-(s-u);return n=this,r=arguments,0>=c?(clearTimeout(i),i=null,u=s,o=t.apply(n,r)):i||(i=setTimeout(a,c)),o}},A.debounce=function(t,e,n){var r,i;return function(){var o=this,u=arguments,a=function(){r=null,n||(i=t.apply(o,u))},s=n&&!r;return clearTimeout(r),r=setTimeout(a,e),s&&(i=t.apply(o,u)),i}},A.once=function(t){var e,n=!1;return function(){return n?e:(n=!0,e=t.apply(this,arguments),t=null,e)}},A.wrap=function(t,e){return function(){var n=[t];return s.apply(n,arguments),e.apply(this,n)}},A.compose=function(){var t=arguments;return function(){for(var e=arguments,n=t.length-1;n>=0;n--)e=[t[n].apply(this,e)];return e[0]}},A.after=function(t,e){return 0>=t?e():function(){return--t<1?e.apply(this,arguments):void 0}},A.keys=_||function(t){if(t!==Object(t))throw new TypeError("Invalid object");var e=[];for(var n in t)A.has(t,n)&&(e[e.length]=n);return e},A.values=function(t){var e=[];for(var n in t)A.has(t,n)&&e.push(t[n]);return e},A.pairs=function(t){var e=[];for(var n in t)A.has(t,n)&&e.push([n,t[n]]);return e},A.invert=function(t){var e={};for(var n in t)A.has(t,n)&&(e[t[n]]=n);return e},A.functions=A.methods=function(t){var e=[];for(var n in t)A.isFunction(t[n])&&e.push(n);return e.sort()},A.extend=function(t){return $(c.call(arguments,1),function(e){if(e)for(var n in e)t[n]=e[n]}),t},A.pick=function(t){var e={},n=f.apply(o,c.call(arguments,1));return $(n,function(n){n in t&&(e[n]=t[n])}),e},A.omit=function(t){var e={},n=f.apply(o,c.call(arguments,1));for(var r in t)A.contains(n,r)||(e[r]=t[r]);return e},A.defaults=function(t){return $(c.call(arguments,1),function(e){if(e)for(var n in e)null==t[n]&&(t[n]=e[n])}),t},A.clone=function(t){return A.isObject(t)?A.isArray(t)?t.slice():A.extend({},t):t},A.tap=function(t,e){return e(t),t};var M=function(t,e,n,r){if(t===e)return 0!==t||1/t==1/e;if(null==t||null==e)return t===e;t instanceof A&&(t=t._wrapped),e instanceof A&&(e=e._wrapped);var i=l.call(t);if(i!=l.call(e))return!1;switch(i){case"[object String]":return t==String(e);case"[object Number]":return t!=+t?e!=+e:0==t?1/t==1/e:t==+e;case"[object Date]":case"[object Boolean]":return+t==+e;case"[object RegExp]":return t.source==e.source&&t.global==e.global&&t.multiline==e.multiline&&t.ignoreCase==e.ignoreCase}if("object"!=typeof t||"object"!=typeof e)return!1;for(var o=n.length;o--;)if(n[o]==t)return r[o]==e;n.push(t),r.push(e);var u=0,a=!0;if("[object Array]"==i){if(u=t.length,a=u==e.length)for(;u--&&(a=M(t[u],e[u],n,r)););}else{var s=t.constructor,c=e.constructor;if(s!==c&&!(A.isFunction(s)&&s instanceof s&&A.isFunction(c)&&c instanceof c))return!1;for(var f in t)if(A.has(t,f)&&(u++,!(a=A.has(e,f)&&M(t[f],e[f],n,r))))break;if(a){for(f in e)if(A.has(e,f)&&!u--)break;a=!u}}return n.pop(),r.pop(),a};A.isEqual=function(t,e){return M(t,e,[],[])},A.isEmpty=function(t){if(null==t)return!0;if(A.isArray(t)||A.isString(t))return 0===t.length;for(var e in t)if(A.has(t,e))return!1;return!0},A.isElement=function(t){return!(!t||1!==t.nodeType)},A.isArray=x||function(t){return"[object Array]"==l.call(t)},A.isObject=function(t){return t===Object(t)},$(["Arguments","Function","String","Number","Date","RegExp"],function(t){A["is"+t]=function(e){return l.call(e)=="[object "+t+"]"}}),A.isArguments(arguments)||(A.isArguments=function(t){return!(!t||!A.has(t,"callee"))}),"function"!=typeof/./&&(A.isFunction=function(t){return"function"==typeof t}),A.isFinite=function(t){return isFinite(t)&&!isNaN(parseFloat(t))},A.isNaN=function(t){return A.isNumber(t)&&t!=+t},A.isBoolean=function(t){return t===!0||t===!1||"[object Boolean]"==l.call(t)},A.isNull=function(t){return null===t},A.isUndefined=function(t){return void 0===t},A.has=function(t,e){return h.call(t,e)},A.noConflict=function(){return t._=r,this},A.identity=function(t){return t},A.times=function(t,e,n){for(var r=Array(t),i=0;t>i;i++)r[i]=e.call(n,i);return r},A.random=function(t,e){return null==e&&(e=t,t=0),t+Math.floor(Math.random()*(e-t+1))};var N={escape:{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;"}};N.unescape=A.invert(N.escape);var P={escape:new RegExp("["+A.keys(N.escape).join("")+"]","g"),unescape:new RegExp("("+A.keys(N.unescape).join("|")+")","g")};A.each(["escape","unescape"],function(t){A[t]=function(e){return null==e?"":(""+e).replace(P[t],function(e){return N[t][e]})}}),A.result=function(t,e){if(null==t)return null;var n=t[e];return A.isFunction(n)?n.call(t):n},A.mixin=function(t){$(A.functions(t),function(e){var n=A[e]=t[e];A.prototype[e]=function(){var t=[this._wrapped];return s.apply(t,arguments),K.call(this,n.apply(A,t))}})};var C=0;A.uniqueId=function(t){var e=++C+"";return t?t+e:e},A.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var I=/(.)^/,F={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},q=/\\|'|\r|\n|\t|\u2028|\u2029/g;A.template=function(t,e,n){var r;n=A.defaults({},n,A.templateSettings);var i=new RegExp([(n.escape||I).source,(n.interpolate||I).source,(n.evaluate||I).source].join("|")+"|$","g"),o=0,u="__p+='";t.replace(i,function(e,n,r,i,a){return u+=t.slice(o,a).replace(q,function(t){return"\\"+F[t]}),n&&(u+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'"),r&&(u+="'+\n((__t=("+r+"))==null?'':__t)+\n'"),i&&(u+="';\n"+i+"\n__p+='"),o=a+e.length,e}),u+="';\n",n.variable||(u="with(obj||{}){\n"+u+"}\n"),u="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+u+"return __p;\n";try{r=new Function(n.variable||"obj","_",u)}catch(a){throw a.source=u,a}if(e)return r(e,A);var s=function(t){return r.call(this,t,A)};return s.source="function("+(n.variable||"obj")+"){\n"+u+"}",s},A.chain=function(t){return A(t).chain()};var K=function(t){return this._chain?A(t).chain():t};A.mixin(A),$(["pop","push","reverse","shift","sort","splice","unshift"],function(t){var e=o[t];A.prototype[t]=function(){var n=this._wrapped;return e.apply(n,arguments),"shift"!=t&&"splice"!=t||0!==n.length||delete n[0],K.call(this,n)}}),$(["concat","join","slice"],function(t){var e=o[t];A.prototype[t]=function(){return K.call(this,e.apply(this._wrapped,arguments))}}),A.extend(A.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this)},{}]},{},[6])(6)});

@@ -8,5 +8,3 @@ /**

var dateToJSON = function () { return { $$date: this.getTime() }; }
, originalDateToJSON = Date.prototype.toJSON
, util = require('util')
var util = require('util')
, _ = require('underscore')

@@ -70,11 +68,12 @@ , modifierFunctions = {}

var res;
// Keep track of the fact that this is a Date object
Date.prototype.toJSON = dateToJSON;
res = JSON.stringify(obj, function (k, v) {
checkKey(k, v);
if (v === undefined) { return undefined; }
if (v === null) { return null; }
if (typeof v === undefined) { return null; }
if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' || v === null) { return v; }
// Hackish way of checking if object is Date (this way it works between execution contexts in node-webkit).
// We can't use value directly because for dates it is already string in this function (date.toJSON was already called), so we use this
if (typeof this[k].getTime === 'function') { return { $$date: this[k].getTime() }; }

@@ -84,5 +83,2 @@ return v;

// Return Date to its original state
Date.prototype.toJSON = originalDateToJSON;
return res;

@@ -89,0 +85,0 @@ }

{
"name": "nedb",
"version": "0.10.6",
"version": "0.10.7",
"author": {

@@ -5,0 +5,0 @@ "name": "Louis Chatriot",

@@ -85,2 +85,3 @@ var model = require('../lib/model')

b.indexOf('\n').should.equal(-1);
b.should.equal('{"test":{"$$date":' + d.getTime() + '}}');
util.isDate(c.test).should.equal(true);

@@ -87,0 +88,0 @@ c.test.getTime().should.equal(d.getTime());

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc