Line-numbers

line-numbers

Add line numbers to a string.

A humble module that will add line number to a given string! Mostly useful for text editor and displaying some code snippet.

Install it: $ npm install --save line-numbers

Simple usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
var lns = require('line-numbers');

code = `function meow(cb) {
  if(!cb) throw new Error("CB is a must!");
  cb("meow");
}`

console.log( lns(code) );

/*
Would log:

 1 | function meow(cb) { 
 2 |   if(!cb) throw new Error("CB is a must!");
 3 |   cb("meow");
 4 | }
*/

P.S: You can also pass in options like: before, number, width, after and line (They are self explanatory?)

GIF FTW!

line-numbers

Thanks to Simon Lydell for line-numbers.

Suggest a module

Comments