# add-line-numbers

> adds line numbers to a source string

Latest version **1.0.1** (published 2015-06-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install add-line-numbers
pnpm add add-line-numbers
yarn add add-line-numbers
bun add add-line-numbers
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-06-23 |
| First published | 2015-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | add, line, numbers, pad, left, padding, pads, space, indent, num |

## Links

- npm: https://www.npmjs.com/package/add-line-numbers
- Repository: https://github.com/Jam3/add-line-numbers
- Issues: https://github.com/Jam3/add-line-numbers/issues
- npm.io page: https://npm.io/package/add-line-numbers

## Dependencies (1)

- [pad-left](https://npm.io/package/pad-left.md) ^1.0.2

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-06-23
- 1.0.0 — 2015-06-23

## README

# add-line-numbers

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Adds line numbers to a source string, padding left and starting at the given offset.

## Example

#### example.js

```js
var addLineNumbers = require('add-line-numbers')
var stdin = require('get-stdin')

stdin(function (body) {
  var src = addLineNumbers(body.toString())
  process.stdout.write(src + '\n')
})
```

Now run the following in bash:

```sh
node example.js < some-file.js
```

Resulting output:

```js
 1: var addLineNumbers = require('./')
 2: var test = require('tape')
 3: 
 4: test('adds line numbers to a source string', function (t) {
 5:   t.equal(addLineNumbers([
 6:     'one',
 7:     'is second'
 8:   ].join('\r\n')), '1: one\n2: is second', 'return carriage')
 9: 
10:   t.equal(addLineNumbers([
11:     'one',
12:     'is second'
13:   ].join('\n'), 0), '0: one\n1: is second', 'start offset')
14: 
...
```

## Usage

[![NPM](https://nodei.co/npm/add-line-numbers.png)](https://www.npmjs.com/package/add-line-numbers)

#### `str = addLineNumbers(str, start, delimiter)`

Adds a number to the start of each line in the `str` text. 

- `start` (Number) number to start counting at, defaults to 1
- `delimiter` (String) joins the number and line, defaults to `": "`

Returns the transformed string.

## License

MIT, see [LICENSE.md](http://github.com/Jam3/add-line-numbers/blob/master/LICENSE.md) for details.

---
_Source: https://npm.io/package/add-line-numbers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
