Son CV dans un terminal web en Javascript!
https://terminal-cv.gregandev.fr
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
1 year ago
|
'use strict'
|
||
|
module.exports = prettyError
|
||
|
|
||
|
function prettyError (err, buf) {
|
||
|
/* istanbul ignore if */
|
||
|
if (err.pos == null || err.line == null) return err
|
||
|
let msg = err.message
|
||
|
msg += ` at row ${err.line + 1}, col ${err.col + 1}, pos ${err.pos}:\n`
|
||
|
|
||
|
/* istanbul ignore else */
|
||
|
if (buf && buf.split) {
|
||
|
const lines = buf.split(/\n/)
|
||
|
const lineNumWidth = String(Math.min(lines.length, err.line + 3)).length
|
||
|
let linePadding = ' '
|
||
|
while (linePadding.length < lineNumWidth) linePadding += ' '
|
||
|
for (let ii = Math.max(0, err.line - 1); ii < Math.min(lines.length, err.line + 2); ++ii) {
|
||
|
let lineNum = String(ii + 1)
|
||
|
if (lineNum.length < lineNumWidth) lineNum = ' ' + lineNum
|
||
|
if (err.line === ii) {
|
||
|
msg += lineNum + '> ' + lines[ii] + '\n'
|
||
|
msg += linePadding + ' '
|
||
|
for (let hh = 0; hh < err.col; ++hh) {
|
||
|
msg += ' '
|
||
|
}
|
||
|
msg += '^\n'
|
||
|
} else {
|
||
|
msg += lineNum + ': ' + lines[ii] + '\n'
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
err.message = msg + '\n'
|
||
|
return err
|
||
|
}
|