-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
78 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 +1,7 @@ | ||
{ | ||
"name": "multithreading", | ||
"version": "0.1.15", | ||
"description": "⚡ Multithreading functions in JavaScript, designed to be as simple and fast as possible.", | ||
"version": "0.1.16", | ||
"description": "⚡ Multithreading functions in JavaScript to speedup heavy workloads, designed to feel like writing vanilla functions.", | ||
"author": "Walter van der Giessen <[email protected]>", | ||
"homepage": "https://multithreading.io", | ||
"license": "MIT", | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const colorRed = "\x1b[31m"; | ||
const colorReset = "\x1b[39m"; | ||
|
||
export function getErrorPreview(error: Error) { | ||
const [message, ...serializedStackFrames] = error.stack!.split("\n"); | ||
|
||
const stackFrame = decodeURIComponent(serializedStackFrames[0]); | ||
|
||
const [functionPart, ...otherParts] = stackFrame.split( | ||
" (data:text/javascript;charset=utf-8," | ||
); | ||
|
||
const other = otherParts.join(); | ||
const codeLines = other.split(/\r?\n/); | ||
const lastLine = codeLines.pop()!; | ||
|
||
const [lineNumber, columnNumber] = lastLine | ||
.slice(0, -1) | ||
.split(":") | ||
.slice(-2) | ||
.map((n) => parseInt(n)); | ||
|
||
const amountOfPreviousLines = Math.min(3, lineNumber - 1); | ||
const amountOfNextLines = 2; | ||
|
||
const previewLines = codeLines.slice( | ||
lineNumber - (amountOfPreviousLines + 1), | ||
lineNumber + amountOfNextLines | ||
); | ||
|
||
const previousLineLength = | ||
codeLines[lineNumber - 1].trimEnd().length - columnNumber; | ||
|
||
previewLines.splice( | ||
amountOfPreviousLines + 1, | ||
0, | ||
colorRed + | ||
" ".repeat(columnNumber - 1) + | ||
"^".repeat(previousLineLength) + | ||
" " + | ||
message + | ||
colorReset | ||
); | ||
|
||
const preview = | ||
`${error.name} ${functionPart.trim()}:\n\n` + previewLines.join("\n"); | ||
|
||
return preview; | ||
} |
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