@slimio/pretty-stack
Advanced tools
Comparing version 0.4.0 to 0.4.1
27
index.js
@@ -51,2 +51,16 @@ "use strict"; | ||
/** | ||
* @function getPattern | ||
* @param {!string} line | ||
* @returns {any} | ||
*/ | ||
function getPattern(line) { | ||
const result = /at\s(.*)\s\((.*)\)/.exec(line); | ||
if (result !== null) { | ||
return result; | ||
} | ||
return /at\s(.*)/.exec(line); | ||
} | ||
/** | ||
* @function prettyStack | ||
@@ -63,4 +77,5 @@ * @param {!Error} error | ||
console.log("\n " + bgRed(white().bold(` ${arrStack.shift()} `)) + "\n"); | ||
// console.log(arrStack); | ||
for (const line of arrStack) { | ||
const result = /at\s(.*)\s\((.*)\)/.exec(line); | ||
const result = getPattern(line); | ||
if (result === null) { | ||
@@ -76,3 +91,3 @@ continue; | ||
path = at; | ||
at = ""; | ||
at = null; | ||
} | ||
@@ -83,5 +98,5 @@ | ||
console.log( | ||
gray().bold(` o at ${white().bold(at)} (${cyan().bold(fileName)} ${yellow().bold(`at line ${fileLine}`)})`) | ||
); | ||
const linePosition = `${cyan().bold(fileName)} ${yellow().bold(`at line ${fileLine}`)}`; | ||
const lineToLog = at === null ? linePosition : `at ${white().bold(at)} (${linePosition})`; | ||
console.log(gray().bold(` o ${lineToLog}`)); | ||
if (!mem.has(fullName)) { | ||
@@ -95,3 +110,3 @@ console.log(gray().bold(` ${path}\n`)); | ||
console.log(""); | ||
const [, at, path = at] = /at\s(.*)\s\((.*)\)/.exec(firstStack); | ||
const [, at, path = at] = getPattern(firstStack); | ||
const [fileName, line, char] = basename(path).split(":"); | ||
@@ -98,0 +113,0 @@ |
{ | ||
"name": "@slimio/pretty-stack", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Pretty Stack Trace to stdout in TTY", | ||
@@ -41,11 +41,11 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@commitlint/cli": "^8.1.0", | ||
"@commitlint/config-conventional": "^8.1.0", | ||
"@commitlint/cli": "^8.2.0", | ||
"@commitlint/config-conventional": "^8.2.0", | ||
"@escommunity/minami": "^1.0.0", | ||
"@slimio/eslint-config": "^3.0.3", | ||
"@slimio/psp": "^0.7.0", | ||
"ava": "^2.3.0", | ||
"cross-env": "^5.2.0", | ||
"eslint": "^6.3.0", | ||
"husky": "^3.0.4", | ||
"@slimio/eslint-config": "^4.0.0-next.2", | ||
"@slimio/psp": "^0.8.0", | ||
"ava": "^2.4.0", | ||
"cross-env": "^6.0.3", | ||
"eslint": "^6.5.1", | ||
"husky": "^3.0.8", | ||
"jsdoc": "^3.6.3", | ||
@@ -52,0 +52,0 @@ "nyc": "^14.1.1", |
# pretty-stack | ||
 | ||
[](https://github.com/SlimIO/is/commit-activity) | ||
 | ||
[](https://github.com/SlimIO/pretty-stack/commit-activity) | ||
 | ||
 | ||
 | ||
@@ -30,8 +32,12 @@ Pretty Stack Trace to stdout in TTY. Use clean-stack of sindresorhus under the hood to improve the whole experience. | ||
const err = new Error("hello world!"); | ||
prettyStack(err); | ||
prettyStack(err, true); | ||
// or go with the stack array | ||
prettyStack(err.stack, false); | ||
``` | ||
## API | ||
TBC | ||
### prettyStack(error: Error | string | string[], printFile?: boolean): void | ||
This method can handle many input types. In case the input is a string it will be splitted by `\n`. | ||
## Dependencies | ||
@@ -38,0 +44,0 @@ |
8711
120
51