Skip to content

Instantly share code, notes, and snippets.

@ndayananda
Created September 7, 2021 06:59
Show Gist options
  • Save ndayananda/de3da538037462caa251fafc8713f568 to your computer and use it in GitHub Desktop.
Save ndayananda/de3da538037462caa251fafc8713f568 to your computer and use it in GitHub Desktop.
const getCallerName = () => {
const stackTrace: any = new Error().stack || '';
let callerName = stackTrace.replace(/^Error\s+/, ''); // Sanitize Chrome
callerName = callerName.split('\n')[2]; // 1st item is this, 2nd item is caller
callerName = callerName.replace(/^\s+at Object./, ''); // Sanitize Chrome
callerName = callerName.replace(/ \(.+\)$/, ''); // Sanitize Chrome
return callerName.replace('at ', '');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment