spy-client 2.1.10 → 2.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SpyLocalCache=e()}(this,function(){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)};function t(t,e){function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var l=(e.prototype.preOrder=function(t){t.push(this),this.left&&this.left.preOrder(t),this.right&&this.right.preOrder(t)},e);function e(t,e){this.data=t,this.weight=e}function n(t){var e=function(t){if(null==t)return null;var i={};return function t(e,o,r){var n=[].concat(r);n.push(o),null!=e&&(null==e.data?(t(e.left,"0",n),t(e.right,"1",n)):i[e.data]=n.join(""))}(t,"",[]),i}(function(t){for(var e=function(t,e){return t.weight-e.weight};1<t.length;){t.sort(e);var o=t.shift(),r=t.shift();if(o&&r){var n=new l(null,o.weight+r.weight);n.left=o,n.right=r,t.unshift(n)}}return t.shift()}(function(t){for(var e=[],o={},r=0,n=t;r<n.length;r++){var i=n[r];null==o[i]?o[i]=1:o[i]++}for(var a=0,s=Object.entries(o);a<s.length;a++){var u=s[a],h=u[0],c=u[1];e.push(new l(h,c))}return e}(t)));return{result:function(t){for(var e=t.join(""),o=Math.ceil(e.length/8),r=new Array(o+1),n=0,i="",a=0;a<e.length;a+=8)i=e.substring(a,a+8),r[n]=parseInt(i,2),n++;return r[n]=i.length,r}(function(t,e){for(var o=[],r=0,n=t;r<n.length;r++){var i=n[r];o.push(e[i])}return o}(t,e)),codes:e}}function y(t,e){t&&(e|=256);var o=Number(e).toString(2);return t?o.substring(o.length-8):o}function i(t){for(var e=[],o=0;o<t.length;o++)e.push(t.charCodeAt(o));return e}function a(t){for(var e="",o=0,r=t;o<r.length;o++){var n=r[o];e+=String.fromCharCode(n)}return e}function o(t,e){return a(function(t,e){for(var o=[],r=0;r<e.length-1;r++){var n=r!==e.length-2;o.push(y(n,e[r]))}var i=o[o.length-1],a=e[e.length-1];i="00000000".substring(8-(a-i.length))+i,o[o.length-1]=i;for(var s={},u=0,h=Object.entries(t);u<h.length;u++){var c=h[u],l=c[0];s[c[1]]=l}var p=o.join(""),f=[],d=p.length;for(r=0;r<d;){for(var g=1,v=(n=!0,null);n&&r+g<=d;){if(""===(l=p.substring(r,r+g)))break;(v=s[l])?n=!1:g++}f.push(parseInt(v,10)),r+=g}return f}(t,i(e)))}var s=(u.prototype.set=function(t,e){},u.prototype.get=function(t,e){},u.prototype.rm=function(t){},u);function u(){}var h,c=(t(p,h=s),p.isSupport=function(){return!!window.localStorage},p.prototype.set=function(t,e){try{localStorage.setItem(t,e)}catch(t){console.error(t)}},p.prototype.get=function(t,e){var o=null;try{o=localStorage.getItem(t)}catch(t){console.error(t)}e&&e(o)},p.prototype.rm=function(t){try{localStorage.removeItem(t)}catch(t){console.error(t)}},p);function p(){return null!==h&&h.apply(this,arguments)||this}var f,d=(t(g,f=s),g.isSupport=function(){return!!window.indexedDB},g.prototype.set=function(t,e){this.db?this.db.transaction([this.databaseName],"readwrite").objectStore(this.databaseName).add({key:t,value:e}):this.setQueue.push({key:t,value:e})},g.prototype.get=function(t,e){if(this.db){var o=this.db.transaction([this.databaseName]).objectStore(this.databaseName).get(t);o.onsuccess=function(){var t=o.result?o.result:{value:""};e(t.value)}}else this.getQueue.push({key:t,cb:e})},g.prototype.runQueueTask=function(){var e=this;this.setQueue.forEach(function(t){e.set(t.key,t.value)}),this.getQueue.forEach(function(t){e.get(t.key,t.cb)})},g);function g(){var e=f.call(this)||this;e.databaseName="spyLC",e.db=null,e.setQueue=[],e.getQueue=[];var t=window.indexedDB.open(e.databaseName);return t.onupgradeneeded=function(t){e.db=t.target&&t.target.result,e.db&&!e.db.objectStoreNames.contains(e.databaseName)&&e.db.createObjectStore(e.databaseName,{keyPath:"key"}),e.runQueueTask()},t.onsuccess=function(){e.db=t.result,e.runQueueTask()},e}function v(t,e){if(void 0===e&&(e=!1),!t)return"";e||(t=function(t){for(var e="",o=0;o<t.length;o++){var r=t.charCodeAt(o);r<128?e+=String.fromCharCode(r):(127<r&&r<2048?e+=String.fromCharCode(r>>6|192):(e+=String.fromCharCode(r>>12|224),e+=String.fromCharCode(r>>6&63|128)),e+=String.fromCharCode(63&r|128))}return e}(t));function o(){s.push(1<u.length?String.fromCharCode(a[u]):u)}var r,n,i,a={},s=[],u=t.charAt(0),h=u,c=h,l=256;for(e&&s.push(u),r=1;r<t.length;r++)n=t.charAt(r),e?(i=t.charCodeAt(r),u=i<256?n:a[i]||u+h,s.push(u),h=u.charAt(0),a[l++]=c+h,c=u):a.hasOwnProperty(u+n)?u+=n:(o(),a[u+n]=l++,u=n);e||o();var p=s.join("");return e&&(p=function(t){for(var e="",o=0,r=0,n=0,i=0;o<t.length;)(r=t.charCodeAt(o))<128?(e+=String.fromCharCode(r),o++):191<r&&r<224?(n=t.charCodeAt(o+1),e+=String.fromCharCode((31&r)<<6|63&n),o+=2):(n=t.charCodeAt(o+1),i=t.charCodeAt(o+2),e+=String.fromCharCode((15&r)<<12|(63&n)<<6|63&i),o+=3);return e}(p)),p}function m(t){void 0===t&&(t={}),this.tmpList=[],this.option=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e=void 0,o=1,r=arguments.length;o<r;o++)for(var n in e=arguments[o])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,t)}({defaultTrigger:!0,compress:"lzw",key:"SpyLocalCache",interval:500,maxRecordLen:30,onFlush:function(){},onSave:function(){},onAdd:function(){return!0},storage:d.isSupport()?"indexedDB":c.isSupport()?"localstorage":"empty"},t),this.load=this.load.bind(this),this.init()}return m.prototype.init=function(){"indexedDB"===this.option.storage?this.storage=new d:"localstorage"===this.option.storage?this.storage=new c:this.storage=new s,"complete"===document.readyState?this.load():window.addEventListener("load",this.load)},m.prototype.load=function(){-1<location.search.indexOf("_FlushLogLocalCache=1")&&this.option.defaultTrigger&&this.flushLog()},m.prototype.addLog=function(t){var e=this;this.option.onAdd&&!this.option.onAdd(t)||(t=JSON.stringify(t),this.tmpList.push(t),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(function(){e.save()},this.option.interval))},m.prototype.getData=function(r){var n=this;try{this.storage.get(this.option.key,function(o){o?n.storage.get(n.option.key+"Codes",function(t){var e=[];try{t=t&&JSON.parse(t),e=n.unzip(o,t).split("\n")}catch(t){console.error(t)}r(e)}):r([])})}catch(t){console.error(t),r([])}},m.prototype.save=function(){var u=this,h=Date.now();this.getData(function(t){var e=u.option.maxRecordLen-1,o=(t.length>e?t.slice(t.length-e,t.length):t).concat(u.tmpList),r=o.join("\n"),n=null,i=0;try{var a=u.zip(r),s="";a.codes?(s=JSON.stringify(a.codes),u.storage.set(u.option.key+"Codes",s)):u.storage.rm(u.option.key+"Codes"),u.storage.set(u.option.key,a.result),i=a.result.length}catch(t){n=t,console.error(t)}u.tmpList=[],u.option.onSave&&u.option.onSave({cost:Date.now()-h,length:i/1024,list:o,error:n})})},m.prototype.flushLog=function(){var o=this;this.getData(function(e){try{for(var t=0;t<e.length;t++)e[t]=JSON.parse(e[t])}catch(t){e=[],o.storage.rm(o.option.key),console.error(t)}for(t=0;t<o.tmpList.length;t++)e.push(JSON.parse(o.tmpList[t]));o.option.onFlush&&o.option.onFlush(e)})},m.prototype.zip=function(t){return"lzw"===this.option.compress?{codes:null,result:v(t)}:"huffman"===this.option.compress?function(t){var e=n(i(t)),o=e.result;return{codes:e.codes,result:a(o)}}(t):{codes:null,result:t}},m.prototype.unzip=function(t,e){return"lzw"===this.option.compress?v(t,!0):"huffman"===this.option.compress?o(e,t):t},m});
1
+ ((t,e)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SpyLocalCache=e()})(this,function(){var r=function(t,e){return(r=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])}))(t,e)};function t(t,e){function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}e.prototype.preOrder=function(t){t.push(this),this.left&&this.left.preOrder(t),this.right&&this.right.preOrder(t)};var c=e;function e(t,e){this.data=t,this.weight=e}function o(t){var n;return null==t?null:(n={},function t(e,o,r){r=[].concat(r);r.push(o),null!=e&&(null==e.data?(t(e.left,"0",r),t(e.right,"1",r)):n[e.data]=r.join(""))}(t,"",[]),n)}function n(t){var e=o((t=>{for(var e=function(t,e){return t.weight-e.weight};1<t.length;){t.sort(e);var o,r=t.shift(),n=t.shift();r&&n&&((o=new c(null,r.weight+n.weight)).left=r,o.right=n,t.unshift(o))}return t.shift()})((t=>{for(var e=[],o={},r=0,n=t;r<n.length;r++){var i=n[r];null==o[i]?o[i]=1:o[i]++}for(var a=0,s=Object.entries(o);a<s.length;a++){var u=s[a],h=u[0];e.push(new c(h,u[1]))}return e})(t)));return{result:(t=>{for(var e=t.join(""),t=Math.ceil(e.length/8),o=new Array(t+1),r=0,n="",i=0;i<e.length;i+=8)n=e.substring(i,i+8),o[r]=parseInt(n,2),r++;return o[r]=n.length,o})(((t,e)=>{for(var o=[],r=0,n=t;r<n.length;r++){var i=n[r];o.push(e[i])}return o})(t,e)),codes:e}}function i(t,e){for(var o,r,n=[],i=0;i<e.length-1;i++){var a=i!==e.length-2;n.push((o=a,r=e[i],o&&(r|=256),r=Number(r).toString(2),o?r.substring(r.length-8):r))}var s=e[e.length-1],s="00000000".substring(8-(s-(s=n[n.length-1]).length))+s;n[n.length-1]=s;for(var u={},h=0,c=Object.entries(t);h<c.length;h++){var l=c[h],p=l[0];u[l[1]]=p}for(var f=n.join(""),d=[],g=f.length,i=0;i<g;){for(var v=1,a=!0,y=null;a&&i+v<=g;){if(""===(p=f.substring(i,i+v)))break;(y=u[p])?a=!1:v++}d.push(parseInt(y,10)),i+=v}return d}function a(t){for(var e=[],o=0;o<t.length;o++)e.push(t.charCodeAt(o));return e}function s(t){for(var e="",o=0,r=t;o<r.length;o++){var n=r[o];e+=String.fromCharCode(n)}return e}h.prototype.set=function(t,e){},h.prototype.get=function(t,e){},h.prototype.rm=function(t){};var u=h;function h(){}t(f,l=u),f.isSupport=function(){return!!window.localStorage},f.prototype.set=function(t,e){try{localStorage.setItem(t,e)}catch(t){console.error(t)}},f.prototype.get=function(t,e){var o=null;try{o=localStorage.getItem(t)}catch(t){console.error(t)}e&&e(o)},f.prototype.rm=function(t){try{localStorage.removeItem(t)}catch(t){console.error(t)}};var l,p=f;function f(){return null!==l&&l.apply(this,arguments)||this}t(v,d=u),v.isSupport=function(){return!!window.indexedDB},v.prototype.set=function(t,e){this.db?this.db.transaction([this.databaseName],"readwrite").objectStore(this.databaseName).add({key:t,value:e}):this.setQueue.push({key:t,value:e})},v.prototype.get=function(t,e){var o;this.db?(o=this.db.transaction([this.databaseName]).objectStore(this.databaseName).get(t)).onsuccess=function(){var t=o.result||{value:""};e(t.value)}:this.getQueue.push({key:t,cb:e})},v.prototype.runQueueTask=function(){var e=this;this.setQueue.forEach(function(t){e.set(t.key,t.value)}),this.getQueue.forEach(function(t){e.get(t.key,t.cb)})};var d,g=v;function v(){var e=d.call(this)||this,t=(e.databaseName="spyLC",e.db=null,e.setQueue=[],e.getQueue=[],window.indexedDB.open(e.databaseName));return t.onupgradeneeded=function(t){e.db=t.target&&t.target.result,e.db&&!e.db.objectStoreNames.contains(e.databaseName)&&e.db.createObjectStore(e.databaseName,{keyPath:"key"}),e.runQueueTask()},t.onsuccess=function(){e.db=t.result,e.runQueueTask()},e}function y(t,e){if(!t)return"";(e=void 0===e?!1:e)||(t=(t=>{for(var e="",o=0;o<t.length;o++){var r=t.charCodeAt(o);r<128?e+=String.fromCharCode(r):e=127<r&&r<2048?(e+=String.fromCharCode(r>>6|192))+String.fromCharCode(63&r|128):(e=(e+=String.fromCharCode(r>>12|224))+String.fromCharCode(r>>6&63|128))+String.fromCharCode(63&r|128)}return e})(t));function o(){s.push(1<u.length?String.fromCharCode(a[u]):u)}var r,n,i,a={},s=[],u=t.charAt(0),h=u,c=h,l=256;for(e&&s.push(u),r=1;r<t.length;r++)n=t.charAt(r),e?(i=t.charCodeAt(r),u=i<256?n:a[i]||u+h,s.push(u),h=u.charAt(0),a[l++]=c+h,c=u):a.hasOwnProperty(u+n)?u+=n:(o(),a[u+n]=l++,u=n);e||o();var p=s.join("");return p=e?(t=>{for(var e,o,r="",n=0,i=0;n<t.length;)(e=t.charCodeAt(n))<128?(r+=String.fromCharCode(e),n++):191<e&&e<224?(i=t.charCodeAt(n+1),r+=String.fromCharCode((31&e)<<6|63&i),n+=2):(i=t.charCodeAt(n+1),o=t.charCodeAt(n+2),r+=String.fromCharCode((15&e)<<12|(63&i)<<6|63&o),n+=3);return r})(p):p}function m(t){void 0===t&&(t={}),this.tmpList=[],this.option=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e,o=1,r=arguments.length;o<r;o++)for(var n in e=arguments[o])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,t)}({defaultTrigger:!0,compress:"lzw",key:"SpyLocalCache",interval:500,maxRecordLen:30,onFlush:function(){},onSave:function(){},onAdd:function(){return!0},storage:g.isSupport()?"indexedDB":p.isSupport()?"localstorage":"empty"},t),this.load=this.load.bind(this),this.init()}return m.prototype.init=function(){"indexedDB"===this.option.storage?this.storage=new g:"localstorage"===this.option.storage?this.storage=new p:this.storage=new u,"complete"===document.readyState?this.load():window.addEventListener("load",this.load)},m.prototype.load=function(){-1<location.search.indexOf("_FlushLogLocalCache=1")&&this.option.defaultTrigger&&this.flushLog()},m.prototype.addLog=function(t){var e=this;this.option.onAdd&&!this.option.onAdd(t)||(t=JSON.stringify(t),this.tmpList.push(t),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(function(){e.save()},this.option.interval))},m.prototype.getData=function(r){var n=this;try{this.storage.get(this.option.key,function(o){o?n.storage.get(n.option.key+"Codes",function(t){var e=[];try{t=t&&JSON.parse(t);e=n.unzip(o,t).split("\n")}catch(t){console.error(t)}r(e)}):r([])})}catch(t){console.error(t),r([])}},m.prototype.save=function(){var a=this,s=Date.now();this.getData(function(t){var e=a.option.maxRecordLen-1,e=(t.length>e?t.slice(t.length-e,t.length):t).concat(a.tmpList),t=e.join("\n"),o=null,r=0;try{var n,i=a.zip(t);i.codes?(n=JSON.stringify(i.codes),a.storage.set(a.option.key+"Codes",n)):a.storage.rm(a.option.key+"Codes"),a.storage.set(a.option.key,i.result),r=i.result.length}catch(t){o=t,console.error(t)}a.tmpList=[],a.option.onSave&&a.option.onSave({cost:Date.now()-s,length:r/1024,list:e,error:o})})},m.prototype.flushLog=function(){var o=this;this.getData(function(e){try{for(var t=0;t<e.length;t++)e[t]=JSON.parse(e[t])}catch(t){e=[],o.storage.rm(o.option.key),console.error(t)}for(t=0;t<o.tmpList.length;t++)e.push(JSON.parse(o.tmpList[t]));o.option.onFlush&&o.option.onFlush(e)})},m.prototype.zip=function(t){var e,o;return"lzw"===this.option.compress?{codes:null,result:y(t)}:"huffman"===this.option.compress?(o=(e=n(a(e=t))).result,{codes:e.codes,result:s(o)}):{codes:null,result:t}},m.prototype.unzip=function(t,e){return"lzw"===this.option.compress?y(t,!0):"huffman"===this.option.compress?s(i(e,a(t))):t},m});
@@ -329,6 +329,10 @@ window.onload = function () {
329
329
  document.dispatchEvent(new Event('visibilitychange'));
330
330
 
331
331
  }, 2000);
332
+
333
+ new Promise((resolve, reject) => {
334
+ reject(new Error('Something went wrong in Promise!'));
335
+ });
332
336
  };
333
337
  </script>
334
338
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spy-client",
3
- "version": "2.1.10",
3
+ "version": "2.1.14",
4
4
  "description": "spy client",
5
5
  "main": "dist/spy-client.js",
6
6
  "module": "dist/spy-client.esm.js",
@@ -16,7 +16,7 @@
16
16
  "example": "npm run dev && echo 'open url http://localhost:8000/example' && python -m SimpleHTTPServer 8000 ",
17
17
  "test": "karma start karma.conf.js",
18
18
  "release_pre": "rm -fr dist && npm run build && npm run lint && npm run test",
19
- "release": "npm version patch && npm publish",
19
+ "release": "npm version patch && npm publish --registry=https://registry.npmjs.org",
20
20
  "release_post": "git push origin master && git push origin --tags"
21
21
  },
22
22
  "directories": {