Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merged - 0.5.5

  • Loading branch information...
commit dec3199f4d106c90047c124eaec020a9102916aa 2 parents 8d13253 + 7bfedd3
shakty shakty authored
3  build/nddb-bare.js
View
@@ -1159,11 +1159,12 @@ NDDB.prototype.reverse = function () {
*
* Changes the order of elements in the current database
*
+ * @return {NDDB} A a reference to the current instance with shuffled entries
*/
NDDB.prototype.shuffle = function () {
// TODO: check do we need to reassign __nddbid__ ?
this.db = JSUS.shuffle(this.db);
- return true;
+ return this;
};
// ## Custom callbacks
2  build/nddb-bare.min.js
View
@@ -26,4 +26,4 @@
* ---
*
*/
-(function(e,t,n){function u(e,n,r){e=e||{};if(!t)throw new Error("JSUS not found.");this.db=[],this.tags={},this.hooks={insert:[],remove:[]},this.nddb_pointer=0,u.compatibility.getter?this.__defineGetter__("length",function(){return this.db.length}):this.length=null,this.__C={},this.__H={},this.__I={},this.__update={},this.__update.pointer=!1,this.__update.indexes=!1,this.__update.sort=!1,this.__parent=r||undefined,this.init(e),this.importDB(n)}var r=null,i=[],s=function(e,t){return!e||!t?(u.log("Attempt to add invalid condition","ERR"),!1):(i.push({type:e,condition:t}),!0)},o=function(e,t,n,i){if(!r)return u.log("No operation found.","ERR"),!1;var o=this._analyzeQuery(t,n,i);return o?s(e,o):!1};u.prototype.and=u.prototype.AND=function(e,t,n){return o("AND",e,t,n)},u.prototype.or=u.prototype.OR=function(e,t,n){return o("OR",e,t,n)},u.prototype.not=u.prototype.NOT=function(e,t,n){return o("NOT",e,t,n)},u.compatibility=t.compatibility(),e.NDDB=u,u.log=console.log,u.__symbols=[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"],u.__operations=["select","groupby","limit","first","fetch","last"],u.decycle=function(e){return JSON&&JSON.decycle&&"function"==typeof JSON.decycle&&(e=JSON.decycle(e)),e},u.retrocycle=function(e){return JSON&&JSON.retrocycle&&"function"==typeof JSON.retrocycle&&(e=JSON.retrocycle(e)),e},u.prototype.init=function(e){e=e||{},this.__options=e,e.log&&(u.log=e.log),e.C&&(this.__C=e.C),e.H&&(this.__H=e.H),e.I&&(this.__I=e.I),e.tags&&(this.tags=e.tags),e.nddb_pointer>0&&(this.nddb_pointer=e.nddb_pointer),e.hooks&&(this.hooks=e.hook),e.update&&("undefined"!=typeof e.update.pointer&&(this.__update.pointer=e.update.pointer),"undefined"!=typeof e.update.indexes&&(this.__update.indexes=e.update.indexes),"undefined"!=typeof e.update.sort&&(this.__update.sort=e.update.sort))},u.prototype.globalCompare=function(e,t){return"undefined"==typeof e&&"undefined"==typeof t?0:"undefined"==typeof t?-1:"undefined"==typeof e?1:e.nddbid<t.nddbid?-1:e.nddbid>t.nddbid?1:0},u.prototype._masquerade=function(e,t){return"undefined"==typeof e?!1:"undefined"!=typeof e.nddbid?e:(t=t||this.db,u.compatibility.defineProperty?Object.defineProperty(e,"nddbid",{value:t.length,configurable:!0,writable:!0}):e.nddbid=t.length,e)},u.prototype._masqueradeDB=function(e){if(!e)return[];var t=[];for(var n=0;n<e.length;n++)t[n]=this._masquerade(e[n],t);return t},u.prototype._autoUpdate=function(e){var n=e?t.merge(e,this.__update):this.__update;n.pointer&&(this.nddb_pointer=this.db.length-1),n.sort&&this.sort(),n.indexes&&this.rebuildIndexes(),this.__parent&&this.__parent._autoUpdate(n)},u.prototype.importDB=function(e){if(!e)return;this.db||(this.db=[]);for(var t=0;t<e.length;t++)this.insert(e[t])},u.prototype.insert=function(e){if("undefined"==typeof e||e===null)return;this.db||(this.db=[]),this._insert(e)},u.prototype._insert=function(e){e=this._masquerade(e),this.db.push(e),this.emit("insert",e),this.__update.indexes&&(this._hashIt(e),this._indexIt(e)),this._autoUpdate({indexes:!1})},u.prototype.breed=function(e){e=e||this.db;var t=this.cloneSettings(),n=this.__parent||this;return new this.constructor(t,e,n)},u.prototype.cloneSettings=function(){var e=this.__options||{};return e.H=this.__H,e.I=this.__I,e.C=this.__C,e.tags=this.tags,e.update=this.__update,t.clone(e)},u.prototype.toString=function(){var e="";for(var t=0;t<this.db.length;t++)e+=this.db[t]+"\n";return e},u.prototype.stringify=function(e){if(!this.length)return"[]";e="undefined"==typeof e?!0:e;var n;e?n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e)}:n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e,null,4)};var r="[";return this.each(function(e){e=u.decycle(e),r+=n(e)+", "}),r=r.replace(/, $/,"]"),r},u.prototype.compare=u.prototype.c=function(e,t){return!e||!t?(u.log("Cannot set empty property or empty comparator","ERR"),!1):(this.__C[e]=t,!0)},u.prototype.comparator=function(e){return"undefined"!=typeof this.__C[e]?this.__C[e]:function(n,r){if("undefined"==typeof n&&"undefined"==typeof r)return 0;if("undefined"==typeof n)return 1;if("undefined"==typeof r)return-1;var i=t.getNestedValue(e,n),s=t.getNestedValue(e,r);return"undefined"==typeof i&&"undefined"==typeof s?0:"undefined"==typeof i?1:"undefined"==typeof s?-1:i>s?1:s>i?-1:0}},u.prototype.isReservedWord=function(e){return this[e]?!0:!1},u.prototype._isValidIndex=function(e){if("undefined"==typeof e)return u.log("A valid index name must be provided","ERR"),!1;if(this.isReservedWord(e)){var t="A reserved word have been selected as an index. ";return t+="Please select another one: "+e,u.log(t,"ERR"),!1}return!0},u.prototype.hash=u.prototype.h=function(e,t){return this._isValidIndex(e)?(this.__H[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.index=u.prototype.i=function(e,t){return this._isValidIndex(e)?(this.__I[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.rebuildIndexes=function(){var e=!1,n=!1;if(!t.isEmpty(this.__H)){e=!0;for(var r in this.__H)this.__H.hasOwnProperty(r)&&(this[r]={})}if(!t.isEmpty(this.__I)){n=!0;for(var r in this.__I)this.__I.hasOwnProperty(r)&&(this[r]={})}e&&!n?this.each(this._hashIt):!e&&n?this.each(this._indexIt):e&&n&&this.each(function(e){this.hashIt(e),this.indexIt(e)})},u.prototype._hashIt=function(e){if(!e)return!1;if(t.isEmpty(this.__H))return!1;var n=null,r=null,i=null;for(var s in this.__H)if(this.__H.hasOwnProperty(s)){n=this.__H[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]||(this[s][i]=new u),this[s][i].insert(e)}},u.prototype._indexIt=function(e){if(!e)return!1;if(t.isEmpty(this.__I))return!1;var n=null,r=null,i=null;for(var s in this.__I)if(this.__I.hasOwnProperty(s)){n=this.__I[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]=e}},u.prototype.on=function(e,t){if(!e||!t||!this.hooks[e])return;return this.hooks[e].push(t),!0},u.prototype.off=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;if(!t)return this.hooks[e]=[],!0;for(var n=0;n<this.hooks[e].length;n++)if(this.hooks[e][n]==t)return this.hooks[e].splice(n,1),!0;return!1},u.prototype.emit=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;for(var n=0;n<this.hooks[e].length;n++)this.hooks[e][n].call(this,t)},u.prototype._analyzeQuery=function(e,n,r){var i=function(e,t,n){var r="(?)",i="Malformed query: "+e||r+" "+t||r+" "+n||r;return u.log(i,"WARN"),!1};"undefined"==typeof e&&i(e,n,r);if("undefined"!=typeof n){"undefined"==typeof r&&i(e,n,r);if(!t.in_array(n,[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"]))return u.log("Query error. Invalid operator detected: "+n,"WARN"),!1;n==="="&&(n="==");if(t.in_array(n,["><","<>","in","!in"])){r instanceof Array||(u.log("Range-queries need an array as third parameter","WARN"),i(e,n,r));if(n==="<>"||n==="><")r[0]=t.setNestedValue(e,r[0]),r[1]=t.setNestedValue(e,r[1])}else r=t.setNestedValue(e,r)}else"undefined"!=typeof r?i(e,n,r):(n="",r="");return{d:e,op:n,value:r}},u.prototype.distinct=function(){return this.breed(t.distinct(this.db))},u.prototype.select=function(e,n,r){var i=this._analyzeQuery(e,n,r);if(!i)return!1;var e=i.d,n=i.op,r=i.value,s=this.comparator(e),o=function(n){if("undefined"!=typeof t.getNestedValue(e,n))return n},a=function(i){try{if(t.eval(s(i,r)+n+0,i))return i}catch(o){return u.log("Malformed select query: "+e+n+r),!1}},f=function(e){if(s(e,r[0])>0&&s(e,r[1])<0)return e},l=function(e){if(s(e,r[0])<0&&s(e,r[1]>0))return e},c=function(n){if(t.in_array(t.getNestedValue(e,n),r))return n},h=function(n){if(!t.in_array(t.getNestedValue(e,n),r))return n};switch(n){case"":var p=o;break;case"<>":var p=l;break;case"><":var p=f;break;case"in":var p=c;break;case"!in":var p=h;break;default:var p=a}return this.filter(p)},u.prototype.limit=function(e){e=e||0;if(e===0)return this.breed();var t=e>0?this.db.slice(0,e):this.db.slice(e);return this.breed(t)},u.prototype.reverse=function(){return this.db.reverse(),this},u.prototype.sort=function(e){if(!e)var t=this.globalCompare;else if("function"==typeof e)var t=e;else if(e instanceof Array)var n=this,t=function(t,r){for(var i=0;i<e.length;i++){var s=n.comparator(e[i]).call(n,t,r);if(s!==0)return s}return s};else var t=this.comparator(e);return this.db.sort(t),this},u.prototype.shuffle=function(){return this.db=t.shuffle(this.db),!0},u.prototype.filter=function(e){return this.breed(this.db.filter(e))},u.prototype.each=u.prototype.forEach=function(){if(arguments.length===0)return;var e=arguments[0];for(var t=0;t<this.db.length;t++)arguments[0]=this.db[t],e.apply(this,arguments)},u.prototype.map=function(){if(arguments.length===0)return;var e=arguments[0],t=[],n=undefined;for(var r=0;r<this.db.length;r++)arguments[0]=this.db[r],n=e.apply(this,arguments),"undefined"!=typeof n&&t.push(n);return t},u.prototype.remove=function(){if(!this.length)return this;if(this.__parent){for(var e=0;e<this.db.length;e++){var t=this.db[e].nddbid-e;this.__parent.db.splice(t,1)}for(var e=0;e<this.__parent.length;e++)this.__parent.db[e].nddbid=e}return this.emit("remove",this.db),this.db=[],this._autoUpdate(),this},u.prototype.clear=function(e){return e?(this.db=[],this._autoUpdate()):u.log("Do you really want to clear the current dataset? Please use clear(true)","WARN"),e},u.prototype.join=function(e,n,r,i){return this._join(e,n,t.equals,r,i)},u.prototype.concat=function(e,t,n,r){return this._join(e,t,function(){return!0},n,r)},u.prototype._join=function(e,n,r,i,s){r=r||t.equals,i="undefined"!=typeof i?i:"joined";if(s)var s=s instanceof Array?s:[s];var o=[],a=[];for(var f=0;f<this.db.length;f++)try{var l=t.eval("this."+e,this.db[f]);if("undefined"!=typeof l)for(var c=f+1;c<this.db.length;c++)try{var h=t.eval("this."+n,this.db[c]);if("undefined"!=typeof h&&r(l,h)){var p=t.clone(this.db[f]),d=s?t.subobj(this.db[c],s):this.db[c];p[i]=d,o.push(p)}}catch(v){u.log("Key not found in entry: "+n,"WARN")}}catch(v){u.log("Key not found in entry: "+e,"WARN")}return this.breed(o)},u.prototype.split=function(e){var n=[];for(var r=0;r<this.db.length;r++)n=n.concat(t.split(this.db[r],e));return this.breed(n)},u.prototype._fetch=function(e,n){function r(e,n){return t.getNestedValue(n,e)}function i(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return t.obj2KeyedArray(r)}function s(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return n.split(".").concat(t.obj2KeyedArray(r))}switch(n){case"VALUES":var o=e?i:t.obj2Array;break;case"KEY_VALUES":var o=e?s:t.obj2KeyedArray;break;default:if(!e)return this.db;var o=r}var u=[];for(var a=0;a<this.db.length;a++){var f=o.call(this.db[a],this.db[a],e);"undefined"!=typeof f&&u.push(f)}return u},u.prototype.fetch=function(e){return this._fetch(e,!0)},u.prototype.fetchArray=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyArray=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.fetchValues=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyValues=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.groupBy=function(e){if(!e)return this.db;var n=[],r=[];for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);if("undefined"==typeof s)continue;if(!t.in_array(s,n)){n.push(s);var o=this.filter(function(n){if(t.equals(t.getNestedValue(e,n),s))return this});o.nddb_pointer=0,r.push(o)}}return r},u.prototype.count=function(e){if("undefined"==typeof e)return this.db.length;var n=0;for(var r=0;r<this.db.length;r++)t.hasOwnNestedProperty(e,this.db[r])&&n++;return n},u.prototype.sum=function(e){if("undefined"==typeof e)return!1;var n=0;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);isNaN(i)||(n+=i)}return n},u.prototype.mean=function(e){if("undefined"==typeof e)return!1;var n=0,r=0;for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);isNaN(s)||(n+=s,r++)}return r===0?0:n/r},u.prototype.stddev=function(e){if("undefined"==typeof e)return!1;var n=this.mean(e);if(isNaN(n))return!1;var r=0;return this.each(function(i){var s=t.getNestedValue(e,i);isNaN(s)||(r+=Math.pow(s-n,2))}),r!==0?Math.sqrt(r):0},u.prototype.min=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i<n||n===!1)&&(n=i)}return n},u.prototype.max=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i>n||n===!1)&&(n=i)}return n},u.prototype.skim=function(e){return e?this.breed(this.map(function(n){var r=t.skim(n,e);if(!t.isEmpty(r))return r})):this},u.prototype.keep=function(e){return e?this.breed(this.map(function(n){var r=t.subobj(n,e);if(!t.isEmpty(r))return r})):this.breed([])},u.prototype.diff=function(e){return!e||!e.length?this:("object"==typeof e&&(e instanceof u||e instanceof this.constructor)&&(e=e.db),this.breed(t.arrayDiff(this.db,e)))},u.prototype.intersect=function(e){if(!e||!e.length)return this;if("object"==typeof e)if(e instanceof u||e instanceof this.constructor)var e=e.db;return this.breed(t.arrayIntersect(this.db,e))},u.prototype.get=function(e){var e=e||this.nddb_pointer;return e<0||e>this.db.length-1?!1:this.db[e]},u.prototype.next=function(){var e=u.prototype.get.call(this,++this.nddb_pointer);return e||this.nddb_pointer--,e},u.prototype.previous=function(){var e=u.prototype.get.call(this,--this.nddb_pointer);return e||this.nddb_pointer++,e},u.prototype.first=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[0].nddbid,t[0]):undefined},u.prototype.last=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[t.length-1].nddbid,t[t.length-1]):undefined},u.prototype.tag=function(e,t){if("undefined"==typeof e)return u.log("Cannot register empty tag.","ERR"),!1;var n=null,r=typeof t;if(r==="undefined")n=this.db[this.nddb_pointer];else if(r==="number"){if(t>this.length||t<0)return u.log("Invalid index provided for tag registration","ERR"),!1;n=this.db[t]}else n=t;return this.tags[e]=n,!0},u.prototype.resolveTag=function(e){return"undefined"==typeof e?(u.log("Cannot resolve empty tag.","ERR"),!1):this.tags[e]};var a=function(){return"function"==typeof n};if(t.isNodeJS()){require("./external/cycle.js");var f=require("fs")}u.prototype.save=function(e,r,i){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;i=i||!1;if(!t.isNodeJS())return a()?(n(e,this.stringify(i)),r&&r(),!0):(u.log("No support for persistent storage found.","ERR"),!1);f.writeFile(e,this.stringify(i),"utf-8",function(e){if(e)throw e;return r&&r(),!0})},u.prototype.load=function(e,r){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;if(!t.isNodeJS()){if(!a())return u.log("No support for persistent storage found.","ERR"),!1;var i=n(e);return this.importDB(i),r&&r(),!0}var s=function(e){var t=JSON.parse(e.toString()),n;for(n=0;n<t.length;n++)t[n]=u.retrocycle(t[n]);this.importDB(t)};if(!r){var o=f.readFileSync(e,"utf-8");s.call(this,o)}else f.readFile(e,"utf-8",function(e,t){if(e)throw e;s.call(this,t),r()})}})("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:window,"undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS||require("JSUS").JSUS,"object"==typeof module&&"function"==typeof require?module.parent.exports.store||require("shelf.js/build/shelf-fs.js").store:this.store)
+(function(e,t,n){function u(e,n,r){e=e||{};if(!t)throw new Error("JSUS not found.");this.db=[],this.tags={},this.hooks={insert:[],remove:[]},this.nddb_pointer=0,u.compatibility.getter?this.__defineGetter__("length",function(){return this.db.length}):this.length=null,this.__C={},this.__H={},this.__I={},this.__update={},this.__update.pointer=!1,this.__update.indexes=!1,this.__update.sort=!1,this.__parent=r||undefined,this.init(e),this.importDB(n)}var r=null,i=[],s=function(e,t){return!e||!t?(u.log("Attempt to add invalid condition","ERR"),!1):(i.push({type:e,condition:t}),!0)},o=function(e,t,n,i){if(!r)return u.log("No operation found.","ERR"),!1;var o=this._analyzeQuery(t,n,i);return o?s(e,o):!1};u.prototype.and=u.prototype.AND=function(e,t,n){return o("AND",e,t,n)},u.prototype.or=u.prototype.OR=function(e,t,n){return o("OR",e,t,n)},u.prototype.not=u.prototype.NOT=function(e,t,n){return o("NOT",e,t,n)},u.compatibility=t.compatibility(),e.NDDB=u,u.log=console.log,u.__symbols=[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"],u.__operations=["select","groupby","limit","first","fetch","last"],u.decycle=function(e){return JSON&&JSON.decycle&&"function"==typeof JSON.decycle&&(e=JSON.decycle(e)),e},u.retrocycle=function(e){return JSON&&JSON.retrocycle&&"function"==typeof JSON.retrocycle&&(e=JSON.retrocycle(e)),e},u.prototype.init=function(e){e=e||{},this.__options=e,e.log&&(u.log=e.log),e.C&&(this.__C=e.C),e.H&&(this.__H=e.H),e.I&&(this.__I=e.I),e.tags&&(this.tags=e.tags),e.nddb_pointer>0&&(this.nddb_pointer=e.nddb_pointer),e.hooks&&(this.hooks=e.hook),e.update&&("undefined"!=typeof e.update.pointer&&(this.__update.pointer=e.update.pointer),"undefined"!=typeof e.update.indexes&&(this.__update.indexes=e.update.indexes),"undefined"!=typeof e.update.sort&&(this.__update.sort=e.update.sort))},u.prototype.globalCompare=function(e,t){return"undefined"==typeof e&&"undefined"==typeof t?0:"undefined"==typeof t?-1:"undefined"==typeof e?1:e.nddbid<t.nddbid?-1:e.nddbid>t.nddbid?1:0},u.prototype._masquerade=function(e,t){return"undefined"==typeof e?!1:"undefined"!=typeof e.nddbid?e:(t=t||this.db,u.compatibility.defineProperty?Object.defineProperty(e,"nddbid",{value:t.length,configurable:!0,writable:!0}):e.nddbid=t.length,e)},u.prototype._masqueradeDB=function(e){if(!e)return[];var t=[];for(var n=0;n<e.length;n++)t[n]=this._masquerade(e[n],t);return t},u.prototype._autoUpdate=function(e){var n=e?t.merge(e,this.__update):this.__update;n.pointer&&(this.nddb_pointer=this.db.length-1),n.sort&&this.sort(),n.indexes&&this.rebuildIndexes(),this.__parent&&this.__parent._autoUpdate(n)},u.prototype.importDB=function(e){if(!e)return;this.db||(this.db=[]);for(var t=0;t<e.length;t++)this.insert(e[t])},u.prototype.insert=function(e){if("undefined"==typeof e||e===null)return;this.db||(this.db=[]),this._insert(e)},u.prototype._insert=function(e){e=this._masquerade(e),this.db.push(e),this.emit("insert",e),this.__update.indexes&&(this._hashIt(e),this._indexIt(e)),this._autoUpdate({indexes:!1})},u.prototype.breed=function(e){e=e||this.db;var t=this.cloneSettings(),n=this.__parent||this;return new this.constructor(t,e,n)},u.prototype.cloneSettings=function(){var e=this.__options||{};return e.H=this.__H,e.I=this.__I,e.C=this.__C,e.tags=this.tags,e.update=this.__update,t.clone(e)},u.prototype.toString=function(){var e="";for(var t=0;t<this.db.length;t++)e+=this.db[t]+"\n";return e},u.prototype.stringify=function(e){if(!this.length)return"[]";e="undefined"==typeof e?!0:e;var n;e?n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e)}:n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e,null,4)};var r="[";return this.each(function(e){e=u.decycle(e),r+=n(e)+", "}),r=r.replace(/, $/,"]"),r},u.prototype.compare=u.prototype.c=function(e,t){return!e||!t?(u.log("Cannot set empty property or empty comparator","ERR"),!1):(this.__C[e]=t,!0)},u.prototype.comparator=function(e){return"undefined"!=typeof this.__C[e]?this.__C[e]:function(n,r){if("undefined"==typeof n&&"undefined"==typeof r)return 0;if("undefined"==typeof n)return 1;if("undefined"==typeof r)return-1;var i=t.getNestedValue(e,n),s=t.getNestedValue(e,r);return"undefined"==typeof i&&"undefined"==typeof s?0:"undefined"==typeof i?1:"undefined"==typeof s?-1:i>s?1:s>i?-1:0}},u.prototype.isReservedWord=function(e){return this[e]?!0:!1},u.prototype._isValidIndex=function(e){if("undefined"==typeof e)return u.log("A valid index name must be provided","ERR"),!1;if(this.isReservedWord(e)){var t="A reserved word have been selected as an index. ";return t+="Please select another one: "+e,u.log(t,"ERR"),!1}return!0},u.prototype.hash=u.prototype.h=function(e,t){return this._isValidIndex(e)?(this.__H[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.index=u.prototype.i=function(e,t){return this._isValidIndex(e)?(this.__I[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.rebuildIndexes=function(){var e=!1,n=!1;if(!t.isEmpty(this.__H)){e=!0;for(var r in this.__H)this.__H.hasOwnProperty(r)&&(this[r]={})}if(!t.isEmpty(this.__I)){n=!0;for(var r in this.__I)this.__I.hasOwnProperty(r)&&(this[r]={})}e&&!n?this.each(this._hashIt):!e&&n?this.each(this._indexIt):e&&n&&this.each(function(e){this.hashIt(e),this.indexIt(e)})},u.prototype._hashIt=function(e){if(!e)return!1;if(t.isEmpty(this.__H))return!1;var n=null,r=null,i=null;for(var s in this.__H)if(this.__H.hasOwnProperty(s)){n=this.__H[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]||(this[s][i]=new u),this[s][i].insert(e)}},u.prototype._indexIt=function(e){if(!e)return!1;if(t.isEmpty(this.__I))return!1;var n=null,r=null,i=null;for(var s in this.__I)if(this.__I.hasOwnProperty(s)){n=this.__I[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]=e}},u.prototype.on=function(e,t){if(!e||!t||!this.hooks[e])return;return this.hooks[e].push(t),!0},u.prototype.off=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;if(!t)return this.hooks[e]=[],!0;for(var n=0;n<this.hooks[e].length;n++)if(this.hooks[e][n]==t)return this.hooks[e].splice(n,1),!0;return!1},u.prototype.emit=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;for(var n=0;n<this.hooks[e].length;n++)this.hooks[e][n].call(this,t)},u.prototype._analyzeQuery=function(e,n,r){var i=function(e,t,n){var r="(?)",i="Malformed query: "+e||r+" "+t||r+" "+n||r;return u.log(i,"WARN"),!1};"undefined"==typeof e&&i(e,n,r);if("undefined"!=typeof n){"undefined"==typeof r&&i(e,n,r);if(!t.in_array(n,[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"]))return u.log("Query error. Invalid operator detected: "+n,"WARN"),!1;n==="="&&(n="==");if(t.in_array(n,["><","<>","in","!in"])){r instanceof Array||(u.log("Range-queries need an array as third parameter","WARN"),i(e,n,r));if(n==="<>"||n==="><")r[0]=t.setNestedValue(e,r[0]),r[1]=t.setNestedValue(e,r[1])}else r=t.setNestedValue(e,r)}else"undefined"!=typeof r?i(e,n,r):(n="",r="");return{d:e,op:n,value:r}},u.prototype.distinct=function(){return this.breed(t.distinct(this.db))},u.prototype.select=function(e,n,r){var i=this._analyzeQuery(e,n,r);if(!i)return!1;var e=i.d,n=i.op,r=i.value,s=this.comparator(e),o=function(n){if("undefined"!=typeof t.getNestedValue(e,n))return n},a=function(i){try{if(t.eval(s(i,r)+n+0,i))return i}catch(o){return u.log("Malformed select query: "+e+n+r),!1}},f=function(e){if(s(e,r[0])>0&&s(e,r[1])<0)return e},l=function(e){if(s(e,r[0])<0&&s(e,r[1]>0))return e},c=function(n){if(t.in_array(t.getNestedValue(e,n),r))return n},h=function(n){if(!t.in_array(t.getNestedValue(e,n),r))return n};switch(n){case"":var p=o;break;case"<>":var p=l;break;case"><":var p=f;break;case"in":var p=c;break;case"!in":var p=h;break;default:var p=a}return this.filter(p)},u.prototype.limit=function(e){e=e||0;if(e===0)return this.breed();var t=e>0?this.db.slice(0,e):this.db.slice(e);return this.breed(t)},u.prototype.reverse=function(){return this.db.reverse(),this},u.prototype.sort=function(e){if(!e)var t=this.globalCompare;else if("function"==typeof e)var t=e;else if(e instanceof Array)var n=this,t=function(t,r){for(var i=0;i<e.length;i++){var s=n.comparator(e[i]).call(n,t,r);if(s!==0)return s}return s};else var t=this.comparator(e);return this.db.sort(t),this},u.prototype.shuffle=function(){return this.db=t.shuffle(this.db),this},u.prototype.filter=function(e){return this.breed(this.db.filter(e))},u.prototype.each=u.prototype.forEach=function(){if(arguments.length===0)return;var e=arguments[0];for(var t=0;t<this.db.length;t++)arguments[0]=this.db[t],e.apply(this,arguments)},u.prototype.map=function(){if(arguments.length===0)return;var e=arguments[0],t=[],n=undefined;for(var r=0;r<this.db.length;r++)arguments[0]=this.db[r],n=e.apply(this,arguments),"undefined"!=typeof n&&t.push(n);return t},u.prototype.remove=function(){if(!this.length)return this;if(this.__parent){for(var e=0;e<this.db.length;e++){var t=this.db[e].nddbid-e;this.__parent.db.splice(t,1)}for(var e=0;e<this.__parent.length;e++)this.__parent.db[e].nddbid=e}return this.emit("remove",this.db),this.db=[],this._autoUpdate(),this},u.prototype.clear=function(e){return e?(this.db=[],this._autoUpdate()):u.log("Do you really want to clear the current dataset? Please use clear(true)","WARN"),e},u.prototype.join=function(e,n,r,i){return this._join(e,n,t.equals,r,i)},u.prototype.concat=function(e,t,n,r){return this._join(e,t,function(){return!0},n,r)},u.prototype._join=function(e,n,r,i,s){r=r||t.equals,i="undefined"!=typeof i?i:"joined";if(s)var s=s instanceof Array?s:[s];var o=[],a=[];for(var f=0;f<this.db.length;f++)try{var l=t.eval("this."+e,this.db[f]);if("undefined"!=typeof l)for(var c=f+1;c<this.db.length;c++)try{var h=t.eval("this."+n,this.db[c]);if("undefined"!=typeof h&&r(l,h)){var p=t.clone(this.db[f]),d=s?t.subobj(this.db[c],s):this.db[c];p[i]=d,o.push(p)}}catch(v){u.log("Key not found in entry: "+n,"WARN")}}catch(v){u.log("Key not found in entry: "+e,"WARN")}return this.breed(o)},u.prototype.split=function(e){var n=[];for(var r=0;r<this.db.length;r++)n=n.concat(t.split(this.db[r],e));return this.breed(n)},u.prototype._fetch=function(e,n){function r(e,n){return t.getNestedValue(n,e)}function i(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return t.obj2KeyedArray(r)}function s(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return n.split(".").concat(t.obj2KeyedArray(r))}switch(n){case"VALUES":var o=e?i:t.obj2Array;break;case"KEY_VALUES":var o=e?s:t.obj2KeyedArray;break;default:if(!e)return this.db;var o=r}var u=[];for(var a=0;a<this.db.length;a++){var f=o.call(this.db[a],this.db[a],e);"undefined"!=typeof f&&u.push(f)}return u},u.prototype.fetch=function(e){return this._fetch(e,!0)},u.prototype.fetchArray=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyArray=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.fetchValues=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyValues=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.groupBy=function(e){if(!e)return this.db;var n=[],r=[];for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);if("undefined"==typeof s)continue;if(!t.in_array(s,n)){n.push(s);var o=this.filter(function(n){if(t.equals(t.getNestedValue(e,n),s))return this});o.nddb_pointer=0,r.push(o)}}return r},u.prototype.count=function(e){if("undefined"==typeof e)return this.db.length;var n=0;for(var r=0;r<this.db.length;r++)t.hasOwnNestedProperty(e,this.db[r])&&n++;return n},u.prototype.sum=function(e){if("undefined"==typeof e)return!1;var n=0;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);isNaN(i)||(n+=i)}return n},u.prototype.mean=function(e){if("undefined"==typeof e)return!1;var n=0,r=0;for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);isNaN(s)||(n+=s,r++)}return r===0?0:n/r},u.prototype.stddev=function(e){if("undefined"==typeof e)return!1;var n=this.mean(e);if(isNaN(n))return!1;var r=0;return this.each(function(i){var s=t.getNestedValue(e,i);isNaN(s)||(r+=Math.pow(s-n,2))}),r!==0?Math.sqrt(r):0},u.prototype.min=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i<n||n===!1)&&(n=i)}return n},u.prototype.max=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i>n||n===!1)&&(n=i)}return n},u.prototype.skim=function(e){return e?this.breed(this.map(function(n){var r=t.skim(n,e);if(!t.isEmpty(r))return r})):this},u.prototype.keep=function(e){return e?this.breed(this.map(function(n){var r=t.subobj(n,e);if(!t.isEmpty(r))return r})):this.breed([])},u.prototype.diff=function(e){return!e||!e.length?this:("object"==typeof e&&(e instanceof u||e instanceof this.constructor)&&(e=e.db),this.breed(t.arrayDiff(this.db,e)))},u.prototype.intersect=function(e){if(!e||!e.length)return this;if("object"==typeof e)if(e instanceof u||e instanceof this.constructor)var e=e.db;return this.breed(t.arrayIntersect(this.db,e))},u.prototype.get=function(e){var e=e||this.nddb_pointer;return e<0||e>this.db.length-1?!1:this.db[e]},u.prototype.next=function(){var e=u.prototype.get.call(this,++this.nddb_pointer);return e||this.nddb_pointer--,e},u.prototype.previous=function(){var e=u.prototype.get.call(this,--this.nddb_pointer);return e||this.nddb_pointer++,e},u.prototype.first=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[0].nddbid,t[0]):undefined},u.prototype.last=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[t.length-1].nddbid,t[t.length-1]):undefined},u.prototype.tag=function(e,t){if("undefined"==typeof e)return u.log("Cannot register empty tag.","ERR"),!1;var n=null,r=typeof t;if(r==="undefined")n=this.db[this.nddb_pointer];else if(r==="number"){if(t>this.length||t<0)return u.log("Invalid index provided for tag registration","ERR"),!1;n=this.db[t]}else n=t;return this.tags[e]=n,!0},u.prototype.resolveTag=function(e){return"undefined"==typeof e?(u.log("Cannot resolve empty tag.","ERR"),!1):this.tags[e]};var a=function(){return"function"==typeof n};if(t.isNodeJS()){require("./external/cycle.js");var f=require("fs")}u.prototype.save=function(e,r,i){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;i=i||!1;if(!t.isNodeJS())return a()?(n(e,this.stringify(i)),r&&r(),!0):(u.log("No support for persistent storage found.","ERR"),!1);f.writeFile(e,this.stringify(i),"utf-8",function(e){if(e)throw e;return r&&r(),!0})},u.prototype.load=function(e,r){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;if(!t.isNodeJS()){if(!a())return u.log("No support for persistent storage found.","ERR"),!1;var i=n(e);return this.importDB(i),r&&r(),!0}var s=function(e){var t=JSON.parse(e.toString()),n;for(n=0;n<t.length;n++)t[n]=u.retrocycle(t[n]);this.importDB(t)};if(!r){var o=f.readFileSync(e,"utf-8");s.call(this,o)}else f.readFile(e,"utf-8",function(e,t){if(e)throw e;s.call(this,t),r()})}})("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:window,"undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS||require("JSUS").JSUS,"object"==typeof module&&"function"==typeof require?module.parent.exports.store||require("shelf.js/build/shelf-fs.js").store:this.store)
501 build/nddb-full.js
View
@@ -1020,498 +1020,6 @@ var prepareString = "a"[0] != "a",
};
});
-/*
- http://www.JSON.org/json2.js
- 2011-02-23
-
- Public Domain.
-
- NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
-
- See http://www.JSON.org/js.html
-
-
- This code should be minified before deployment.
- See http://javascript.crockford.com/jsmin.html
-
- USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
- NOT CONTROL.
-
-
- This file creates a global JSON object containing two methods: stringify
- and parse.
-
- JSON.stringify(value, replacer, space)
- value any JavaScript value, usually an object or array.
-
- replacer an optional parameter that determines how object
- values are stringified for objects. It can be a
- function or an array of strings.
-
- space an optional parameter that specifies the indentation
- of nested structures. If it is omitted, the text will
- be packed without extra whitespace. If it is a number,
- it will specify the number of spaces to indent at each
- level. If it is a string (such as '\t' or '&nbsp;'),
- it contains the characters used to indent at each level.
-
- This method produces a JSON text from a JavaScript value.
-
- When an object value is found, if the object contains a toJSON
- method, its toJSON method will be called and the result will be
- stringified. A toJSON method does not serialize: it returns the
- value represented by the name/value pair that should be serialized,
- or undefined if nothing should be serialized. The toJSON method
- will be passed the key associated with the value, and this will be
- bound to the value
-
- For example, this would serialize Dates as ISO strings.
-
- Date.prototype.toJSON = function (key) {
- function f(n) {
- // Format integers to have at least two digits.
- return n < 10 ? '0' + n : n;
- }
-
- return this.getUTCFullYear() + '-' +
- f(this.getUTCMonth() + 1) + '-' +
- f(this.getUTCDate()) + 'T' +
- f(this.getUTCHours()) + ':' +
- f(this.getUTCMinutes()) + ':' +
- f(this.getUTCSeconds()) + 'Z';
- };
-
- You can provide an optional replacer method. It will be passed the
- key and value of each member, with this bound to the containing
- object. The value that is returned from your method will be
- serialized. If your method returns undefined, then the member will
- be excluded from the serialization.
-
- If the replacer parameter is an array of strings, then it will be
- used to select the members to be serialized. It filters the results
- such that only members with keys listed in the replacer array are
- stringified.
-
- Values that do not have JSON representations, such as undefined or
- functions, will not be serialized. Such values in objects will be
- dropped; in arrays they will be replaced with null. You can use
- a replacer function to replace those with JSON values.
- JSON.stringify(undefined) returns undefined.
-
- The optional space parameter produces a stringification of the
- value that is filled with line breaks and indentation to make it
- easier to read.
-
- If the space parameter is a non-empty string, then that string will
- be used for indentation. If the space parameter is a number, then
- the indentation will be that many spaces.
-
- Example:
-
- text = JSON.stringify(['e', {pluribus: 'unum'}]);
- // text is '["e",{"pluribus":"unum"}]'
-
-
- text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
- // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
-
- text = JSON.stringify([new Date()], function (key, value) {
- return this[key] instanceof Date ?
- 'Date(' + this[key] + ')' : value;
- });
- // text is '["Date(---current time---)"]'
-
-
- JSON.parse(text, reviver)
- This method parses a JSON text to produce an object or array.
- It can throw a SyntaxError exception.
-
- The optional reviver parameter is a function that can filter and
- transform the results. It receives each of the keys and values,
- and its return value is used instead of the original value.
- If it returns what it received, then the structure is not modified.
- If it returns undefined then the member is deleted.
-
- Example:
-
- // Parse the text. Values that look like ISO date strings will
- // be converted to Date objects.
-
- myData = JSON.parse(text, function (key, value) {
- var a;
- if (typeof value === 'string') {
- a =
-/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
- if (a) {
- return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
- +a[5], +a[6]));
- }
- }
- return value;
- });
-
- myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
- var d;
- if (typeof value === 'string' &&
- value.slice(0, 5) === 'Date(' &&
- value.slice(-1) === ')') {
- d = new Date(value.slice(5, -1));
- if (d) {
- return d;
- }
- }
- return value;
- });
-
-
- This is a reference implementation. You are free to copy, modify, or
- redistribute.
-*/
-
-/*jslint evil: true, strict: false, regexp: false */
-
-/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
- call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
- getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
- lastIndex, length, parse, prototype, push, replace, slice, stringify,
- test, toJSON, toString, valueOf
-*/
-
-
-// Create a JSON object only if one does not already exist. We create the
-// methods in a closure to avoid creating global variables.
-
-var JSON;
-if (!JSON) {
- JSON = {};
-}
-
-(function () {
- "use strict";
-
- var global = Function('return this')()
- , JSON = global.JSON
- ;
-
- if (!JSON) {
- JSON = {};
- }
-
- function f(n) {
- // Format integers to have at least two digits.
- return n < 10 ? '0' + n : n;
- }
-
- if (typeof Date.prototype.toJSON !== 'function') {
-
- Date.prototype.toJSON = function (key) {
-
- return isFinite(this.valueOf()) ?
- this.getUTCFullYear() + '-' +
- f(this.getUTCMonth() + 1) + '-' +
- f(this.getUTCDate()) + 'T' +
- f(this.getUTCHours()) + ':' +
- f(this.getUTCMinutes()) + ':' +
- f(this.getUTCSeconds()) + 'Z' : null;
- };
-
- String.prototype.toJSON =
- Number.prototype.toJSON =
- Boolean.prototype.toJSON = function (key) {
- return this.valueOf();
- };
- }
-
- var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
- escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
- gap,
- indent,
- meta = { // table of character substitutions
- '\b': '\\b',
- '\t': '\\t',
- '\n': '\\n',
- '\f': '\\f',
- '\r': '\\r',
- '"' : '\\"',
- '\\': '\\\\'
- },
- rep;
-
-
- function quote(string) {
-
-// If the string contains no control characters, no quote characters, and no
-// backslash characters, then we can safely slap some quotes around it.
-// Otherwise we must also replace the offending characters with safe escape
-// sequences.
-
- escapable.lastIndex = 0;
- return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
- var c = meta[a];
- return typeof c === 'string' ? c :
- '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
- }) + '"' : '"' + string + '"';
- }
-
-
- function str(key, holder) {
-
-// Produce a string from holder[key].
-
- var i, // The loop counter.
- k, // The member key.
- v, // The member value.
- length,
- mind = gap,
- partial,
- value = holder[key];
-
-// If the value has a toJSON method, call it to obtain a replacement value.
-
- if (value && typeof value === 'object' &&
- typeof value.toJSON === 'function') {
- value = value.toJSON(key);
- }
-
-// If we were called with a replacer function, then call the replacer to
-// obtain a replacement value.
-
- if (typeof rep === 'function') {
- value = rep.call(holder, key, value);
- }
-
-// What happens next depends on the value's type.
-
- switch (typeof value) {
- case 'string':
- return quote(value);
-
- case 'number':
-
-// JSON numbers must be finite. Encode non-finite numbers as null.
-
- return isFinite(value) ? String(value) : 'null';
-
- case 'boolean':
- case 'null':
-
-// If the value is a boolean or null, convert it to a string. Note:
-// typeof null does not produce 'null'. The case is included here in
-// the remote chance that this gets fixed someday.
-
- return String(value);
-
-// If the type is 'object', we might be dealing with an object or an array or
-// null.
-
- case 'object':
-
-// Due to a specification blunder in ECMAScript, typeof null is 'object',
-// so watch out for that case.
-
- if (!value) {
- return 'null';
- }
-
-// Make an array to hold the partial results of stringifying this object value.
-
- gap += indent;
- partial = [];
-
-// Is the value an array?
-
- if (Object.prototype.toString.apply(value) === '[object Array]') {
-
-// The value is an array. Stringify every element. Use null as a placeholder
-// for non-JSON values.
-
- length = value.length;
- for (i = 0; i < length; i += 1) {
- partial[i] = str(i, value) || 'null';
- }
-
-// Join all of the elements together, separated with commas, and wrap them in
-// brackets.
-
- v = partial.length === 0 ? '[]' : gap ?
- '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
- '[' + partial.join(',') + ']';
- gap = mind;
- return v;
- }
-
-// If the replacer is an array, use it to select the members to be stringified.
-
- if (rep && typeof rep === 'object') {
- length = rep.length;
- for (i = 0; i < length; i += 1) {
- if (typeof rep[i] === 'string') {
- k = rep[i];
- v = str(k, value);
- if (v) {
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
- }
- }
- }
- } else {
-
-// Otherwise, iterate through all of the keys in the object.
-
- for (k in value) {
- if (Object.prototype.hasOwnProperty.call(value, k)) {
- v = str(k, value);
- if (v) {
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
- }
- }
- }
- }
-
-// Join all of the member texts together, separated with commas,
-// and wrap them in braces.
-
- v = partial.length === 0 ? '{}' : gap ?
- '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
- '{' + partial.join(',') + '}';
- gap = mind;
- return v;
- }
- }
-
-// If the JSON object does not yet have a stringify method, give it one.
-
- if (typeof JSON.stringify !== 'function') {
- JSON.stringify = function (value, replacer, space) {
-
-// The stringify method takes a value and an optional replacer, and an optional
-// space parameter, and returns a JSON text. The replacer can be a function
-// that can replace values, or an array of strings that will select the keys.
-// A default replacer method can be provided. Use of the space parameter can
-// produce text that is more easily readable.
-
- var i;
- gap = '';
- indent = '';
-
-// If the space parameter is a number, make an indent string containing that
-// many spaces.
-
- if (typeof space === 'number') {
- for (i = 0; i < space; i += 1) {
- indent += ' ';
- }
-
-// If the space parameter is a string, it will be used as the indent string.
-
- } else if (typeof space === 'string') {
- indent = space;
- }
-
-// If there is a replacer, it must be a function or an array.
-// Otherwise, throw an error.
-
- rep = replacer;
- if (replacer && typeof replacer !== 'function' &&
- (typeof replacer !== 'object' ||
- typeof replacer.length !== 'number')) {
- throw new Error('JSON.stringify');
- }
-
-// Make a fake root object containing our value under the key of ''.
-// Return the result of stringifying the value.
-
- return str('', {'': value});
- };
- }
-
-
-// If the JSON object does not yet have a parse method, give it one.
-
- if (typeof JSON.parse !== 'function') {
- JSON.parse = function (text, reviver) {
-
-// The parse method takes a text and an optional reviver function, and returns
-// a JavaScript value if the text is a valid JSON text.
-
- var j;
-
- function walk(holder, key) {
-
-// The walk method is used to recursively walk the resulting structure so
-// that modifications can be made.
-
- var k, v, value = holder[key];
- if (value && typeof value === 'object') {
- for (k in value) {
- if (Object.prototype.hasOwnProperty.call(value, k)) {
- v = walk(value, k);
- if (v !== undefined) {
- value[k] = v;
- } else {
- delete value[k];
- }
- }
- }
- }
- return reviver.call(holder, key, value);
- }
-
-
-// Parsing happens in four stages. In the first stage, we replace certain
-// Unicode characters with escape sequences. JavaScript handles many characters
-// incorrectly, either silently deleting them, or treating them as line endings.
-
- text = String(text);
- cx.lastIndex = 0;
- if (cx.test(text)) {
- text = text.replace(cx, function (a) {
- return '\\u' +
- ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
- });
- }
-
-// In the second stage, we run the text against regular expressions that look
-// for non-JSON patterns. We are especially concerned with '()' and 'new'
-// because they can cause invocation, and '=' because it can cause mutation.
-// But just to be safe, we want to reject all unexpected forms.
-
-// We split the second stage into 4 regexp operations in order to work around
-// crippling inefficiencies in IE's and Safari's regexp engines. First we
-// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
-// replace all simple value tokens with ']' characters. Third, we delete all
-// open brackets that follow a colon or comma or that begin the text. Finally,
-// we look to see that the remaining characters are only whitespace or ']' or
-// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
-
- if (/^[\],:{}\s]*$/
- .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
- .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
- .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
-
-// In the third stage we use the eval function to compile the text into a
-// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
-// in JavaScript: it can begin a block or an object literal. We wrap the text
-// in parens to eliminate the ambiguity.
-
- j = eval('(' + text + ')');
-
-// In the optional fourth stage, we recursively walk the new structure, passing
-// each name/value pair to a reviver function for possible transformation.
-
- return typeof reviver === 'function' ?
- walk({'': j}, '') : j;
- }
-
-// If the text is not JSON parseable, then a SyntaxError is thrown.
-
- throw new SyntaxError('JSON.parse');
- };
- }
-
- global.JSON = JSON;
- module.exports = JSON;
-}());
-
// cycle.js
// 2011-08-24
@@ -1709,7 +1217,7 @@ store.verbosity = 0;
store.types = {};
-var mainStorageType = null;
+var mainStorageType = "volatile";
//if Object.defineProperty works...
try {
@@ -1759,8 +1267,8 @@ store.log = function(text) {
};
store.isPersistent = function() {
- if (!store.types.length) return false;
- if (store.types.length === 1 && store.type === "volatile") return false;
+ if (!store.types) return false;
+ if (store.type === "volatile") return false;
return true;
};
@@ -5517,11 +5025,12 @@ NDDB.prototype.reverse = function () {
*
* Changes the order of elements in the current database
*
+ * @return {NDDB} A a reference to the current instance with shuffled entries
*/
NDDB.prototype.shuffle = function () {
// TODO: check do we need to reassign __nddbid__ ?
this.db = JSUS.shuffle(this.db);
- return true;
+ return this;
};
// ## Custom callbacks
2  build/nddb-full.min.js
View
@@ -23,4 +23,4 @@
MIT License. http://github.com/280north/narwhal/blob/master/README.md
*/// Module systems magic dance
-(function(e){typeof define=="function"?define(e):e()})(function(){function h(e){try{return Object.defineProperty(e,"sentinel",{}),"sentinel"in e}catch(t){}}Function.prototype.bind||(Function.prototype.bind=function(t){var n=this;if(typeof n!="function")throw new TypeError;var i=r.call(arguments,1),s=function(){if(this instanceof s){var e=function(){};e.prototype=n.prototype;var o=new e,u=n.apply(o,i.concat(r.call(arguments)));return u!==null&&Object(u)===u?u:o}return n.apply(t,i.concat(r.call(arguments)))};return s});var e=Function.prototype.call,t=Array.prototype,n=Object.prototype,r=t.slice,i=e.bind(n.toString),s=e.bind(n.hasOwnProperty),o,u,a,f,l;if(l=s(n,"__defineGetter__"))o=e.bind(n.__defineGetter__),u=e.bind(n.__defineSetter__),a=e.bind(n.__lookupGetter__),f=e.bind(n.__lookupSetter__);Array.isArray||(Array.isArray=function(t){return i(t)=="[object Array]"}),Array.prototype.forEach||(Array.prototype.forEach=function(t){var n=A(this),r=arguments[1],s=0,o=n.length>>>0;if(i(t)!="[object Function]")throw new TypeError;while(s<o)s in n&&t.call(r,n[s],s,n),s++}),Array.prototype.map||(Array.prototype.map=function(t){var n=A(this),r=n.length>>>0,s=Array(r),o=arguments[1];if(i(t)!="[object Function]")throw new TypeError;for(var u=0;u<r;u++)u in n&&(s[u]=t.call(o,n[u],u,n));return s}),Array.prototype.filter||(Array.prototype.filter=function(t){var n=A(this),r=n.length>>>0,s=[],o=arguments[1];if(i(t)!="[object Function]")throw new TypeError;for(var u=0;u<r;u++)u in n&&t.call(o,n[u],u,n)&&s.push(n[u]);return s}),Array.prototype.every||(Array.prototype.every=function(t){var n=A(this),r=n.length>>>0,s=arguments[1];if(i(t)!="[object Function]")throw new TypeError;for(var o=0;o<r;o++)if(o in n&&!t.call(s,n[o],o,n))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(t){var n=A(this),r=n.length>>>0,s=arguments[1];if(i(t)!="[object Function]")throw new TypeError;for(var o=0;o<r;o++)if(o in n&&t.call(s,n[o],o,n))return!0;return!1}),Array.prototype.reduce||(Array.prototype.reduce=function(t){var n=A(this),r=n.length>>>0;if(i(t)!="[object Function]")throw new TypeError;if(!r&&arguments.length==1)throw new TypeError;var s=0,o;if(arguments.length>=2)o=arguments[1];else do{if(s in n){o=n[s++];break}if(++s>=r)throw new TypeError}while(!0);for(;s<r;s++)s in n&&(o=t.call(void 0,o,n[s],s,n));return o}),Array.prototype.reduceRight||(Array.prototype.reduceRight=function(t){var n=A(this),r=n.length>>>0;if(i(t)!="[object Function]")throw new TypeError;if(!r&&arguments.length==1)throw new TypeError;var s,o=r-1;if(arguments.length>=2)s=arguments[1];else do{if(o in n){s=n[o--];break}if(--o<0)throw new TypeError}while(!0);do o in this&&(s=t.call(void 0,s,n[o],o,n));while(o--);return s}),Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var n=A(this),r=n.length>>>0;if(!r)return-1;var i=0;arguments.length>1&&(i=k(arguments[1])),i=i>=0?i:r-Math.abs(i);for(;i<r;i++)if(i in n&&n[i]===t)return i;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(t){var n=A(this),r=n.length>>>0;if(!r)return-1;var i=r-1;arguments.length>1&&(i=k(arguments[1])),i=i>=0?i:r-Math.abs(i);for(;i>=0;i--)if(i in n&&t===n[i])return i;return-1}),Object.getPrototypeOf||(Object.getPrototypeOf=function(t){return t.__proto__||(t.constructor?t.constructor.prototype:n)});if(!Object.getOwnPropertyDescriptor){var c="Object.getOwnPropertyDescriptor called on a non-object: ";Object.getOwnPropertyDescriptor=function(t,r){if(typeof t!="object"&&typeof t!="function"||t===null)throw new TypeError(c+t);if(!s(t,r))return;var i,o,u;i={enumerable:!0,configurable:!0};if(l){var h=t.__proto__;t.__proto__=n;var o=a(t,r),u=f(t,r);t.__proto__=h;if(o||u)return o&&(i.get=o),u&&(i.set=u),i}return i.value=t[r],i}}Object.getOwnPropertyNames||(Object.getOwnPropertyNames=function(t){return Object.keys(t)}),Object.create||(Object.create=function(t,n){var r;if(t===null)r={__proto__:null};else{if(typeof t!="object")throw new TypeError("typeof prototype["+typeof t+"] != 'object'");var i=function(){};i.prototype=t,r=new i,r.__proto__=t}return n!==void 0&&Object.defineProperties(r,n),r});if(Object.defineProperty){var p=h({}),d=typeof document=="undefined"||h(document.createElement("div"));if(!p||!d)var v=Object.defineProperty}if(!Object.defineProperty||v){var m="Property description must be an object: ",g="Object.defineProperty called on non-object: ",y="getters & setters can not be defined on this javascript engine";Object.defineProperty=function(t,r,i){if(typeof t!="object"&&typeof t!="function"||t===null)throw new TypeError(g+t);if(typeof i!="object"&&typeof i!="function"||i===null)throw new TypeError(m+i);if(v)try{return v.call(Object,t,r,i)}catch(c){}if(s(i,"value"))if(l&&(a(t,r)||f(t,r))){var h=t.__proto__;t.__proto__=n,delete t[r],t[r]=i.value,t.__proto__=h}else t[r]=i.value;else{if(!l)throw new TypeError(y);s(i,"get")&&o(t,r,i.get),s(i,"set")&&u(t,r,i.set)}return t}}Object.defineProperties||(Object.defineProperties=function(t,n){for(var r in n)s(n,r)&&Object.defineProperty(t,r,n[r]);return t}),Object.seal||(Object.seal=function(t){return t}),Object.freeze||(Object.freeze=function(t){return t});try{Object.freeze(function(){})}catch(b){Object.freeze=function(t){return function(n){return typeof n=="function"?n:t(n)}}(Object.freeze)}Object.preventExtensions||(Object.preventExtensions=function(t){return t}),Object.isSealed||(Object.isSealed=function(t){return!1}),Object.isFrozen||(Object.isFrozen=function(t){return!1}),Object.isExtensible||(Object.isExtensible=function(t){if(Object(t)===t)throw new TypeError;var n="";while(s(t,n))n+="?";t[n]=!0;var r=s(t,n);return delete t[n],r});if(!Object.keys){var w=!0,E=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],S=E.length;for(var x in{toString:null})w=!1;Object.keys=function O(e){if(typeof e!="object"&&typeof e!="function"||e===null)throw new TypeError("Object.keys called on a non-object");var O=[];for(var t in e)s(e,t)&&O.push(t);if(w)for(var n=0,r=S;n<r;n++){var i=E[n];s(e,i)&&O.push(i)}return O}}Date.prototype.toISOString||(Date.prototype.toISOString=function(){var t,n,r;if(!isFinite(this))throw new RangeError;t=[this.getUTCFullYear(),this.getUTCMonth()+1,this.getUTCDate(),this.getUTCHours(),this.getUTCMinutes(),this.getUTCSeconds()],n=t.length;while(n--)r=t[n],r<10&&(t[n]="0"+r);return t.slice(0,3).join("-")+"T"+t.slice(3).join(":")+"."+("000"+this.getUTCMilliseconds()).slice(-3)+"Z"}),Date.now||(Date.now=function(){return(new Date).getTime()}),Date.prototype.toJSON||(Date.prototype.toJSON=function(t){if(typeof this.toISOString!="function")throw new TypeError;return this.toISOString()}),isNaN(Date.parse("2011-06-15T21:40:05+06:00"))&&(Date=function(e){var t=function i(t,n,r,s,o,u,a){var f=arguments.length;if(this instanceof e){var l=f==1&&String(t)===t?new e(i.parse(t)):f>=7?new e(t,n,r,s,o,u,a):f>=6?new e(t,n,r,s,o,u):f>=5?new e(t,n,r,s,o):f>=4?new e(t,n,r,s):f>=3?new e(t,n,r):f>=2?new e(t,n):f>=1?new e(t):new e;return l.constructor=i,l}return e.apply(this,arguments)},n=new RegExp("^(\\d{4})(?:-(\\d{2})(?:-(\\d{2})(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{3}))?)?(?:Z|(?:([-+])(\\d{2}):(\\d{2})))?)?)?)?$");for(var r in e)t[r]=e[r];return t.now=e.now,t.UTC=e.UTC,t.prototype=e.prototype,t.prototype.constructor=t,t.parse=function(r){var i=n.exec(r);if(i){i.shift();for(var s=1;s<7;s++)i[s]=+(i[s]||(s<3?1:0)),s==1&&i[s]--;var o=+i.pop(),u=+i.pop(),a=i.pop(),f=0;if(a){if(u>23||o>59)return NaN;f=(u*60+o)*6e4*(a=="+"?-1:1)}return e.UTC.apply(this,i)+f}return e.parse.apply(this,arguments)},t}(Date));var T=" \n \f\r   ᠎              \u2028\u2029";if(!String.prototype.trim||T.trim()){T="["+T+"]";var N=new RegExp("^"+T+T+"*"),C=new RegExp(T+T+"*$");String.prototype.trim=function(){return String(this).replace(N,"").replace(C,"")}}var k=function(e){return e=+e,e!==e?e=-1:e!==0&&e!==1/0&&e!==-1/0&&(e=(e>0||-1)*Math.floor(Math.abs(e))),e},L="a"[0]!="a",A=function(e){if(e==null)throw new TypeError;return L&&typeof e=="string"&&e?e.split(""):Object(e)}});var JSON;JSON||(JSON={}),function(){"use strict";function f(e){return e<10?"0"+e:e}function quote(e){return escapable.lastIndex=0,escapable.test(e)?'"'+e.replace(escapable,function(e){var t=meta[e];return typeof t=="string"?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function str(e,t){var n,r,i,s,o=gap,u,a=t[e];a&&typeof a=="object"&&typeof a.toJSON=="function"&&(a=a.toJSON(e)),typeof rep=="function"&&(a=rep.call(t,e,a));switch(typeof a){case"string":return quote(a);case"number":return isFinite(a)?String(a):"null";case"boolean":case"null":return String(a);case"object":if(!a)return"null";gap+=indent,u=[];if(Object.prototype.toString.apply(a)==="[object Array]"){s=a.length;for(n=0;n<s;n+=1)u[n]=str(n,a)||"null";return i=u.length===0?"[]":gap?"[\n"+gap+u.join(",\n"+gap)+"\n"+o+"]":"["+u.join(",")+"]",gap=o,i}if(rep&&typeof rep=="object"){s=rep.length;for(n=0;n<s;n+=1)typeof rep[n]=="string"&&(r=rep[n],i=str(r,a),i&&u.push(quote(r)+(gap?": ":":")+i))}else for(r in a)Object.prototype.hasOwnProperty.call(a,r)&&(i=str(r,a),i&&u.push(quote(r)+(gap?": ":":")+i));return i=u.length===0?"{}":gap?"{\n"+gap+u.join(",\n"+gap)+"\n"+o+"}":"{"+u.join(",")+"}",gap=o,i}}var global=Function("return this")(),JSON=global.JSON;JSON||(JSON={}),typeof Date.prototype.toJSON!="function"&&(Date.prototype.toJSON=function(e){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(e){return this.valueOf()});var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;typeof JSON.stringify!="function"&&(JSON.stringify=function(e,t,n){var r;gap="",indent="";if(typeof n=="number")for(r=0;r<n;r+=1)indent+=" ";else typeof n=="string"&&(indent=n);rep=t;if(!t||typeof t=="function"||typeof t=="object"&&typeof t.length=="number")return str("",{"":e});throw new Error("JSON.stringify")}),typeof JSON.parse!="function"&&(JSON.parse=function(text,reviver){function walk(e,t){var n,r,i=e[t];if(i&&typeof i=="object")for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(r=walk(i,n),r!==undefined?i[n]=r:delete i[n]);return reviver.call(e,t,i)}var j;text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),typeof reviver=="function"?walk({"":j},""):j;throw new SyntaxError("JSON.parse")}),global.JSON=JSON,module.exports=JSON}(),typeof JSON.decycle!="function"&&(JSON.decycle=function(t){"use strict";var n=[],r=[];return function i(e,t){var s,o,u;switch(typeof e){case"object":if(!e)return null;for(s=0;s<n.length;s+=1)if(n[s]===e)return{$ref:r[s]};n.push(e),r.push(t);if(Object.prototype.toString.apply(e)==="[object Array]"){u=[];for(s=0;s<e.length;s+=1)u[s]=i(e[s],t+"["+s+"]")}else{u={};for(o in e)Object.prototype.hasOwnProperty.call(e,o)&&(u[o]=i(e[o],t+"["+JSON.stringify(o)+"]"))}return u;case"number":case"string":case"boolean":return e}}(t,"$")}),typeof JSON.retrocycle!="function"&&(JSON.retrocycle=function retrocycle($){"use strict";var px=/^\$(?:\[(?:\d+|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;return function rez(value){var i,item,name,path;if(value&&typeof value=="object")if(Object.prototype.toString.apply(value)==="[object Array]")for(i=0;i<value.length;i+=1)item=value[i],item&&typeof item=="object"&&(path=item.$ref,typeof path=="string"&&px.test(path)?value[i]=eval(path):rez(item));else for(name in value)typeof value[name]=="object"&&(item=value[name],item&&(path=item.$ref,typeof path=="string"&&px.test(path)?value[name]=eval(path):rez(item)))}($),$}),function(e){var t="0.3",n=e.store=function(e,t,r,i){r=r||{},i=r.type&&r.type in n.types?r.type:n.type;if(!i||!n.types[i]){n.log("Cannot save/load value. Invalid storage type selected: "+i,"ERR");return}return n.log("Accessing "+i+" storage"),n.types[i](e,t,r)};n.name="__shelf__",n.verbosity=0,n.types={};var r=null;try{Object.defineProperty(n,"type",{set:function(e){return"undefined"==typeof n.types[e]?(n.log("Cannot set store.type to an invalid type: "+e),!1):(r=e,e)},get:function(){return r},configurable:!1,enumerable:!0})}catch(i){n.type=r}n.addType=function(e,t){n.types[e]=t,n[e]=function(t,r,i){return i=i||{},i.type=e,n(t,r,i)};if(!n.type||n.type==="volatile")n.type=e},n.error=function(){return"shelf quota exceeded"},n.log=function(e){n.verbosity>0&&console.log("Shelf v."+t+": "+e)},n.isPersistent=function(){return n.types.length?n.types.length===1&&n.type==="volatile"?!1:!0:!1};try{Object.defineProperty(n,"persistent",{set:function(){},get:n.isPersistent,configurable:!1})}catch(i){n.persistent=!1}n.decycle=function(e){return JSON&&JSON.decycle&&"function"==typeof JSON.decycle&&(e=JSON.decycle(e)),e},n.retrocycle=function(e){return JSON&&JSON.retrocycle&&"function"==typeof JSON.retrocycle&&(e=JSON.retrocycle(e)),e},n.stringify=function(e){if(!JSON||!JSON.stringify||"function"!=typeof JSON.stringify)throw new Error("JSON.stringify not found. Received non-string value and could not serialize.");return e=n.decycle(e),JSON.stringify(e)},n.parse=function(e){if("undefined"==typeof e)return undefined;if(JSON&&JSON.parse&&"function"==typeof JSON.parse)try{e=JSON.parse(e)}catch(t){n.log("Error while parsing a value: "+t,"ERR"),n.log(e)}return e=n.retrocycle(e),e},function(){function r(e){return n.parse(n.stringify(e))}var e={},t={};n.addType("volatile",function(n,i,s){return n?i===undefined?r(e[n]):(t[n]&&(clearTimeout(t[n]),delete t[n]),i===null?(delete e[n],null):(e[n]=i,s.expires&&(t[n]=setTimeout(function(){delete e[n],delete t[n]},s.expires)),i)):r(e)})}()}("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:this),function(e){var t=e.store;if(!t){console.log("cookie.shelf.js: shelf.js core not found. Cookie storage not available.");return}if("undefined"==typeof window){console.log("cookie.shelf.js: am I running in a browser? Cookie storage not available.");return}var n=function(){var e,n,r,i,s={expiresAt:null,path:"/",domain:null,secure:!1};return e=function(e){var t,n;return typeof e!="object"||e===null?t=s:(t={expiresAt:s.expiresAt,path:s.path,domain:s.domain,secure:s.secure},typeof e.expiresAt=="object"&&e.expiresAt instanceof Date?t.expiresAt=e.expiresAt:typeof e.hoursToLive=="number"&&e.hoursToLive!==0&&(n=new Date,n.setTime(n.getTime()+e.hoursToLive*60*60*1e3),t.expiresAt=n),typeof e.path=="string"&&e.path!==""&&(t.path=e.path),typeof e.domain=="string"&&e.domain!==""&&(t.domain=e.domain),e.secure===!0&&(t.secure=e.secure)),t},n=function(t){return t=e(t),(typeof t.expiresAt=="object"&&t.expiresAt instanceof Date?"; expires="+t.expiresAt.toGMTString():"")+"; path="+t.path+(typeof t.domain=="string"?"; domain="+t.domain:"")+(t.secure===!0?"; secure":"")},r=function(){var e={},n,r,i,s,o=document.cookie.split(";"),u;for(n=0;n<o.length;n+=1){r=o[n].split("="),i=r[0].replace(/^\s*/,"").replace(/\s*$/,"");try{s=decodeURIComponent(r[1])}catch(a){s=r[1]}e[i]=t.parse(s)}return e},i=function(){},i.prototype.get=function(e){var t,n,i=r();if(typeof e=="string")t=typeof i[e]!="undefined"?i[e]:null;else if(typeof e=="object"&&e!==null){t={};for(n in e)typeof i[e[n]]!="undefined"?t[e[n]]=i[e[n]]:t[e[n]]=null}else t=i;return t},i.prototype.filter=function(e){var t,n={},i=r();typeof e=="string"&&(e=new RegExp(e));for(t in i)t.match(e)&&(n[t]=i[t]);return n},i.prototype.set=function(e,r,i){if(typeof i!="object"||i===null)i={};typeof r=="undefined"||r===null?(r="",i.hoursToLive=-8760):typeof r!="string"&&(r=t.stringify(r));var s=n(i);document.cookie=e+"="+encodeURIComponent(r)+s},i.prototype.del=function(e,t){var n={},r;if(typeof t!="object"||t===null)t={};typeof e=="boolean"&&e===!0?n=this.get():typeof e=="string"&&(n[e]=!0);for(r in n)typeof r=="string"&&r!==""&&this.set(r,null,t)},i.prototype.test=function(){var e=!1,t="cT",n="data";return this.set(t,n),this.get(t)===n&&(this.del(t),e=!0),e},i.prototype.setOptions=function(t){typeof t!="object"&&(t=null),s=e(t)},new i}();n.test()&&t.addType("cookie",function(e,t,r){return"undefined"==typeof e?n.get():"undefined"==typeof t?n.get(e):t===null?(n.del(e),null):n.set(e,t,r)})}(this),function(e){var t=e.store;if(!t){console.log("fs.shelf.js: shelf.js core not found. File system storage not available.");return}t.filename="./shelf.out";var n=require("fs"),r=require("path"),i=require("util"),s=function(e,t,r){var i,s;return i=n.createReadStream(e),s=n.createWriteStream(t),i.on("end",function(){return r(null)}),i.pipe(s)},o={},u=function(e,i){var o=e||t.filename;if(!o)return t.log("You must specify a valid file.","ERR"),!1;var u=r.dirname(o)+"."+r.basename(o);s(o,u,function(){var e=t.stringify(i);e=e.substr(1,e=e.substr(0,e.legth-1)),n.writeFile(o,e,"utf-8",function(e){if(e)throw e;return n.unlink(u,function(e){if(e)throw e}),!0})})};if("undefined"!=typeof n.appendFileSync)var a=function(e,r,i){var s=e||t.filename;if(!s)return t.log("You must specify a valid file.","ERR"),!1;if(!r)return;var o=t.stringify(r)+": "+t.stringify(i)+",\n";return n.appendFileSync(s,o,"utf-8")};else var a=function(e,r,i){var s=e||t.filename;if(!s)return t.log("You must specify a valid file.","ERR"),!1;if(!r)return;var o=t.stringify(r)+": "+t.stringify(i)+",\n";return n.open(s,"a",666,function(e,t){n.write(t,o,null,"utf8",function(){n.close(t,function(){})})}),!0};var f=function(e,r){var i=e||t.filename;if(!i)return t.log("You must specify a valid file.","ERR"),!1;var s=n.readFileSync(i,"utf-8");s=s.substr(0,s.length-2);var o=t.parse("{"+s+"}");return r?o[r]:o},l=function(e,n){var r=e||t.filename,i=f(r);return delete i[n],u(r,i),null};t.addType("fs",function(e,n,r){var i=r.file||t.filename;return e?n===undefined?f(i,e):(o[e]&&(clearTimeout(o[e]),l(i,e)),n===null?(l(i,e),null):(a(i,e,n),r.expires&&(o[e]=setTimeout(function(){l(i,e)},r.expires)),n)):f(i)})}("undefined"!=typeof module&&"function"==typeof require?module.exports||module.parent.exports:{}),function(e){function r(e,r){t.addType(e,function(i,s,o){var u,a,f,l,c=s,h=(new Date).getTime();if(!i){c={},l=[],f=0;try{i=r.length;while(i=r.key(f++))n.test(i)&&(a=t.parse(r.getItem(i)),a.expires&&a.expires<=h?l.push(i):c[i.replace(rprefix,"")]=a.data);while(i=l.pop())r.removeItem(i)}catch(p){}return c}i=t.name+i;if(s===undefined){u=r.getItem(i),a=u?t.parse(u):{expires:-1};if(!(a.expires&&a.expires<=h))return a.data;r.removeItem(i)}else if(s===null)r.removeItem(i);else{a=t.stringify({data:s,expires:o.expires?h+o.expires:null});try{r.setItem(i,a)}catch(p){t[e]();try{r.setItem(i,a)}catch(p){throw t.error()}}}return c})}var t=e.store;if(!t){console.log("amplify.shelf.js: shelf.js core not found. Amplify storage not available.");return}if("undefined"==typeof window){console.log("amplify.shelf.js: am I running in a browser? Amplify storage not available.");return}var n=new RegExp("^"+t.name);for(var i in{localStorage:1,sessionStorage:1})try{window[i].getItem&&r(i,window[i])}catch(s){}if(!t.types.localStorage&&window.globalStorage)try{r("globalStorage",window.globalStorage[window.location.hostname]),t.type==="sessionStorage"&&(t.type="globalStorage")}catch(s){}(function(){if(t.types.localStorage)return;var e=document.createElement("div"),n="shelf";e.style.display="none",document.getElementsByTagName("head")[0].appendChild(e);try{e.addBehavior("#default#userdata"),e.load(n)}catch(r){e.parentNode.removeChild(e);return}t.addType("userData",function(r,i,s){e.load(n);var o,u,a,f,l,c=i,h=(new Date).getTime();if(!r){c={},l=[],f=0;while(o=e.XMLDocument.documentElement.attributes[f++])u=t.parse(o.value),u.expires&&u.expires<=h?l.push(o.name):c[o.name]=u.data;while(r=l.pop())e.removeAttribute(r);return e.save(n),c}r=r.replace(/[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g,"-"),r=r.replace(/^-/,"_-");if(i===undefined){o=e.getAttribute(r),u=o?t.parse(o):{expires:-1};if(!(u.expires&&u.expires<=h))return u.data;e.removeAttribute(r)}else i===null?e.removeAttribute(r):(a=e.getAttribute(r),u=t.stringify({data:i,expires:s.expires?h+s.expires:null}),e.setAttribute(r,u));try{e.save(n)}catch(p){a===null?e.removeAttribute(r):e.setAttribute(r,a),t.userData();try{e.setAttribute(r,u),e.save(n)}catch(p){throw a===null?e.removeAttribute(r):e.setAttribute(r,a),t.error()}}return c})})()}(this),function(e){var t=e.JSUS={};t._classes={},t.log=function(e){console.log(e)},t.extend=function(e,n){if("object"!=typeof e&&"function"!=typeof e)return n;if("undefined"==typeof n){n=n||this;if("function"==typeof e){var r=e.toString();r=r.substr("function ".length),r=r.substr(0,r.indexOf("("))}else var r=e.constructor||e.__proto__.constructor;r&&(this._classes[r]=e)}for(var i in e)e.hasOwnProperty(i)&&(typeof n[i]!="object"?n[i]=e[i]:t.extend(e[i],n[i]));return e.prototype&&t.extend(e.prototype,n.prototype||n),n},t.require=t.get=function(e){return"undefined"==typeof t.clone?(t.log("JSUS.clone not found. Cannot continue."),!1):"undefined"==typeof e?t.clone(t._classes):"undefined"==typeof t._classes[e]?(t.log("Could not find class "+e),!1):t.clone(t._classes[e])},t.isNodeJS=function(){return"undefined"!=typeof module&&"undefined"!=typeof module.exports&&"function"==typeof require},t.isNodeJS()&&(require("./lib/compatibility"),require("./lib/obj"),require("./lib/array"),require("./lib/time"),require("./lib/eval"),require("./lib/dom"),require("./lib/random"),require("./lib/parse"),require("./lib/fs"))}("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:window),function(JSUS){function COMPATIBILITY(){}COMPATIBILITY.compatibility=function(){var support={};try{Object.defineProperty({},"a",{enumerable:!1,value:1}),support.defineProperty=!0}catch(e){support.defineProperty=!1}try{eval("({ get x(){ return 1 } }).x === 1"),support.setter=!0}catch(err){support.setter=!1}try{var value;eval("({ set x(v){ value = v; } }).x = 1"),support.getter=!0}catch(err){support.getter=!1}return support},JSUS.extend(COMPATIBILITY)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e){function t(){}Array.prototype.filter||(Array.prototype.filter=function(e){"use strict";if(this===void 0||this===null)throw new TypeError;var t=Object(this),n=t.length>>>0;if(typeof e!="function")throw new TypeError;var r=[],i=arguments[1];for(var s=0;s<n;s++)if(s in t){var o=t[s];e.call(i,o,s,t)&&r.push(o)}return r}),t.isArray=function(e){return e?Object.prototype.toString.call(e)==="[object Array]":!1},t.seq=function(t,n,r,i){if("number"!=typeof t)return!1;if(t===Infinity)return!1;if("number"!=typeof n)return!1;if(n===Infinity)return!1;if(t===n)return[t];if(r===0)return!1;if(!e.in_array(typeof r,["undefined","number"]))return!1;r=r||1,i=i||function(e){return e};var s=t,o=[];if(t<n)while(s<=n)o.push(i(s)),s+=r;else while(s>=n)o.push(i(s)),s-=r;return o},t.each=function(e,t,n){if("object"!=typeof e)return!1;if(!t)return!1;n=n||this;var r,i=e.length;for(r=0;r<i;r++)t.call(n,e[r]);return!0},t.map=function(){if(arguments.length<2)return;var n=Array.prototype.slice.call(arguments),r=n.shift(),i=n[0];if(!t.isArray(r)){e.log("ARRAY.map() the first argument must be an array. Found: "+r);return}var s=[],o=undefined;for(var u=0;u<r.length;u++)n[0]=r[u],o=i.apply(this,n),"undefined"!=typeof o&&s.push(o);return s},t.removeElement=function(t,n){if("undefined"==typeof t||!n)return!1;if("object"==typeof t)var r=e.equals;else var r=function(e,t){return e===t};for(var i=0;i<n.length;i++)if(r(t,n[i]))return n.splice(i,1);return!1},t.inArray=t.in_array=function(t,n){if(!n)return!1;var r=e.equals;for(var i=0;i<n.length;i++)if(r.call(this,t,n[i]))return!0;return!1},t.getNGroups=function(e,n){return t.getGroupsSizeN(e,Math.floor(e.length/n))},t.getGroupsSizeN=function(e,t){var n=e.slice(0),r=n.length,i=n.length,s=[],o,u,a=[],f=0;for(o=0;o<i;o++)u=Math.floor(Math.random()*r),f>=t&&(s.push(a),f=0,a=[]),a.push(n[u]),n.splice(u,1),r=n.length,f++;return a.length>0&&s.push(a),s},t._latinSquare=function(t,n,r){r="undefined"==typeof r?!0:r;if(t===n&&!r)return!1;var i=[],s=[];for(var o=0;o<t;o++)i[o]=o;var u=null,a=0,f=t,l=[];r||(f=t-1);for(o=0;o<n;o++){do u=e.randomInt(a,f);while(e.in_array(u,l));l.push(u),u==1?(s[o]=i.slice(u),s[o].push(0)):s[o]=i.slice(u).concat(i.slice(0,u))}return s},t.latinSquare=function(e,n){return n||(n=e),!e||e<0||n<0?!1:(n>e&&(n=e),t._latinSquare(e,n,!0))},t.latinSquareNoSelf=function(e,n){return n||(n=e-1),!e||e<0||n<0?!1:(n>e&&(n=e-1),t._latinSquare(e,n,!1))},t.generateCombinations=function(t,n){function r(e,t){var n=[];for(var r=0;r<e.length;r++)n.push(t[e[r]]);return n}var i=t.length,s=[];for(var o=0;o<n;o++)s.push(o);var u=[];for(var o=i-n;o<i;o++)u.push(o);while(!e.equals(s,u)){callback(r(s,t));var o=n-1;while(s[o]==i-n+o)o-=1;s[o]+=1;for(var a=o+1;a<n;a++)s[a]=s[o]+a-o}return r(s,t)},t.matchN=function(e,n,r){if(!e)return;if(!n)return e;var i=[],s=e.length,o=[];for(var u=0;u<s;u++){var a=e.slice(0);a.splice(u,1),r&&(a=t.arrayDiff(a,o));var f=t.getNRandom(a,n);o=o.concat(f),f.splice(0,0,e[u]),i.push(f),f=[]}return i},t.rep=function(t,n){if(!t)return;if(!n)return t.slice(0);if(n<1){e.log("times must be greater or equal 1","ERR");return}var r=1,i=t.slice(0);for(;r<n;r++)i=i.concat(t);return i},t.stretch=function(n,r){if(!n)return;if(!r)return n.slice(0);if("number"==typeof r){if(r<1){e.log("times must be greater or equal 1","ERR");return}r=t.rep([r],n.length)}var i=[];for(var s=0;s<n.length;s++){var o=r[s%r.length];for(var u=0;u<o;u++)i.push(n[s])}return i},t.arrayIntersect=function(t,n){return t.filter(function(t){return e.in_array(t,n)})},t.arrayDiff=function(t,n){return t.filter(function(t){return!e.in_array(t,n)})},t.shuffle=function(e){if(!e)return;var t=e.slice(0),n=e.length-1,r,i;for(var s=n;s>0;s--)r=Math.floor(Math.random()*(s+1)),i=t[r],t[r]=t[s],t[s]=i;return t},t.getNRandom=function(e,n){return t.shuffle(e).slice(0,n)},t.distinct=function(e){var n=[];return e?(t.each(e,function(e){t.in_array(e,n)||n.push(e)}),n):n},t.transpose=function(e){if(!e)return;var n,r,i,s,o=[];n=e.length||0,r=t.isArray(e[0])?e[0].length:0;if(n===0||r===0)return o;for(i=0;i<r;i++){o[i]=[];for(s=0;s<n;s++)o[i][s]=e[s][i]}return o},e.extend(t)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e){function t(){}var n=null;"undefined"!=typeof e.compatibility&&(n=e.compatibility()),t.equals=function(e,n){if("undefined"==typeof e||"undefined"==typeof n)return e===n;if(e===null||n===null)return e===n;if("number"==typeof e&&isNaN(e)&&"number"==typeof n&&isNaN(n))return isNaN(e)&&isNaN(n);var r={number:"",string:"","boolean":""};if(typeof e in r)return typeof n in r?e===n:!1;if(typeof n in{number:"",string:"","boolean":""})return!1;for(var i in e)if(e.hasOwnProperty(i)){if("undefined"==typeof n[i]&&"undefined"!=typeof e[i])return!1;if(!n[i]&&e[i])return!1;switch(typeof e[i]){case"function":if(e[i].toString()!==n[i].toString())return!1;default:if(!t.equals(e[i],n[i]))return!1}}for(i in n)if(n.hasOwnProperty(i)){if("undefined"==typeof e[i]&&"undefined"!=typeof n[i])return!1;if(!e[i]&&n[i])return!1}return!0},t.isEmpty=function(e){if("undefined"==typeof e)return!0;for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},t.size=t.getListSize=function(e){if(!e)return 0;if("number"==typeof e)return 0;if("string"==typeof e)return 0;var t=0;for(var n in e)e.hasOwnProperty(n)&&t++;return t},t._obj2Array=function(e,n,r,i){if("object"!=typeof e)return[e];if(r){i="undefined"!=typeof i?i:1;if(i>r)return[e];i+=1}var s=[];for(var o in e)e.hasOwnProperty(o)&&("object"==typeof e[o]?s=s.concat(t._obj2Array(e[o],n,r,i)):(n&&s.push(o),s.push(e[o])));return s},t.obj2Array=function(e,n){return t._obj2Array(e,!1,n)},t.obj2KeyedArray=t.obj2KeyArray=function(e,n){return t._obj2Array(e,!0,n)},t.keys=t.objGetAllKeys=function(e,n,r){if(!e)return[];n="number"==typeof n&&n>=0?n:0,r="number"==typeof r&&r>=0?r:0;var i=[];for(var s in e)e.hasOwnProperty(s)&&(i.push(s),r<n&&"object"==typeof e[s]&&(i=i.concat(t.objGetAllKeys(e[s],r+1))));return i},t.implode=t.implodeObj=function(e){if(!e)return[];var t=[];for(var n in e)if(e.hasOwnProperty(n)){var r={};r[n]=e[n],t.push(r)}return t},t.clone=function(e){if(!e)return e;if("number"==typeof e)return e;if("string"==typeof e)return e;if("boolean"==typeof e)return e;if(e===NaN)return e;if(e===Infinity)return e;var r;"function"==typeof e?r=function(){return e.apply(r,arguments)}:r=Object.prototype.toString.call(e)==="[object Array]"?[]:{};for(var i in e){var s;e[i]&&"object"==typeof e[i]?Object.prototype.toString.call(e[i])==="[object Array]"?s=e[i].slice(0):s=t.clone(e[i]):s=e[i];if(e.hasOwnProperty(i))r[i]=s;else if(n&&n.defineProperty)Object.defineProperty(r,i,{value:s,writable:!0,configurable:!0});else try{Object.defineProperty(r,i,{value:s,writable:!0,configurable:!0})}catch(o){r[i]=s}}return r},t.join=function(e,n){var r=t.clone(e);if(!n)return r;for(var i in r)r.hasOwnProperty(i)&&"undefined"!=typeof n[i]&&("object"==typeof n[i]?r[i]=t.join(r[i],n[i]):r[i]=n[i]);return r},t.merge=function(e,n){if(!e&&!n)return!1;if(!e)return t.clone(n);if(!n)return t.clone(e);var r=t.clone(e);for(var i in n)n.hasOwnProperty(i)&&(n[i]&&"object"==typeof n[i]?("object"!=typeof r[i]&&(Object.prototype.toString.call(n[i])==="[object Array]"?r[i]=[]:r[i]={}),r[i]=t.merge(r[i],n[i])):r[i]=n[i]);return r},t.mixin=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]=t[n]},t.mixout=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]||(e[n]=t[n])},t.mixcommon=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]&&(e[n]=t[n])},t.mergeOnKey=function(e,n,r){var i=t.clone(e);if(!n||!r)return i;for(var s in n)if(n.hasOwnProperty(s)){if(!i[s]||"object"!=typeof i[s])i[s]={};i[s][r]=n[s]}return i},t.subobj=function(e,n){if(!e)return!1;var r={};if(!n)return r;n instanceof Array||(n=[n]);for(var i=0;i<n.length;i++){var s=n[i];t.hasOwnNestedProperty(s,e)&&t.setNestedValue(s,t.getNestedValue(s,e),r)}return r},t.skim=function(e,n){if(!e)return!1;var r=t.clone(e);if(!n)return r;n instanceof Array||(n=[n]);for(var i=0;i<n.length;i++)t.deleteNestedKey(n[i],r);return r},t.setNestedValue=function(n,r,i){if(!n)return e.log("Cannot set value of undefined property","ERR"),!1;i="object"==typeof i?i:{};var s=n.split(".");if(s.length===1)return i[n]=r,i;var o=s.shift();return i[o]=t.setNestedValue(s.join("."),r,i[o]),i},t.getNestedValue=function(e,n){if(!n)return;var r=e.split(".");if(r.length===1)return n[e];var i=r.shift();return t.getNestedValue(r.join("."),n[i])},t.deleteNestedKey=function(e,n){if(!n)return;var r=e.split(".");if(r.length===1)return delete n[e],!0;var i=r.shift();return"undefined"==typeof n[i]?!1:t.deleteNestedKey(r.join("."),n[i])},t.hasOwnNestedProperty=function(e,n){if(!n)return!1;var r=e.split(".");if(r.length===1)return n.hasOwnProperty(e);var i=r.shift();return t.hasOwnNestedProperty(r.join("."),n[i])},t.split=function(t,n){if(!t)return;if(!n||"object"!=typeof t[n])return e.clone(t);var r=[],i=e.clone(t);i[n]={};var s=function(t){for(var o in t){var u=e.clone(i);t.hasOwnProperty(o)&&("object"==typeof t[o]?r=r.concat(s(t[o])):(u[n][o]=t[o],r.push(u)))}return r};return s(t[n])},e.extend(t)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e,t,n){function u(e,n,r){e=e||{};if(!t)throw new Error("JSUS not found.");this.db=[],this.tags={},this.hooks={insert:[],remove:[]},this.nddb_pointer=0,u.compatibility.getter?this.__defineGetter__("length",function(){return this.db.length}):this.length=null,this.__C={},this.__H={},this.__I={},this.__update={},this.__update.pointer=!1,this.__update.indexes=!1,this.__update.sort=!1,this.__parent=r||undefined,this.init(e),this.importDB(n)}var r=null,i=[],s=function(e,t){return!e||!t?(u.log("Attempt to add invalid condition","ERR"),!1):(i.push({type:e,condition:t}),!0)},o=function(e,t,n,i){if(!r)return u.log("No operation found.","ERR"),!1;var o=this._analyzeQuery(t,n,i);return o?s(e,o):!1};u.prototype.and=u.prototype.AND=function(e,t,n){return o("AND",e,t,n)},u.prototype.or=u.prototype.OR=function(e,t,n){return o("OR",e,t,n)},u.prototype.not=u.prototype.NOT=function(e,t,n){return o("NOT",e,t,n)},u.compatibility=t.compatibility(),e.NDDB=u,u.log=console.log,u.__symbols=[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"],u.__operations=["select","groupby","limit","first","fetch","last"],u.decycle=function(e){return JSON&&JSON.decycle&&"function"==typeof JSON.decycle&&(e=JSON.decycle(e)),e},u.retrocycle=function(e){return JSON&&JSON.retrocycle&&"function"==typeof JSON.retrocycle&&(e=JSON.retrocycle(e)),e},u.prototype.init=function(e){e=e||{},this.__options=e,e.log&&(u.log=e.log),e.C&&(this.__C=e.C),e.H&&(this.__H=e.H),e.I&&(this.__I=e.I),e.tags&&(this.tags=e.tags),e.nddb_pointer>0&&(this.nddb_pointer=e.nddb_pointer),e.hooks&&(this.hooks=e.hook),e.update&&("undefined"!=typeof e.update.pointer&&(this.__update.pointer=e.update.pointer),"undefined"!=typeof e.update.indexes&&(this.__update.indexes=e.update.indexes),"undefined"!=typeof e.update.sort&&(this.__update.sort=e.update.sort))},u.prototype.globalCompare=function(e,t){return"undefined"==typeof e&&"undefined"==typeof t?0:"undefined"==typeof t?-1:"undefined"==typeof e?1:e.nddbid<t.nddbid?-1:e.nddbid>t.nddbid?1:0},u.prototype._masquerade=function(e,t){return"undefined"==typeof e?!1:"undefined"!=typeof e.nddbid?e:(t=t||this.db,u.compatibility.defineProperty?Object.defineProperty(e,"nddbid",{value:t.length,configurable:!0,writable:!0}):e.nddbid=t.length,e)},u.prototype._masqueradeDB=function(e){if(!e)return[];var t=[];for(var n=0;n<e.length;n++)t[n]=this._masquerade(e[n],t);return t},u.prototype._autoUpdate=function(e){var n=e?t.merge(e,this.__update):this.__update;n.pointer&&(this.nddb_pointer=this.db.length-1),n.sort&&this.sort(),n.indexes&&this.rebuildIndexes(),this.__parent&&this.__parent._autoUpdate(n)},u.prototype.importDB=function(e){if(!e)return;this.db||(this.db=[]);for(var t=0;t<e.length;t++)this.insert(e[t])},u.prototype.insert=function(e){if("undefined"==typeof e||e===null)return;this.db||(this.db=[]),this._insert(e)},u.prototype._insert=function(e){e=this._masquerade(e),this.db.push(e),this.emit("insert",e),this.__update.indexes&&(this._hashIt(e),this._indexIt(e)),this._autoUpdate({indexes:!1})},u.prototype.breed=function(e){e=e||this.db;var t=this.cloneSettings(),n=this.__parent||this;return new this.constructor(t,e,n)},u.prototype.cloneSettings=function(){var e=this.__options||{};return e.H=this.__H,e.I=this.__I,e.C=this.__C,e.tags=this.tags,e.update=this.__update,t.clone(e)},u.prototype.toString=function(){var e="";for(var t=0;t<this.db.length;t++)e+=this.db[t]+"\n";return e},u.prototype.stringify=function(e){if(!this.length)return"[]";e="undefined"==typeof e?!0:e;var n;e?n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e)}:n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e,null,4)};var r="[";return this.each(function(e){e=u.decycle(e),r+=n(e)+", "}),r=r.replace(/, $/,"]"),r},u.prototype.compare=u.prototype.c=function(e,t){return!e||!t?(u.log("Cannot set empty property or empty comparator","ERR"),!1):(this.__C[e]=t,!0)},u.prototype.comparator=function(e){return"undefined"!=typeof this.__C[e]?this.__C[e]:function(n,r){if("undefined"==typeof n&&"undefined"==typeof r)return 0;if("undefined"==typeof n)return 1;if("undefined"==typeof r)return-1;var i=t.getNestedValue(e,n),s=t.getNestedValue(e,r);return"undefined"==typeof i&&"undefined"==typeof s?0:"undefined"==typeof i?1:"undefined"==typeof s?-1:i>s?1:s>i?-1:0}},u.prototype.isReservedWord=function(e){return this[e]?!0:!1},u.prototype._isValidIndex=function(e){if("undefined"==typeof e)return u.log("A valid index name must be provided","ERR"),!1;if(this.isReservedWord(e)){var t="A reserved word have been selected as an index. ";return t+="Please select another one: "+e,u.log(t,"ERR"),!1}return!0},u.prototype.hash=u.prototype.h=function(e,t){return this._isValidIndex(e)?(this.__H[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.index=u.prototype.i=function(e,t){return this._isValidIndex(e)?(this.__I[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.rebuildIndexes=function(){var e=!1,n=!1;if(!t.isEmpty(this.__H)){e=!0;for(var r in this.__H)this.__H.hasOwnProperty(r)&&(this[r]={})}if(!t.isEmpty(this.__I)){n=!0;for(var r in this.__I)this.__I.hasOwnProperty(r)&&(this[r]={})}e&&!n?this.each(this._hashIt):!e&&n?this.each(this._indexIt):e&&n&&this.each(function(e){this.hashIt(e),this.indexIt(e)})},u.prototype._hashIt=function(e){if(!e)return!1;if(t.isEmpty(this.__H))return!1;var n=null,r=null,i=null;for(var s in this.__H)if(this.__H.hasOwnProperty(s)){n=this.__H[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]||(this[s][i]=new u),this[s][i].insert(e)}},u.prototype._indexIt=function(e){if(!e)return!1;if(t.isEmpty(this.__I))return!1;var n=null,r=null,i=null;for(var s in this.__I)if(this.__I.hasOwnProperty(s)){n=this.__I[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]=e}},u.prototype.on=function(e,t){if(!e||!t||!this.hooks[e])return;return this.hooks[e].push(t),!0},u.prototype.off=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;if(!t)return this.hooks[e]=[],!0;for(var n=0;n<this.hooks[e].length;n++)if(this.hooks[e][n]==t)return this.hooks[e].splice(n,1),!0;return!1},u.prototype.emit=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;for(var n=0;n<this.hooks[e].length;n++)this.hooks[e][n].call(this,t)},u.prototype._analyzeQuery=function(e,n,r){var i=function(e,t,n){var r="(?)",i="Malformed query: "+e||r+" "+t||r+" "+n||r;return u.log(i,"WARN"),!1};"undefined"==typeof e&&i(e,n,r);if("undefined"!=typeof n){"undefined"==typeof r&&i(e,n,r);if(!t.in_array(n,[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"]))return u.log("Query error. Invalid operator detected: "+n,"WARN"),!1;n==="="&&(n="==");if(t.in_array(n,["><","<>","in","!in"])){r instanceof Array||(u.log("Range-queries need an array as third parameter","WARN"),i(e,n,r));if(n==="<>"||n==="><")r[0]=t.setNestedValue(e,r[0]),r[1]=t.setNestedValue(e,r[1])}else r=t.setNestedValue(e,r)}else"undefined"!=typeof r?i(e,n,r):(n="",r="");return{d:e,op:n,value:r}},u.prototype.distinct=function(){return this.breed(t.distinct(this.db))},u.prototype.select=function(e,n,r){var i=this._analyzeQuery(e,n,r);if(!i)return!1;var e=i.d,n=i.op,r=i.value,s=this.comparator(e),o=function(n){if("undefined"!=typeof t.getNestedValue(e,n))return n},a=function(i){try{if(t.eval(s(i,r)+n+0,i))return i}catch(o){return u.log("Malformed select query: "+e+n+r),!1}},f=function(e){if(s(e,r[0])>0&&s(e,r[1])<0)return e},l=function(e){if(s(e,r[0])<0&&s(e,r[1]>0))return e},c=function(n){if(t.in_array(t.getNestedValue(e,n),r))return n},h=function(n){if(!t.in_array(t.getNestedValue(e,n),r))return n};switch(n){case"":var p=o;break;case"<>":var p=l;break;case"><":var p=f;break;case"in":var p=c;break;case"!in":var p=h;break;default:var p=a}return this.filter(p)},u.prototype.limit=function(e){e=e||0;if(e===0)return this.breed();var t=e>0?this.db.slice(0,e):this.db.slice(e);return this.breed(t)},u.prototype.reverse=function(){return this.db.reverse(),this},u.prototype.sort=function(e){if(!e)var t=this.globalCompare;else if("function"==typeof e)var t=e;else if(e instanceof Array)var n=this,t=function(t,r){for(var i=0;i<e.length;i++){var s=n.comparator(e[i]).call(n,t,r);if(s!==0)return s}return s};else var t=this.comparator(e);return this.db.sort(t),this},u.prototype.shuffle=function(){return this.db=t.shuffle(this.db),!0},u.prototype.filter=function(e){return this.breed(this.db.filter(e))},u.prototype.each=u.prototype.forEach=function(){if(arguments.length===0)return;var e=arguments[0];for(var t=0;t<this.db.length;t++)arguments[0]=this.db[t],e.apply(this,arguments)},u.prototype.map=function(){if(arguments.length===0)return;var e=arguments[0],t=[],n=undefined;for(var r=0;r<this.db.length;r++)arguments[0]=this.db[r],n=e.apply(this,arguments),"undefined"!=typeof n&&t.push(n);return t},u.prototype.remove=function(){if(!this.length)return this;if(this.__parent){for(var e=0;e<this.db.length;e++){var t=this.db[e].nddbid-e;this.__parent.db.splice(t,1)}for(var e=0;e<this.__parent.length;e++)this.__parent.db[e].nddbid=e}return this.emit("remove",this.db),this.db=[],this._autoUpdate(),this},u.prototype.clear=function(e){return e?(this.db=[],this._autoUpdate()):u.log("Do you really want to clear the current dataset? Please use clear(true)","WARN"),e},u.prototype.join=function(e,n,r,i){return this._join(e,n,t.equals,r,i)},u.prototype.concat=function(e,t,n,r){return this._join(e,t,function(){return!0},n,r)},u.prototype._join=function(e,n,r,i,s){r=r||t.equals,i="undefined"!=typeof i?i:"joined";if(s)var s=s instanceof Array?s:[s];var o=[],a=[];for(var f=0;f<this.db.length;f++)try{var l=t.eval("this."+e,this.db[f]);if("undefined"!=typeof l)for(var c=f+1;c<this.db.length;c++)try{var h=t.eval("this."+n,this.db[c]);if("undefined"!=typeof h&&r(l,h)){var p=t.clone(this.db[f]),d=s?t.subobj(this.db[c],s):this.db[c];p[i]=d,o.push(p)}}catch(v){u.log("Key not found in entry: "+n,"WARN")}}catch(v){u.log("Key not found in entry: "+e,"WARN")}return this.breed(o)},u.prototype.split=function(e){var n=[];for(var r=0;r<this.db.length;r++)n=n.concat(t.split(this.db[r],e));return this.breed(n)},u.prototype._fetch=function(e,n){function r(e,n){return t.getNestedValue(n,e)}function i(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return t.obj2KeyedArray(r)}function s(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return n.split(".").concat(t.obj2KeyedArray(r))}switch(n){case"VALUES":var o=e?i:t.obj2Array;break;case"KEY_VALUES":var o=e?s:t.obj2KeyedArray;break;default:if(!e)return this.db;var o=r}var u=[];for(var a=0;a<this.db.length;a++){var f=o.call(this.db[a],this.db[a],e);"undefined"!=typeof f&&u.push(f)}return u},u.prototype.fetch=function(e){return this._fetch(e,!0)},u.prototype.fetchArray=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyArray=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.fetchValues=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyValues=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.groupBy=function(e){if(!e)return this.db;var n=[],r=[];for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);if("undefined"==typeof s)continue;if(!t.in_array(s,n)){n.push(s);var o=this.filter(function(n){if(t.equals(t.getNestedValue(e,n),s))return this});o.nddb_pointer=0,r.push(o)}}return r},u.prototype.count=function(e){if("undefined"==typeof e)return this.db.length;var n=0;for(var r=0;r<this.db.length;r++)t.hasOwnNestedProperty(e,this.db[r])&&n++;return n},u.prototype.sum=function(e){if("undefined"==typeof e)return!1;var n=0;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);isNaN(i)||(n+=i)}return n},u.prototype.mean=function(e){if("undefined"==typeof e)return!1;var n=0,r=0;for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);isNaN(s)||(n+=s,r++)}return r===0?0:n/r},u.prototype.stddev=function(e){if("undefined"==typeof e)return!1;var n=this.mean(e);if(isNaN(n))return!1;var r=0;return this.each(function(i){var s=t.getNestedValue(e,i);isNaN(s)||(r+=Math.pow(s-n,2))}),r!==0?Math.sqrt(r):0},u.prototype.min=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i<n||n===!1)&&(n=i)}return n},u.prototype.max=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i>n||n===!1)&&(n=i)}return n},u.prototype.skim=function(e){return e?this.breed(this.map(function(n){var r=t.skim(n,e);if(!t.isEmpty(r))return r})):this},u.prototype.keep=function(e){return e?this.breed(this.map(function(n){var r=t.subobj(n,e);if(!t.isEmpty(r))return r})):this.breed([])},u.prototype.diff=function(e){return!e||!e.length?this:("object"==typeof e&&(e instanceof u||e instanceof this.constructor)&&(e=e.db),this.breed(t.arrayDiff(this.db,e)))},u.prototype.intersect=function(e){if(!e||!e.length)return this;if("object"==typeof e)if(e instanceof u||e instanceof this.constructor)var e=e.db;return this.breed(t.arrayIntersect(this.db,e))},u.prototype.get=function(e){var e=e||this.nddb_pointer;return e<0||e>this.db.length-1?!1:this.db[e]},u.prototype.next=function(){var e=u.prototype.get.call(this,++this.nddb_pointer);return e||this.nddb_pointer--,e},u.prototype.previous=function(){var e=u.prototype.get.call(this,--this.nddb_pointer);return e||this.nddb_pointer++,e},u.prototype.first=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[0].nddbid,t[0]):undefined},u.prototype.last=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[t.length-1].nddbid,t[t.length-1]):undefined},u.prototype.tag=function(e,t){if("undefined"==typeof e)return u.log("Cannot register empty tag.","ERR"),!1;var n=null,r=typeof t;if(r==="undefined")n=this.db[this.nddb_pointer];else if(r==="number"){if(t>this.length||t<0)return u.log("Invalid index provided for tag registration","ERR"),!1;n=this.db[t]}else n=t;return this.tags[e]=n,!0},u.prototype.resolveTag=function(e){return"undefined"==typeof e?(u.log("Cannot resolve empty tag.","ERR"),!1):this.tags[e]};var a=function(){return"function"==typeof n};if(t.isNodeJS()){require("./external/cycle.js");var f=require("fs")}u.prototype.save=function(e,r,i){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;i=i||!1;if(!t.isNodeJS())return a()?(n(e,this.stringify(i)),r&&r(),!0):(u.log("No support for persistent storage found.","ERR"),!1);f.writeFile(e,this.stringify(i),"utf-8",function(e){if(e)throw e;return r&&r(),!0})},u.prototype.load=function(e,r){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;if(!t.isNodeJS()){if(!a())return u.log("No support for persistent storage found.","ERR"),!1;var i=n(e);return this.importDB(i),r&&r(),!0}var s=function(e){var t=JSON.parse(e.toString()),n;for(n=0;n<t.length;n++)t[n]=u.retrocycle(t[n]);this.importDB(t)};if(!r){var o=f.readFileSync(e,"utf-8");s.call(this,o)}else f.readFile(e,"utf-8",function(e,t){if(e)throw e;s.call(this,t),r()})}}("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:window,"undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS||require("JSUS").JSUS,"object"==typeof module&&"function"==typeof require?module.parent.exports.store||require("shelf.js/build/shelf-fs.js").store:this.store)
+(function(e){typeof define=="function"?define(e):e()})(function(){function h(e){try{return Object.defineProperty(e,"sentinel",{}),"sentinel"in e}catch(t){}}Function.prototype.bind||(Function.prototype.bind=function(t){var n=this;if(typeof n!="function")throw new TypeError;var i=r.call(arguments,1),s=function(){if(this instanceof s){var e=function(){};e.prototype=n.prototype;var o=new e,u=n.apply(o,i.concat(r.call(arguments)));return u!==null&&Object(u)===u?u:o}return n.apply(t,i.concat(r.call(arguments)))};return s});var e=Function.prototype.call,t=Array.prototype,n=Object.prototype,r=t.slice,i=e.bind(n.toString),s=e.bind(n.hasOwnProperty),o,u,a,f,l;if(l=s(n,"__defineGetter__"))o=e.bind(n.__defineGetter__),u=e.bind(n.__defineSetter__),a=e.bind(n.__lookupGetter__),f=e.bind(n.__lookupSetter__);Array.isArray||(Array.isArray=function(t){return i(t)=="[object Array]"}),Array.prototype.forEach||(Array.prototype.forEach=function(t){var n=A(this),r=arguments[1],s=0,o=n.length>>>0;if(i(t)!="[object Function]")throw new TypeError;while(s<o)s in n&&t.call(r,n[s],s,n),s++}),Array.prototype.map||(Array.prototype.map=function(t){var n=A(this),r=n.length>>>0,s=Array(r),o=arguments[1];if(i(t)!="[object Function]")throw new TypeError;for(var u=0;u<r;u++)u in n&&(s[u]=t.call(o,n[u],u,n));return s}),Array.prototype.filter||(Array.prototype.filter=function(t){var n=A(this),r=n.length>>>0,s=[],o=arguments[1];if(i(t)!="[object Function]")throw new TypeError;for(var u=0;u<r;u++)u in n&&t.call(o,n[u],u,n)&&s.push(n[u]);return s}),Array.prototype.every||(Array.prototype.every=function(t){var n=A(this),r=n.length>>>0,s=arguments[1];if(i(t)!="[object Function]")throw new TypeError;for(var o=0;o<r;o++)if(o in n&&!t.call(s,n[o],o,n))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(t){var n=A(this),r=n.length>>>0,s=arguments[1];if(i(t)!="[object Function]")throw new TypeError;for(var o=0;o<r;o++)if(o in n&&t.call(s,n[o],o,n))return!0;return!1}),Array.prototype.reduce||(Array.prototype.reduce=function(t){var n=A(this),r=n.length>>>0;if(i(t)!="[object Function]")throw new TypeError;if(!r&&arguments.length==1)throw new TypeError;var s=0,o;if(arguments.length>=2)o=arguments[1];else do{if(s in n){o=n[s++];break}if(++s>=r)throw new TypeError}while(!0);for(;s<r;s++)s in n&&(o=t.call(void 0,o,n[s],s,n));return o}),Array.prototype.reduceRight||(Array.prototype.reduceRight=function(t){var n=A(this),r=n.length>>>0;if(i(t)!="[object Function]")throw new TypeError;if(!r&&arguments.length==1)throw new TypeError;var s,o=r-1;if(arguments.length>=2)s=arguments[1];else do{if(o in n){s=n[o--];break}if(--o<0)throw new TypeError}while(!0);do o in this&&(s=t.call(void 0,s,n[o],o,n));while(o--);return s}),Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var n=A(this),r=n.length>>>0;if(!r)return-1;var i=0;arguments.length>1&&(i=k(arguments[1])),i=i>=0?i:r-Math.abs(i);for(;i<r;i++)if(i in n&&n[i]===t)return i;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(t){var n=A(this),r=n.length>>>0;if(!r)return-1;var i=r-1;arguments.length>1&&(i=k(arguments[1])),i=i>=0?i:r-Math.abs(i);for(;i>=0;i--)if(i in n&&t===n[i])return i;return-1}),Object.getPrototypeOf||(Object.getPrototypeOf=function(t){return t.__proto__||(t.constructor?t.constructor.prototype:n)});if(!Object.getOwnPropertyDescriptor){var c="Object.getOwnPropertyDescriptor called on a non-object: ";Object.getOwnPropertyDescriptor=function(t,r){if(typeof t!="object"&&typeof t!="function"||t===null)throw new TypeError(c+t);if(!s(t,r))return;var i,o,u;i={enumerable:!0,configurable:!0};if(l){var h=t.__proto__;t.__proto__=n;var o=a(t,r),u=f(t,r);t.__proto__=h;if(o||u)return o&&(i.get=o),u&&(i.set=u),i}return i.value=t[r],i}}Object.getOwnPropertyNames||(Object.getOwnPropertyNames=function(t){return Object.keys(t)}),Object.create||(Object.create=function(t,n){var r;if(t===null)r={__proto__:null};else{if(typeof t!="object")throw new TypeError("typeof prototype["+typeof t+"] != 'object'");var i=function(){};i.prototype=t,r=new i,r.__proto__=t}return n!==void 0&&Object.defineProperties(r,n),r});if(Object.defineProperty){var p=h({}),d=typeof document=="undefined"||h(document.createElement("div"));if(!p||!d)var v=Object.defineProperty}if(!Object.defineProperty||v){var m="Property description must be an object: ",g="Object.defineProperty called on non-object: ",y="getters & setters can not be defined on this javascript engine";Object.defineProperty=function(t,r,i){if(typeof t!="object"&&typeof t!="function"||t===null)throw new TypeError(g+t);if(typeof i!="object"&&typeof i!="function"||i===null)throw new TypeError(m+i);if(v)try{return v.call(Object,t,r,i)}catch(c){}if(s(i,"value"))if(l&&(a(t,r)||f(t,r))){var h=t.__proto__;t.__proto__=n,delete t[r],t[r]=i.value,t.__proto__=h}else t[r]=i.value;else{if(!l)throw new TypeError(y);s(i,"get")&&o(t,r,i.get),s(i,"set")&&u(t,r,i.set)}return t}}Object.defineProperties||(Object.defineProperties=function(t,n){for(var r in n)s(n,r)&&Object.defineProperty(t,r,n[r]);return t}),Object.seal||(Object.seal=function(t){return t}),Object.freeze||(Object.freeze=function(t){return t});try{Object.freeze(function(){})}catch(b){Object.freeze=function(t){return function(n){return typeof n=="function"?n:t(n)}}(Object.freeze)}Object.preventExtensions||(Object.preventExtensions=function(t){return t}),Object.isSealed||(Object.isSealed=function(t){return!1}),Object.isFrozen||(Object.isFrozen=function(t){return!1}),Object.isExtensible||(Object.isExtensible=function(t){if(Object(t)===t)throw new TypeError;var n="";while(s(t,n))n+="?";t[n]=!0;var r=s(t,n);return delete t[n],r});if(!Object.keys){var w=!0,E=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],S=E.length;for(var x in{toString:null})w=!1;Object.keys=function O(e){if(typeof e!="object"&&typeof e!="function"||e===null)throw new TypeError("Object.keys called on a non-object");var O=[];for(var t in e)s(e,t)&&O.push(t);if(w)for(var n=0,r=S;n<r;n++){var i=E[n];s(e,i)&&O.push(i)}return O}}Date.prototype.toISOString||(Date.prototype.toISOString=function(){var t,n,r;if(!isFinite(this))throw new RangeError;t=[this.getUTCFullYear(),this.getUTCMonth()+1,this.getUTCDate(),this.getUTCHours(),this.getUTCMinutes(),this.getUTCSeconds()],n=t.length;while(n--)r=t[n],r<10&&(t[n]="0"+r);return t.slice(0,3).join("-")+"T"+t.slice(3).join(":")+"."+("000"+this.getUTCMilliseconds()).slice(-3)+"Z"}),Date.now||(Date.now=function(){return(new Date).getTime()}),Date.prototype.toJSON||(Date.prototype.toJSON=function(t){if(typeof this.toISOString!="function")throw new TypeError;return this.toISOString()}),isNaN(Date.parse("2011-06-15T21:40:05+06:00"))&&(Date=function(e){var t=function i(t,n,r,s,o,u,a){var f=arguments.length;if(this instanceof e){var l=f==1&&String(t)===t?new e(i.parse(t)):f>=7?new e(t,n,r,s,o,u,a):f>=6?new e(t,n,r,s,o,u):f>=5?new e(t,n,r,s,o):f>=4?new e(t,n,r,s):f>=3?new e(t,n,r):f>=2?new e(t,n):f>=1?new e(t):new e;return l.constructor=i,l}return e.apply(this,arguments)},n=new RegExp("^(\\d{4})(?:-(\\d{2})(?:-(\\d{2})(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{3}))?)?(?:Z|(?:([-+])(\\d{2}):(\\d{2})))?)?)?)?$");for(var r in e)t[r]=e[r];return t.now=e.now,t.UTC=e.UTC,t.prototype=e.prototype,t.prototype.constructor=t,t.parse=function(r){var i=n.exec(r);if(i){i.shift();for(var s=1;s<7;s++)i[s]=+(i[s]||(s<3?1:0)),s==1&&i[s]--;var o=+i.pop(),u=+i.pop(),a=i.pop(),f=0;if(a){if(u>23||o>59)return NaN;f=(u*60+o)*6e4*(a=="+"?-1:1)}return e.UTC.apply(this,i)+f}return e.parse.apply(this,arguments)},t}(Date));var T=" \n \f\r   ᠎              \u2028\u2029";if(!String.prototype.trim||T.trim()){T="["+T+"]";var N=new RegExp("^"+T+T+"*"),C=new RegExp(T+T+"*$");String.prototype.trim=function(){return String(this).replace(N,"").replace(C,"")}}var k=function(e){return e=+e,e!==e?e=-1:e!==0&&e!==1/0&&e!==-1/0&&(e=(e>0||-1)*Math.floor(Math.abs(e))),e},L="a"[0]!="a",A=function(e){if(e==null)throw new TypeError;return L&&typeof e=="string"&&e?e.split(""):Object(e)}}),typeof JSON.decycle!="function"&&(JSON.decycle=function(t){"use strict";var n=[],r=[];return function i(e,t){var s,o,u;switch(typeof e){case"object":if(!e)return null;for(s=0;s<n.length;s+=1)if(n[s]===e)return{$ref:r[s]};n.push(e),r.push(t);if(Object.prototype.toString.apply(e)==="[object Array]"){u=[];for(s=0;s<e.length;s+=1)u[s]=i(e[s],t+"["+s+"]")}else{u={};for(o in e)Object.prototype.hasOwnProperty.call(e,o)&&(u[o]=i(e[o],t+"["+JSON.stringify(o)+"]"))}return u;case"number":case"string":case"boolean":return e}}(t,"$")}),typeof JSON.retrocycle!="function"&&(JSON.retrocycle=function retrocycle($){"use strict";var px=/^\$(?:\[(?:\d+|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;return function rez(value){var i,item,name,path;if(value&&typeof value=="object")if(Object.prototype.toString.apply(value)==="[object Array]")for(i=0;i<value.length;i+=1)item=value[i],item&&typeof item=="object"&&(path=item.$ref,typeof path=="string"&&px.test(path)?value[i]=eval(path):rez(item));else for(name in value)typeof value[name]=="object"&&(item=value[name],item&&(path=item.$ref,typeof path=="string"&&px.test(path)?value[name]=eval(path):rez(item)))}($),$}),function(e){var t="0.3",n=e.store=function(e,t,r,i){r=r||{},i=r.type&&r.type in n.types?r.type:n.type;if(!i||!n.types[i]){n.log("Cannot save/load value. Invalid storage type selected: "+i,"ERR");return}return n.log("Accessing "+i+" storage"),n.types[i](e,t,r)};n.name="__shelf__",n.verbosity=0,n.types={};var r="volatile";try{Object.defineProperty(n,"type",{set:function(e){return"undefined"==typeof n.types[e]?(n.log("Cannot set store.type to an invalid type: "+e),!1):(r=e,e)},get:function(){return r},configurable:!1,enumerable:!0})}catch(i){n.type=r}n.addType=function(e,t){n.types[e]=t,n[e]=function(t,r,i){return i=i||{},i.type=e,n(t,r,i)};if(!n.type||n.type==="volatile")n.type=e},n.error=function(){return"shelf quota exceeded"},n.log=function(e){n.verbosity>0&&console.log("Shelf v."+t+": "+e)},n.isPersistent=function(){return n.types?n.type==="volatile"?!1:!0:!1};try{Object.defineProperty(n,"persistent",{set:function(){},get:n.isPersistent,configurable:!1})}catch(i){n.persistent=!1}n.decycle=function(e){return JSON&&JSON.decycle&&"function"==typeof JSON.decycle&&(e=JSON.decycle(e)),e},n.retrocycle=function(e){return JSON&&JSON.retrocycle&&"function"==typeof JSON.retrocycle&&(e=JSON.retrocycle(e)),e},n.stringify=function(e){if(!JSON||!JSON.stringify||"function"!=typeof JSON.stringify)throw new Error("JSON.stringify not found. Received non-string value and could not serialize.");return e=n.decycle(e),JSON.stringify(e)},n.parse=function(e){if("undefined"==typeof e)return undefined;if(JSON&&JSON.parse&&"function"==typeof JSON.parse)try{e=JSON.parse(e)}catch(t){n.log("Error while parsing a value: "+t,"ERR"),n.log(e)}return e=n.retrocycle(e),e},function(){function r(e){return n.parse(n.stringify(e))}var e={},t={};n.addType("volatile",function(n,i,s){return n?i===undefined?r(e[n]):(t[n]&&(clearTimeout(t[n]),delete t[n]),i===null?(delete e[n],null):(e[n]=i,s.expires&&(t[n]=setTimeout(function(){delete e[n],delete t[n]},s.expires)),i)):r(e)})}()}("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:this),function(e){var t=e.store;if(!t){console.log("cookie.shelf.js: shelf.js core not found. Cookie storage not available.");return}if("undefined"==typeof window){console.log("cookie.shelf.js: am I running in a browser? Cookie storage not available.");return}var n=function(){var e,n,r,i,s={expiresAt:null,path:"/",domain:null,secure:!1};return e=function(e){var t,n;return typeof e!="object"||e===null?t=s:(t={expiresAt:s.expiresAt,path:s.path,domain:s.domain,secure:s.secure},typeof e.expiresAt=="object"&&e.expiresAt instanceof Date?t.expiresAt=e.expiresAt:typeof e.hoursToLive=="number"&&e.hoursToLive!==0&&(n=new Date,n.setTime(n.getTime()+e.hoursToLive*60*60*1e3),t.expiresAt=n),typeof e.path=="string"&&e.path!==""&&(t.path=e.path),typeof e.domain=="string"&&e.domain!==""&&(t.domain=e.domain),e.secure===!0&&(t.secure=e.secure)),t},n=function(t){return t=e(t),(typeof t.expiresAt=="object"&&t.expiresAt instanceof Date?"; expires="+t.expiresAt.toGMTString():"")+"; path="+t.path+(typeof t.domain=="string"?"; domain="+t.domain:"")+(t.secure===!0?"; secure":"")},r=function(){var e={},n,r,i,s,o=document.cookie.split(";"),u;for(n=0;n<o.length;n+=1){r=o[n].split("="),i=r[0].replace(/^\s*/,"").replace(/\s*$/,"");try{s=decodeURIComponent(r[1])}catch(a){s=r[1]}e[i]=t.parse(s)}return e},i=function(){},i.prototype.get=function(e){var t,n,i=r();if(typeof e=="string")t=typeof i[e]!="undefined"?i[e]:null;else if(typeof e=="object"&&e!==null){t={};for(n in e)typeof i[e[n]]!="undefined"?t[e[n]]=i[e[n]]:t[e[n]]=null}else t=i;return t},i.prototype.filter=function(e){var t,n={},i=r();typeof e=="string"&&(e=new RegExp(e));for(t in i)t.match(e)&&(n[t]=i[t]);return n},i.prototype.set=function(e,r,i){if(typeof i!="object"||i===null)i={};typeof r=="undefined"||r===null?(r="",i.hoursToLive=-8760):typeof r!="string"&&(r=t.stringify(r));var s=n(i);document.cookie=e+"="+encodeURIComponent(r)+s},i.prototype.del=function(e,t){var n={},r;if(typeof t!="object"||t===null)t={};typeof e=="boolean"&&e===!0?n=this.get():typeof e=="string"&&(n[e]=!0);for(r in n)typeof r=="string"&&r!==""&&this.set(r,null,t)},i.prototype.test=function(){var e=!1,t="cT",n="data";return this.set(t,n),this.get(t)===n&&(this.del(t),e=!0),e},i.prototype.setOptions=function(t){typeof t!="object"&&(t=null),s=e(t)},new i}();n.test()&&t.addType("cookie",function(e,t,r){return"undefined"==typeof e?n.get():"undefined"==typeof t?n.get(e):t===null?(n.del(e),null):n.set(e,t,r)})}(this),function(e){var t=e.store;if(!t){console.log("fs.shelf.js: shelf.js core not found. File system storage not available.");return}t.filename="./shelf.out";var n=require("fs"),r=require("path"),i=require("util"),s=function(e,t,r){var i,s;return i=n.createReadStream(e),s=n.createWriteStream(t),i.on("end",function(){return r(null)}),i.pipe(s)},o={},u=function(e,i){var o=e||t.filename;if(!o)return t.log("You must specify a valid file.","ERR"),!1;var u=r.dirname(o)+"."+r.basename(o);s(o,u,function(){var e=t.stringify(i);e=e.substr(1,e=e.substr(0,e.legth-1)),n.writeFile(o,e,"utf-8",function(e){if(e)throw e;return n.unlink(u,function(e){if(e)throw e}),!0})})};if("undefined"!=typeof n.appendFileSync)var a=function(e,r,i){var s=e||t.filename;if(!s)return t.log("You must specify a valid file.","ERR"),!1;if(!r)return;var o=t.stringify(r)+": "+t.stringify(i)+",\n";return n.appendFileSync(s,o,"utf-8")};else var a=function(e,r,i){var s=e||t.filename;if(!s)return t.log("You must specify a valid file.","ERR"),!1;if(!r)return;var o=t.stringify(r)+": "+t.stringify(i)+",\n";return n.open(s,"a",666,function(e,t){n.write(t,o,null,"utf8",function(){n.close(t,function(){})})}),!0};var f=function(e,r){var i=e||t.filename;if(!i)return t.log("You must specify a valid file.","ERR"),!1;var s=n.readFileSync(i,"utf-8");s=s.substr(0,s.length-2);var o=t.parse("{"+s+"}");return r?o[r]:o},l=function(e,n){var r=e||t.filename,i=f(r);return delete i[n],u(r,i),null};t.addType("fs",function(e,n,r){var i=r.file||t.filename;return e?n===undefined?f(i,e):(o[e]&&(clearTimeout(o[e]),l(i,e)),n===null?(l(i,e),null):(a(i,e,n),r.expires&&(o[e]=setTimeout(function(){l(i,e)},r.expires)),n)):f(i)})}("undefined"!=typeof module&&"function"==typeof require?module.exports||module.parent.exports:{}),function(e){function r(e,r){t.addType(e,function(i,s,o){var u,a,f,l,c=s,h=(new Date).getTime();if(!i){c={},l=[],f=0;try{i=r.length;while(i=r.key(f++))n.test(i)&&(a=t.parse(r.getItem(i)),a.expires&&a.expires<=h?l.push(i):c[i.replace(rprefix,"")]=a.data);while(i=l.pop())r.removeItem(i)}catch(p){}return c}i=t.name+i;if(s===undefined){u=r.getItem(i),a=u?t.parse(u):{expires:-1};if(!(a.expires&&a.expires<=h))return a.data;r.removeItem(i)}else if(s===null)r.removeItem(i);else{a=t.stringify({data:s,expires:o.expires?h+o.expires:null});try{r.setItem(i,a)}catch(p){t[e]();try{r.setItem(i,a)}catch(p){throw t.error()}}}return c})}var t=e.store;if(!t){console.log("amplify.shelf.js: shelf.js core not found. Amplify storage not available.");return}if("undefined"==typeof window){console.log("amplify.shelf.js: am I running in a browser? Amplify storage not available.");return}var n=new RegExp("^"+t.name);for(var i in{localStorage:1,sessionStorage:1})try{window[i].getItem&&r(i,window[i])}catch(s){}if(!t.types.localStorage&&window.globalStorage)try{r("globalStorage",window.globalStorage[window.location.hostname]),t.type==="sessionStorage"&&(t.type="globalStorage")}catch(s){}(function(){if(t.types.localStorage)return;var e=document.createElement("div"),n="shelf";e.style.display="none",document.getElementsByTagName("head")[0].appendChild(e);try{e.addBehavior("#default#userdata"),e.load(n)}catch(r){e.parentNode.removeChild(e);return}t.addType("userData",function(r,i,s){e.load(n);var o,u,a,f,l,c=i,h=(new Date).getTime();if(!r){c={},l=[],f=0;while(o=e.XMLDocument.documentElement.attributes[f++])u=t.parse(o.value),u.expires&&u.expires<=h?l.push(o.name):c[o.name]=u.data;while(r=l.pop())e.removeAttribute(r);return e.save(n),c}r=r.replace(/[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g,"-"),r=r.replace(/^-/,"_-");if(i===undefined){o=e.getAttribute(r),u=o?t.parse(o):{expires:-1};if(!(u.expires&&u.expires<=h))return u.data;e.removeAttribute(r)}else i===null?e.removeAttribute(r):(a=e.getAttribute(r),u=t.stringify({data:i,expires:s.expires?h+s.expires:null}),e.setAttribute(r,u));try{e.save(n)}catch(p){a===null?e.removeAttribute(r):e.setAttribute(r,a),t.userData();try{e.setAttribute(r,u),e.save(n)}catch(p){throw a===null?e.removeAttribute(r):e.setAttribute(r,a),t.error()}}return c})})()}(this),function(e){var t=e.JSUS={};t._classes={},t.log=function(e){console.log(e)},t.extend=function(e,n){if("object"!=typeof e&&"function"!=typeof e)return n;if("undefined"==typeof n){n=n||this;if("function"==typeof e){var r=e.toString();r=r.substr("function ".length),r=r.substr(0,r.indexOf("("))}else var r=e.constructor||e.__proto__.constructor;r&&(this._classes[r]=e)}for(var i in e)e.hasOwnProperty(i)&&(typeof n[i]!="object"?n[i]=e[i]:t.extend(e[i],n[i]));return e.prototype&&t.extend(e.prototype,n.prototype||n),n},t.require=t.get=function(e){return"undefined"==typeof t.clone?(t.log("JSUS.clone not found. Cannot continue."),!1):"undefined"==typeof e?t.clone(t._classes):"undefined"==typeof t._classes[e]?(t.log("Could not find class "+e),!1):t.clone(t._classes[e])},t.isNodeJS=function(){return"undefined"!=typeof module&&"undefined"!=typeof module.exports&&"function"==typeof require},t.isNodeJS()&&(require("./lib/compatibility"),require("./lib/obj"),require("./lib/array"),require("./lib/time"),require("./lib/eval"),require("./lib/dom"),require("./lib/random"),require("./lib/parse"),require("./lib/fs"))}("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:window),function(JSUS){function COMPATIBILITY(){}COMPATIBILITY.compatibility=function(){var support={};try{Object.defineProperty({},"a",{enumerable:!1,value:1}),support.defineProperty=!0}catch(e){support.defineProperty=!1}try{eval("({ get x(){ return 1 } }).x === 1"),support.setter=!0}catch(err){support.setter=!1}try{var value;eval("({ set x(v){ value = v; } }).x = 1"),support.getter=!0}catch(err){support.getter=!1}return support},JSUS.extend(COMPATIBILITY)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e){function t(){}Array.prototype.filter||(Array.prototype.filter=function(e){"use strict";if(this===void 0||this===null)throw new TypeError;var t=Object(this),n=t.length>>>0;if(typeof e!="function")throw new TypeError;var r=[],i=arguments[1];for(var s=0;s<n;s++)if(s in t){var o=t[s];e.call(i,o,s,t)&&r.push(o)}return r}),t.isArray=function(e){return e?Object.prototype.toString.call(e)==="[object Array]":!1},t.seq=function(t,n,r,i){if("number"!=typeof t)return!1;if(t===Infinity)return!1;if("number"!=typeof n)return!1;if(n===Infinity)return!1;if(t===n)return[t];if(r===0)return!1;if(!e.in_array(typeof r,["undefined","number"]))return!1;r=r||1,i=i||function(e){return e};var s=t,o=[];if(t<n)while(s<=n)o.push(i(s)),s+=r;else while(s>=n)o.push(i(s)),s-=r;return o},t.each=function(e,t,n){if("object"!=typeof e)return!1;if(!t)return!1;n=n||this;var r,i=e.length;for(r=0;r<i;r++)t.call(n,e[r]);return!0},t.map=function(){if(arguments.length<2)return;var n=Array.prototype.slice.call(arguments),r=n.shift(),i=n[0];if(!t.isArray(r)){e.log("ARRAY.map() the first argument must be an array. Found: "+r);return}var s=[],o=undefined;for(var u=0;u<r.length;u++)n[0]=r[u],o=i.apply(this,n),"undefined"!=typeof o&&s.push(o);return s},t.removeElement=function(t,n){if("undefined"==typeof t||!n)return!1;if("object"==typeof t)var r=e.equals;else var r=function(e,t){return e===t};for(var i=0;i<n.length;i++)if(r(t,n[i]))return n.splice(i,1);return!1},t.inArray=t.in_array=function(t,n){if(!n)return!1;var r=e.equals;for(var i=0;i<n.length;i++)if(r.call(this,t,n[i]))return!0;return!1},t.getNGroups=function(e,n){return t.getGroupsSizeN(e,Math.floor(e.length/n))},t.getGroupsSizeN=function(e,t){var n=e.slice(0),r=n.length,i=n.length,s=[],o,u,a=[],f=0;for(o=0;o<i;o++)u=Math.floor(Math.random()*r),f>=t&&(s.push(a),f=0,a=[]),a.push(n[u]),n.splice(u,1),r=n.length,f++;return a.length>0&&s.push(a),s},t._latinSquare=function(t,n,r){r="undefined"==typeof r?!0:r;if(t===n&&!r)return!1;var i=[],s=[];for(var o=0;o<t;o++)i[o]=o;var u=null,a=0,f=t,l=[];r||(f=t-1);for(o=0;o<n;o++){do u=e.randomInt(a,f);while(e.in_array(u,l));l.push(u),u==1?(s[o]=i.slice(u),s[o].push(0)):s[o]=i.slice(u).concat(i.slice(0,u))}return s},t.latinSquare=function(e,n){return n||(n=e),!e||e<0||n<0?!1:(n>e&&(n=e),t._latinSquare(e,n,!0))},t.latinSquareNoSelf=function(e,n){return n||(n=e-1),!e||e<0||n<0?!1:(n>e&&(n=e-1),t._latinSquare(e,n,!1))},t.generateCombinations=function(t,n){function r(e,t){var n=[];for(var r=0;r<e.length;r++)n.push(t[e[r]]);return n}var i=t.length,s=[];for(var o=0;o<n;o++)s.push(o);var u=[];for(var o=i-n;o<i;o++)u.push(o);while(!e.equals(s,u)){callback(r(s,t));var o=n-1;while(s[o]==i-n+o)o-=1;s[o]+=1;for(var a=o+1;a<n;a++)s[a]=s[o]+a-o}return r(s,t)},t.matchN=function(e,n,r){if(!e)return;if(!n)return e;var i=[],s=e.length,o=[];for(var u=0;u<s;u++){var a=e.slice(0);a.splice(u,1),r&&(a=t.arrayDiff(a,o));var f=t.getNRandom(a,n);o=o.concat(f),f.splice(0,0,e[u]),i.push(f),f=[]}return i},t.rep=function(t,n){if(!t)return;if(!n)return t.slice(0);if(n<1){e.log("times must be greater or equal 1","ERR");return}var r=1,i=t.slice(0);for(;r<n;r++)i=i.concat(t);return i},t.stretch=function(n,r){if(!n)return;if(!r)return n.slice(0);if("number"==typeof r){if(r<1){e.log("times must be greater or equal 1","ERR");return}r=t.rep([r],n.length)}var i=[];for(var s=0;s<n.length;s++){var o=r[s%r.length];for(var u=0;u<o;u++)i.push(n[s])}return i},t.arrayIntersect=function(t,n){return t.filter(function(t){return e.in_array(t,n)})},t.arrayDiff=function(t,n){return t.filter(function(t){return!e.in_array(t,n)})},t.shuffle=function(e){if(!e)return;var t=e.slice(0),n=e.length-1,r,i;for(var s=n;s>0;s--)r=Math.floor(Math.random()*(s+1)),i=t[r],t[r]=t[s],t[s]=i;return t},t.getNRandom=function(e,n){return t.shuffle(e).slice(0,n)},t.distinct=function(e){var n=[];return e?(t.each(e,function(e){t.in_array(e,n)||n.push(e)}),n):n},t.transpose=function(e){if(!e)return;var n,r,i,s,o=[];n=e.length||0,r=t.isArray(e[0])?e[0].length:0;if(n===0||r===0)return o;for(i=0;i<r;i++){o[i]=[];for(s=0;s<n;s++)o[i][s]=e[s][i]}return o},e.extend(t)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e){function t(){}var n=null;"undefined"!=typeof e.compatibility&&(n=e.compatibility()),t.equals=function(e,n){if("undefined"==typeof e||"undefined"==typeof n)return e===n;if(e===null||n===null)return e===n;if("number"==typeof e&&isNaN(e)&&"number"==typeof n&&isNaN(n))return isNaN(e)&&isNaN(n);var r={number:"",string:"","boolean":""};if(typeof e in r)return typeof n in r?e===n:!1;if(typeof n in{number:"",string:"","boolean":""})return!1;for(var i in e)if(e.hasOwnProperty(i)){if("undefined"==typeof n[i]&&"undefined"!=typeof e[i])return!1;if(!n[i]&&e[i])return!1;switch(typeof e[i]){case"function":if(e[i].toString()!==n[i].toString())return!1;default:if(!t.equals(e[i],n[i]))return!1}}for(i in n)if(n.hasOwnProperty(i)){if("undefined"==typeof e[i]&&"undefined"!=typeof n[i])return!1;if(!e[i]&&n[i])return!1}return!0},t.isEmpty=function(e){if("undefined"==typeof e)return!0;for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},t.size=t.getListSize=function(e){if(!e)return 0;if("number"==typeof e)return 0;if("string"==typeof e)return 0;var t=0;for(var n in e)e.hasOwnProperty(n)&&t++;return t},t._obj2Array=function(e,n,r,i){if("object"!=typeof e)return[e];if(r){i="undefined"!=typeof i?i:1;if(i>r)return[e];i+=1}var s=[];for(var o in e)e.hasOwnProperty(o)&&("object"==typeof e[o]?s=s.concat(t._obj2Array(e[o],n,r,i)):(n&&s.push(o),s.push(e[o])));return s},t.obj2Array=function(e,n){return t._obj2Array(e,!1,n)},t.obj2KeyedArray=t.obj2KeyArray=function(e,n){return t._obj2Array(e,!0,n)},t.keys=t.objGetAllKeys=function(e,n,r){if(!e)return[];n="number"==typeof n&&n>=0?n:0,r="number"==typeof r&&r>=0?r:0;var i=[];for(var s in e)e.hasOwnProperty(s)&&(i.push(s),r<n&&"object"==typeof e[s]&&(i=i.concat(t.objGetAllKeys(e[s],r+1))));return i},t.implode=t.implodeObj=function(e){if(!e)return[];var t=[];for(var n in e)if(e.hasOwnProperty(n)){var r={};r[n]=e[n],t.push(r)}return t},t.clone=function(e){if(!e)return e;if("number"==typeof e)return e;if("string"==typeof e)return e;if("boolean"==typeof e)return e;if(e===NaN)return e;if(e===Infinity)return e;var r;"function"==typeof e?r=function(){return e.apply(r,arguments)}:r=Object.prototype.toString.call(e)==="[object Array]"?[]:{};for(var i in e){var s;e[i]&&"object"==typeof e[i]?Object.prototype.toString.call(e[i])==="[object Array]"?s=e[i].slice(0):s=t.clone(e[i]):s=e[i];if(e.hasOwnProperty(i))r[i]=s;else if(n&&n.defineProperty)Object.defineProperty(r,i,{value:s,writable:!0,configurable:!0});else try{Object.defineProperty(r,i,{value:s,writable:!0,configurable:!0})}catch(o){r[i]=s}}return r},t.join=function(e,n){var r=t.clone(e);if(!n)return r;for(var i in r)r.hasOwnProperty(i)&&"undefined"!=typeof n[i]&&("object"==typeof n[i]?r[i]=t.join(r[i],n[i]):r[i]=n[i]);return r},t.merge=function(e,n){if(!e&&!n)return!1;if(!e)return t.clone(n);if(!n)return t.clone(e);var r=t.clone(e);for(var i in n)n.hasOwnProperty(i)&&(n[i]&&"object"==typeof n[i]?("object"!=typeof r[i]&&(Object.prototype.toString.call(n[i])==="[object Array]"?r[i]=[]:r[i]={}),r[i]=t.merge(r[i],n[i])):r[i]=n[i]);return r},t.mixin=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]=t[n]},t.mixout=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]||(e[n]=t[n])},t.mixcommon=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]&&(e[n]=t[n])},t.mergeOnKey=function(e,n,r){var i=t.clone(e);if(!n||!r)return i;for(var s in n)if(n.hasOwnProperty(s)){if(!i[s]||"object"!=typeof i[s])i[s]={};i[s][r]=n[s]}return i},t.subobj=function(e,n){if(!e)return!1;var r={};if(!n)return r;n instanceof Array||(n=[n]);for(var i=0;i<n.length;i++){var s=n[i];t.hasOwnNestedProperty(s,e)&&t.setNestedValue(s,t.getNestedValue(s,e),r)}return r},t.skim=function(e,n){if(!e)return!1;var r=t.clone(e);if(!n)return r;n instanceof Array||(n=[n]);for(var i=0;i<n.length;i++)t.deleteNestedKey(n[i],r);return r},t.setNestedValue=function(n,r,i){if(!n)return e.log("Cannot set value of undefined property","ERR"),!1;i="object"==typeof i?i:{};var s=n.split(".");if(s.length===1)return i[n]=r,i;var o=s.shift();return i[o]=t.setNestedValue(s.join("."),r,i[o]),i},t.getNestedValue=function(e,n){if(!n)return;var r=e.split(".");if(r.length===1)return n[e];var i=r.shift();return t.getNestedValue(r.join("."),n[i])},t.deleteNestedKey=function(e,n){if(!n)return;var r=e.split(".");if(r.length===1)return delete n[e],!0;var i=r.shift();return"undefined"==typeof n[i]?!1:t.deleteNestedKey(r.join("."),n[i])},t.hasOwnNestedProperty=function(e,n){if(!n)return!1;var r=e.split(".");if(r.length===1)return n.hasOwnProperty(e);var i=r.shift();return t.hasOwnNestedProperty(r.join("."),n[i])},t.split=function(t,n){if(!t)return;if(!n||"object"!=typeof t[n])return e.clone(t);var r=[],i=e.clone(t);i[n]={};var s=function(t){for(var o in t){var u=e.clone(i);t.hasOwnProperty(o)&&("object"==typeof t[o]?r=r.concat(s(t[o])):(u[n][o]=t[o],r.push(u)))}return r};return s(t[n])},e.extend(t)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e,t,n){function u(e,n,r){e=e||{};if(!t)throw new Error("JSUS not found.");this.db=[],this.tags={},this.hooks={insert:[],remove:[]},this.nddb_pointer=0,u.compatibility.getter?this.__defineGetter__("length",function(){return this.db.length}):this.length=null,this.__C={},this.__H={},this.__I={},this.__update={},this.__update.pointer=!1,this.__update.indexes=!1,this.__update.sort=!1,this.__parent=r||undefined,this.init(e),this.importDB(n)}var r=null,i=[],s=function(e,t){return!e||!t?(u.log("Attempt to add invalid condition","ERR"),!1):(i.push({type:e,condition:t}),!0)},o=function(e,t,n,i){if(!r)return u.log("No operation found.","ERR"),!1;var o=this._analyzeQuery(t,n,i);return o?s(e,o):!1};u.prototype.and=u.prototype.AND=function(e,t,n){return o("AND",e,t,n)},u.prototype.or=u.prototype.OR=function(e,t,n){return o("OR",e,t,n)},u.prototype.not=u.prototype.NOT=function(e,t,n){return o("NOT",e,t,n)},u.compatibility=t.compatibility(),e.NDDB=u,u.log=console.log,u.__symbols=[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"],u.__operations=["select","groupby","limit","first","fetch","last"],u.decycle=function(e){return JSON&&JSON.decycle&&"function"==typeof JSON.decycle&&(e=JSON.decycle(e)),e},u.retrocycle=function(e){return JSON&&JSON.retrocycle&&"function"==typeof JSON.retrocycle&&(e=JSON.retrocycle(e)),e},u.prototype.init=function(e){e=e||{},this.__options=e,e.log&&(u.log=e.log),e.C&&(this.__C=e.C),e.H&&(this.__H=e.H),e.I&&(this.__I=e.I),e.tags&&(this.tags=e.tags),e.nddb_pointer>0&&(this.nddb_pointer=e.nddb_pointer),e.hooks&&(this.hooks=e.hook),e.update&&("undefined"!=typeof e.update.pointer&&(this.__update.pointer=e.update.pointer),"undefined"!=typeof e.update.indexes&&(this.__update.indexes=e.update.indexes),"undefined"!=typeof e.update.sort&&(this.__update.sort=e.update.sort))},u.prototype.globalCompare=function(e,t){return"undefined"==typeof e&&"undefined"==typeof t?0:"undefined"==typeof t?-1:"undefined"==typeof e?1:e.nddbid<t.nddbid?-1:e.nddbid>t.nddbid?1:0},u.prototype._masquerade=function(e,t){return"undefined"==typeof e?!1:"undefined"!=typeof e.nddbid?e:(t=t||this.db,u.compatibility.defineProperty?Object.defineProperty(e,"nddbid",{value:t.length,configurable:!0,writable:!0}):e.nddbid=t.length,e)},u.prototype._masqueradeDB=function(e){if(!e)return[];var t=[];for(var n=0;n<e.length;n++)t[n]=this._masquerade(e[n],t);return t},u.prototype._autoUpdate=function(e){var n=e?t.merge(e,this.__update):this.__update;n.pointer&&(this.nddb_pointer=this.db.length-1),n.sort&&this.sort(),n.indexes&&this.rebuildIndexes(),this.__parent&&this.__parent._autoUpdate(n)},u.prototype.importDB=function(e){if(!e)return;this.db||(this.db=[]);for(var t=0;t<e.length;t++)this.insert(e[t])},u.prototype.insert=function(e){if("undefined"==typeof e||e===null)return;this.db||(this.db=[]),this._insert(e)},u.prototype._insert=function(e){e=this._masquerade(e),this.db.push(e),this.emit("insert",e),this.__update.indexes&&(this._hashIt(e),this._indexIt(e)),this._autoUpdate({indexes:!1})},u.prototype.breed=function(e){e=e||this.db;var t=this.cloneSettings(),n=this.__parent||this;return new this.constructor(t,e,n)},u.prototype.cloneSettings=function(){var e=this.__options||{};return e.H=this.__H,e.I=this.__I,e.C=this.__C,e.tags=this.tags,e.update=this.__update,t.clone(e)},u.prototype.toString=function(){var e="";for(var t=0;t<this.db.length;t++)e+=this.db[t]+"\n";return e},u.prototype.stringify=function(e){if(!this.length)return"[]";e="undefined"==typeof e?!0:e;var n;e?n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e)}:n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e,null,4)};var r="[";return this.each(function(e){e=u.decycle(e),r+=n(e)+", "}),r=r.replace(/, $/,"]"),r},u.prototype.compare=u.prototype.c=function(e,t){return!e||!t?(u.log("Cannot set empty property or empty comparator","ERR"),!1):(this.__C[e]=t,!0)},u.prototype.comparator=function(e){return"undefined"!=typeof this.__C[e]?this.__C[e]:function(n,r){if("undefined"==typeof n&&"undefined"==typeof r)return 0;if("undefined"==typeof n)return 1;if("undefined"==typeof r)return-1;var i=t.getNestedValue(e,n),s=t.getNestedValue(e,r);return"undefined"==typeof i&&"undefined"==typeof s?0:"undefined"==typeof i?1:"undefined"==typeof s?-1:i>s?1:s>i?-1:0}},u.prototype.isReservedWord=function(e){return this[e]?!0:!1},u.prototype._isValidIndex=function(e){if("undefined"==typeof e)return u.log("A valid index name must be provided","ERR"),!1;if(this.isReservedWord(e)){var t="A reserved word have been selected as an index. ";return t+="Please select another one: "+e,u.log(t,"ERR"),!1}return!0},u.prototype.hash=u.prototype.h=function(e,t){return this._isValidIndex(e)?(this.__H[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.index=u.prototype.i=function(e,t){return this._isValidIndex(e)?(this.__I[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.rebuildIndexes=function(){var e=!1,n=!1;if(!t.isEmpty(this.__H)){e=!0;for(var r in this.__H)this.__H.hasOwnProperty(r)&&(this[r]={})}if(!t.isEmpty(this.__I)){n=!0;for(var r in this.__I)this.__I.hasOwnProperty(r)&&(this[r]={})}e&&!n?this.each(this._hashIt):!e&&n?this.each(this._indexIt):e&&n&&this.each(function(e){this.hashIt(e),this.indexIt(e)})},u.prototype._hashIt=function(e){if(!e)return!1;if(t.isEmpty(this.__H))return!1;var n=null,r=null,i=null;for(var s in this.__H)if(this.__H.hasOwnProperty(s)){n=this.__H[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]||(this[s][i]=new u),this[s][i].insert(e)}},u.prototype._indexIt=function(e){if(!e)return!1;if(t.isEmpty(this.__I))return!1;var n=null,r=null,i=null;for(var s in this.__I)if(this.__I.hasOwnProperty(s)){n=this.__I[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]=e}},u.prototype.on=function(e,t){if(!e||!t||!this.hooks[e])return;return this.hooks[e].push(t),!0},u.prototype.off=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;if(!t)return this.hooks[e]=[],!0;for(var n=0;n<this.hooks[e].length;n++)if(this.hooks[e][n]==t)return this.hooks[e].splice(n,1),!0;return!1},u.prototype.emit=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;for(var n=0;n<this.hooks[e].length;n++)this.hooks[e][n].call(this,t)},u.prototype._analyzeQuery=function(e,n,r){var i=function(e,t,n){var r="(?)",i="Malformed query: "+e||r+" "+t||r+" "+n||r;return u.log(i,"WARN"),!1};"undefined"==typeof e&&i(e,n,r);if("undefined"!=typeof n){"undefined"==typeof r&&i(e,n,r);if(!t.in_array(n,[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"]))return u.log("Query error. Invalid operator detected: "+n,"WARN"),!1;n==="="&&(n="==");if(t.in_array(n,["><","<>","in","!in"])){r instanceof Array||(u.log("Range-queries need an array as third parameter","WARN"),i(e,n,r));if(n==="<>"||n==="><")r[0]=t.setNestedValue(e,r[0]),r[1]=t.setNestedValue(e,r[1])}else r=t.setNestedValue(e,r)}else"undefined"!=typeof r?i(e,n,r):(n="",r="");return{d:e,op:n,value:r}},u.prototype.distinct=function(){return this.breed(t.distinct(this.db))},u.prototype.select=function(e,n,r){var i=this._analyzeQuery(e,n,r);if(!i)return!1;var e=i.d,n=i.op,r=i.value,s=this.comparator(e),o=function(n){if("undefined"!=typeof t.getNestedValue(e,n))return n},a=function(i){try{if(t.eval(s(i,r)+n+0,i))return i}catch(o){return u.log("Malformed select query: "+e+n+r),!1}},f=function(e){if(s(e,r[0])>0&&s(e,r[1])<0)return e},l=function(e){if(s(e,r[0])<0&&s(e,r[1]>0))return e},c=function(n){if(t.in_array(t.getNestedValue(e,n),r))return n},h=function(n){if(!t.in_array(t.getNestedValue(e,n),r))return n};switch(n){case"":var p=o;break;case"<>":var p=l;break;case"><":var p=f;break;case"in":var p=c;break;case"!in":var p=h;break;default:var p=a}return this.filter(p)},u.prototype.limit=function(e){e=e||0;if(e===0)return this.breed();var t=e>0?this.db.slice(0,e):this.db.slice(e);return this.breed(t)},u.prototype.reverse=function(){return this.db.reverse(),this},u.prototype.sort=function(e){if(!e)var t=this.globalCompare;else if("function"==typeof e)var t=e;else if(e instanceof Array)var n=this,t=function(t,r){for(var i=0;i<e.length;i++){var s=n.comparator(e[i]).call(n,t,r);if(s!==0)return s}return s};else var t=this.comparator(e);return this.db.sort(t),this},u.prototype.shuffle=function(){return this.db=t.shuffle(this.db),this},u.prototype.filter=function(e){return this.breed(this.db.filter(e))},u.prototype.each=u.prototype.forEach=function(){if(arguments.length===0)return;var e=arguments[0];for(var t=0;t<this.db.length;t++)arguments[0]=this.db[t],e.apply(this,arguments)},u.prototype.map=function(){if(arguments.length===0)return;var e=arguments[0],t=[],n=undefined;for(var r=0;r<this.db.length;r++)arguments[0]=this.db[r],n=e.apply(this,arguments),"undefined"!=typeof n&&t.push(n);return t},u.prototype.remove=function(){if(!this.length)return this;if(this.__parent){for(var e=0;e<this.db.length;e++){var t=this.db[e].nddbid-e;this.__parent.db.splice(t,1)}for(var e=0;e<this.__parent.length;e++)this.__parent.db[e].nddbid=e}return this.emit("remove",this.db),this.db=[],this._autoUpdate(),this},u.prototype.clear=function(e){return e?(this.db=[],this._autoUpdate()):u.log("Do you really want to clear the current dataset? Please use clear(true)","WARN"),e},u.prototype.join=function(e,n,r,i){return this._join(e,n,t.equals,r,i)},u.prototype.concat=function(e,t,n,r){return this._join(e,t,function(){return!0},n,r)},u.prototype._join=function(e,n,r,i,s){r=r||t.equals,i="undefined"!=typeof i?i:"joined";if(s)var s=s instanceof Array?s:[s];var o=[],a=[];for(var f=0;f<this.db.length;f++)try{var l=t.eval("this."+e,this.db[f]);if("undefined"!=typeof l)for(var c=f+1;c<this.db.length;c++)try{var h=t.eval("this."+n,this.db[c]);if("undefined"!=typeof h&&r(l,h)){var p=t.clone(this.db[f]),d=s?t.subobj(this.db[c],s):this.db[c];p[i]=d,o.push(p)}}catch(v){u.log("Key not found in entry: "+n,"WARN")}}catch(v){u.log("Key not found in entry: "+e,"WARN")}return this.breed(o)},u.prototype.split=function(e){var n=[];for(var r=0;r<this.db.length;r++)n=n.concat(t.split(this.db[r],e));return this.breed(n)},u.prototype._fetch=function(e,n){function r(e,n){return t.getNestedValue(n,e)}function i(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return t.obj2KeyedArray(r)}function s(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return n.split(".").concat(t.obj2KeyedArray(r))}switch(n){case"VALUES":var o=e?i:t.obj2Array;break;case"KEY_VALUES":var o=e?s:t.obj2KeyedArray;break;default:if(!e)return this.db;var o=r}var u=[];for(var a=0;a<this.db.length;a++){var f=o.call(this.db[a],this.db[a],e);"undefined"!=typeof f&&u.push(f)}return u},u.prototype.fetch=function(e){return this._fetch(e,!0)},u.prototype.fetchArray=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyArray=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.fetchValues=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyValues=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.groupBy=function(e){if(!e)return this.db;var n=[],r=[];for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);if("undefined"==typeof s)continue;if(!t.in_array(s,n)){n.push(s);var o=this.filter(function(n){if(t.equals(t.getNestedValue(e,n),s))return this});o.nddb_pointer=0,r.push(o)}}return r},u.prototype.count=function(e){if("undefined"==typeof e)return this.db.length;var n=0;for(var r=0;r<this.db.length;r++)t.hasOwnNestedProperty(e,this.db[r])&&n++;return n},u.prototype.sum=function(e){if("undefined"==typeof e)return!1;var n=0;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);isNaN(i)||(n+=i)}return n},u.prototype.mean=function(e){if("undefined"==typeof e)return!1;var n=0,r=0;for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);isNaN(s)||(n+=s,r++)}return r===0?0:n/r},u.prototype.stddev=function(e){if("undefined"==typeof e)return!1;var n=this.mean(e);if(isNaN(n))return!1;var r=0;return this.each(function(i){var s=t.getNestedValue(e,i);isNaN(s)||(r+=Math.pow(s-n,2))}),r!==0?Math.sqrt(r):0},u.prototype.min=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i<n||n===!1)&&(n=i)}return n},u.prototype.max=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i>n||n===!1)&&(n=i)}return n},u.prototype.skim=function(e){return e?this.breed(this.map(function(n){var r=t.skim(n,e);if(!t.isEmpty(r))return r})):this},u.prototype.keep=function(e){return e?this.breed(this.map(function(n){var r=t.subobj(n,e);if(!t.isEmpty(r))return r})):this.breed([])},u.prototype.diff=function(e){return!e||!e.length?this:("object"==typeof e&&(e instanceof u||e instanceof this.constructor)&&(e=e.db),this.breed(t.arrayDiff(this.db,e)))},u.prototype.intersect=function(e){if(!e||!e.length)return this;if("object"==typeof e)if(e instanceof u||e instanceof this.constructor)var e=e.db;return this.breed(t.arrayIntersect(this.db,e))},u.prototype.get=function(e){var e=e||this.nddb_pointer;return e<0||e>this.db.length-1?!1:this.db[e]},u.prototype.next=function(){var e=u.prototype.get.call(this,++this.nddb_pointer);return e||this.nddb_pointer--,e},u.prototype.previous=function(){var e=u.prototype.get.call(this,--this.nddb_pointer);return e||this.nddb_pointer++,e},u.prototype.first=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[0].nddbid,t[0]):undefined},u.prototype.last=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[t.length-1].nddbid,t[t.length-1]):undefined},u.prototype.tag=function(e,t){if("undefined"==typeof e)return u.log("Cannot register empty tag.","ERR"),!1;var n=null,r=typeof t;if(r==="undefined")n=this.db[this.nddb_pointer];else if(r==="number"){if(t>this.length||t<0)return u.log("Invalid index provided for tag registration","ERR"),!1;n=this.db[t]}else n=t;return this.tags[e]=n,!0},u.prototype.resolveTag=function(e){return"undefined"==typeof e?(u.log("Cannot resolve empty tag.","ERR"),!1):this.tags[e]};var a=function(){return"function"==typeof n};if(t.isNodeJS()){require("./external/cycle.js");var f=require("fs")}u.prototype.save=function(e,r,i){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;i=i||!1;if(!t.isNodeJS())return a()?(n(e,this.stringify(i)),r&&r(),!0):(u.log("No support for persistent storage found.","ERR"),!1);f.writeFile(e,this.stringify(i),"utf-8",function(e){if(e)throw e;return r&&r(),!0})},u.prototype.load=function(e,r){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;if(!t.isNodeJS()){if(!a())return u.log("No support for persistent storage found.","ERR"),!1;var i=n(e);return this.importDB(i),r&&r(),!0}var s=function(e){var t=JSON.parse(e.toString()),n;for(n=0;n<t.length;n++)t[n]=u.retrocycle(t[n]);this.importDB(t)};if(!r){var o=f.readFileSync(e,"utf-8");s.call(this,o)}else f.readFile(e,"utf-8",function(e,t){if(e)throw e;s.call(this,t),r()})}}("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:window,"undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS||require("JSUS").JSUS,"object"==typeof module&&"function"==typeof require?module.parent.exports.store||require("shelf.js/build/shelf-fs.js").store:this.store)
3  build/nddb.js
View
@@ -2922,11 +2922,12 @@ NDDB.prototype.reverse = function () {
*
* Changes the order of elements in the current database
*
+ * @return {NDDB} A a reference to the current instance with shuffled entries
*/
NDDB.prototype.shuffle = function () {
// TODO: check do we need to reassign __nddbid__ ?
this.db = JSUS.shuffle(this.db);
- return true;
+ return this;
};
// ## Custom callbacks
2  build/nddb.min.js
View
@@ -7,4 +7,4 @@
*
* See README.md for extra help.
*/
-(function(e){var t=e.JSUS={};t._classes={},t.log=function(e){console.log(e)},t.extend=function(e,n){if("object"!=typeof e&&"function"!=typeof e)return n;if("undefined"==typeof n){n=n||this;if("function"==typeof e){var r=e.toString();r=r.substr("function ".length),r=r.substr(0,r.indexOf("("))}else var r=e.constructor||e.__proto__.constructor;r&&(this._classes[r]=e)}for(var i in e)e.hasOwnProperty(i)&&(typeof n[i]!="object"?n[i]=e[i]:t.extend(e[i],n[i]));return e.prototype&&t.extend(e.prototype,n.prototype||n),n},t.require=t.get=function(e){return"undefined"==typeof t.clone?(t.log("JSUS.clone not found. Cannot continue."),!1):"undefined"==typeof e?t.clone(t._classes):"undefined"==typeof t._classes[e]?(t.log("Could not find class "+e),!1):t.clone(t._classes[e])},t.isNodeJS=function(){return"undefined"!=typeof module&&"undefined"!=typeof module.exports&&"function"==typeof require},t.isNodeJS()&&(require("./lib/compatibility"),require("./lib/obj"),require("./lib/array"),require("./lib/time"),require("./lib/eval"),require("./lib/dom"),require("./lib/random"),require("./lib/parse"),require("./lib/fs"))})("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:window),function(JSUS){function COMPATIBILITY(){}COMPATIBILITY.compatibility=function(){var support={};try{Object.defineProperty({},"a",{enumerable:!1,value:1}),support.defineProperty=!0}catch(e){support.defineProperty=!1}try{eval("({ get x(){ return 1 } }).x === 1"),support.setter=!0}catch(err){support.setter=!1}try{var value;eval("({ set x(v){ value = v; } }).x = 1"),support.getter=!0}catch(err){support.getter=!1}return support},JSUS.extend(COMPATIBILITY)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e){function t(){}Array.prototype.filter||(Array.prototype.filter=function(e){"use strict";if(this===void 0||this===null)throw new TypeError;var t=Object(this),n=t.length>>>0;if(typeof e!="function")throw new TypeError;var r=[],i=arguments[1];for(var s=0;s<n;s++)if(s in t){var o=t[s];e.call(i,o,s,t)&&r.push(o)}return r}),t.isArray=function(e){return e?Object.prototype.toString.call(e)==="[object Array]":!1},t.seq=function(t,n,r,i){if("number"!=typeof t)return!1;if(t===Infinity)return!1;if("number"!=typeof n)return!1;if(n===Infinity)return!1;if(t===n)return[t];if(r===0)return!1;if(!e.in_array(typeof r,["undefined","number"]))return!1;r=r||1,i=i||function(e){return e};var s=t,o=[];if(t<n)while(s<=n)o.push(i(s)),s+=r;else while(s>=n)o.push(i(s)),s-=r;return o},t.each=function(e,t,n){if("object"!=typeof e)return!1;if(!t)return!1;n=n||this;var r,i=e.length;for(r=0;r<i;r++)t.call(n,e[r]);return!0},t.map=function(){if(arguments.length<2)return;var n=Array.prototype.slice.call(arguments),r=n.shift(),i=n[0];if(!t.isArray(r)){e.log("ARRAY.map() the first argument must be an array. Found: "+r);return}var s=[],o=undefined;for(var u=0;u<r.length;u++)n[0]=r[u],o=i.apply(this,n),"undefined"!=typeof o&&s.push(o);return s},t.removeElement=function(t,n){if("undefined"==typeof t||!n)return!1;if("object"==typeof t)var r=e.equals;else var r=function(e,t){return e===t};for(var i=0;i<n.length;i++)if(r(t,n[i]))return n.splice(i,1);return!1},t.inArray=t.in_array=function(t,n){if(!n)return!1;var r=e.equals;for(var i=0;i<n.length;i++)if(r.call(this,t,n[i]))return!0;return!1},t.getNGroups=function(e,n){return t.getGroupsSizeN(e,Math.floor(e.length/n))},t.getGroupsSizeN=function(e,t){var n=e.slice(0),r=n.length,i=n.length,s=[],o,u,a=[],f=0;for(o=0;o<i;o++)u=Math.floor(Math.random()*r),f>=t&&(s.push(a),f=0,a=[]),a.push(n[u]),n.splice(u,1),r=n.length,f++;return a.length>0&&s.push(a),s},t._latinSquare=function(t,n,r){r="undefined"==typeof r?!0:r;if(t===n&&!r)return!1;var i=[],s=[];for(var o=0;o<t;o++)i[o]=o;var u=null,a=0,f=t,l=[];r||(f=t-1);for(o=0;o<n;o++){do u=e.randomInt(a,f);while(e.in_array(u,l));l.push(u),u==1?(s[o]=i.slice(u),s[o].push(0)):s[o]=i.slice(u).concat(i.slice(0,u))}return s},t.latinSquare=function(e,n){return n||(n=e),!e||e<0||n<0?!1:(n>e&&(n=e),t._latinSquare(e,n,!0))},t.latinSquareNoSelf=function(e,n){return n||(n=e-1),!e||e<0||n<0?!1:(n>e&&(n=e-1),t._latinSquare(e,n,!1))},t.generateCombinations=function(t,n){function r(e,t){var n=[];for(var r=0;r<e.length;r++)n.push(t[e[r]]);return n}var i=t.length,s=[];for(var o=0;o<n;o++)s.push(o);var u=[];for(var o=i-n;o<i;o++)u.push(o);while(!e.equals(s,u)){callback(r(s,t));var o=n-1;while(s[o]==i-n+o)o-=1;s[o]+=1;for(var a=o+1;a<n;a++)s[a]=s[o]+a-o}return r(s,t)},t.matchN=function(e,n,r){if(!e)return;if(!n)return e;var i=[],s=e.length,o=[];for(var u=0;u<s;u++){var a=e.slice(0);a.splice(u,1),r&&(a=t.arrayDiff(a,o));var f=t.getNRandom(a,n);o=o.concat(f),f.splice(0,0,e[u]),i.push(f),f=[]}return i},t.rep=function(t,n){if(!t)return;if(!n)return t.slice(0);if(n<1){e.log("times must be greater or equal 1","ERR");return}var r=1,i=t.slice(0);for(;r<n;r++)i=i.concat(t);return i},t.stretch=function(n,r){if(!n)return;if(!r)return n.slice(0);if("number"==typeof r){if(r<1){e.log("times must be greater or equal 1","ERR");return}r=t.rep([r],n.length)}var i=[];for(var s=0;s<n.length;s++){var o=r[s%r.length];for(var u=0;u<o;u++)i.push(n[s])}return i},t.arrayIntersect=function(t,n){return t.filter(function(t){return e.in_array(t,n)})},t.arrayDiff=function(t,n){return t.filter(function(t){return!e.in_array(t,n)})},t.shuffle=function(e){if(!e)return;var t=e.slice(0),n=e.length-1,r,i;for(var s=n;s>0;s--)r=Math.floor(Math.random()*(s+1)),i=t[r],t[r]=t[s],t[s]=i;return t},t.getNRandom=function(e,n){return t.shuffle(e).slice(0,n)},t.distinct=function(e){var n=[];return e?(t.each(e,function(e){t.in_array(e,n)||n.push(e)}),n):n},t.transpose=function(e){if(!e)return;var n,r,i,s,o=[];n=e.length||0,r=t.isArray(e[0])?e[0].length:0;if(n===0||r===0)return o;for(i=0;i<r;i++){o[i]=[];for(s=0;s<n;s++)o[i][s]=e[s][i]}return o},e.extend(t)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e){function t(){}var n=null;"undefined"!=typeof e.compatibility&&(n=e.compatibility()),t.equals=function(e,n){if("undefined"==typeof e||"undefined"==typeof n)return e===n;if(e===null||n===null)return e===n;if("number"==typeof e&&isNaN(e)&&"number"==typeof n&&isNaN(n))return isNaN(e)&&isNaN(n);var r={number:"",string:"","boolean":""};if(typeof e in r)return typeof n in r?e===n:!1;if(typeof n in{number:"",string:"","boolean":""})return!1;for(var i in e)if(e.hasOwnProperty(i)){if("undefined"==typeof n[i]&&"undefined"!=typeof e[i])return!1;if(!n[i]&&e[i])return!1;switch(typeof e[i]){case"function":if(e[i].toString()!==n[i].toString())return!1;default:if(!t.equals(e[i],n[i]))return!1}}for(i in n)if(n.hasOwnProperty(i)){if("undefined"==typeof e[i]&&"undefined"!=typeof n[i])return!1;if(!e[i]&&n[i])return!1}return!0},t.isEmpty=function(e){if("undefined"==typeof e)return!0;for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},t.size=t.getListSize=function(e){if(!e)return 0;if("number"==typeof e)return 0;if("string"==typeof e)return 0;var t=0;for(var n in e)e.hasOwnProperty(n)&&t++;return t},t._obj2Array=function(e,n,r,i){if("object"!=typeof e)return[e];if(r){i="undefined"!=typeof i?i:1;if(i>r)return[e];i+=1}var s=[];for(var o in e)e.hasOwnProperty(o)&&("object"==typeof e[o]?s=s.concat(t._obj2Array(e[o],n,r,i)):(n&&s.push(o),s.push(e[o])));return s},t.obj2Array=function(e,n){return t._obj2Array(e,!1,n)},t.obj2KeyedArray=t.obj2KeyArray=function(e,n){return t._obj2Array(e,!0,n)},t.keys=t.objGetAllKeys=function(e,n,r){if(!e)return[];n="number"==typeof n&&n>=0?n:0,r="number"==typeof r&&r>=0?r:0;var i=[];for(var s in e)e.hasOwnProperty(s)&&(i.push(s),r<n&&"object"==typeof e[s]&&(i=i.concat(t.objGetAllKeys(e[s],r+1))));return i},t.implode=t.implodeObj=function(e){if(!e)return[];var t=[];for(var n in e)if(e.hasOwnProperty(n)){var r={};r[n]=e[n],t.push(r)}return t},t.clone=function(e){if(!e)return e;if("number"==typeof e)return e;if("string"==typeof e)return e;if("boolean"==typeof e)return e;if(e===NaN)return e;if(e===Infinity)return e;var r;"function"==typeof e?r=function(){return e.apply(r,arguments)}:r=Object.prototype.toString.call(e)==="[object Array]"?[]:{};for(var i in e){var s;e[i]&&"object"==typeof e[i]?Object.prototype.toString.call(e[i])==="[object Array]"?s=e[i].slice(0):s=t.clone(e[i]):s=e[i];if(e.hasOwnProperty(i))r[i]=s;else if(n&&n.defineProperty)Object.defineProperty(r,i,{value:s,writable:!0,configurable:!0});else try{Object.defineProperty(r,i,{value:s,writable:!0,configurable:!0})}catch(o){r[i]=s}}return r},t.join=function(e,n){var r=t.clone(e);if(!n)return r;for(var i in r)r.hasOwnProperty(i)&&"undefined"!=typeof n[i]&&("object"==typeof n[i]?r[i]=t.join(r[i],n[i]):r[i]=n[i]);return r},t.merge=function(e,n){if(!e&&!n)return!1;if(!e)return t.clone(n);if(!n)return t.clone(e);var r=t.clone(e);for(var i in n)n.hasOwnProperty(i)&&(n[i]&&"object"==typeof n[i]?("object"!=typeof r[i]&&(Object.prototype.toString.call(n[i])==="[object Array]"?r[i]=[]:r[i]={}),r[i]=t.merge(r[i],n[i])):r[i]=n[i]);return r},t.mixin=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]=t[n]},t.mixout=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]||(e[n]=t[n])},t.mixcommon=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]&&(e[n]=t[n])},t.mergeOnKey=function(e,n,r){var i=t.clone(e);if(!n||!r)return i;for(var s in n)if(n.hasOwnProperty(s)){if(!i[s]||"object"!=typeof i[s])i[s]={};i[s][r]=n[s]}return i},t.subobj=function(e,n){if(!e)return!1;var r={};if(!n)return r;n instanceof Array||(n=[n]);for(var i=0;i<n.length;i++){var s=n[i];t.hasOwnNestedProperty(s,e)&&t.setNestedValue(s,t.getNestedValue(s,e),r)}return r},t.skim=function(e,n){if(!e)return!1;var r=t.clone(e);if(!n)return r;n instanceof Array||(n=[n]);for(var i=0;i<n.length;i++)t.deleteNestedKey(n[i],r);return r},t.setNestedValue=function(n,r,i){if(!n)return e.log("Cannot set value of undefined property","ERR"),!1;i="object"==typeof i?i:{};var s=n.split(".");if(s.length===1)return i[n]=r,i;var o=s.shift();return i[o]=t.setNestedValue(s.join("."),r,i[o]),i},t.getNestedValue=function(e,n){if(!n)return;var r=e.split(".");if(r.length===1)return n[e];var i=r.shift();return t.getNestedValue(r.join("."),n[i])},t.deleteNestedKey=function(e,n){if(!n)return;var r=e.split(".");if(r.length===1)return delete n[e],!0;var i=r.shift();return"undefined"==typeof n[i]?!1:t.deleteNestedKey(r.join("."),n[i])},t.hasOwnNestedProperty=function(e,n){if(!n)return!1;var r=e.split(".");if(r.length===1)return n.hasOwnProperty(e);var i=r.shift();return t.hasOwnNestedProperty(r.join("."),n[i])},t.split=function(t,n){if(!t)return;if(!n||"object"!=typeof t[n])return e.clone(t);var r=[],i=e.clone(t);i[n]={};var s=function(t){for(var o in t){var u=e.clone(i);t.hasOwnProperty(o)&&("object"==typeof t[o]?r=r.concat(s(t[o])):(u[n][o]=t[o],r.push(u)))}return r};return s(t[n])},e.extend(t)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e,t,n){function u(e,n,r){e=e||{};if(!t)throw new Error("JSUS not found.");this.db=[],this.tags={},this.hooks={insert:[],remove:[]},this.nddb_pointer=0,u.compatibility.getter?this.__defineGetter__("length",function(){return this.db.length}):this.length=null,this.__C={},this.__H={},this.__I={},this.__update={},this.__update.pointer=!1,this.__update.indexes=!1,this.__update.sort=!1,this.__parent=r||undefined,this.init(e),this.importDB(n)}var r=null,i=[],s=function(e,t){return!e||!t?(u.log("Attempt to add invalid condition","ERR"),!1):(i.push({type:e,condition:t}),!0)},o=function(e,t,n,i){if(!r)return u.log("No operation found.","ERR"),!1;var o=this._analyzeQuery(t,n,i);return o?s(e,o):!1};u.prototype.and=u.prototype.AND=function(e,t,n){return o("AND",e,t,n)},u.prototype.or=u.prototype.OR=function(e,t,n){return o("OR",e,t,n)},u.prototype.not=u.prototype.NOT=function(e,t,n){return o("NOT",e,t,n)},u.compatibility=t.compatibility(),e.NDDB=u,u.log=console.log,u.__symbols=[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"],u.__operations=["select","groupby","limit","first","fetch","last"],u.decycle=function(e){return JSON&&JSON.decycle&&"function"==typeof JSON.decycle&&(e=JSON.decycle(e)),e},u.retrocycle=function(e){return JSON&&JSON.retrocycle&&"function"==typeof JSON.retrocycle&&(e=JSON.retrocycle(e)),e},u.prototype.init=function(e){e=e||{},this.__options=e,e.log&&(u.log=e.log),e.C&&(this.__C=e.C),e.H&&(this.__H=e.H),e.I&&(this.__I=e.I),e.tags&&(this.tags=e.tags),e.nddb_pointer>0&&(this.nddb_pointer=e.nddb_pointer),e.hooks&&(this.hooks=e.hook),e.update&&("undefined"!=typeof e.update.pointer&&(this.__update.pointer=e.update.pointer),"undefined"!=typeof e.update.indexes&&(this.__update.indexes=e.update.indexes),"undefined"!=typeof e.update.sort&&(this.__update.sort=e.update.sort))},u.prototype.globalCompare=function(e,t){return"undefined"==typeof e&&"undefined"==typeof t?0:"undefined"==typeof t?-1:"undefined"==typeof e?1:e.nddbid<t.nddbid?-1:e.nddbid>t.nddbid?1:0},u.prototype._masquerade=function(e,t){return"undefined"==typeof e?!1:"undefined"!=typeof e.nddbid?e:(t=t||this.db,u.compatibility.defineProperty?Object.defineProperty(e,"nddbid",{value:t.length,configurable:!0,writable:!0}):e.nddbid=t.length,e)},u.prototype._masqueradeDB=function(e){if(!e)return[];var t=[];for(var n=0;n<e.length;n++)t[n]=this._masquerade(e[n],t);return t},u.prototype._autoUpdate=function(e){var n=e?t.merge(e,this.__update):this.__update;n.pointer&&(this.nddb_pointer=this.db.length-1),n.sort&&this.sort(),n.indexes&&this.rebuildIndexes(),this.__parent&&this.__parent._autoUpdate(n)},u.prototype.importDB=function(e){if(!e)return;this.db||(this.db=[]);for(var t=0;t<e.length;t++)this.insert(e[t])},u.prototype.insert=function(e){if("undefined"==typeof e||e===null)return;this.db||(this.db=[]),this._insert(e)},u.prototype._insert=function(e){e=this._masquerade(e),this.db.push(e),this.emit("insert",e),this.__update.indexes&&(this._hashIt(e),this._indexIt(e)),this._autoUpdate({indexes:!1})},u.prototype.breed=function(e){e=e||this.db;var t=this.cloneSettings(),n=this.__parent||this;return new this.constructor(t,e,n)},u.prototype.cloneSettings=function(){var e=this.__options||{};return e.H=this.__H,e.I=this.__I,e.C=this.__C,e.tags=this.tags,e.update=this.__update,t.clone(e)},u.prototype.toString=function(){var e="";for(var t=0;t<this.db.length;t++)e+=this.db[t]+"\n";return e},u.prototype.stringify=function(e){if(!this.length)return"[]";e="undefined"==typeof e?!0:e;var n;e?n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e)}:n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e,null,4)};var r="[";return this.each(function(e){e=u.decycle(e),r+=n(e)+", "}),r=r.replace(/, $/,"]"),r},u.prototype.compare=u.prototype.c=function(e,t){return!e||!t?(u.log("Cannot set empty property or empty comparator","ERR"),!1):(this.__C[e]=t,!0)},u.prototype.comparator=function(e){return"undefined"!=typeof this.__C[e]?this.__C[e]:function(n,r){if("undefined"==typeof n&&"undefined"==typeof r)return 0;if("undefined"==typeof n)return 1;if("undefined"==typeof r)return-1;var i=t.getNestedValue(e,n),s=t.getNestedValue(e,r);return"undefined"==typeof i&&"undefined"==typeof s?0:"undefined"==typeof i?1:"undefined"==typeof s?-1:i>s?1:s>i?-1:0}},u.prototype.isReservedWord=function(e){return this[e]?!0:!1},u.prototype._isValidIndex=function(e){if("undefined"==typeof e)return u.log("A valid index name must be provided","ERR"),!1;if(this.isReservedWord(e)){var t="A reserved word have been selected as an index. ";return t+="Please select another one: "+e,u.log(t,"ERR"),!1}return!0},u.prototype.hash=u.prototype.h=function(e,t){return this._isValidIndex(e)?(this.__H[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.index=u.prototype.i=function(e,t){return this._isValidIndex(e)?(this.__I[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.rebuildIndexes=function(){var e=!1,n=!1;if(!t.isEmpty(this.__H)){e=!0;for(var r in this.__H)this.__H.hasOwnProperty(r)&&(this[r]={})}if(!t.isEmpty(this.__I)){n=!0;for(var r in this.__I)this.__I.hasOwnProperty(r)&&(this[r]={})}e&&!n?this.each(this._hashIt):!e&&n?this.each(this._indexIt):e&&n&&this.each(function(e){this.hashIt(e),this.indexIt(e)})},u.prototype._hashIt=function(e){if(!e)return!1;if(t.isEmpty(this.__H))return!1;var n=null,r=null,i=null;for(var s in this.__H)if(this.__H.hasOwnProperty(s)){n=this.__H[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]||(this[s][i]=new u),this[s][i].insert(e)}},u.prototype._indexIt=function(e){if(!e)return!1;if(t.isEmpty(this.__I))return!1;var n=null,r=null,i=null;for(var s in this.__I)if(this.__I.hasOwnProperty(s)){n=this.__I[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]=e}},u.prototype.on=function(e,t){if(!e||!t||!this.hooks[e])return;return this.hooks[e].push(t),!0},u.prototype.off=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;if(!t)return this.hooks[e]=[],!0;for(var n=0;n<this.hooks[e].length;n++)if(this.hooks[e][n]==t)return this.hooks[e].splice(n,1),!0;return!1},u.prototype.emit=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;for(var n=0;n<this.hooks[e].length;n++)this.hooks[e][n].call(this,t)},u.prototype._analyzeQuery=function(e,n,r){var i=function(e,t,n){var r="(?)",i="Malformed query: "+e||r+" "+t||r+" "+n||r;return u.log(i,"WARN"),!1};"undefined"==typeof e&&i(e,n,r);if("undefined"!=typeof n){"undefined"==typeof r&&i(e,n,r);if(!t.in_array(n,[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"]))return u.log("Query error. Invalid operator detected: "+n,"WARN"),!1;n==="="&&(n="==");if(t.in_array(n,["><","<>","in","!in"])){r instanceof Array||(u.log("Range-queries need an array as third parameter","WARN"),i(e,n,r));if(n==="<>"||n==="><")r[0]=t.setNestedValue(e,r[0]),r[1]=t.setNestedValue(e,r[1])}else r=t.setNestedValue(e,r)}else"undefined"!=typeof r?i(e,n,r):(n="",r="");return{d:e,op:n,value:r}},u.prototype.distinct=function(){return this.breed(t.distinct(this.db))},u.prototype.select=function(e,n,r){var i=this._analyzeQuery(e,n,r);if(!i)return!1;var e=i.d,n=i.op,r=i.value,s=this.comparator(e),o=function(n){if("undefined"!=typeof t.getNestedValue(e,n))return n},a=function(i){try{if(t.eval(s(i,r)+n+0,i))return i}catch(o){return u.log("Malformed select query: "+e+n+r),!1}},f=function(e){if(s(e,r[0])>0&&s(e,r[1])<0)return e},l=function(e){if(s(e,r[0])<0&&s(e,r[1]>0))return e},c=function(n){if(t.in_array(t.getNestedValue(e,n),r))return n},h=function(n){if(!t.in_array(t.getNestedValue(e,n),r))return n};switch(n){case"":var p=o;break;case"<>":var p=l;break;case"><":var p=f;break;case"in":var p=c;break;case"!in":var p=h;break;default:var p=a}return this.filter(p)},u.prototype.limit=function(e){e=e||0;if(e===0)return this.breed();var t=e>0?this.db.slice(0,e):this.db.slice(e);return this.breed(t)},u.prototype.reverse=function(){return this.db.reverse(),this},u.prototype.sort=function(e){if(!e)var t=this.globalCompare;else if("function"==typeof e)var t=e;else if(e instanceof Array)var n=this,t=function(t,r){for(var i=0;i<e.length;i++){var s=n.comparator(e[i]).call(n,t,r);if(s!==0)return s}return s};else var t=this.comparator(e);return this.db.sort(t),this},u.prototype.shuffle=function(){return this.db=t.shuffle(this.db),!0},u.prototype.filter=function(e){return this.breed(this.db.filter(e))},u.prototype.each=u.prototype.forEach=function(){if(arguments.length===0)return;var e=arguments[0];for(var t=0;t<this.db.length;t++)arguments[0]=this.db[t],e.apply(this,arguments)},u.prototype.map=function(){if(arguments.length===0)return;var e=arguments[0],t=[],n=undefined;for(var r=0;r<this.db.length;r++)arguments[0]=this.db[r],n=e.apply(this,arguments),"undefined"!=typeof n&&t.push(n);return t},u.prototype.remove=function(){if(!this.length)return this;if(this.__parent){for(var e=0;e<this.db.length;e++){var t=this.db[e].nddbid-e;this.__parent.db.splice(t,1)}for(var e=0;e<this.__parent.length;e++)this.__parent.db[e].nddbid=e}return this.emit("remove",this.db),this.db=[],this._autoUpdate(),this},u.prototype.clear=function(e){return e?(this.db=[],this._autoUpdate()):u.log("Do you really want to clear the current dataset? Please use clear(true)","WARN"),e},u.prototype.join=function(e,n,r,i){return this._join(e,n,t.equals,r,i)},u.prototype.concat=function(e,t,n,r){return this._join(e,t,function(){return!0},n,r)},u.prototype._join=function(e,n,r,i,s){r=r||t.equals,i="undefined"!=typeof i?i:"joined";if(s)var s=s instanceof Array?s:[s];var o=[],a=[];for(var f=0;f<this.db.length;f++)try{var l=t.eval("this."+e,this.db[f]);if("undefined"!=typeof l)for(var c=f+1;c<this.db.length;c++)try{var h=t.eval("this."+n,this.db[c]);if("undefined"!=typeof h&&r(l,h)){var p=t.clone(this.db[f]),d=s?t.subobj(this.db[c],s):this.db[c];p[i]=d,o.push(p)}}catch(v){u.log("Key not found in entry: "+n,"WARN")}}catch(v){u.log("Key not found in entry: "+e,"WARN")}return this.breed(o)},u.prototype.split=function(e){var n=[];for(var r=0;r<this.db.length;r++)n=n.concat(t.split(this.db[r],e));return this.breed(n)},u.prototype._fetch=function(e,n){function r(e,n){return t.getNestedValue(n,e)}function i(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return t.obj2KeyedArray(r)}function s(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return n.split(".").concat(t.obj2KeyedArray(r))}switch(n){case"VALUES":var o=e?i:t.obj2Array;break;case"KEY_VALUES":var o=e?s:t.obj2KeyedArray;break;default:if(!e)return this.db;var o=r}var u=[];for(var a=0;a<this.db.length;a++){var f=o.call(this.db[a],this.db[a],e);"undefined"!=typeof f&&u.push(f)}return u},u.prototype.fetch=function(e){return this._fetch(e,!0)},u.prototype.fetchArray=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyArray=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.fetchValues=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyValues=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.groupBy=function(e){if(!e)return this.db;var n=[],r=[];for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);if("undefined"==typeof s)continue;if(!t.in_array(s,n)){n.push(s);var o=this.filter(function(n){if(t.equals(t.getNestedValue(e,n),s))return this});o.nddb_pointer=0,r.push(o)}}return r},u.prototype.count=function(e){if("undefined"==typeof e)return this.db.length;var n=0;for(var r=0;r<this.db.length;r++)t.hasOwnNestedProperty(e,this.db[r])&&n++;return n},u.prototype.sum=function(e){if("undefined"==typeof e)return!1;var n=0;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);isNaN(i)||(n+=i)}return n},u.prototype.mean=function(e){if("undefined"==typeof e)return!1;var n=0,r=0;for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);isNaN(s)||(n+=s,r++)}return r===0?0:n/r},u.prototype.stddev=function(e){if("undefined"==typeof e)return!1;var n=this.mean(e);if(isNaN(n))return!1;var r=0;return this.each(function(i){var s=t.getNestedValue(e,i);isNaN(s)||(r+=Math.pow(s-n,2))}),r!==0?Math.sqrt(r):0},u.prototype.min=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i<n||n===!1)&&(n=i)}return n},u.prototype.max=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i>n||n===!1)&&(n=i)}return n},u.prototype.skim=function(e){return e?this.breed(this.map(function(n){var r=t.skim(n,e);if(!t.isEmpty(r))return r})):this},u.prototype.keep=function(e){return e?this.breed(this.map(function(n){var r=t.subobj(n,e);if(!t.isEmpty(r))return r})):this.breed([])},u.prototype.diff=function(e){return!e||!e.length?this:("object"==typeof e&&(e instanceof u||e instanceof this.constructor)&&(e=e.db),this.breed(t.arrayDiff(this.db,e)))},u.prototype.intersect=function(e){if(!e||!e.length)return this;if("object"==typeof e)if(e instanceof u||e instanceof this.constructor)var e=e.db;return this.breed(t.arrayIntersect(this.db,e))},u.prototype.get=function(e){var e=e||this.nddb_pointer;return e<0||e>this.db.length-1?!1:this.db[e]},u.prototype.next=function(){var e=u.prototype.get.call(this,++this.nddb_pointer);return e||this.nddb_pointer--,e},u.prototype.previous=function(){var e=u.prototype.get.call(this,--this.nddb_pointer);return e||this.nddb_pointer++,e},u.prototype.first=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[0].nddbid,t[0]):undefined},u.prototype.last=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[t.length-1].nddbid,t[t.length-1]):undefined},u.prototype.tag=function(e,t){if("undefined"==typeof e)return u.log("Cannot register empty tag.","ERR"),!1;var n=null,r=typeof t;if(r==="undefined")n=this.db[this.nddb_pointer];else if(r==="number"){if(t>this.length||t<0)return u.log("Invalid index provided for tag registration","ERR"),!1;n=this.db[t]}else n=t;return this.tags[e]=n,!0},u.prototype.resolveTag=function(e){return"undefined"==typeof e?(u.log("Cannot resolve empty tag.","ERR"),!1):this.tags[e]};var a=function(){return"function"==typeof n};if(t.isNodeJS()){require("./external/cycle.js");var f=require("fs")}u.prototype.save=function(e,r,i){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;i=i||!1;if(!t.isNodeJS())return a()?(n(e,this.stringify(i)),r&&r(),!0):(u.log("No support for persistent storage found.","ERR"),!1);f.writeFile(e,this.stringify(i),"utf-8",function(e){if(e)throw e;return r&&r(),!0})},u.prototype.load=function(e,r){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;if(!t.isNodeJS()){if(!a())return u.log("No support for persistent storage found.","ERR"),!1;var i=n(e);return this.importDB(i),r&&r(),!0}var s=function(e){var t=JSON.parse(e.toString()),n;for(n=0;n<t.length;n++)t[n]=u.retrocycle(t[n]);this.importDB(t)};if(!r){var o=f.readFileSync(e,"utf-8");s.call(this,o)}else f.readFile(e,"utf-8",function(e,t){if(e)throw e;s.call(this,t),r()})}}("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:window,"undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS||require("JSUS").JSUS,"object"==typeof module&&"function"==typeof require?module.parent.exports.store||require("shelf.js/build/shelf-fs.js").store:this.store)
+(function(e){var t=e.JSUS={};t._classes={},t.log=function(e){console.log(e)},t.extend=function(e,n){if("object"!=typeof e&&"function"!=typeof e)return n;if("undefined"==typeof n){n=n||this;if("function"==typeof e){var r=e.toString();r=r.substr("function ".length),r=r.substr(0,r.indexOf("("))}else var r=e.constructor||e.__proto__.constructor;r&&(this._classes[r]=e)}for(var i in e)e.hasOwnProperty(i)&&(typeof n[i]!="object"?n[i]=e[i]:t.extend(e[i],n[i]));return e.prototype&&t.extend(e.prototype,n.prototype||n),n},t.require=t.get=function(e){return"undefined"==typeof t.clone?(t.log("JSUS.clone not found. Cannot continue."),!1):"undefined"==typeof e?t.clone(t._classes):"undefined"==typeof t._classes[e]?(t.log("Could not find class "+e),!1):t.clone(t._classes[e])},t.isNodeJS=function(){return"undefined"!=typeof module&&"undefined"!=typeof module.exports&&"function"==typeof require},t.isNodeJS()&&(require("./lib/compatibility"),require("./lib/obj"),require("./lib/array"),require("./lib/time"),require("./lib/eval"),require("./lib/dom"),require("./lib/random"),require("./lib/parse"),require("./lib/fs"))})("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:window),function(JSUS){function COMPATIBILITY(){}COMPATIBILITY.compatibility=function(){var support={};try{Object.defineProperty({},"a",{enumerable:!1,value:1}),support.defineProperty=!0}catch(e){support.defineProperty=!1}try{eval("({ get x(){ return 1 } }).x === 1"),support.setter=!0}catch(err){support.setter=!1}try{var value;eval("({ set x(v){ value = v; } }).x = 1"),support.getter=!0}catch(err){support.getter=!1}return support},JSUS.extend(COMPATIBILITY)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e){function t(){}Array.prototype.filter||(Array.prototype.filter=function(e){"use strict";if(this===void 0||this===null)throw new TypeError;var t=Object(this),n=t.length>>>0;if(typeof e!="function")throw new TypeError;var r=[],i=arguments[1];for(var s=0;s<n;s++)if(s in t){var o=t[s];e.call(i,o,s,t)&&r.push(o)}return r}),t.isArray=function(e){return e?Object.prototype.toString.call(e)==="[object Array]":!1},t.seq=function(t,n,r,i){if("number"!=typeof t)return!1;if(t===Infinity)return!1;if("number"!=typeof n)return!1;if(n===Infinity)return!1;if(t===n)return[t];if(r===0)return!1;if(!e.in_array(typeof r,["undefined","number"]))return!1;r=r||1,i=i||function(e){return e};var s=t,o=[];if(t<n)while(s<=n)o.push(i(s)),s+=r;else while(s>=n)o.push(i(s)),s-=r;return o},t.each=function(e,t,n){if("object"!=typeof e)return!1;if(!t)return!1;n=n||this;var r,i=e.length;for(r=0;r<i;r++)t.call(n,e[r]);return!0},t.map=function(){if(arguments.length<2)return;var n=Array.prototype.slice.call(arguments),r=n.shift(),i=n[0];if(!t.isArray(r)){e.log("ARRAY.map() the first argument must be an array. Found: "+r);return}var s=[],o=undefined;for(var u=0;u<r.length;u++)n[0]=r[u],o=i.apply(this,n),"undefined"!=typeof o&&s.push(o);return s},t.removeElement=function(t,n){if("undefined"==typeof t||!n)return!1;if("object"==typeof t)var r=e.equals;else var r=function(e,t){return e===t};for(var i=0;i<n.length;i++)if(r(t,n[i]))return n.splice(i,1);return!1},t.inArray=t.in_array=function(t,n){if(!n)return!1;var r=e.equals;for(var i=0;i<n.length;i++)if(r.call(this,t,n[i]))return!0;return!1},t.getNGroups=function(e,n){return t.getGroupsSizeN(e,Math.floor(e.length/n))},t.getGroupsSizeN=function(e,t){var n=e.slice(0),r=n.length,i=n.length,s=[],o,u,a=[],f=0;for(o=0;o<i;o++)u=Math.floor(Math.random()*r),f>=t&&(s.push(a),f=0,a=[]),a.push(n[u]),n.splice(u,1),r=n.length,f++;return a.length>0&&s.push(a),s},t._latinSquare=function(t,n,r){r="undefined"==typeof r?!0:r;if(t===n&&!r)return!1;var i=[],s=[];for(var o=0;o<t;o++)i[o]=o;var u=null,a=0,f=t,l=[];r||(f=t-1);for(o=0;o<n;o++){do u=e.randomInt(a,f);while(e.in_array(u,l));l.push(u),u==1?(s[o]=i.slice(u),s[o].push(0)):s[o]=i.slice(u).concat(i.slice(0,u))}return s},t.latinSquare=function(e,n){return n||(n=e),!e||e<0||n<0?!1:(n>e&&(n=e),t._latinSquare(e,n,!0))},t.latinSquareNoSelf=function(e,n){return n||(n=e-1),!e||e<0||n<0?!1:(n>e&&(n=e-1),t._latinSquare(e,n,!1))},t.generateCombinations=function(t,n){function r(e,t){var n=[];for(var r=0;r<e.length;r++)n.push(t[e[r]]);return n}var i=t.length,s=[];for(var o=0;o<n;o++)s.push(o);var u=[];for(var o=i-n;o<i;o++)u.push(o);while(!e.equals(s,u)){callback(r(s,t));var o=n-1;while(s[o]==i-n+o)o-=1;s[o]+=1;for(var a=o+1;a<n;a++)s[a]=s[o]+a-o}return r(s,t)},t.matchN=function(e,n,r){if(!e)return;if(!n)return e;var i=[],s=e.length,o=[];for(var u=0;u<s;u++){var a=e.slice(0);a.splice(u,1),r&&(a=t.arrayDiff(a,o));var f=t.getNRandom(a,n);o=o.concat(f),f.splice(0,0,e[u]),i.push(f),f=[]}return i},t.rep=function(t,n){if(!t)return;if(!n)return t.slice(0);if(n<1){e.log("times must be greater or equal 1","ERR");return}var r=1,i=t.slice(0);for(;r<n;r++)i=i.concat(t);return i},t.stretch=function(n,r){if(!n)return;if(!r)return n.slice(0);if("number"==typeof r){if(r<1){e.log("times must be greater or equal 1","ERR");return}r=t.rep([r],n.length)}var i=[];for(var s=0;s<n.length;s++){var o=r[s%r.length];for(var u=0;u<o;u++)i.push(n[s])}return i},t.arrayIntersect=function(t,n){return t.filter(function(t){return e.in_array(t,n)})},t.arrayDiff=function(t,n){return t.filter(function(t){return!e.in_array(t,n)})},t.shuffle=function(e){if(!e)return;var t=e.slice(0),n=e.length-1,r,i;for(var s=n;s>0;s--)r=Math.floor(Math.random()*(s+1)),i=t[r],t[r]=t[s],t[s]=i;return t},t.getNRandom=function(e,n){return t.shuffle(e).slice(0,n)},t.distinct=function(e){var n=[];return e?(t.each(e,function(e){t.in_array(e,n)||n.push(e)}),n):n},t.transpose=function(e){if(!e)return;var n,r,i,s,o=[];n=e.length||0,r=t.isArray(e[0])?e[0].length:0;if(n===0||r===0)return o;for(i=0;i<r;i++){o[i]=[];for(s=0;s<n;s++)o[i][s]=e[s][i]}return o},e.extend(t)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e){function t(){}var n=null;"undefined"!=typeof e.compatibility&&(n=e.compatibility()),t.equals=function(e,n){if("undefined"==typeof e||"undefined"==typeof n)return e===n;if(e===null||n===null)return e===n;if("number"==typeof e&&isNaN(e)&&"number"==typeof n&&isNaN(n))return isNaN(e)&&isNaN(n);var r={number:"",string:"","boolean":""};if(typeof e in r)return typeof n in r?e===n:!1;if(typeof n in{number:"",string:"","boolean":""})return!1;for(var i in e)if(e.hasOwnProperty(i)){if("undefined"==typeof n[i]&&"undefined"!=typeof e[i])return!1;if(!n[i]&&e[i])return!1;switch(typeof e[i]){case"function":if(e[i].toString()!==n[i].toString())return!1;default:if(!t.equals(e[i],n[i]))return!1}}for(i in n)if(n.hasOwnProperty(i)){if("undefined"==typeof e[i]&&"undefined"!=typeof n[i])return!1;if(!e[i]&&n[i])return!1}return!0},t.isEmpty=function(e){if("undefined"==typeof e)return!0;for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},t.size=t.getListSize=function(e){if(!e)return 0;if("number"==typeof e)return 0;if("string"==typeof e)return 0;var t=0;for(var n in e)e.hasOwnProperty(n)&&t++;return t},t._obj2Array=function(e,n,r,i){if("object"!=typeof e)return[e];if(r){i="undefined"!=typeof i?i:1;if(i>r)return[e];i+=1}var s=[];for(var o in e)e.hasOwnProperty(o)&&("object"==typeof e[o]?s=s.concat(t._obj2Array(e[o],n,r,i)):(n&&s.push(o),s.push(e[o])));return s},t.obj2Array=function(e,n){return t._obj2Array(e,!1,n)},t.obj2KeyedArray=t.obj2KeyArray=function(e,n){return t._obj2Array(e,!0,n)},t.keys=t.objGetAllKeys=function(e,n,r){if(!e)return[];n="number"==typeof n&&n>=0?n:0,r="number"==typeof r&&r>=0?r:0;var i=[];for(var s in e)e.hasOwnProperty(s)&&(i.push(s),r<n&&"object"==typeof e[s]&&(i=i.concat(t.objGetAllKeys(e[s],r+1))));return i},t.implode=t.implodeObj=function(e){if(!e)return[];var t=[];for(var n in e)if(e.hasOwnProperty(n)){var r={};r[n]=e[n],t.push(r)}return t},t.clone=function(e){if(!e)return e;if("number"==typeof e)return e;if("string"==typeof e)return e;if("boolean"==typeof e)return e;if(e===NaN)return e;if(e===Infinity)return e;var r;"function"==typeof e?r=function(){return e.apply(r,arguments)}:r=Object.prototype.toString.call(e)==="[object Array]"?[]:{};for(var i in e){var s;e[i]&&"object"==typeof e[i]?Object.prototype.toString.call(e[i])==="[object Array]"?s=e[i].slice(0):s=t.clone(e[i]):s=e[i];if(e.hasOwnProperty(i))r[i]=s;else if(n&&n.defineProperty)Object.defineProperty(r,i,{value:s,writable:!0,configurable:!0});else try{Object.defineProperty(r,i,{value:s,writable:!0,configurable:!0})}catch(o){r[i]=s}}return r},t.join=function(e,n){var r=t.clone(e);if(!n)return r;for(var i in r)r.hasOwnProperty(i)&&"undefined"!=typeof n[i]&&("object"==typeof n[i]?r[i]=t.join(r[i],n[i]):r[i]=n[i]);return r},t.merge=function(e,n){if(!e&&!n)return!1;if(!e)return t.clone(n);if(!n)return t.clone(e);var r=t.clone(e);for(var i in n)n.hasOwnProperty(i)&&(n[i]&&"object"==typeof n[i]?("object"!=typeof r[i]&&(Object.prototype.toString.call(n[i])==="[object Array]"?r[i]=[]:r[i]={}),r[i]=t.merge(r[i],n[i])):r[i]=n[i]);return r},t.mixin=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]=t[n]},t.mixout=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]||(e[n]=t[n])},t.mixcommon=function(e,t){if(!e&&!t)return;if(!e)return t;if(!t)return e;for(var n in t)e[n]&&(e[n]=t[n])},t.mergeOnKey=function(e,n,r){var i=t.clone(e);if(!n||!r)return i;for(var s in n)if(n.hasOwnProperty(s)){if(!i[s]||"object"!=typeof i[s])i[s]={};i[s][r]=n[s]}return i},t.subobj=function(e,n){if(!e)return!1;var r={};if(!n)return r;n instanceof Array||(n=[n]);for(var i=0;i<n.length;i++){var s=n[i];t.hasOwnNestedProperty(s,e)&&t.setNestedValue(s,t.getNestedValue(s,e),r)}return r},t.skim=function(e,n){if(!e)return!1;var r=t.clone(e);if(!n)return r;n instanceof Array||(n=[n]);for(var i=0;i<n.length;i++)t.deleteNestedKey(n[i],r);return r},t.setNestedValue=function(n,r,i){if(!n)return e.log("Cannot set value of undefined property","ERR"),!1;i="object"==typeof i?i:{};var s=n.split(".");if(s.length===1)return i[n]=r,i;var o=s.shift();return i[o]=t.setNestedValue(s.join("."),r,i[o]),i},t.getNestedValue=function(e,n){if(!n)return;var r=e.split(".");if(r.length===1)return n[e];var i=r.shift();return t.getNestedValue(r.join("."),n[i])},t.deleteNestedKey=function(e,n){if(!n)return;var r=e.split(".");if(r.length===1)return delete n[e],!0;var i=r.shift();return"undefined"==typeof n[i]?!1:t.deleteNestedKey(r.join("."),n[i])},t.hasOwnNestedProperty=function(e,n){if(!n)return!1;var r=e.split(".");if(r.length===1)return n.hasOwnProperty(e);var i=r.shift();return t.hasOwnNestedProperty(r.join("."),n[i])},t.split=function(t,n){if(!t)return;if(!n||"object"!=typeof t[n])return e.clone(t);var r=[],i=e.clone(t);i[n]={};var s=function(t){for(var o in t){var u=e.clone(i);t.hasOwnProperty(o)&&("object"==typeof t[o]?r=r.concat(s(t[o])):(u[n][o]=t[o],r.push(u)))}return r};return s(t[n])},e.extend(t)}("undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS),function(e,t,n){function u(e,n,r){e=e||{};if(!t)throw new Error("JSUS not found.");this.db=[],this.tags={},this.hooks={insert:[],remove:[]},this.nddb_pointer=0,u.compatibility.getter?this.__defineGetter__("length",function(){return this.db.length}):this.length=null,this.__C={},this.__H={},this.__I={},this.__update={},this.__update.pointer=!1,this.__update.indexes=!1,this.__update.sort=!1,this.__parent=r||undefined,this.init(e),this.importDB(n)}var r=null,i=[],s=function(e,t){return!e||!t?(u.log("Attempt to add invalid condition","ERR"),!1):(i.push({type:e,condition:t}),!0)},o=function(e,t,n,i){if(!r)return u.log("No operation found.","ERR"),!1;var o=this._analyzeQuery(t,n,i);return o?s(e,o):!1};u.prototype.and=u.prototype.AND=function(e,t,n){return o("AND",e,t,n)},u.prototype.or=u.prototype.OR=function(e,t,n){return o("OR",e,t,n)},u.prototype.not=u.prototype.NOT=function(e,t,n){return o("NOT",e,t,n)},u.compatibility=t.compatibility(),e.NDDB=u,u.log=console.log,u.__symbols=[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"],u.__operations=["select","groupby","limit","first","fetch","last"],u.decycle=function(e){return JSON&&JSON.decycle&&"function"==typeof JSON.decycle&&(e=JSON.decycle(e)),e},u.retrocycle=function(e){return JSON&&JSON.retrocycle&&"function"==typeof JSON.retrocycle&&(e=JSON.retrocycle(e)),e},u.prototype.init=function(e){e=e||{},this.__options=e,e.log&&(u.log=e.log),e.C&&(this.__C=e.C),e.H&&(this.__H=e.H),e.I&&(this.__I=e.I),e.tags&&(this.tags=e.tags),e.nddb_pointer>0&&(this.nddb_pointer=e.nddb_pointer),e.hooks&&(this.hooks=e.hook),e.update&&("undefined"!=typeof e.update.pointer&&(this.__update.pointer=e.update.pointer),"undefined"!=typeof e.update.indexes&&(this.__update.indexes=e.update.indexes),"undefined"!=typeof e.update.sort&&(this.__update.sort=e.update.sort))},u.prototype.globalCompare=function(e,t){return"undefined"==typeof e&&"undefined"==typeof t?0:"undefined"==typeof t?-1:"undefined"==typeof e?1:e.nddbid<t.nddbid?-1:e.nddbid>t.nddbid?1:0},u.prototype._masquerade=function(e,t){return"undefined"==typeof e?!1:"undefined"!=typeof e.nddbid?e:(t=t||this.db,u.compatibility.defineProperty?Object.defineProperty(e,"nddbid",{value:t.length,configurable:!0,writable:!0}):e.nddbid=t.length,e)},u.prototype._masqueradeDB=function(e){if(!e)return[];var t=[];for(var n=0;n<e.length;n++)t[n]=this._masquerade(e[n],t);return t},u.prototype._autoUpdate=function(e){var n=e?t.merge(e,this.__update):this.__update;n.pointer&&(this.nddb_pointer=this.db.length-1),n.sort&&this.sort(),n.indexes&&this.rebuildIndexes(),this.__parent&&this.__parent._autoUpdate(n)},u.prototype.importDB=function(e){if(!e)return;this.db||(this.db=[]);for(var t=0;t<e.length;t++)this.insert(e[t])},u.prototype.insert=function(e){if("undefined"==typeof e||e===null)return;this.db||(this.db=[]),this._insert(e)},u.prototype._insert=function(e){e=this._masquerade(e),this.db.push(e),this.emit("insert",e),this.__update.indexes&&(this._hashIt(e),this._indexIt(e)),this._autoUpdate({indexes:!1})},u.prototype.breed=function(e){e=e||this.db;var t=this.cloneSettings(),n=this.__parent||this;return new this.constructor(t,e,n)},u.prototype.cloneSettings=function(){var e=this.__options||{};return e.H=this.__H,e.I=this.__I,e.C=this.__C,e.tags=this.tags,e.update=this.__update,t.clone(e)},u.prototype.toString=function(){var e="";for(var t=0;t<this.db.length;t++)e+=this.db[t]+"\n";return e},u.prototype.stringify=function(e){if(!this.length)return"[]";e="undefined"==typeof e?!0:e;var n;e?n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e)}:n=function(e){return t.isEmpty(e)?"{}":JSON.stringify(e,null,4)};var r="[";return this.each(function(e){e=u.decycle(e),r+=n(e)+", "}),r=r.replace(/, $/,"]"),r},u.prototype.compare=u.prototype.c=function(e,t){return!e||!t?(u.log("Cannot set empty property or empty comparator","ERR"),!1):(this.__C[e]=t,!0)},u.prototype.comparator=function(e){return"undefined"!=typeof this.__C[e]?this.__C[e]:function(n,r){if("undefined"==typeof n&&"undefined"==typeof r)return 0;if("undefined"==typeof n)return 1;if("undefined"==typeof r)return-1;var i=t.getNestedValue(e,n),s=t.getNestedValue(e,r);return"undefined"==typeof i&&"undefined"==typeof s?0:"undefined"==typeof i?1:"undefined"==typeof s?-1:i>s?1:s>i?-1:0}},u.prototype.isReservedWord=function(e){return this[e]?!0:!1},u.prototype._isValidIndex=function(e){if("undefined"==typeof e)return u.log("A valid index name must be provided","ERR"),!1;if(this.isReservedWord(e)){var t="A reserved word have been selected as an index. ";return t+="Please select another one: "+e,u.log(t,"ERR"),!1}return!0},u.prototype.hash=u.prototype.h=function(e,t){return this._isValidIndex(e)?(this.__H[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.index=u.prototype.i=function(e,t){return this._isValidIndex(e)?(this.__I[e]=t||Object.toString,this[e]={},!0):!1},u.prototype.rebuildIndexes=function(){var e=!1,n=!1;if(!t.isEmpty(this.__H)){e=!0;for(var r in this.__H)this.__H.hasOwnProperty(r)&&(this[r]={})}if(!t.isEmpty(this.__I)){n=!0;for(var r in this.__I)this.__I.hasOwnProperty(r)&&(this[r]={})}e&&!n?this.each(this._hashIt):!e&&n?this.each(this._indexIt):e&&n&&this.each(function(e){this.hashIt(e),this.indexIt(e)})},u.prototype._hashIt=function(e){if(!e)return!1;if(t.isEmpty(this.__H))return!1;var n=null,r=null,i=null;for(var s in this.__H)if(this.__H.hasOwnProperty(s)){n=this.__H[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]||(this[s][i]=new u),this[s][i].insert(e)}},u.prototype._indexIt=function(e){if(!e)return!1;if(t.isEmpty(this.__I))return!1;var n=null,r=null,i=null;for(var s in this.__I)if(this.__I.hasOwnProperty(s)){n=this.__I[s],i=n(e);if("undefined"==typeof i)continue;this[s]||(this[s]={}),this[s][i]=e}},u.prototype.on=function(e,t){if(!e||!t||!this.hooks[e])return;return this.hooks[e].push(t),!0},u.prototype.off=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;if(!t)return this.hooks[e]=[],!0;for(var n=0;n<this.hooks[e].length;n++)if(this.hooks[e][n]==t)return this.hooks[e].splice(n,1),!0;return!1},u.prototype.emit=function(e,t){if(!e||!this.hooks[e]||!this.hooks[e].length)return;for(var n=0;n<this.hooks[e].length;n++)this.hooks[e][n].call(this,t)},u.prototype._analyzeQuery=function(e,n,r){var i=function(e,t,n){var r="(?)",i="Malformed query: "+e||r+" "+t||r+" "+n||r;return u.log(i,"WARN"),!1};"undefined"==typeof e&&i(e,n,r);if("undefined"!=typeof n){"undefined"==typeof r&&i(e,n,r);if(!t.in_array(n,[">",">=",">==","<","<=","<==","!=","!==","=","==","===","><","<>","in","!in"]))return u.log("Query error. Invalid operator detected: "+n,"WARN"),!1;n==="="&&(n="==");if(t.in_array(n,["><","<>","in","!in"])){r instanceof Array||(u.log("Range-queries need an array as third parameter","WARN"),i(e,n,r));if(n==="<>"||n==="><")r[0]=t.setNestedValue(e,r[0]),r[1]=t.setNestedValue(e,r[1])}else r=t.setNestedValue(e,r)}else"undefined"!=typeof r?i(e,n,r):(n="",r="");return{d:e,op:n,value:r}},u.prototype.distinct=function(){return this.breed(t.distinct(this.db))},u.prototype.select=function(e,n,r){var i=this._analyzeQuery(e,n,r);if(!i)return!1;var e=i.d,n=i.op,r=i.value,s=this.comparator(e),o=function(n){if("undefined"!=typeof t.getNestedValue(e,n))return n},a=function(i){try{if(t.eval(s(i,r)+n+0,i))return i}catch(o){return u.log("Malformed select query: "+e+n+r),!1}},f=function(e){if(s(e,r[0])>0&&s(e,r[1])<0)return e},l=function(e){if(s(e,r[0])<0&&s(e,r[1]>0))return e},c=function(n){if(t.in_array(t.getNestedValue(e,n),r))return n},h=function(n){if(!t.in_array(t.getNestedValue(e,n),r))return n};switch(n){case"":var p=o;break;case"<>":var p=l;break;case"><":var p=f;break;case"in":var p=c;break;case"!in":var p=h;break;default:var p=a}return this.filter(p)},u.prototype.limit=function(e){e=e||0;if(e===0)return this.breed();var t=e>0?this.db.slice(0,e):this.db.slice(e);return this.breed(t)},u.prototype.reverse=function(){return this.db.reverse(),this},u.prototype.sort=function(e){if(!e)var t=this.globalCompare;else if("function"==typeof e)var t=e;else if(e instanceof Array)var n=this,t=function(t,r){for(var i=0;i<e.length;i++){var s=n.comparator(e[i]).call(n,t,r);if(s!==0)return s}return s};else var t=this.comparator(e);return this.db.sort(t),this},u.prototype.shuffle=function(){return this.db=t.shuffle(this.db),this},u.prototype.filter=function(e){return this.breed(this.db.filter(e))},u.prototype.each=u.prototype.forEach=function(){if(arguments.length===0)return;var e=arguments[0];for(var t=0;t<this.db.length;t++)arguments[0]=this.db[t],e.apply(this,arguments)},u.prototype.map=function(){if(arguments.length===0)return;var e=arguments[0],t=[],n=undefined;for(var r=0;r<this.db.length;r++)arguments[0]=this.db[r],n=e.apply(this,arguments),"undefined"!=typeof n&&t.push(n);return t},u.prototype.remove=function(){if(!this.length)return this;if(this.__parent){for(var e=0;e<this.db.length;e++){var t=this.db[e].nddbid-e;this.__parent.db.splice(t,1)}for(var e=0;e<this.__parent.length;e++)this.__parent.db[e].nddbid=e}return this.emit("remove",this.db),this.db=[],this._autoUpdate(),this},u.prototype.clear=function(e){return e?(this.db=[],this._autoUpdate()):u.log("Do you really want to clear the current dataset? Please use clear(true)","WARN"),e},u.prototype.join=function(e,n,r,i){return this._join(e,n,t.equals,r,i)},u.prototype.concat=function(e,t,n,r){return this._join(e,t,function(){return!0},n,r)},u.prototype._join=function(e,n,r,i,s){r=r||t.equals,i="undefined"!=typeof i?i:"joined";if(s)var s=s instanceof Array?s:[s];var o=[],a=[];for(var f=0;f<this.db.length;f++)try{var l=t.eval("this."+e,this.db[f]);if("undefined"!=typeof l)for(var c=f+1;c<this.db.length;c++)try{var h=t.eval("this."+n,this.db[c]);if("undefined"!=typeof h&&r(l,h)){var p=t.clone(this.db[f]),d=s?t.subobj(this.db[c],s):this.db[c];p[i]=d,o.push(p)}}catch(v){u.log("Key not found in entry: "+n,"WARN")}}catch(v){u.log("Key not found in entry: "+e,"WARN")}return this.breed(o)},u.prototype.split=function(e){var n=[];for(var r=0;r<this.db.length;r++)n=n.concat(t.split(this.db[r],e));return this.breed(n)},u.prototype._fetch=function(e,n){function r(e,n){return t.getNestedValue(n,e)}function i(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return t.obj2KeyedArray(r)}function s(e,n){var r=t.getNestedValue(n,e);if("undefined"!=typeof r)return n.split(".").concat(t.obj2KeyedArray(r))}switch(n){case"VALUES":var o=e?i:t.obj2Array;break;case"KEY_VALUES":var o=e?s:t.obj2KeyedArray;break;default:if(!e)return this.db;var o=r}var u=[];for(var a=0;a<this.db.length;a++){var f=o.call(this.db[a],this.db[a],e);"undefined"!=typeof f&&u.push(f)}return u},u.prototype.fetch=function(e){return this._fetch(e,!0)},u.prototype.fetchArray=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyArray=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.fetchValues=function(e){return this._fetch(e,"VALUES")},u.prototype.fetchKeyValues=function(e){return this._fetch(e,"KEY_VALUES")},u.prototype.groupBy=function(e){if(!e)return this.db;var n=[],r=[];for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);if("undefined"==typeof s)continue;if(!t.in_array(s,n)){n.push(s);var o=this.filter(function(n){if(t.equals(t.getNestedValue(e,n),s))return this});o.nddb_pointer=0,r.push(o)}}return r},u.prototype.count=function(e){if("undefined"==typeof e)return this.db.length;var n=0;for(var r=0;r<this.db.length;r++)t.hasOwnNestedProperty(e,this.db[r])&&n++;return n},u.prototype.sum=function(e){if("undefined"==typeof e)return!1;var n=0;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);isNaN(i)||(n+=i)}return n},u.prototype.mean=function(e){if("undefined"==typeof e)return!1;var n=0,r=0;for(var i=0;i<this.db.length;i++){var s=t.getNestedValue(e,this.db[i]);isNaN(s)||(n+=s,r++)}return r===0?0:n/r},u.prototype.stddev=function(e){if("undefined"==typeof e)return!1;var n=this.mean(e);if(isNaN(n))return!1;var r=0;return this.each(function(i){var s=t.getNestedValue(e,i);isNaN(s)||(r+=Math.pow(s-n,2))}),r!==0?Math.sqrt(r):0},u.prototype.min=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i<n||n===!1)&&(n=i)}return n},u.prototype.max=function(e){if("undefined"==typeof e)return!1;var n=!1;for(var r=0;r<this.db.length;r++){var i=t.getNestedValue(e,this.db[r]);!isNaN(i)&&(i>n||n===!1)&&(n=i)}return n},u.prototype.skim=function(e){return e?this.breed(this.map(function(n){var r=t.skim(n,e);if(!t.isEmpty(r))return r})):this},u.prototype.keep=function(e){return e?this.breed(this.map(function(n){var r=t.subobj(n,e);if(!t.isEmpty(r))return r})):this.breed([])},u.prototype.diff=function(e){return!e||!e.length?this:("object"==typeof e&&(e instanceof u||e instanceof this.constructor)&&(e=e.db),this.breed(t.arrayDiff(this.db,e)))},u.prototype.intersect=function(e){if(!e||!e.length)return this;if("object"==typeof e)if(e instanceof u||e instanceof this.constructor)var e=e.db;return this.breed(t.arrayIntersect(this.db,e))},u.prototype.get=function(e){var e=e||this.nddb_pointer;return e<0||e>this.db.length-1?!1:this.db[e]},u.prototype.next=function(){var e=u.prototype.get.call(this,++this.nddb_pointer);return e||this.nddb_pointer--,e},u.prototype.previous=function(){var e=u.prototype.get.call(this,--this.nddb_pointer);return e||this.nddb_pointer++,e},u.prototype.first=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[0].nddbid,t[0]):undefined},u.prototype.last=function(e){var t=this.fetch(e);return t.length?(this.nddb_pointer=t[t.length-1].nddbid,t[t.length-1]):undefined},u.prototype.tag=function(e,t){if("undefined"==typeof e)return u.log("Cannot register empty tag.","ERR"),!1;var n=null,r=typeof t;if(r==="undefined")n=this.db[this.nddb_pointer];else if(r==="number"){if(t>this.length||t<0)return u.log("Invalid index provided for tag registration","ERR"),!1;n=this.db[t]}else n=t;return this.tags[e]=n,!0},u.prototype.resolveTag=function(e){return"undefined"==typeof e?(u.log("Cannot resolve empty tag.","ERR"),!1):this.tags[e]};var a=function(){return"function"==typeof n};if(t.isNodeJS()){require("./external/cycle.js");var f=require("fs")}u.prototype.save=function(e,r,i){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;i=i||!1;if(!t.isNodeJS())return a()?(n(e,this.stringify(i)),r&&r(),!0):(u.log("No support for persistent storage found.","ERR"),!1);f.writeFile(e,this.stringify(i),"utf-8",function(e){if(e)throw e;return r&&r(),!0})},u.prototype.load=function(e,r){if(!e)return u.log("You must specify a valid file / id.","ERR"),!1;if(!t.isNodeJS()){if(!a())return u.log("No support for persistent storage found.","ERR"),!1;var i=n(e);return this.importDB(i),r&&r(),!0}var s=function(e){var t=JSON.parse(e.toString()),n;for(n=0;n<t.length;n++)t[n]=u.retrocycle(t[n]);this.importDB(t)};if(!r){var o=f.readFileSync(e,"utf-8");s.call(this,o)}else f.readFile(e,"utf-8",function(e,t){if(e)throw e;s.call(this,t),r()})}}("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:window,"undefined"!=typeof JSUS?JSUS:module.parent.exports.JSUS||require("JSUS").JSUS,"object"==typeof module&&"function"==typeof require?module.parent.exports.store||require("shelf.js/build/shelf-fs.js").store:this.store)
527 build/shelf-fs.js
View
@@ -0,0 +1,527 @@
+// cycle.js
+// 2011-08-24
+
+/*jslint evil: true, regexp: true */
+
+/*members $ref, apply, call, decycle, hasOwnProperty, length, prototype, push,
+ retrocycle, stringify, test, toString
+*/
+
+if (typeof JSON.decycle !== 'function') {
+ JSON.decycle = function decycle(object) {
+ 'use strict';
+
+// Make a deep copy of an object or array, assuring that there is at most
+// one instance of each object or array in the resulting structure. The
+// duplicate references (which might be forming cycles) are replaced with
+// an object of the form
+// {$ref: PATH}
+// where the PATH is a JSONPath string that locates the first occurance.
+// So,
+// var a = [];
+// a[0] = a;
+// return JSON.stringify(JSON.decycle(a));
+// produces the string '[{"$ref":"$"}]'.
+
+// JSONPath is used to locate the unique object. $ indicates the top level of
+// the object or array. [NUMBER] or [STRING] indicates a child member or
+// property.
+
+ var objects = [], // Keep a reference to each unique object or array
+ paths = []; // Keep the path to each unique object or array
+
+ return (function derez(value, path) {
+
+// The derez recurses through the object, producing the deep copy.
+
+ var i, // The loop counter
+ name, // Property name
+ nu; // The new object or array
+
+ switch (typeof value) {
+ case 'object':
+
+// typeof null === 'object', so get out if this value is not really an object.
+
+ if (!value) {
+ return null;
+ }
+
+// If the value is an object or array, look to see if we have already
+// encountered it. If so, return a $ref/path object. This is a hard way,
+// linear search that will get slower as the number of unique objects grows.
+
+ for (i = 0; i < objects.length; i += 1) {
+ if (objects[i] === value) {
+ return {$ref: paths[i]};
+ }
+ }
+
+// Otherwise, accumulate the unique value and its path.
+
+ objects.push(value);
+ paths.push(path);
+
+// If it is an array, replicate the array.
+
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
+ nu = [];
+ for (i = 0; i < value.length; i += 1) {
+ nu[i] = derez(value[i], path + '[' + i + ']');
+ }
+ } else {
+
+// If it is an object, replicate the object.
+
+ nu = {};
+ for (name in value) {
+ if (Object.prototype.hasOwnProperty.call(value, name)) {
+ nu[name] = derez(value[name],
+ path + '[' + JSON.stringify(name) + ']');
+ }
+ }
+ }
+ return nu;
+ case 'number':
+ case 'string':
+ case 'boolean':
+ return value;
+ }
+ }(object, '$'));
+ };
+}
+
+
+if (typeof JSON.retrocycle !== 'function') {
+ JSON.retrocycle = function retrocycle($) {
+ 'use strict';
+
+// Restore an object that was reduced by decycle. Members whose values are
+// objects of the form
+// {$ref: PATH}
+// are replaced with references to the value found by the PATH. This will
+// restore cycles. The object will be mutated.
+
+// The eval function is used to locate the values described by a PATH. The
+// root object is kept in a $ variable. A regular expression is used to
+// assure that the PATH is extremely well formed. The regexp contains nested
+// * quantifiers. That has been known to have extremely bad performance
+// problems on some browsers for very long strings. A PATH is expected to be
+// reasonably short. A PATH is allowed to belong to a very restricted subset of
+// Goessner's JSONPath.
+
+// So,
+// var s = '[{"$ref":"$"}]';
+// return JSON.retrocycle(JSON.parse(s));
+// produces an array containing a single element which is the array itself.
+
+ var px =
+ /^\$(?:\[(?:\d+|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;
+
+ (function rez(value) {
+
+// The rez function walks recursively through the object looking for $ref
+// properties. When it finds one that has a value that is a path, then it
+// replaces the $ref object with a reference to the value that is found by
+// the path.
+
+ var i, item, name, path;
+
+ if (value && typeof value === 'object') {
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
+ for (i = 0; i < value.length; i += 1) {
+ item = value[i];
+ if (item && typeof item === 'object') {
+ path = item.$ref;
+ if (typeof path === 'string' && px.test(path)) {
+ value[i] = eval(path);
+ } else {
+ rez(item);
+ }
+ }
+ }
+ } else {
+ for (name in value) {
+ if (typeof value[name] === 'object') {
+ item = value[name];
+ if (item) {
+ path = item.$ref;
+ if (typeof path === 'string' && px.test(path)) {
+ value[name] = eval(path);
+ } else {
+ rez(item);
+ }
+ }
+ }
+ }
+ }
+ }
+ }($));
+ return $;
+ };
+}
+/**
+ * # Shelf.JS
+ *
+ * Persistent Client-Side Storage @VERSION
+ *
+ * Copyright 2012 Stefano Balietti
+ * GPL licenses.
+ *
+ * ---
+ *
+ */
+(function(exports){
+
+var version = '0.3';
+
+var store = exports.store = function (key, value, options, type) {
+ options = options || {};
+ type = (options.type && options.type in store.types) ? options.type : store.type;
+ if (!type || !store.types[type]) {
+ store.log("Cannot save/load value. Invalid storage type selected: " + type, 'ERR');
+ return;
+ }
+ store.log('Accessing ' + type + ' storage');
+
+ return store.types[type](key, value, options);
+};
+
+// Adding functions and properties to store
+///////////////////////////////////////////
+store.name = "__shelf__";
+
+store.verbosity = 0;
+store.types = {};
+
+
+var mainStorageType = "volatile";
+
+//if Object.defineProperty works...
+try {
+
+ Object.defineProperty(store, 'type', {
+ set: function(type){
+ if ('undefined' === typeof store.types[type]) {
+ store.log('Cannot set store.type to an invalid type: ' + type);
+ return false;
+ }
+ mainStorageType = type;
+ return type;
+ },
+ get: function(){
+ return mainStorageType;
+ },
+ configurable: false,
+ enumerable: true
+ });
+}
+catch(e) {
+ store.type = mainStorageType; // default: memory
+}
+
+store.addType = function (type, storage) {
+ store.types[type] = storage;
+ store[type] = function (key, value, options) {
+ options = options || {};
+ options.type = type;
+ return store(key, value, options);
+ };
+
+ if (!store.type || store.type === "volatile") {
+ store.type = type;
+ }
+};
+
+store.error = function() {
+ return "shelf quota exceeded";
+};
+
+store.log = function(text) {
+ if (store.verbosity > 0) {
+ console.log('Shelf v.' + version + ': ' + text);
+ }
+
+};
+
+store.isPersistent = function() {
+ if (!store.types) return false;
+ if (store.type === "volatile") return false;
+ return true;
+};
+
+//if Object.defineProperty works...
+try {
+ Object.defineProperty(store, 'persistent', {
+ set: function(){},
+ get: store.isPersistent,
+ configurable: false
+ });
+}
+catch(e) {
+ // safe case
+ store.persistent = false;
+}
+
+store.decycle = function(o) {
+ if (JSON && JSON.decycle && 'function' === typeof JSON.decycle) {
+ o = JSON.decycle(o);
+ }
+ return o;
+};
+
+store.retrocycle = function(o) {
+ if (JSON && JSON.retrocycle && 'function' === typeof JSON.retrocycle) {
+ o = JSON.retrocycle(o);
+ }
+ return o;
+};
+
+store.stringify = function(o) {
+ if (!JSON || !JSON.stringify || 'function' !== typeof JSON.stringify) {
+ throw new Error('JSON.stringify not found. Received non-string value and could not serialize.');
+ }
+
+ o = store.decycle(o);
+ return JSON.stringify(o);
+};
+
+store.parse = function(o) {
+ if ('undefined' === typeof o) return undefined;
+ if (JSON && JSON.parse && 'function' === typeof JSON.parse) {
+ try {
+ o = JSON.parse(o);
+ }
+ catch (e) {
+ store.log('Error while parsing a value: ' + e, 'ERR');
+ store.log(o);
+ }
+ }
+
+ o = store.retrocycle(o);
+ return o;
+};
+
+// ## In-memory storage
+// ### fallback for all browsers to enable the API even if we can't persist data
+(function() {
+
+ var memory = {},
+ timeout = {};
+
+ function copy(obj) {
+ return store.parse(store.stringify(obj));
+ }
+
+ store.addType("volatile", function(key, value, options) {
+
+ if (!key) {
+ return copy(memory);
+ }
+
+ if (value === undefined) {
+ return copy(memory[key]);
+ }
+
+ if (timeout[key]) {
+ clearTimeout(timeout[key]);
+ delete timeout[key];
+ }
+
+ if (value === null) {
+ delete memory[key];
+ return null;
+ }
+
+ memory[key] = value;
+ if (options.expires) {
+ timeout[key] = setTimeout(function() {
+ delete memory[key];
+ delete timeout[key];
+ }, options.expires);
+ }
+
+ return value;
+ });
+}());
+
+}('undefined' !== typeof module && 'undefined' !== typeof module.exports ? module.exports: this));
+/**
+ * ## File System storage for Shelf.js
+ *
+ * ### Available only in Node.JS
+ */
+
+(function(exports) {
+
+var store = exports.store;
+
+if (!store) {
+ console.log('fs.shelf.js: shelf.js core not found. File system storage not available.');
+ return;
+}
+
+store.filename = './shelf.out';
+
+var fs = require('fs'),
+ path = require('path'),
+ util = require('util');
+
+// https://github.com/jprichardson/node-fs-extra/blob/master/lib/copy.js
+var copyFile = function(srcFile, destFile, cb) {
+ var fdr, fdw;
+ fdr = fs.createReadStream(srcFile);
+ fdw = fs.createWriteStream(destFile);
+ fdr.on('end', function() {
+ return cb(null);
+ });
+ return fdr.pipe(fdw);
+ };
+
+
+var timeout = {};
+
+var overwrite = function (fileName, items) {
+ var file = fileName || store.filename;
+ if (!file) {
+ store.log('You must specify a valid file.', 'ERR');
+ return false;
+ }
+
+ var tmp_copy = path.dirname(file) + '.' + path.basename(file);
+
+// console.log('files')
+// console.log(file);
+// console.log(fileName);
+// console.log(tmp_copy)
+
+ copyFile(file, tmp_copy, function(){
+ var s = store.stringify(items);
+ // removing leading { and trailing }
+ s = s.substr(1, s = s.substr(0, s.legth-1));
+// console.log('SAVING')
+// console.log(s)
+ fs.writeFile(file, s, 'utf-8', function(e) {
+ if (e) throw e;
+ fs.unlink(tmp_copy, function (err) {
+ if (err) throw err;
+ });
+ return true;
+ });
+
+ });
+
+};
+
+if ('undefined' !== typeof fs.appendFileSync) {
+ // node 0.8
+ var save = function (fileName, key, value) {
+ var file = fileName || store.filename;
+ if (!file) {
+ store.log('You must specify a valid file.', 'ERR');
+ return false;
+ }
+ if (!key) return;
+
+ var item = store.stringify(key) + ": " + store.stringify(value) + ",\n";
+
+ return fs.appendFileSync(file, item, 'utf-8');
+ };
+}
+else {
+ // node < 0.8
+ var save = function (fileName, key, value) {
+ var file = fileName || store.filename;
+ if (!file) {
+ store.log('You must specify a valid file.', 'ERR');
+ return false;
+ }
+ if (!key) return;
+
+ var item = store.stringify(key) + ": " + store.stringify(value) + ",\n";
+
+
+
+ fs.open(file, 'a', 666, function( e, id ) {
+ fs.write( id, item, null, 'utf8', function(){
+ fs.close(id, function(){});
+ });
+ });
+
+ return true;
+ };
+}
+
+var load = function (fileName, key) {
+ var file = fileName || store.filename;
+ if (!file) {
+ store.log('You must specify a valid file.', 'ERR');
+ return false;
+ }
+
+ var s = fs.readFileSync(file, 'utf-8');
+
+// console.log('BEFORE removing end')
+// console.log(s)
+
+
+ s = s.substr(0, s.length-2); // removing last ',' and /n
+
+// console.log('BEFORE PARSING')
+// console.log(s)
+
+ var items = store.parse('{' + s + '}');
+
+// console.log('PARSED')
+// console.log(items)
+
+ return (key) ? items[key] : items;
+
+};
+
+var deleteVariable = function (fileName, key) {
+ var file = fileName || store.filename;
+ var items = load(file);
+// console.log('dele')
+// console.log(items)
+// console.log(key)
+ delete items[key];
+ overwrite(file, items);
+ return null;
+};
+
+store.addType("fs", function(key, value, options) {
+
+ var filename = options.file || store.filename;
+
+ if (!key) {
+ return load(filename);
+ }
+
+ if (value === undefined) {
+ return load(filename, key);
+ }
+
+ if (timeout[key]) {
+ clearTimeout(timeout[key]);
+ deleteVariable(filename, key);
+ }
+
+ if (value === null) {
+ deleteVariable(filename, key);
+ return null;
+ }
+
+ // save item
+ save(filename, key, value);
+
+ if (options.expires) {
+ timeout[key] = setTimeout(function() {
+ deleteVariable(filename, key);
+ }, options.expires);
+ }
+
+ return value;
+});
+
+}(('undefined' !== typeof module && 'function' === typeof require) ? module.exports || module.parent.exports : {}));
6 build/shelf-fs.min.js
View
@@ -0,0 +1,6 @@
+// cycle.js
+// 2011-08-24
+/*jslint evil: true, regexp: true *//*members $ref, apply, call, decycle, hasOwnProperty, length, prototype, push,
+ retrocycle, stringify, test, toString
+*/
+typeof JSON.decycle!="function"&&(JSON.decycle=function(t){"use strict";var n=[],r=[];return function i(e,t){var s,o,u;switch(typeof e){case"object":if(!e)return null;for(s=0;s<n.length;s+=1)if(n[s]===e)return{$ref:r[s]};n.push(e),r.push(t);if(Object.prototype.toString.apply(e)==="[object Array]"){u=[];for(s=0;s<e.length;s+=1)u[s]=i(e[s],t+"["+s+"]")}else{u={};for(o in e)Object.prototype.hasOwnProperty.call(e,o)&&(u[o]=i(e[o],t+"["+JSON.stringify(o)+"]"))}return u;case"number":case"string":case"boolean":return e}}(t,"$")}),typeof JSON.retrocycle!="function"&&(JSON.retrocycle=function retrocycle($){"use strict";var px=/^\$(?:\[(?:\d+|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;return function rez(value){var i,item,name,path;if(value&&typeof value=="object")if(Object.prototype.toString.apply(value)==="[object Array]")for(i=0;i<value.length;i+=1)item=value[i],item&&typeof item=="object"&&(path=item.$ref,typeof path=="string"&&px.test(path)?value[i]=eval(path):rez(item));else for(name in value)typeof value[name]=="object"&&(item=value[name],item&&(path=item.$ref,typeof path=="string"&&px.test(path)?value[name]=eval(path):rez(item)))}($),$}),function(e){var t="0.3",n=e.store=function(e,t,r,i){r=r||{},i=r.type&&r.type in n.types?r.type:n.type;if(!i||!n.types[i]){n.log("Cannot save/load value. Invalid storage type selected: "+i,"ERR");return}return n.log("Accessing "+i+" storage"),n.types[i](e,t,r)};n.name="__shelf__",n.verbosity=0,n.types={};var r="volatile";try{Object.defineProperty(n,"type",{set:function(e){return"undefined"==typeof n.types[e]?(n.log("Cannot set store.type to an invalid type: "+e),!1):(r=e,e)},get:function(){return r},configurable:!1,enumerable:!0})}catch(i){n.type=r}n.addType=function(e,t){n.types[e]=t,n[e]=function(t,r,i){return i=i||{},i.type=e,n(t,r,i)};if(!n.type||n.type==="volatile")n.type=e},n.error=function(){return"shelf quota exceeded"},n.log=function(e){n.verbosity>0&&console.log("Shelf v."+t+": "+e)},n.isPersistent=function(){return n.types?n.type==="volatile"?!1:!0:!1};try{Object.defineProperty(n,"persistent",{set:function(){},get:n.isPersistent,configurable:!1})}catch(i){n.persistent=!1}n.decycle=function(e){return JSON&&JSON.decycle&&"function"==typeof JSON.decycle&&(e=JSON.decycle(e)),e},n.retrocycle=function(e){return JSON&&JSON.retrocycle&&"function"==typeof JSON.retrocycle&&(e=JSON.retrocycle(e)),e},n.stringify=function(e){if(!JSON||!JSON.stringify||"function"!=typeof JSON.stringify)throw new Error("JSON.stringify not found. Received non-string value and could not serialize.");return e=n.decycle(e),JSON.stringify(e)},n.parse=function(e){if("undefined"==typeof e)return undefined;if(JSON&&JSON.parse&&"function"==typeof JSON.parse)try{e=JSON.parse(e)}catch(t){n.log("Error while parsing a value: "+t,"ERR"),n.log(e)}return e=n.retrocycle(e),e},function(){function r(e){return n.parse(n.stringify(e))}var e={},t={};n.addType("volatile",function(n,i,s){return n?i===undefined?r(e[n]):(t[n]&&(clearTimeout(t[n]),delete t[n]),i===null?(delete e[n],null):(e[n]=i,s.expires&&(t[n]=setTimeout(function(){delete e[n],delete t[n]},s.expires)),i)):r(e)})}()}("undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports:this),function(e){var t=e.store;if(!t){console.log("fs.shelf.js: shelf.js core not found. File system storage not available.");return}t.filename="./shelf.out";var n=require("fs"),r=require("path"),i=require("util"),s=function(e,t,r){var i,s;return i=n.createReadStream(e),s=n.createWriteStream(t),i.on("end",function(){return r(null)}),i.pipe(s)},o={},u=function(e,i){var o=e||t.filename;if(!o)return t.log("You must specify a valid file.","ERR"),!1;var u=r.dirname(o)+"."+r.basename(o);s(o,u,function(){var e=t.stringify(i);e=e.substr(1,e=e.substr(0,e.legth-1)),n.writeFile(o,e,"utf-8",function(e){if(e)throw e;return n.unlink(u,function(e){if(e)throw e}),!0})})};if("undefined"!=typeof n.appendFileSync)var a=function(e,r,i){var s=e||t.filename;if(!s)return t.log("You must specify a valid file.","ERR"),!1;if(!r)return;var o=t.stringify(r)+": "+t.stringify(i)+",\n";return n.appendFileSync(s,o,"utf-8")};else var a=function(e,r,i){var s=e||t.filename;if(!s)return t.log("You must specify a valid file.","ERR"),!1;if(!r)return;var o=t.stringify(r)+": "+t.stringify(i)+",\n";return n.open(s,"a",666,function(e,t){n.write(t,o,null,"utf8",function(){n.close(t,function(){})})}),!0};var f=function(e,r){var i=e||t.filename;if(!i)return t.log("You must specify a valid file.","ERR"),!1;var s=n.readFileSync(i,"utf-8");s=s.substr(0,s.length-2);var o=t.parse("{"+s+"}");return r?o[r]:o},l=function(e,n){var r=e||t.filename,i=f(r);return delete i[n],u(r,i),null};t.addType("fs",function(e,n,r){var i=r.file||t.filename;return e?n===undefined?f(i,e):(o[e]&&(clearTimeout(o[e]),l(i,e)),n===null?(l(i,e),null):(a(i,e,n),r.expires&&(o[e]=setTimeout(function(){l(i,e)},r.expires)),n)):f(i)})}("undefined"!=typeof module&&"function"==typeof require?module.exports||module.parent.exports:{})
1,081 build/shelf.js
View
@@ -0,0 +1,1081 @@
+// cycle.js
+// 2011-08-24
+
+/*jslint evil: true, regexp: true */
+
+/*members $ref, apply, call, decycle, hasOwnProperty, length, prototype, push,
+ retrocycle, stringify, test, toString
+*/
+
+if (typeof JSON.decycle !== 'function') {
+ JSON.decycle = function decycle(object) {
+ 'use strict';
+
+// Make a deep copy of an object or array, assuring that there is at most
+// one instance of each object or array in the resulting structure. The
+// duplicate references (which might be forming cycles) are replaced with
+// an object of the form
+// {$ref: PATH}
+// where the PATH is a JSONPath string that locates the first occurance.
+// So,
+// var a = [];
+// a[0] = a;
+// return JSON.stringify(JSON.decycle(a));
+// produces the string '[{"$ref":"$"}]'.
+
+// JSONPath is used to locate the unique object. $ indicates the top level of
+// the object or array. [NUMBER] or [STRING] indicates a child member or
+// property.
+
+ var objects = [], // Keep a reference to each unique object or array
+ paths = []; // Keep the path to each unique object or array
+
+ return (function derez(value, path) {
+
+// The derez recurses through the object, producing the deep copy.
+
+ var i, // The loop counter
+ name, // Property name
+ nu; // The new object or array
+
+ switch (typeof value) {
+ case 'object':
+
+// typeof null === 'object', so get out if this value is not really an object.
+
+ if (!value) {
+ return null;
+ }
+
+// If the value is an object or array, look to see if we have already
+// encountered it. If so, return a $ref/path object. This is a hard way,
+// linear search that will get slower as the number of unique objects grows.
+
+ for (i = 0; i < objects.length; i += 1) {
+ if (objects[i] === value) {
+ return {$ref: paths[i]};
+ }
+ }
+
+// Otherwise, accumulate the unique value and its path.
+
+ objects.push(value);
+ paths.push(path);
+
+// If it is an array, replicate the array.
+
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
+ nu = [];
+ for (i = 0; i < value.length; i += 1) {
+ nu[i] = derez(value[i], path + '[' + i + ']');
+ }
+ } else {
+
+// If it is an object, replicate the object.
+
+ nu = {};
+ for (name in value) {
+ if (Object.prototype.hasOwnProperty.call(value, name)) {
+ nu[name] = derez(value[name],
+ path + '[' + JSON.stringify(name) + ']');
+ }
+ }
+ }
+ return nu;
+ case 'number':
+ case 'string':
+ case 'boolean':
+ return value;
+ }
+ }(object, '$'));
+ };
+}
+
+
+if (typeof JSON.retrocycle !== 'function') {
+ JSON.retrocycle = function retrocycle($) {
+ 'use strict';
+
+// Restore an object that was reduced by decycle. Members whose values are
+// objects of the form
+// {$ref: PATH}
+// are replaced with references to the value found by the PATH. This will
+// restore cycles. The object will be mutated.
+
+// The eval function is used to locate the values described by a PATH. The
+// root object is kept in a $ variable. A regular expression is used to
+// assure that the PATH is extremely well formed. The regexp contains nested
+// * quantifiers. That has been known to have extremely bad performance
+// problems on some browsers for very long strings. A PATH is expected to be
+// reasonably short. A PATH is allowed to belong to a very restricted subset of
+// Goessner's JSONPath.
+
+// So,
+// var s = '[{"$ref":"$"}]';
+// return JSON.retrocycle(JSON.parse(s));
+// produces an array containing a single element which is the array itself.
+
+ var px =
+ /^\$(?:\[(?:\d+|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;
+
+ (function rez(value) {
+
+// The rez function walks recursively through the object looking for $ref
+// properties. When it finds one that has a value that is a path, then it
+// replaces the $ref object with a reference to the value that is found by
+// the path.
+
+ var i, item, name, path;
+
+ if (value && typeof value === 'object') {
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
+ for (i = 0; i < value.length; i += 1) {
+ item = value[i];
+ if (item && typeof item === 'object') {
+ path = item.$ref;
+ if (typeof path === 'string' && px.test(path)) {
+ value[i] = eval(path);
+ } else {
+ rez(item);
+ }
+ }
+ }
+ } else {
+ for (name in value) {
+ if (typeof value[name] === 'object') {
+ item = value[name];
+ if (item) {
+ path = item.$ref;
+ if (typeof path === 'string' && px.test(path)) {
+ value[name] = eval(path);
+ } else {
+ rez(item);
+ }
+ }
+ }
+ }
+ }
+ }
+ }($));
+ return $;
+ };
+}
+/**
+ * # Shelf.JS
+ *
+ * Persistent Client-Side Storage @VERSION
+ *
+ * Copyright 2012 Stefano Balietti
+ * GPL licenses.
+ *
+ * ---
+ *
+ */
+(function(exports){
+
+var version = '0.3';
+
+var store = exports.store = function (key, value, options, type) {
+ options = options || {};
+ type = (options.type && options.type in store.types) ? options.type : store.type;
+ if (!type || !store.types[type]) {
+ store.log("Cannot save/load value. Invalid storage type selected: " + type, 'ERR');
+ return;
+ }
+ store.log('Accessing ' + type + ' storage');
+
+ return store.types[type](key, value, options);
+};
+
+// Adding functions and properties to store
+///////////////////////////////////////////
+store.name = "__shelf__";
+
+store.verbosity = 0;
+store.types = {};
+
+
+var mainStorageType = "volatile";
+
+//if Object.defineProperty works...
+try {
+
+ Object.defineProperty(store, 'type', {
+ set: function(type){
+ if ('undefined' === typeof store.types[type]) {
+ store.log('Cannot set store.type to an invalid type: ' + type);
+ return false;
+ }
+ mainStorageType = type;
+ return type;
+ },
+ get: function(){
+ return mainStorageType;
+ },
+ configurable: false,
+ enumerable: true
+ });
+}
+catch(e) {
+ store.type = mainStorageType; // default: memory
+}
+
+store.addType = function (type, storage) {
+ store.types[type] = storage;
+ store[type] = function (key, value, options) {
+ options = options || {};
+ options.type = type;
+ return store(key, value, options);
+ };
+
+ if (!store.type || store.type === "volatile") {
+ store.type = type;
+ }
+};
+
+store.error = function() {
+ return "shelf quota exceeded";
+};
+
+store.log = function(text) {
+ if (store.verbosity > 0) {
+ console.log('Shelf v.' + version + ': ' + text);
+ }
+
+};
+
+store.isPersistent = function() {
+ if (!store.types) return false;
+ if (store.type === "volatile") return false;
+ return true;
+};
+
+//if Object.defineProperty works...
+try {
+ Object.defineProperty(store, 'persistent', {
+ set: function(){},
+ get: store.isPersistent,
+ configurable: false
+ });
+}
+catch(e) {
+ // safe case
+ store.persistent = false;
+}
+
+store.decycle = function(o) {
+ if (JSON && JSON.decycle && 'function' === typeof JSON.decycle) {
+ o = JSON.decycle(o);
+ }
+ return o;
+};
+
+store.retrocycle = function(o) {
+ if (JSON && JSON.retrocycle && 'function' === typeof JSON.retrocycle) {
+ o = JSON.retrocycle(o);
+ }
+ return o;
+};
+
+store.stringify = function(o) {
+ if (!JSON || !JSON.stringify || 'function' !== typeof JSON.stringify) {
+ throw new Error('JSON.stringify not found. Received non-string value and could not serialize.');
+ }
+
+ o = store.decycle(o);
+ return JSON.stringify(o);
+};
+
+store.parse = function(o) {
+ if ('undefined' === typeof o) return undefined;
+ if (JSON && JSON.parse && 'function' === typeof JSON.parse) {
+ try {
+ o = JSON.parse(o);
+ }
+ catch (e) {
+ store.log('Error while parsing a value: ' + e, 'ERR');
+ store.log(o);
+ }
+ }
+
+ o = store.retrocycle(o);
+ return o;
+};
+
+// ## In-memory storage
+// ### fallback for all browsers to enable the API even if we can't persist data
+(function() {
+
+ var memory = {},
+ timeout = {};
+
+ function copy(obj) {
+ return store.parse(store.stringify(obj));
+ }
+
+ store.addType("volatile", function(key, value, options) {
+
+ if (!key) {
+ return copy(memory);
+ }
+
+ if (value === undefined) {
+ return copy(memory[key]);
+ }
+
+ if (timeout[key]) {
+ clearTimeout(timeout[key]);
+ delete timeout[key];
+ }
+
+ if (value === null) {
+ delete memory[key];
+ return null;
+ }
+
+ memory[key] = value;
+ if (options.expires) {
+ timeout[key] = setTimeout(function() {
+ delete memory[key];
+ delete timeout[key];
+ }, options.expires);
+ }
+
+ return value;
+ });
+}());
+
+}('undefined' !== typeof module && 'undefined' !== typeof module.exports ? module.exports: this));
+/**
+ * ## Cookie storage for Shelf.js
+ *
+ */
+
+(function(exports) {
+
+var store = exports.store;
+
+if (!store) {
+ console.log('cookie.shelf.js: shelf.js core not found. Cookie storage not available.');
+ return;
+}
+
+if ('undefined' === typeof window) {
+ console.log('cookie.shelf.js: am I running in a browser? Cookie storage not available.');
+ return;
+}
+
+var cookie = (function() {
+
+ var resolveOptions, assembleOptionsString, parseCookies, constructor, defaultOptions = {
+ expiresAt: null,
+ path: '/',
+ domain: null,
+ secure: false
+ };
+
+ /**
+ * resolveOptions - receive an options object and ensure all options are present and valid, replacing with defaults where necessary
+ *
+ * @access private
+ * @static
+ * @parameter Object options - optional options to start with
+ * @return Object complete and valid options object
+ */
+ resolveOptions = function(options){
+
+ var returnValue, expireDate;
+
+ if(typeof options !== 'object' || options === null){
+ returnValue = defaultOptions;
+ }
+ else {
+ returnValue = {
+ expiresAt: defaultOptions.expiresAt,
+ path: defaultOptions.path,
+ domain: defaultOptions.domain,
+ secure: defaultOptions.secure
+ };
+
+ if (typeof options.expiresAt === 'object' && options.expiresAt instanceof Date) {
+ returnValue.expiresAt = options.expiresAt;
+ }
+ else if (typeof options.hoursToLive === 'number' && options.hoursToLive !== 0){
+ expireDate = new Date();
+ expireDate.setTime(expireDate.getTime() + (options.hoursToLive * 60 * 60 * 1000));
+ returnValue.expiresAt = expireDate;
+ }
+
+ if (typeof options.path === 'string' && options.path !== '') {
+ returnValue.path = options.path;
+ }
+
+ if (typeof options.domain === 'string' && options.domain !== '') {
+ returnValue.domain = options.domain;
+ }
+
+ if (options.secure === true) {
+ returnValue.secure = options.secure;
+ }
+ }
+
+ return returnValue;
+ };
+
+ /**
+ * assembleOptionsString - analyze options and assemble appropriate string for setting a cookie with those options
+ *
+ * @access private
+ * @static
+ * @parameter options OBJECT - optional options to start with
+ * @return STRING - complete and valid cookie setting options
+ */
+ assembleOptionsString = function (options) {
+ options = resolveOptions(options);
+
+ return (
+ (typeof options.expiresAt === 'object' && options.expiresAt instanceof Date ? '; expires=' + options.expiresAt.toGMTString() : '') +
+ '; path=' + options.path +
+ (typeof options.domain === 'string' ? '; domain=' + options.domain : '') +
+ (options.secure === true ? '; secure' : '')
+ );
+ };
+
+ /**
+ * parseCookies - retrieve document.cookie string and break it into a hash with values decoded and unserialized
+ *
+ * @access private
+ * @static
+ * @return OBJECT - hash of cookies from document.cookie
+ */
+ parseCookies = function() {
+ var cookies = {}, i, pair, name, value, separated = document.cookie.split(';'), unparsedValue;
+ for(i = 0; i < separated.length; i = i + 1){
+ pair = separated[i].split('=');
+ name = pair[0].replace(/^\s*/, '').replace(/\s*$/, '');
+
+ try {
+ value = decodeURIComponent(pair[1]);
+ }
+ catch(e1) {
+ value = pair[1];
+ }
+
+// if (JSON && 'object' === typeof JSON && 'function' === typeof JSON.parse) {
+// try {
+// unparsedValue = value;
+// value = JSON.parse(value);
+// }
+// catch (e2) {
+// value = unparsedValue;
+// }
+// }
+
+ cookies[name] = store.parse(value);
+ }
+ return cookies;
+ };
+
+ constructor = function(){};
+
+
+ /**
+ * get - get one, several, or all cookies
+ *
+ * @access public
+ * @paramater Mixed cookieName - String:name of single cookie; Array:list of multiple cookie names; Void (no param):if you want all cookies
+ * @return Mixed - Value of cookie as set; Null:if only one cookie is requested and is not found; Object:hash of multiple or all cookies (if multiple or all requested);
+ */
+ constructor.prototype.get = function(cookieName) {
+
+ var returnValue, item, cookies = parseCookies();
+
+ if(typeof cookieName === 'string') {
+ returnValue = (typeof cookies[cookieName] !== 'undefined') ? cookies[cookieName] : null;
+ }
+ else if (typeof cookieName === 'object' && cookieName !== null) {
+ returnValue = {};
+ for (item in cookieName) {
+ if (typeof cookies[cookieName[item]] !== 'undefined') {
+ returnValue[cookieName[item]] = cookies[cookieName[item]];
+ }
+ else {
+ returnValue[cookieName[item]] = null;
+ }
+ }
+ }
+ else {
+ returnValue = cookies;
+ }
+
+ return returnValue;
+ };
+
+ /**
+ * filter - get array of cookies whose names match the provided RegExp
+ *
+ * @access public
+ * @paramater Object RegExp - The regular expression to match against cookie names
+ * @return Mixed - Object:hash of cookies whose names match the RegExp
+ */
+ constructor.prototype.filter = function (cookieNameRegExp) {
+ var cookieName, returnValue = {}, cookies = parseCookies();
+
+ if (typeof cookieNameRegExp === 'string') {
+ cookieNameRegExp = new RegExp(cookieNameRegExp);
+ }
+
+ for (cookieName in cookies) {
+ if (cookieName.match(cookieNameRegExp)) {
+ returnValue[cookieName] = cookies[cookieName];
+ }
+ }
+
+ return returnValue;
+ };
+
+ /**
+ * set - set or delete a cookie with desired options
+ *
+ * @access public
+ * @paramater String cookieName - name of cookie to set
+ * @paramater Mixed value - Any JS value. If not a string, will be JSON encoded; NULL to delete
+ * @paramater Object options - optional list of cookie options to specify
+ * @return void
+ */
+ constructor.prototype.set = function(cookieName, value, options){
+ if (typeof options !== 'object' || options === null) {
+ options = {};
+ }
+
+ if (typeof value === 'undefined' || value === null) {
+ value = '';
+ options.hoursToLive = -8760;
+ }
+
+ else if (typeof value !== 'string'){
+// if(typeof JSON === 'object' && JSON !== null && typeof store.stringify === 'function') {
+//
+// value = JSON.stringify(value);
+// }
+// else {
+// throw new Error('cookies.set() received non-string value and could not serialize.');
+// }
+
+ value = store.stringify(value);
+ }
+
+
+ var optionsString = assembleOptionsString(options);
+
+ document.cookie = cookieName + '=' + encodeURIComponent(value) + optionsString;
+ };
+
+ /**
+ * del - delete a cookie (domain and path options must match those with which the cookie was set; this is really an alias for set() with parameters simplified for this use)
+ *
+ * @access public
+ * @paramater MIxed cookieName - String name of cookie to delete, or Bool true to delete all
+ * @paramater Object options - optional list of cookie options to specify (path, domain)
+ * @return void
+ */
+ constructor.prototype.del = function(cookieName, options) {
+ var allCookies = {}, name;
+
+ if(typeof options !== 'object' || options === null) {
+ options = {};
+ }
+
+ if(typeof cookieName === 'boolean' && cookieName === true) {
+ allCookies = this.get();
+ }
+ else if(typeof cookieName === 'string') {
+ allCookies[cookieName] = true;
+ }
+
+ for(name in allCookies) {
+ if(typeof name === 'string' && name !== '') {
+ this.set(name, null, options);
+ }
+ }
+ };
+
+ /**
+ * test - test whether the browser is accepting cookies
+ *
+ * @access public
+ * @return Boolean
+ */
+ constructor.prototype.test = function() {
+ var returnValue = false, testName = 'cT', testValue = 'data';
+
+ this.set(testName, testValue);
+
+ if(this.get(testName) === testValue) {
+ this.del(testName);
+ returnValue = true;
+ }
+
+ return returnValue;
+ };
+
+ /**
+ * setOptions - set default options for calls to cookie methods
+ *
+ * @access public
+ * @param Object options - list of cookie options to specify
+ * @return void
+ */
+ constructor.prototype.setOptions = function(options) {
+ if(typeof options !== 'object') {
+ options = null;
+ }
+
+ defaultOptions = resolveOptions(options);
+ };
+
+ return new constructor();
+})();
+
+// if cookies are supported by the browser
+if (cookie.test()) {
+
+ store.addType("cookie", function (key, value, options) {
+
+ if ('undefined' === typeof key) {
+ return cookie.get();
+ }
+
+ if ('undefined' === typeof value) {
+ return cookie.get(key);
+ }
+
+ // Set to NULL means delete
+ if (value === null) {
+ cookie.del(key);
+ return null;
+ }
+
+ return cookie.set(key, value, options);
+ });
+}
+
+}(this));
+/**
+ * ## File System storage for Shelf.js
+ *
+ * ### Available only in Node.JS
+ */
+
+(function(exports) {
+
+var store = exports.store;
+
+if (!store) {
+ console.log('fs.shelf.js: shelf.js core not found. File system storage not available.');
+ return;
+}
+
+store.filename = './shelf.out';
+
+var fs = require('fs'),
+ path = require('path'),
+ util = require('util');
+
+// https://github.com/jprichardson/node-fs-extra/blob/master/lib/copy.js
+var copyFile = function(srcFile, destFile, cb) {
+ var fdr, fdw;
+ fdr = fs.createReadStream(srcFile);
+ fdw = fs.createWriteStream(destFile);
+ fdr.on('end', function() {
+ return cb(null);
+ });
+ return fdr.pipe(fdw);
+ };
+
+
+var timeout = {};
+
+var overwrite = function (fileName, items) {
+ var file = fileName || store.filename;
+ if (!file) {
+ store.log('You must specify a valid file.', 'ERR');
+ return false;
+ }
+
+ var tmp_copy = path.dirname(file) + '.' + path.basename(file);
+
+// console.log('files')
+// console.log(file);
+// console.log(fileName);
+// console.log(tmp_copy)
+
+ copyFile(file, tmp_copy, function(){
+ var s = store.stringify(items);
+ // removing leading { and trailing }
+ s = s.substr(1, s = s.substr(0, s.legth-1));
+// console.log('SAVING')
+// console.log(s)
+ fs.writeFile(file, s, 'utf-8', function(e) {
+ if (e) throw e;
+ fs.unlink(tmp_copy, function (err) {
+ if (err) throw err;
+ });
+ return true;
+ });
+
+ });
+
+};
+
+if ('undefined' !== typeof fs.appendFileSync) {
+ // node 0.8
+ var save = function (fileName, key, value) {
+ var file = fileName || store.filename;
+ if (!file) {
+ store.log('You must specify a valid file.', 'ERR');
+ return false;
+ }
+ if (!key) return;
+
+ var item = store.stringify(key) + ": " + store.stringify(value) + ",\n";
+
+ return fs.appendFileSync(file, item, 'utf-8');
+ };
+}
+else {
+ // node < 0.8
+ var save = function (fileName, key, value) {
+ var file = fileName || store.filename;
+ if (!file) {
+ store.log('You must specify a valid file.', 'ERR');
+ return false;
+ }
+ if (!key) return;
+
+ var item = store.stringify(key) + ": " + store.stringify(value) + ",\n";
+
+
+
+ fs.open(file, 'a', 666, function( e, id ) {
+ fs.write( id, item, null, 'utf8', function(){
+ fs.close(id, function(){});
+ });
+ });
+
+ return true;
+ };
+}
+
+var load = function (fileName, key) {
+ var file = fileName || store.filename;
+ if (!file) {
+ store.log('You must specify a valid file.', 'ERR');
+ return false;
+ }
+
+ var s = fs.readFileSync(file, 'utf-8');
+
+// console.log('BEFORE removing end')
+// console.log(s)
+
+
+ s = s.substr(0, s.length-2); // removing last ',' and /n
+
+// console.log('BEFORE PARSING')
+// console.log(s)
+
+ var items = store.parse('{' + s + '}');
+
+// console.log('PARSED')
+// console.log(items)
+
+ return (key) ? items[key] : items;
+
+};
+
+var deleteVariable = function (fileName, key) {
+ var file = fileName || store.filename;
+ var items = load(file);
+// console.log('dele')
+// console.log(items)
+// console.log(key)
+ delete items[key];
+ overwrite(file, items);
+ return null;
+};
+
+store.addType("fs", function(key, value, options) {
+
+ var filename = options.file || store.filename;
+
+ if (!key) {
+ return load(filename);
+ }
+
+ if (value === undefined) {
+ return load(filename, key);
+ }
+
+ if (timeout[key]) {
+ clearTimeout(timeout[key]);
+ deleteVariable(filename, key);
+ }
+
+ if (value === null) {
+ deleteVariable(filename, key);
+ return null;
+ }
+
+ // save item
+ save(filename, key, value);
+
+ if (options.expires) {
+ timeout[key] = setTimeout(function() {
+ deleteVariable(filename, key);
+ }, options.expires);
+ }
+
+ return value;
+});
+
+}(('undefined' !== typeof module && 'function' === typeof require) ? module.exports || module.parent.exports : {}));
+/**
+ * ## Amplify storage for Shelf.js
+ *
+ */
+
+(function(exports) {
+
+var store = exports.store;
+
+if (!store) {
+ console.log('amplify.shelf.js: shelf.js core not found. Amplify storage not available.');
+ return;
+}
+
+if ('undefined' === typeof window) {
+ console.log('amplify.shelf.js: am I running in a browser? Amplify storage not available.');
+ return;
+}
+
+//var rprefix = /^__shelf__/;
+var regex = new RegExp("^" + store.name);
+function createFromStorageInterface(storageType, storage) {
+ store.addType(storageType, function(key, value, options) {
+ var storedValue, parsed, i, remove,
+ ret = value,
+ now = (new Date()).getTime();
+
+ if (!key) {
+ ret = {};
+ remove = [];
+ i = 0;
+ try {
+ // accessing the length property works around a localStorage bug
+ // in Firefox 4.0 where the keys don't update cross-page
+ // we assign to key just to avoid Closure Compiler from removing
+ // the access as "useless code"
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=662511
+ key = storage.length;
+
+ while (key = storage.key(i++)) {
+ if (regex.test(key)) {
+ parsed = store.parse(storage.getItem(key));
+ if (parsed.expires && parsed.expires <= now) {
+ remove.push(key);
+ } else {
+ ret[key.replace(rprefix, "")] = parsed.data;
+ }
+ }
+ }
+ while (key = remove.pop()) {
+ storage.removeItem(key);
+ }
+ } catch (error) {}
+ return ret;
+ }
+
+ // protect against name collisions with direct storage
+ key = store.name + key;
+
+
+ if (value === undefined) {
+ storedValue = storage.getItem(key);
+ parsed = storedValue ? store.parse(storedValue) : { expires: -1 };
+ if (parsed.expires && parsed.expires <= now) {
+ storage.removeItem(key);
+ } else {
+ return parsed.data;
+ }
+ } else {
+ if (value === null) {
+ storage.removeItem(key);
+ } else {
+ parsed = store.stringify({
+ data: value,
+ expires: options.expires ? now + options.expires : null
+ });
+ try {
+ storage.setItem(key, parsed);
+ // quota exceeded
+ } catch(error) {
+ // expire old data and try again
+ store[storageType]();
+ try {
+ storage.setItem(key, parsed);
+ } catch(error) {
+ throw store.error();
+ }
+ }
+ }
+ }
+
+ return ret;
+ });
+}
+
+// ## localStorage + sessionStorage
+// IE 8+, Firefox 3.5+, Safari 4+, Chrome 4+, Opera 10.5+, iPhone 2+, Android 2+
+for (var webStorageType in { localStorage: 1, sessionStorage: 1 }) {
+ // try/catch for file protocol in Firefox
+ try {
+ if (window[webStorageType].getItem) {
+ createFromStorageInterface(webStorageType, window[webStorageType]);
+ }
+ } catch(e) {}
+}
+
+// ## globalStorage
+// non-standard: Firefox 2+
+// https://developer.mozilla.org/en/dom/storage#globalStorage
+if (!store.types.localStorage && window.globalStorage) {
+ // try/catch for file protocol in Firefox
+ try {
+ createFromStorageInterface("globalStorage",
+ window.globalStorage[window.location.hostname]);
+ // Firefox 2.0 and 3.0 have sessionStorage and globalStorage
+ // make sure we default to globalStorage
+ // but don't default to globalStorage in 3.5+ which also has localStorage
+ if (store.type === "sessionStorage") {
+ store.type = "globalStorage";
+ }
+ } catch(e) {}
+}
+
+// ## userData
+// non-standard: IE 5+