Socket
Socket
Sign inDemoInstall

line-numbers

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    line-numbers

Add line numbers to a string.


Version published
Maintainers
1
Install size
9.74 kB
Created

Changelog

Source

Version 0.2.0 (2015-02-21) ###

  • Improved: You may now pass an already split string as an array.
  • Changed: options.transform is now passed an object with all the elements of the current line, allowing you to modify any part of it. (Backwards-incompatible change.)

Readme

Source

Overview Build Status

Add line numbers to a string.

var lineNumbers = require("line-numbers")

var string = [
  "function sum(a, b) {",
  "  return a + b;",
  "}"
].join("\n")

lineNumbers(string)
// 1 | function sum(a, b) {
// 2 |   return a + b;
// 3 | }

Installation

  • npm install line-numbers
var lineNumbers = require("line-numbers")

Usage

lineNumbers(code, [options])

Inserts a line number at the beginning of each line in code, which is either a string or an array of strings—one for each line. All the line numbers are of the same width; shorter numbers are padded on the left side.

The return value is of the same type as code.

options:

  • start: Number. The number to use for the first line. Defaults to 1.

  • padding: String. The character to pad numbers with. Defaults to " ".

  • before: String. String to put before the line number. Defaults to " ".

  • after: String. String to put between the line number and the line itself. Defaults to " | ".

  • transform: Function. It is called for each line and passed an object with the following properties:

    • before: options.before
    • number: Number. The current line number.
    • width: Number. The padded width of the line numbers.
    • after: options.after
    • line: String. The current line.

    You may modify the above properties to alter the line numbering for the current line. This is useful if before and after aren’t enough, if you want to colorize the line numbers, or highlight the current line.

License

The X11 (“MIT”) License.

Keywords

FAQs

Last updated on 21 Feb 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc