(errorOrStack, options = {})
| 195 | |
| 196 | // ---------- Pretty Stack ----------- |
| 197 | function prettyStack(errorOrStack, options = {}) { |
| 198 | const { |
| 199 | stripQuery = true, |
| 200 | decode = true, |
| 201 | maxUrlLength = 90, |
| 202 | dropExtensionUuid = true, |
| 203 | pathSegments = 2, |
| 204 | indent = " ", |
| 205 | minFnWidth = 8, |
| 206 | maxFnWidth = 48, |
| 207 | minLocWidth = 5, |
| 208 | maxLocWidth = 12, |
| 209 | maxLines = -1, |
| 210 | } = options; |
| 211 | |
| 212 | const rawStack = |
| 213 | typeof errorOrStack === "string" |
| 214 | ? errorOrStack |
| 215 | : errorOrStack && errorOrStack.stack |
| 216 | ? errorOrStack.stack |
| 217 | : String(errorOrStack); |
| 218 | |
| 219 | const lines = rawStack.split(/\r?\n/).filter(Boolean); |
| 220 | |
| 221 | const frames = lines |
| 222 | .filter((line, j) => maxLines > 0 ? j < maxLines : true) |
| 223 | .map(parseStackLine) |
| 224 | .filter(Boolean) |
| 225 | .map(frame => ({ |
| 226 | ...frame, |
| 227 | fn: cleanFunctionName(frame.fn), |
| 228 | file: cleanFileName(frame.file, { |
| 229 | stripQuery, |
| 230 | decode, |
| 231 | maxUrlLength, |
| 232 | dropExtensionUuid, |
| 233 | pathSegments, |
| 234 | }), |
| 235 | })); |
| 236 | |
| 237 | if (!frames.length) return rawStack; |
| 238 | |
| 239 | const fnWidth = clamp( |
| 240 | frames.reduce((max, f) => Math.max(max, f.fn.length), minFnWidth), |
| 241 | minFnWidth, |
| 242 | maxFnWidth |
| 243 | ); |
| 244 | |
| 245 | const locWidth = clamp( |
| 246 | frames.reduce((max, f) => { |
| 247 | return Math.max(max, `${f.line}:${f.col}`.length); |
| 248 | }, minLocWidth), |
| 249 | minLocWidth, |
| 250 | maxLocWidth |
| 251 | ); |
| 252 | |
| 253 | return frames |
| 254 | .map(f => { |
no test coverage detected