backtracker
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -5,2 +5,3 @@ "use strict"; | ||
}; | ||
const Caller_1 = __importDefault(require("./Caller")); | ||
@@ -15,6 +16,8 @@ const Stack_1 = __importDefault(require("./Stack")); | ||
]; | ||
class BackTracker { | ||
constructor() { | ||
this.parent = BackTracker.stack.first; | ||
this.parent = BackTracker.stack.first(); | ||
} | ||
static get stack() { | ||
@@ -27,4 +30,6 @@ const stack = new Error().stack; | ||
} | ||
const split = stack.split("\n"); | ||
const frames = split.slice(3, split.length).map(item => item.trim()); | ||
for (const frame of frames) { | ||
@@ -36,2 +41,3 @@ const test1 = evalreg.exec(frame); | ||
} | ||
const test2 = somethingreg.exec(frame); | ||
@@ -42,2 +48,3 @@ if (test2 && test2.length > 0) { | ||
} | ||
const test3 = namedreg.exec(frame); | ||
@@ -48,2 +55,3 @@ if (test3 && test3.length > 0) { | ||
} | ||
const test4 = anonymousreg.exec(frame); | ||
@@ -54,2 +62,3 @@ if (test4 && test4.length > 0) { | ||
} | ||
const test5 = notnamedreg.exec(frame); | ||
@@ -60,2 +69,3 @@ if (test5 && test5.length > 0) { | ||
} | ||
for (const caller of callers) { | ||
@@ -68,2 +78,3 @@ const index = callers.indexOf(caller); | ||
} | ||
module.exports = { | ||
@@ -70,0 +81,0 @@ BackTracker, |
declare class Stack extends Array<import("./Caller")> { | ||
constructor(); | ||
get first(): import("./Caller"); | ||
get last(): import("./Caller"); | ||
first(amount?: number): import("./Caller") | Array<import("./Caller")>; | ||
last(amount?: number): import("./Caller") | Array<import("./Caller")>; | ||
} | ||
export = Stack; |
"use strict"; | ||
class Stack extends Array { | ||
constructor() { | ||
super(); | ||
super(...arguments); | ||
} | ||
get first() { | ||
return this[0]; | ||
first(amount) { | ||
if (!Number.isInteger(amount) || amount === 0) return this[0]; | ||
if (amount < 0) return this.last(amount * -1); | ||
return this.slice(0, amount); | ||
} | ||
get last() { | ||
return this[this.length - 1] || null; | ||
last(amount) { | ||
if (!Number.isInteger(amount) || amount === 0) return this[this.length - 1]; | ||
if (amount < 0) return this.first(amount * -1); | ||
return this.slice(-amount); | ||
} | ||
} | ||
module.exports = Stack; |
{ | ||
"name": "backtracker", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Back track in JS code execution and find where a function was called", | ||
@@ -5,0 +5,0 @@ "main": "dist/index", |
@@ -23,3 +23,3 @@ # BackTracker | ||
console.log("Okay. This is epic."); | ||
console.log(BackTracker.stack.first)); | ||
console.log(BackTracker.stack.first())); | ||
} | ||
@@ -26,0 +26,0 @@ |
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
55883
143