Skip to content

Commit

Permalink
Merge pull request #2 from supernova350/master
Browse files Browse the repository at this point in the history
nullish checking
  • Loading branch information
dsc8x authored Mar 23, 2022
2 parents da34afd + 2bb7048 commit c282311
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/getCallee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ export function getCallee(): Callee {
try {
throw new Error()
} catch (e) {
const line = e.stack.split('\n')[3] || ''
const error = e as Error;

const line = error.stack?.split('\n')[3] ?? ''
const functionNameMatch = line.match(/\w+@|at (([^(]+)) \(.*/)
const functionName = (functionNameMatch && functionNameMatch[1]) || ''

const result = line.match(/(\/[^:]+):([0-9]+):[0-9]+/)
const filePath = result[1] || ''
const lineNumber = result[2] || ''
const filePath = result?.[1] ?? ''
const lineNumber = result?.[2] ?? ''

return {
functionName,
Expand Down

0 comments on commit c282311

Please sign in to comment.