spy-client 2.1.12 → 2.1.15
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.
- package/README.md +4 -1
- package/dist/head/base.d.ts +3 -2
- package/dist/lib/interface.d.ts +13 -13
- package/dist/lib/spyHeadInterface.d.ts +8 -0
- package/dist/spy-client-basic.d.ts +14 -0
- package/dist/spy-client-basic.esm.js +12 -8
- package/dist/spy-client-basic.iife.js +13 -9
- package/dist/spy-client-basic.iife.min.js +1 -1
- package/dist/spy-client-basic.js +14 -10
- package/dist/spy-client-basic.min.js +1 -1
- package/dist/spy-client-basic.mjs +12 -8
- package/dist/spy-client.esm.js +22 -18
- package/dist/spy-client.iife.js +23 -19
- package/dist/spy-client.iife.min.js +1 -1
- package/dist/spy-client.js +24 -20
- package/dist/spy-client.min.js +1 -1
- package/dist/spy-client.mjs +22 -18
- package/dist/spy-head.js +22 -18
- package/dist/spy-head.min.js +1 -1
- package/dist/spy-local-cache.js +12 -12
- package/dist/spy-local-cache.min.js +1 -1
- package/package.json +1 -1
package/dist/spy-head.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.__spyHead = factory());
|
|
5
|
-
}(this, (function () { 'use strict';
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @file utils
|
|
@@ -92,6 +92,9 @@
|
|
|
92
92
|
init: function (conf) {
|
|
93
93
|
this.conf = conf;
|
|
94
94
|
},
|
|
95
|
+
update: function (conf) {
|
|
96
|
+
this.conf = Object.assign(this.conf, conf || {});
|
|
97
|
+
},
|
|
95
98
|
addError: function (obj) {
|
|
96
99
|
// 有些错误一下出现很多次,都聚合都一个错误,加上次数
|
|
97
100
|
if (this.winerrors.length > 0) {
|
|
@@ -117,8 +120,8 @@
|
|
|
117
120
|
return;
|
|
118
121
|
}
|
|
119
122
|
logServer = logServer || conf.logServer;
|
|
120
|
-
var logUrl = logServer
|
|
121
|
-
+
|
|
123
|
+
var logUrl = "".concat(logServer, "?pid=").concat(obj.pid, "&lid=").concat(obj.lid, "&ts=").concat(obj.ts)
|
|
124
|
+
+ "&type=".concat(obj.type, "&group=").concat(obj.group, "&info=").concat(encodeURIComponent(JSON.stringify(obj.info)));
|
|
122
125
|
if (obj.dim) {
|
|
123
126
|
logUrl += '&dim=' + encodeURIComponent(JSON.stringify(obj.dim));
|
|
124
127
|
}
|
|
@@ -148,12 +151,12 @@
|
|
|
148
151
|
var info = obj.info;
|
|
149
152
|
var srcElement = event.srcElement;
|
|
150
153
|
// 设备信息
|
|
151
|
-
|
|
152
|
-
info.downlink = dataConnection.downlink; // 网站下载速度 M/s
|
|
153
|
-
info.effectiveType = dataConnection.effectiveType; // 网络类型
|
|
154
|
-
info.rtt = dataConnection.rtt; // 网络往返时间 ms
|
|
155
|
-
info.deviceMemory = navigator.deviceMemory || 0;
|
|
156
|
-
info.hardwareConcurrency = navigator.hardwareConcurrency || 0;
|
|
154
|
+
// const dataConnection = navigator.connection || {};
|
|
155
|
+
// info.downlink = dataConnection.downlink; // 网站下载速度 M/s
|
|
156
|
+
// info.effectiveType = dataConnection.effectiveType; // 网络类型
|
|
157
|
+
// info.rtt = dataConnection.rtt; // 网络往返时间 ms
|
|
158
|
+
// info.deviceMemory = navigator.deviceMemory || 0;
|
|
159
|
+
// info.hardwareConcurrency = navigator.hardwareConcurrency || 0;
|
|
157
160
|
// JS错误
|
|
158
161
|
if (srcElement === window) {
|
|
159
162
|
obj.group = jsError.group;
|
|
@@ -177,7 +180,7 @@
|
|
|
177
180
|
var historys = [];
|
|
178
181
|
for (var index = 0; index < winerrors.length; index++) {
|
|
179
182
|
var item = winerrors[index];
|
|
180
|
-
var prefix = item.info.count > 1 ? "("
|
|
183
|
+
var prefix = item.info.count > 1 ? "(".concat(item.info.count, ")") : '';
|
|
181
184
|
historys.push(prefix + item.info.msg);
|
|
182
185
|
}
|
|
183
186
|
info.hisErrors = historys.join('----');
|
|
@@ -281,11 +284,11 @@
|
|
|
281
284
|
return false;
|
|
282
285
|
}
|
|
283
286
|
var pf = getResTiming(window.performance.timing);
|
|
284
|
-
var netStr = "&wait="
|
|
285
|
-
+
|
|
286
|
-
+
|
|
287
|
-
+
|
|
288
|
-
+
|
|
287
|
+
var netStr = "&wait=".concat(pf.wait)
|
|
288
|
+
+ "&dns=".concat(pf.dns)
|
|
289
|
+
+ "&connect=".concat(pf.connect)
|
|
290
|
+
+ "&requestTime=".concat(pf.req)
|
|
291
|
+
+ "&resoneTime=".concat(pf.res);
|
|
289
292
|
return netStr;
|
|
290
293
|
}
|
|
291
294
|
// 补充白屏信息:期间发生的JS Error 和 资源 Error
|
|
@@ -297,7 +300,7 @@
|
|
|
297
300
|
var historys = [];
|
|
298
301
|
for (var i = 0; i < errors.length; i++) {
|
|
299
302
|
var stack = (errors[i].info.stack || '').split('\n')[0];
|
|
300
|
-
historys.push("("
|
|
303
|
+
historys.push("(".concat(i, ")").concat(stack || errors[i].info.msg));
|
|
301
304
|
}
|
|
302
305
|
return historys.join(';;');
|
|
303
306
|
}
|
|
@@ -368,8 +371,9 @@
|
|
|
368
371
|
// 兼容全局变量定义的初始化方式
|
|
369
372
|
if (window.__spyclientConf) {
|
|
370
373
|
spyHead.init(window.__spyclientConf);
|
|
371
|
-
}
|
|
374
|
+
}
|
|
375
|
+
window.__spyHead = window.__spyHead || spyHead;
|
|
372
376
|
|
|
373
377
|
return spyHead;
|
|
374
378
|
|
|
375
|
-
}))
|
|
379
|
+
}));
|
package/dist/spy-head.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
((e,n)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).__spyHead=n()})(this,function(){function y(e){var n,r=(e=>{if(URL&&e)try{var n=new URL(e);if(void 0!==n.host)return{protocol:n.protocol,host:n.host,pathname:n.pathname,ext:""}}catch(e){console.error(e)}})(e),e=(r||((n=document.createElement("a")).href=e,r={protocol:n.protocol,host:n.host||location.host,pathname:n.pathname,ext:""}),r.pathname.split("."));return r.ext=e[e.length-1],r}function n(e){return+e.toFixed(1)}var E={conf:{},winerrors:[],errorDestroy:function(){},observerDestroy:function(){},entryMap:{},init:function(e){this.conf=e},update:function(e){this.conf=Object.assign(this.conf,e||{})},addError:function(e){if(0<this.winerrors.length){var n=this.winerrors[this.winerrors.length-1];if(e.info.msg===n.info.msg)return void(n.info.count+=n.info.count||0)}this.winerrors.length<1e3&&this.winerrors.push(e)},send:function(e,n,r){var t,o=this.conf;e.type=e.type||"except",e.pid=o.pid,e.lid=o.lid,e.ts=Date.now(),this.addError(e),this.interceptor&&this.interceptor(e),!1!==n&&(r=r||o.logServer,n="".concat(r,"?pid=").concat(e.pid,"&lid=").concat(e.lid,"&ts=").concat(e.ts)+"&type=".concat(e.type,"&group=").concat(e.group,"&info=").concat(encodeURIComponent(JSON.stringify(e.info))),e.dim&&(n+="&dim="+encodeURIComponent(JSON.stringify(e.dim))),(t=new Image).src=n,t.onload=t.onerror=function(){t=null})}};function r(e){var h=e.resourceError||{},l=e.jsError||{},m=Math.random()<(l.sample||0),g=Math.random()<(h.sample||0),w=E.winerrors,v=0;function n(e){try{var n=e.target,r={info:{},dim:{},group:""},t=r.info,o=e.srcElement;if(o===window){r.group=l.group;for(var i,s=e.error||e.reason||{},a=(t.msg=e.message||s.message||"",t.file=e.filename,t.ln=e.lineno,t.col=e.colno,t.stack=(s.stack||"").split("\n").slice(0,3).join("\n"),-1!==t.msg.indexOf("MODULE_TIMEOUT")&&(i=t.msg.match(/^.*Hang:(.*); Miss:(.*)/))&&i[2]&&(t.msg="MODULE_TIMEOUT for miss:"+i[2]),[]),c=0;c<w.length;c++){var d=w[c],f=1<d.info.count?"(".concat(d.info.count,")"):"";a.push(f+d.info.msg)}t.hisErrors=a.join("----");var p=!0;!1!==(p=l.handler?l.handler(r):p)&&E.send(r,m)}else{r.group=h.group,r.dim.type=o.tagName.toLowerCase();var u=o.src||o.href||"";-1<u.indexOf("/mwb2.gif?")||(t.msg=u||"unknown load eror",r.dim.host=y(u).host,n&&"IMG"===n.tagName&&(t.xpath=(e=>{if(!e)return{xpath:""};for(var n=[];e&&1===e.nodeType&&e!==e.parentNode;){var r=e.tagName.toLowerCase();if(e.getAttribute("id")?r+="[#"+e.getAttribute("id")+"]":e.classList&&e.classList.length&&(r+="[."+e.classList[e.classList.length-1]+"]"),n.push(r),e===document.body)break;e=e.parentNode}return{xpath:n.join("<")}})(n).xpath),v&&(t.hisErrCount=v),!(p=!0)!==(p=h.handler?h.handler(r):p)&&E.send(r,g),v++)}}catch(e){console.error(e)}}window.addEventListener("error",n,!0),window.addEventListener("unhandledrejection",n,!0),E.errorDestroy=function(){window.removeEventListener("error",n,!0),window.removeEventListener("unhandledrejection",n,!0),E.winerrors=[]}}function t(e){var t=e.whiteScreenError||{},o=t.handler,i=t.selector,s=t.subSelector,e=t.timeout||6e3,a=Math.random()<(t.sample||0);function c(){var e;return!!window.performance&&(e={wait:n((e=window.performance.timing).domainLookupStart-(e.navigationStart||e.fetchStart||e.startTime)),dns:n(e.domainLookupEnd-e.domainLookupStart),connect:n(e.connectEnd-e.connectStart),req:n(e.responseStart-e.requestStart),res:n(e.responseEnd-e.responseStart)},"&wait=".concat(e.wait)+"&dns=".concat(e.dns)+"&connect=".concat(e.connect)+"&requestTime=".concat(e.req)+"&resoneTime=".concat(e.res))}i&&setTimeout(function(){var e,n,r;(r=document.querySelector(i))&&r.querySelector(s)&&!(r.clientHeight<2*window.innerHeight/3)||(r=!0,!((n={group:t.group,info:{msg:"",netTime:c(),hisErrors:(()=>{if(!E.winerrors)return!1;for(var e=E.winerrors,n=[],r=0;r<e.length;r++){var t=(e[r].info.stack||"").split("\n")[0];n.push("(".concat(r,")").concat(t||e[r].info.msg))}return n.join(";;")})(),deviceInfo:(e={},n=navigator.connection||{},e.downlink=n.downlink,e.effectiveType=n.effectiveType,e.rtt=n.rtt,e.deviceMemory=navigator.deviceMemory||0,e.hardwareConcurrency=navigator.hardwareConcurrency||0,e)}}).info.msg="WhiteScren Error")!==(r=o?o(n):r)&&n.info.msg&&E&&E.send(n,a))},e)}return E.init=function(e){if(e.logServer||(e.logServer="https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif"),r(this.conf=e),window.PerformanceObserver){var n=new window.PerformanceObserver(function(e){for(var n=E.entryMap,r=e.getEntries(),t=0;t<r.length;t++){var o=r[t];n[o.entryType]||(n[o.entryType]=[]),n[o.entryType].push(o)}});E.observerDestroy=function(){n.disconnect()};try{n.observe({entryTypes:["longtask","layout-shift","first-input","largest-contentful-paint"]})}catch(e){}}t(e)},window.__spyclientConf&&E.init(window.__spyclientConf),window.__spyHead=window.__spyHead||E,E});
|
package/dist/spy-local-cache.js
CHANGED
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SpyLocalCache = factory());
|
|
5
|
-
}(this, (function () { 'use strict';
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*! *****************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
10
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
11
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
16
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
***************************************************************************** */
|
|
21
21
|
/* global Reflect, Promise */
|
|
22
22
|
|
|
@@ -749,4 +749,4 @@
|
|
|
749
749
|
|
|
750
750
|
return SpyLocalCache;
|
|
751
751
|
|
|
752
|
-
}))
|
|
752
|
+
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
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});
|