Skip to content

Instantly share code, notes, and snippets.

@lsongdev
Last active August 10, 2017 09:17
Show Gist options
  • Save lsongdev/0e54610db7b134c95350aaf0dcc98608 to your computer and use it in GitHub Desktop.
Save lsongdev/0e54610db7b134c95350aaf0dcc98608 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const draw = (src, line, column, n) => {
n = n || 3;
const lines = src.split('\n');
const start = Math.max(line - n, 0);
const end = Math.min(lines.length, line + n);
const context = lines.slice(start, end).map((text, i) => {
const curr = start + i + 1;
const out = `${curr} ${text}`;
if(curr === line && column){
out += '\n>' + '-'.repeat(column) + '^';
}
return out;
}).join('\n');
return context;
}
console.log(draw(fs.readFileSync('error-context.js', 'utf8'), 7, 24));
@lsongdev
Copy link
Author

screen shot 2017-08-10 at 4 35 42 pm

@terry3
Copy link

terry3 commented Aug 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment