Display an arrow in a string of code to point to a location


Add line numbers and an arrow to a string of code that points to a specific location.

npm install pinpoint

With this code:

function add(leftright) {
  return left + right;
console.log(add(1 + 1));

When being asked to point to line 2 and column 2, generates this:

1function add(leftright) {
2|   return left + right;
5console.log(add(1 + 1));
var pinpoint = require('pinpoint');
var str = pinpoint(code, options);
  • code - a string of code
  • options - an object literal supports these options:
    • line - the line number to point to, 1-based.
    • column - the column number to point to, 1-based.
    • showLines - the number of lines to show. The pointed line will try to stay in the middle of the displays lines.
    • indent - indent string prepend to each line, before the line number.
    • tabSize - width of a tab character.