cordova-plugin-nano-sqlite
Version:
NanoSQL SQLite Plugin: exposes a well documented, easy to use API for SQLite. Uses IndexedDB/WebSQL when testing in the browser, then uses SQLite on the device with the exact same API. Includes typescript support, an ORM and undo/redo built in.
1 lines • 22.2 kB
JavaScript
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(window,function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(e,t,n){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0});var n=0,i={},r=Array.prototype.slice,o="undefined"!=typeof window&&window.postMessage&&window.addEventListener,s=function(e){return e[0].apply(null,r.call(e,1))};o&&window.addEventListener("message",function(e){var t,n=e.data;"string"==typeof n&&0===n.indexOf("setMsg")&&(t=i[n])&&(delete i[n],s(t))});var a=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=n++,o="setMsg"+r;return i[o]=e,window.postMessage(o,"*"),r};t.setFast=o?a:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];setTimeout(function(){s(e)},0)};var u=function(){},c=["R"],f=["F"],l=["P"],d=function(){function t(e){this._state=l,this._queue=[],this._outcome=void 0,e!==u&&y(this,e)}return t.doPolyFill=function(){void 0!==e&&(e.Promise||(e.Promise=this)),"undefined"!=typeof window&&(window.Promise||(window.Promise=this))},t.prototype.catch=function(e){return this.then(function(){},e)},t.prototype.then=function(e,n){if("function"!=typeof e&&this._state===f||"function"!=typeof n&&this._state===c)return this;var i=new t(u);this._state!==l?p(i,this._state===f?e:n,this._outcome):this._queue.push(new h(i,e,n));return i},t.resolve=function(e){return e instanceof this?e:_._resolve(new t(u),e)},t.reject=function(e){return _._reject(new t(u),e)},t.all=function(e){return new t(function(t,n){var i=[];if(e.length)for(var r=function(n,r,o){void 0!==o?i.push(o):i.push(r),i.length==e.length&&t(i)},o=function(t){e[t].then(function(e){r(0,e,void 0)}).catch(function(e){r(0,void 0,e)})},s=0;s<e.length;s++)o(s);else t([])})},t.race=function(e){var n=this,i=e.length,r=!1,o=-1,s=new t(u);if(!1!==Array.isArray(e))return this.reject(new TypeError);function a(e){n.resolve(e).then(function(e){r||(r=!0,_._resolve(s,e))},function(e){r||(r=!0,_._reject(s,e))})}if(!i)return this.resolve([]);for(;++o<i;)a(e[o]);return s},t}();t.Promise=d;var h=function(){function e(e,t,n){this._promise=e,"function"==typeof t&&(this._onFulfilled=t,this._callFulfilled=this._otherCallFulfilled),"function"==typeof n&&(this._onRejected=n,this._callRejected=this._otherCallRejected)}return e.prototype._callFulfilled=function(e){_._resolve(this._promise,e)},e.prototype._otherCallFulfilled=function(e){p(this._promise,this._onFulfilled,e)},e.prototype._callRejected=function(e){_._reject(this._promise,e)},e.prototype._otherCallRejected=function(e){p(this._promise,this._onRejected,e)},e}();function p(e,n,i){t.setFast(function(){var t;try{t=n.apply(null,i)}catch(t){return _._reject(e,t)}return t===e?_._reject(e,new TypeError):_._resolve(e,t),null})}t._QueueItem=h;var _=function(){function e(){}return e._resolve=function(t,n){var i=v(g,n),r=i._value,o=-1,s=t._queue.length;if("error"===i._status)return e._reject(t,i._value);if(r)y(t,r);else for(t._state=f,t._outcome=n;++o<s;)t._queue[o]._callFulfilled(n);return t},e._reject=function(e,t){e._state=c,e._outcome=t;for(var n=-1,i=e._queue.length;++n<i;)e._queue[n]._callRejected(t);return e},e}();function g(e){var t=e&&e.then;return!e||"object"!=typeof e&&"function"!=typeof e||"function"!=typeof t?null:function(){t.apply(e,arguments)}}function y(e,t){var n=!1;function i(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];n||(n=!0,_._reject(e,t))}function r(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];n||(n=!0,_._resolve(e,t))}var o=v(function(){t(r,i)});"error"===o._status&&i(o._value)}function v(e,t){var n={_status:null,_value:null};try{n._value=e(t),n._status="success"}catch(e){n._status="error",n._value=e}return n}}).call(this,n(1))},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){(function(e){Object.defineProperty(t,"__esModule",{value:!0});var i=n(5),r=n(6);n(0).Promise.doPolyFill(),t.stopWords=["a","about","after","all","also","am","an","and","andor","another","any","are","as","at","be","because","been","before","being","between","both","but","by","came","can","come","could","did","do","each","for","from","get","got","had","has","have","he","her","here","him","himself","his","how","i","if","in","into","is","it","like","make","many","me","might","more","most","much","must","my","never","now","of","on","only","or","other","our","out","over","said","same","see","should","since","some","still","such","take","than","that","the","their","them","then","there","these","they","this","those","through","to","too","under","up","very","was","way","we","well","were","what","where","which","while","who","with","would","you","your"],t._assign=function(e){return e?JSON.parse(JSON.stringify(e)):null},t.splitArr=function(e,t){for(var n=e.length%t,i=n,r=Math.floor(e.length/t),o=[],s=0;s<e.length;s+=r){var a=r+s,u=!1;0!==n&&i&&(a++,i--,u=!0),o.push(e.slice(s,a)),u&&s++}return o},t.fastCHAIN=function(e,n){return new Promise(function(i,r){if(e&&e.length){var o=[],s=!1,a=function(){if(o.length<e.length)n(e[o.length],o.length,function(e){o.push(e),o.length%100==0?t.setFast(a):a()},function(e){s=!0,r(e)});else{if(s)return;i(o)}};a()}else i([])})},t.fastRACE=function(e,t){return new Promise(function(n,i){if(e&&e.length){var r=!1,o=0,s=function(){o<e.length&&(t(e[o],o,function(e){r||(r=!0,n([e]))},function(e){r||(r=!0,i(e))}),o++,s())};s()}else n([])})},t.fastALL=function(e,t){return Promise.all((e||[]).map(function(e,n){return new Promise(function(i,r){t(e,n,i,r)})}))};var o="undefined"==typeof window?"":navigator.userAgent||"";t.isSafari=0!==o.length&&(/^((?!chrome|android).)*safari/i.test(o)||/iPad|iPhone|iPod/.test(o)&&!window.MSStream),t.isMSBrowser=0!==o.length&&(o.indexOf("MSIE ")>0||o.indexOf("Trident/")>0||o.indexOf("Edge/")>0),t.isAndroid=/Android/.test(o),t.random16Bits=function(){if("undefined"==typeof crypto)return Math.round(Math.random()*Math.pow(2,16));if(crypto.getRandomValues){var t=new Uint16Array(1);return crypto.getRandomValues(t),t[0]}return void 0!==e&&e._crypto.randomBytes?e._crypto.randomBytes(2).reduce(function(e,t){return t*e}):Math.round(Math.random()*Math.pow(2,16))},t.tokenizer=function(e,n,o,s,a){var u=function(e){return!e||(1===String(e).length||-1!==t.stopWords.indexOf(e))},c=(s||"").toLowerCase().replace(/(\d+)\/(\d+)|(?:\d+(?:,\d+)*|\d+)(?:\.\d+)?/gim,function(e,t,n){return t||n?(parseInt(t)/parseInt(n)).toFixed(a||4):parseFloat(e.replace(/\,/gim,"")).toFixed(a||4)}).replace(/\-|\_|\[|\]|\(|\)|\{|\}|\r?\n|\r|\t/gim," ").replace(/[^\w\s]|(\d\.)/gim,"$1").replace(/\s+/g," ").split(" ");switch(o[1]){case"english":return c.map(function(e,t){return{i:t,o:e,w:isNaN(e)?u(e)?"":i(r(e)):e}});case"english-stem":return c.map(function(e,t){return{i:t,o:e,w:isNaN(e)?u(e)?"":r(e):e}});case"english-meta":return c.map(function(e,t){return{i:t,o:e,w:isNaN(e)?u(e)?"":i(e):e}})}return c.map(function(e,t){return{o:e,w:e,i:t}})},t.timeid=function(e){for(var n=Math.round((new Date).getTime()/(e?1:1e3)).toString();n.length<(e?13:10);)n="0"+n;return n+"-"+(t.random16Bits()+t.random16Bits()).toString(16)},t.intersect=function(e,t){return!(!e||!t)&&(!(!e.length||!t.length)&&(e||[]).filter(function(e){return-1!==(t||[]).indexOf(e)}).length>0)},t.uuid=function(){var e,n,i="";return[i,i,i,i,i,i,i,i].reduce(function(r,o,s){for(e=t.random16Bits(),n=3===s?4:4===s?(e%16&3|8).toString(16):i,e=e.toString(16);e.length<4;)e="0"+e;return r+([2,3,4,5].indexOf(s)>-1?"-":i)+(n+e).slice(0,4)},i)},t.hash=function(e){for(var t=5381,n=e.length;n;)t=33*t^e.charCodeAt(--n);return(t>>>0).toString(16)};var s={int:function(e){return e},uuid:t.uuid,timeId:function(){return t.timeid()},timeIdms:function(){return t.timeid(!0)}};t.generateID=function(e,t){return s[e]?s[e](t||1):""},t.cleanArgs=function(e,n){for(var i={},r=e.length;r--;){var o=e[r].split(":");o.length>1?i[o[0]]=t.cast(o[1],n[o[0]]||void 0):i[o[0]]=n[o[0]]||void 0}return i},t.isObject=function(e){return"[object Object]"===Object.prototype.toString.call(e)},t.cast=function(e,n){if("any"===e||"blob"===e)return n;var i=typeof n;if("undefined"===i||null===n)return n;var r={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="},o=function(e,n){switch(e){case"safestr":return o("string",n).replace(/[&<>"'`=\/]/gim,function(e){return r[e]});case"int":return"number"!==i||n%1!=0?parseInt(n||0):n;case"number":case"float":return"number"!==i?parseFloat(n||0):n;case"any[]":case"array":return Array.isArray(n)?n:[];case"uuid":case"timeId":case"timeIdms":case"string":return"string"!==i?String(n):n;case"object":case"obj":case"map":return t.isObject(n)?n:{};case"boolean":case"bool":return!0===n}return n},s=o(String(e||"").toLowerCase(),n);if(-1!==e.indexOf("[]")){var a=e.slice(0,e.lastIndexOf("[]"));return(n||[]).map(function(e){return t.cast(a,e)})}return void 0!==s?["int","float","number"].indexOf(e)>-1&&isNaN(s)?0:s:void 0},t.binarySearch=function(e,n,i,r){var o=i||0,s=r||e.length;if(e[o]>n)return o;if(e[s]<n)return s+1;var a=Math.floor((o+s)/2);return n===e[a]?a:s-1===o?s:n>e[a]?t.binarySearch(e,n,a,s):n<e[a]?t.binarySearch(e,n,o,a):s},t.deepFreeze=function(e){return Object.getOwnPropertyNames(e||{}).forEach(function(n){var i=e[n];"object"==typeof i&&null!==i&&(e[n]=t.deepFreeze(i))}),Object.freeze(e)},t.crowDistance=function(e,t,n,i,r){void 0===r&&(r=6371);var o=function(e){return e*(Math.PI/180)},s=o(n-e),a=o(i-t),u=Math.sin(s/2)*Math.sin(s/2)+Math.cos(o(e))*Math.cos(o(n))*Math.sin(a/2)*Math.sin(a/2);return r*(2*Math.atan2(Math.sqrt(u),Math.sqrt(1-u)))};var a={};t.objQuery=function(e,t,n){var i=function(e,t,n){return e[t]&&n?i(e,t+1,n[e[t]]):n},r=e+(n?"1":"0");if(a[r])return i(a[r],0,t);var o=[];if(o=e.indexOf("[")>-1?[].concat.apply([],e.split(".").map(function(e){return e.match(/([^\[]+)|\[([^\]]+)\]\[/gim)||e})).map(function(e){return e.replace(/\[|\]/gim,"")}):e.split("."),n){var s=o.shift()+"."+o.shift();o.unshift(s)}return a[r]=o,i(a[r],0,t)};var u=0,c={},f=Array.prototype.slice,l="undefined"!=typeof window&&window.postMessage&&window.addEventListener,d=function(e){return e[0].apply(null,f.call(e,1))};l&&window.addEventListener("message",function(e){var t,n=e.data;"string"==typeof n&&0===n.indexOf("setMsg")&&(t=c[n])&&(delete c[n],d(t))});var h=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=u++,i="setMsg"+n;return c[i]=e,window.postMessage(i,"*"),n};t.setFast=l?h:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];setTimeout(function(){d(e)},0)}}).call(this,n(1))},function(e,t,n){e.exports=n(4)},function(e,t,n){var i=this&&this.__assign||Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e};Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),o=n(2),s=n(7);t.getMode=function(){return"undefined"!=typeof cordova&&window.sqlitePlugin&&window.device&&window.device.platform&&"browser"!==window.device.platform?new a:"PERM"};var a=function(){function e(){this._pkKey={},this._dbIndex={},this._pkIsNum={}}return e.prototype.setID=function(e){this._id=e},e.prototype.connect=function(e){var t=this;if(!window.sqlitePlugin)throw Error("SQLite plugin not installed or nanoSQL plugin called before device ready!");console.log('NanoSQL "'+this._id+'" using SQLite.'),this._db=window.sqlitePlugin.openDatabase({name:this._id+"_db",location:"default"}),o.fastALL(Object.keys(this._pkKey),function(e,n,i){t._sql(!0,'CREATE TABLE IF NOT EXISTS "'+e+'" (id '+(t._pkIsNum[e]?"REAL":"TEXT")+" PRIMARY KEY UNIQUE, data TEXT)",[],function(){t._sql(!1,'SELECT id FROM "'+e+'"',[],function(n){for(var r=[],o=0;o<n.rows.length;o++)r.push(n.rows.item(o).id);r=r.sort(),t._dbIndex[e].set(r),i()})})}).then(e)},e.prototype._chkTable=function(e){if(-1===Object.keys(this._dbIndex).indexOf(e))throw Error("No table "+e+" found!");return'"'+e+'"'},e.prototype.makeTable=function(e,t){var n=this;this._dbIndex[e]=new s.DatabaseIndex,t.forEach(function(t){t.props&&o.intersect(["pk","pk()"],t.props)&&(n._dbIndex[e].pkType=t.type,n._pkKey[e]=t.key,t.props&&o.intersect(["ai","ai()"],t.props)&&("int"===t.type||"number"===t.type)&&(n._dbIndex[e].doAI=!0),-1!==["number","float","int"].indexOf(n._dbIndex[e].pkType)&&(n._pkIsNum[e]=!0),(t.props&&o.intersect(["ns","ns()"],t.props)||-1!==["uuid","timeId","timeIdms"].indexOf(n._dbIndex[e].pkType))&&(n._dbIndex[e].sortIndex=!1))})},e.prototype._sql=function(e,t,n,i){this._db.executeSql(t,n,function(e){i(e)},function(e){return console.error(t,n,e),!1})},e.prototype.write=function(e,t,n,r){var s=this;if(!(t=t||o.generateID(this._dbIndex[e].pkType,this._dbIndex[e].ai)))throw new Error("Can't add a row without a primary key!");this._sql(!1,"SELECT id FROM "+this._chkTable(e)+" WHERE id = ?",[t],function(o){var a,u;if(o.rows.length){var c=i({},n,((u={})[s._pkKey[e]]=t,u));s._sql(!0,"UPDATE "+s._chkTable(e)+" SET data = ? WHERE id = ?",[JSON.stringify(c),t],function(){r(c)})}else{s._dbIndex[e].add(t);var f=i({},n,((a={})[s._pkKey[e]]=t,a));s._sql(!0,"INSERT into "+s._chkTable(e)+" (id, data) VALUES (?, ?)",[t,JSON.stringify(f)],function(e){r(f)})}})},e.prototype.delete=function(e,t,n){-1!==this._dbIndex[e].indexOf(t)&&this._dbIndex[e].remove(t),this._sql(!0,"DELETE FROM "+this._chkTable(e)+" WHERE id = ?",[t],function(){n()})},e.prototype.read=function(e,t,n){this._sql(!1,"SELECT data FROM "+this._chkTable(e)+" WHERE id = ?",[t],function(e){e.rows.length?n(JSON.parse(e.rows.item(0).data)):n(void 0)})},e.prototype.rangeRead=function(e,t,n,i,o,s){var a=this,u=this._dbIndex[e].keys(),c=-1===[typeof i,typeof o].indexOf("undefined"),f=c?[i,o]:[];if(u.length){s&&c||!1!==this._dbIndex[e].sortIndex||(u=u.sort()),s&&c&&(f=f.map(function(t){return a._dbIndex[e].getLocation(t)}));var l=f[0]||0,d=[],h=f[0],p="SELECT data from "+this._chkTable(e);if(f.length){for(var _="number"==typeof u[h];h<=f[1];)d.push(_?u[h]:'"'+u[h]+'"'),h++;p+=" WHERE id IN ("+d.map(function(e){return"?"}).join(", ")+")"}p+=" ORDER BY id",d.length?this.batchRead(e,d,function(e){var i=0,o=function(){e.length>i?t(e[i],l,function(){l++,++i%500==0?r.setFast(o):o()}):n()};o()}):this._sql(!1,p,[],function(e){var i=0,o=function(){e.rows.length>i?t(JSON.parse(e.rows.item(i).data),l,function(){l++,++i%500==0?r.setFast(o):o()}):n()};o()})}else n()},e.prototype.batchRead=function(e,t,n){var i=this,r=o.splitArr(t,500),s=[];o.fastCHAIN(r,function(t,n,r){i._sql(!1,"SELECT data from "+i._chkTable(e)+" WHERE id IN ("+t.map(function(e){return"?"}).join(", ")+") ORDER BY id",t.map(function(e){return"string"==typeof e?"'"+e+"'":e}),function(e){for(var t=e.rows.length;t--;)s.push(JSON.parse(e.rows.item(t).data));r()})}).then(function(){n(s)})},e.prototype.drop=function(e,t){var n=new s.DatabaseIndex;n.doAI=this._dbIndex[e].doAI,this._dbIndex[e]=n,this._sql(!0,"DELETE FROM "+this._chkTable(e),[],function(e){t()})},e.prototype.getIndex=function(e,t,n){n(t?this._dbIndex[e].keys().length:this._dbIndex[e].keys())},e.prototype.destroy=function(e){var t=this;o.fastALL(Object.keys(this._dbIndex),function(e,n,i){t.drop(e,i)}).then(e)},e}();t.SQLiteStore=a},function(e,t,n){"use strict";e.exports=function(e){var t,n,f,l,d="",h=0;function p(e){d+=e}function _(t){return e.charAt(h+t).toUpperCase()}function g(e){return function(){return _(e)}}if(!(e=String(e||"")))return"";n=g(1),f=g(0),l=g(-1);for(;!c(f());){if(!f())return"";h++}switch(f()){case"A":"E"===n()?(p("E"),h+=2):(p("A"),h++);break;case"G":case"K":case"P":"N"===n()&&(p("N"),h+=2);break;case"W":"R"===n()?(p(n()),h+=2):"H"===n()?(p(f()),h+=2):a(n())&&(p("W"),h+=2);break;case"X":p("S"),h++;break;case"E":case"I":case"O":case"U":p(f()),h++}for(;f();)if(t=1,!c(f())||f()===l()&&"C"!==f())h+=t;else{switch(f()){case"B":"M"!==l()&&p("B");break;case"C":s(n())?"I"===n()&&"A"===_(2)?p(i):"S"!==l()&&p("S"):"H"===n()?(p(i),t++):p("K");break;case"D":"G"===n()&&s(_(2))?(p("J"),t++):p("T");break;case"G":"H"===n()?o(_(-3))||"H"===_(-4)||(p("F"),t++):"N"===n()?!c(_(2))||"E"===_(2)&&"D"===_(3)||p("K"):s(n())&&"G"!==l()?p("J"):p("K");break;case"H":a(n())&&!u(l())&&p("H");break;case"K":"C"!==l()&&p("K");break;case"P":"H"===n()?p("F"):p("P");break;case"Q":p("K");break;case"S":"I"!==n()||"O"!==_(2)&&"A"!==_(2)?"H"===n()?(p(i),t++):p("S"):p(i);break;case"T":"I"!==n()||"O"!==_(2)&&"A"!==_(2)?"H"===n()?(p(r),t++):"C"===n()&&"H"===_(2)||p("T"):p(i);break;case"V":p("F");break;case"W":a(n())&&p("W");break;case"X":p("KS");break;case"Y":a(n())&&p("Y");break;case"Z":p("S");break;case"F":case"J":case"L":case"M":case"N":case"R":p(f())}h+=t}return d};var i="X",r="0";function o(e){return"B"===(e=f(e))||"D"===e||"H"===e}function s(e){return"E"===(e=f(e))||"I"===e||"Y"===e}function a(e){return"A"===(e=f(e))||"E"===e||"I"===e||"O"===e||"U"===e}function u(e){return"C"===(e=f(e))||"G"===e||"P"===e||"S"===e||"T"===e}function c(e){var t=function(e){return f(e).charCodeAt(0)}(e);return t>=65&&t<=90}function f(e){return String(e).charAt(0).toUpperCase()}},function(e,t,n){"use strict";e.exports=function(e){var t,n;if((e=String(e).toLowerCase()).length<3)return e;121===e.charCodeAt(0)&&(t=!0,e="Y"+e.substr(1));m.test(e)?e=e.substr(0,e.length-2):b.test(e)&&(e=e.substr(0,e.length-1));(n=v.exec(e))?a.test(n[1])&&(e=e.substr(0,e.length-1)):(n=g.exec(e))&&f.test(n[1])&&(e=n[1],y.test(e)?e+="e":w.test(e)?e=e.substr(0,e.length-1):l.test(e)&&(e+="e"));(n=p.exec(e))&&f.test(n[1])&&(e=n[1]+"i");(n=x.exec(e))&&a.test(n[1])&&(e=n[1]+i[n[2]]);(n=I.exec(e))&&a.test(n[1])&&(e=n[1]+r[n[2]]);(n=E.exec(e))?c.test(n[1])&&(e=n[1]):(n=_.exec(e))&&c.test(n[1])&&(e=n[1]);(n=h.exec(e))&&(c.test(n[1])||u.test(n[1])&&!l.test(n[1]))&&(e=n[1]);d.test(e)&&c.test(e)&&(e=e.substr(0,e.length-1));t&&(e="y"+e.substr(1));return e};var i={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},r={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},o="([^aeiou][^aeiouy]*)",s="([aeiouy][aeiou]*)",a=new RegExp("^"+o+"?"+s+o),u=new RegExp("^"+o+"?"+s+o+s+"?$"),c=new RegExp("^"+o+"?("+s+o+"){2,}"),f=new RegExp("^"+o+"?[aeiouy]"),l=new RegExp("^"+o+"[aeiouy][^aeiouwxy]$"),d=/ll$/,h=/^(.+?)e$/,p=/^(.+?)y$/,_=/^(.+?(s|t))(ion)$/,g=/^(.+?)(ed|ing)$/,y=/(at|bl|iz)$/,v=/^(.+?)eed$/,b=/^.+?[^s]s$/,m=/^.+?(ss|i)es$/,w=/([^aeiouylsz])\1$/,x=new RegExp("^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$"),I=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,E=new RegExp("^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$")},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var i=n(2),r=function(){function e(){this._sorted=[],this._exists={},this.ai=1,this.sortIndex=!0,this.doAI=!1}return e.prototype.clone=function(t){this._changeCB&&!t&&this._changeCB(this._ta,"drop",null);var n=new e;return n.doAI=this.doAI,n.ai=this.ai,n.sortIndex=this.sortIndex,n._changeCB=this._changeCB,n._ta=this._ta,n.pkType=this.pkType,t&&this.set([]),n},e.prototype.onChange=function(e,t){this._ta=e,this._changeCB=t},e.prototype.set=function(e){var t=this;this._sorted=e||[],this._exists={},this._sorted.forEach(function(e,n){t._exists[String(e)]=!0}),this.doAI&&this._sorted.length&&(this.ai=this._sorted[this._sorted.length-1]+1)},e.prototype.getLocation=function(e,t){var n=this.indexOf(e);return-1!==n?n:this.sortIndex?i.binarySearch(this._sorted,e,t):i.binarySearch(this._sorted.sort(function(e,t){return e>t?1:-1}),e,t)},e.prototype.add=function(e,t){if(!this._exists[String(e)])if(this._changeCB&&!t&&this._changeCB(this._ta,"add",e),this._exists[String(e)]=!0,t&&-1!==["number","int","float"].indexOf(this.pkType)&&(e=parseFloat(e)),this.doAI)this.ai++,this._sorted.push(e);else if(this.sortIndex){var n=i.binarySearch(this._sorted,e);this._sorted.splice(n,0,e)}else this._sorted.push(e)},e.prototype.keys=function(){return this._sorted},e.prototype.exists=function(e){return!!this._exists[String(e)]},e.prototype.indexOf=function(e){return this._exists[String(e)]?this.sortIndex?i.binarySearch(this._sorted,e):this._sorted.indexOf(e):-1},e.prototype.remove=function(e,t){if(this._changeCB&&!t&&this._changeCB(this._ta,"rm",e),t&&-1!==["number","int","float"].indexOf(this.pkType)&&(e=parseFloat(e)),this._exists[String(e)]){var n=this.indexOf(e);this._exists[String(e)]=!1,this._sorted.splice(n,1)}},e}();t.DatabaseIndex=r,t.syncPeerIndex=function(e,t){e.peerMode&&(Object.keys(t).forEach(function(n){t[n].onChange(n,function(t,n,r){e.peers.filter(function(t){return t!==e.pid}).forEach(function(e){localStorage.setItem(e+"::"+i.random16Bits().toString(16),n+","+t+","+(r||""))})})}),window.addEventListener("storage",function(n){if(n.key&&-1!==n.key.indexOf(e.pid+"::")){var i=(n.newValue||"").split(",");switch(localStorage.removeItem(n.key),i[0]){case"rm":t[i[1]].remove(i[2],!0);break;case"add":t[i[1]].add(i[2],!0);break;case"drop":t[i[1]].clone(!0)}}}))}}])});