umd.min.js 5.8 KB

1234567891011121314151617181920212223242526
  1. /*!
  2. MIT License
  3. Copyright (c) 2018 Arturas Molcanovas <a.molcanovas@gmail.com>
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. */
  20. !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define("localforage-driver-commons",["exports"],r):r(e.LocalforageDriverCommons={})}(this,function(e){"use strict";var r=/^~~local_forage_type~([^~]+)~/,n="__lfsc__:".length,t=n+"arbf".length,o=Object.prototype.toString;function a(e){var r=.75*e.length,n=e.length;"="===e[e.length-1]&&(r--,"="===e[e.length-2]&&r--);for(var t=new ArrayBuffer(r),o=new Uint8Array(t),a=0,i=0;a<n;a+=4){var l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(e[a]),f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(e[a+1]),u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(e[a+2]),c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(e[a+3]);o[i++]=l<<2|f>>4,o[i++]=(15&f)<<4|u>>2,o[i++]=(3&u)<<6|63&c}return t}function i(e){for(var r=new Uint8Array(e),n="",t=0;t<r.length;t+=3)n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[r[t]>>2],n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(3&r[t])<<4|r[t+1]>>4],n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(15&r[t+1])<<2|r[t+2]>>6],n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[63&r[t+2]];return r.length%3==2?n=n.substring(0,n.length-1)+"=":r.length%3==1&&(n=n.substring(0,n.length-2)+"=="),n}function l(e,r){return(e.name||r.name)+"/"+(e.storeName||r.storeName)+"/"}function f(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(arguments.length&&"function"==typeof arguments[arguments.length-1])return arguments[arguments.length-1]}var u={bufferToString:i,deserialize:function(e){if("__lfsc__:"!==e.substring(0,n))return JSON.parse(e);var o,i=e.substring(t),l=e.substring(n,t);if("blob"===l&&r.test(i)){var f=i.match(r);o=f[1],i=i.substring(f[0].length)}var u=a(i);switch(l){case"arbf":return u;case"blob":return function(e,r){e=e||[],r=r||{};try{return new Blob(e,r)}catch(o){if("TypeError"!==o.name)throw o;for(var n=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),t=0;t<e.length;t+=1)n.append(e[t]);return n.getBlob(r.type)}}([u],{type:o});case"si08":return new Int8Array(u);case"ui08":return new Uint8Array(u);case"uic8":return new Uint8ClampedArray(u);case"si16":return new Int16Array(u);case"ur16":return new Uint16Array(u);case"si32":return new Int32Array(u);case"ui32":return new Uint32Array(u);case"fl32":return new Float32Array(u);case"fl64":return new Float64Array(u);default:throw new Error("Unkown type: "+l)}},serialize:function(e,r){var n="";if(e&&(n=o.call(e)),e&&("[object ArrayBuffer]"===n||e.buffer&&"[object ArrayBuffer]"===o.call(e.buffer))){var t=void 0,a="__lfsc__:";e instanceof ArrayBuffer?(t=e,a+="arbf"):(t=e.buffer,"[object Int8Array]"===n?a+="si08":"[object Uint8Array]"===n?a+="ui08":"[object Uint8ClampedArray]"===n?a+="uic8":"[object Int16Array]"===n?a+="si16":"[object Uint16Array]"===n?a+="ur16":"[object Int32Array]"===n?a+="si32":"[object Uint32Array]"===n?a+="ui32":"[object Float32Array]"===n?a+="fl32":"[object Float64Array]"===n?a+="fl64":r(new Error("Failed to get type for BinaryArray"))),r(a+i(t))}else if("[object Blob]"===n){var l=new FileReader;l.onload=function(){var n="~~local_forage_type~"+e.type+"~"+i(this.result);r("__lfsc__:blob"+n)},l.readAsArrayBuffer(e)}else try{r(JSON.stringify(e))}catch(n){console.error("Couldn't convert value into a JSON string: ",e),r(null,n)}},stringToBuffer:a};e.serialiser=u,e.clone=function e(r){var n,t;if(null===r||"object"!=typeof r||"isActiveClone"in r)return r;var o=r instanceof Date?new Date(r):r.constructor();try{for(var a=function(e){var r="function"==typeof Symbol&&e[Symbol.iterator],n=0;return r?r.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}(Object.keys(r)),i=a.next();!i.done;i=a.next()){var l=i.value;Object.prototype.hasOwnProperty.call(r,l)&&(r.isActiveClone=null,o[l]=e(r[l]),delete r.isActiveClone)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(t=a.return)&&t.call(a)}finally{if(n)throw n.error}}return o},e.getKeyPrefix=l,e.executeCallback=function(e,r){r&&e.then(function(e){r(null,e)},function(e){r(e)})},e.getCallback=f,e.dropInstanceCommon=function(e,r){var n=this;if(r=f.apply(this,arguments),!(e="function"!=typeof e&&e||{}).name){var t=this.config();e.name=e.name||t.name,e.storeName=e.storeName||t.storeName}return{promise:e.name?new Promise(function(r){e.storeName?r(l(e,n._defaultConfig)):r(e.name+"/")}):Promise.reject("Invalid arguments"),callback:r}},e.normaliseKey=function(e){return"string"!=typeof e&&(console.warn(e+" used as a key, but it is not a string."),e=String(e)),e},Object.defineProperty(e,"__esModule",{value:!0})});