Skip to content

Commit

Permalink
account for functions that have weird names (usually webpack imports)
Browse files Browse the repository at this point in the history
  • Loading branch information
santiago-elustondo committed Jun 1, 2018
1 parent a980be6 commit e983e9c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/utils/function-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ export const functionName = (fn: Function): string => {
if (name == null || name.length === 0) {
const match = extract(fn.toString());
if (match != null && match.length > 1) {
return match[1];
name = match[1];
}
return 'anonymous';
}

name = name.replace(/[^\w]/gi, '')

if (typeof name != 'string' || name == '') {
name = 'anonymous';
}

if (!isNaN(parseInt(name[0]))) {
name = '__num_' + name[0];
}

return name;
};

0 comments on commit e983e9c

Please sign in to comment.