UNPKG

@kwiz/common

Version:

KWIZ common utilities and helpers for M365 platform

21 lines 1.04 kB
import { firstOrNull } from "./collections.base"; import { isNotEmptyArray } from "./typecheckers"; export const getStackCallersDefaultFilter = () => ['node_modules', 'node:internal']; /** looks through the current call stack to find all calling functions. default filter: ['node_modules','node:internal'] */ export function getStackCallers(levels, skip, filter) { filter = isNotEmptyArray(filter) ? filter : getStackCallersDefaultFilter(); const allLines = new Error().stack.split('\n'); const stack = allLines .filter(s => s.indexOf('at ') > 0) .map(s => { const value = s.slice(s.indexOf(' at ') + 4).split(' '); return value[0] === "async" ? value[1] : value[0]; }) //filter based on the names... .filter(s => !firstOrNull(filter, f => s.includes(f))) .reverse(); const end = (skip > 0 ? skip + 1 : 1) * -1; const start = levels > 0 ? stack.length - levels + end : 0; return stack.slice(start > 0 ? start : 0, end); } //# sourceMappingURL=console.js.map