-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(functions): added support for prefixing traced function name wit…
…h layer
- Loading branch information
1 parent
6f8d322
commit 22ec0bf
Showing
3 changed files
with
16 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import chalk from "chalk"; | ||
|
||
export const fnName = (fn) => { | ||
export const fnName = (fn, prefix) => { | ||
let name = fn.name; | ||
while (1) { | ||
const replaced = name?.replace("bound", ""); | ||
if (name.startsWith("bound") && replaced?.startsWith(" ")) name = replaced?.trim(); | ||
else break; | ||
} | ||
if (!name) return coloredFnName("Unnamed function"); | ||
if (!name) return coloredFnName("Unnamed function", prefix); | ||
if (name.startsWith(" ")) return name.slice(1); | ||
return coloredFnName(name); | ||
return coloredFnName(name, prefix); | ||
}; | ||
|
||
export const coloredFnName = (fn) => chalk.bold(chalk.magentaBright(fn)); | ||
export const coloredFnName = (fn, prefix) => chalk.bold(chalk.magentaBright(prefix ? `${prefix}->${fn}` : fn)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters