@jovian/type-tools
Version:
TypeTools is a Typescript library for providing extensible tooling runtime validations and type helpers.
96 lines • 3.07 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.spotfull = exports.spot = exports.StackUtilSourceMapEnv = void 0;
var StackUtilSourceMapEnv = (function () {
function StackUtilSourceMapEnv() {
}
StackUtilSourceMapEnv.isBrowser = false;
StackUtilSourceMapEnv.isTypescript = false;
return StackUtilSourceMapEnv;
}());
exports.StackUtilSourceMapEnv = StackUtilSourceMapEnv;
function spot(e, step) {
if (e === void 0) { e = new Error(); }
if (step === void 0) { step = 2; }
var source;
if (e.stack.startsWith('Error') && !StackUtilSourceMapEnv.isTypescript) {
var targetLine = e.stack.split('\n')[step];
if (!targetLine) {
return null;
}
if (targetLine.charAt(targetLine.length - 1) === ')') {
source = targetLine.split('/').pop().split(')')[0];
}
else {
source = targetLine.split('/').pop();
}
}
else {
var stack = void 0;
if (StackUtilSourceMapEnv.isBrowser) {
var stackLit = e.stack.split('\n at');
stackLit.shift();
stack = '\n at' + stackLit.join('\n at');
}
else {
var stackLit = e.stack.split('\nError');
stackLit.shift();
stack = stackLit.join('\nError');
}
var targetLine = stack.split('\n')[step];
if (!targetLine) {
return null;
}
if (targetLine.charAt(targetLine.length - 1) === ')') {
source = targetLine.split('/').pop().split(')')[0];
}
else {
source = targetLine.split('/').pop();
}
}
return source;
}
exports.spot = spot;
function spotfull(e, step) {
if (e === void 0) { e = new Error(); }
if (step === void 0) { step = 2; }
var source;
if (e.stack.startsWith('Error') && !StackUtilSourceMapEnv.isTypescript) {
var targetLine = e.stack.split('\n')[step];
if (!targetLine) {
return null;
}
if (targetLine.charAt(targetLine.length - 1) === ')') {
source = targetLine.split('(')[1].split(')')[0];
}
else {
source = targetLine.split('at ')[1];
}
}
else {
var stack = void 0;
if (StackUtilSourceMapEnv.isBrowser) {
var stackLit = e.stack.split('\n at');
stackLit.shift();
stack = '\n at' + stackLit.join('\n at');
}
else {
var stackLit = e.stack.split('\nError');
stackLit.shift();
stack = stackLit.join('\nError');
}
var targetLine = stack.split('\n')[step];
if (!targetLine) {
return null;
}
if (targetLine.charAt(targetLine.length - 1) === ')') {
source = targetLine.split('(')[1].split(')')[0];
}
else {
source = targetLine.split('at ')[1];
}
}
return source;
}
exports.spotfull = spotfull;
//# sourceMappingURL=stack.util.js.map
;