Comparing version 1.8.0 to 1.8.1
@@ -62,2 +62,17 @@ const DEFAULT_MAX_AGE = 3e3; | ||
const cache = _globalStore[globalKey]; | ||
let callStack = ""; | ||
const printLogs = (...msg) => { | ||
if (console.groupCollapsed) { | ||
console.groupCollapsed(...msg); | ||
console.log("globalKey:", globalKey); | ||
console.log("callStack:", callStack); | ||
console.log("data:", cache[ | ||
2 | ||
/* resData */ | ||
]); | ||
console.groupEnd(); | ||
} else { | ||
console.log(...msg); | ||
} | ||
}; | ||
const reset = () => { | ||
@@ -92,7 +107,10 @@ cache[ | ||
if (i === 0) { | ||
console.log(`[idmp info] ${globalKey == null ? void 0 : globalKey.toString()} from origin`); | ||
printLogs( | ||
`%c[idmp info] ${globalKey == null ? void 0 : globalKey.toString()} from origin`, | ||
"font-weight: lighter" | ||
); | ||
} else { | ||
console.log( | ||
printLogs( | ||
`%c[idmp info] ${globalKey == null ? void 0 : globalKey.toString()} from cache`, | ||
"color: gray" | ||
"color: gray; font-weight: lighter" | ||
); | ||
@@ -143,2 +161,28 @@ } | ||
} catch (err) { | ||
const getCodeLine = (stack, offset = 0) => { | ||
try { | ||
let arr = stack.split("\n").filter((o) => o.includes(":")); | ||
let idx = Infinity; | ||
$0: | ||
for (let key of [ | ||
"idmp/src/index.ts", | ||
"idmp/", | ||
"idmp\\", | ||
"idmp" | ||
]) { | ||
let _idx = arr.length - 1; | ||
$1: | ||
for (; _idx >= 0; --_idx) { | ||
if (arr[_idx].indexOf(key) > -1) { | ||
idx = _idx; | ||
break $0; | ||
} | ||
} | ||
} | ||
const line = arr[idx + offset + 1] || ""; | ||
return line; | ||
} catch (e) { | ||
} | ||
}; | ||
callStack = getCodeLine(err.stack, 1).split(" ").pop() || ""; | ||
!cache[ | ||
@@ -155,27 +199,2 @@ 6 | ||
] !== err.stack) { | ||
const getCodeLine = (stack) => { | ||
try { | ||
const arr = stack.split("\n").filter((o) => o.includes(":")); | ||
let idx = Infinity; | ||
$0: | ||
for (let key of [ | ||
"idmp/src/index.ts", | ||
"idmp/", | ||
"idmp\\", | ||
"idmp" | ||
]) { | ||
let _idx = arr.length - 1; | ||
$1: | ||
for (; _idx >= 0; --_idx) { | ||
if (arr[_idx].indexOf(key) > -1) { | ||
idx = _idx; | ||
break $0; | ||
} | ||
} | ||
} | ||
const line = arr[idx + 1] || ""; | ||
return line; | ||
} catch (e) { | ||
} | ||
}; | ||
const line1 = getCodeLine(cache[ | ||
@@ -204,5 +223,5 @@ 6 | ||
if (process.env.NODE_ENV !== "production") { | ||
console.log( | ||
printLogs( | ||
`%c[idmp info] \`${globalKey == null ? void 0 : globalKey.toString()}\` from cache`, | ||
"color: gray" | ||
"color: gray;font-weight: lighter" | ||
); | ||
@@ -209,0 +228,0 @@ } |
{ | ||
"name": "idmp", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "cache response", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65928
1035