aboutsummaryrefslogtreecommitdiff
path: root/node_modules/last-line-stream/readme.md
blob: de6922adccbdc1a1a05fd9cbdd04451fabe49af0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# last-line-stream 

> A PassThrough stream that keeps track of last line written.

[![Build Status](https://travis-ci.org/jamestalmage/last-line-stream.svg?branch=master)](https://travis-ci.org/jamestalmage/last-line-stream) [![Coverage Status](https://coveralls.io/repos/jamestalmage/last-line-stream/badge.svg?branch=master&service=github)](https://coveralls.io/github/jamestalmage/last-line-stream?branch=master)


## Install

```
$ npm install --save last-line-stream
```


## Usage

```js
const lastLineStream = require('last-line-stream');

const stream = lastLineStream();

stream.write('foo');

assert(stream.lastLine === 'foo');

stream.write('bar');

assert(stream.lastLine === 'foobar');

stream.write('baz\nquz');

assert(stream.lastLine === 'quz');
```


## API

### lastLineStream([pipeTo])

Returns a new instance of the spying PassThrough stream, 

#### pipeTo

Type: `stream`

If supplied, the new instance will automatically be piped to this stream.

### stream.lastLine

Type: `string`

The last line written out to this stream. The `lastLine` value will grow until the stream sees a newline character (`'\n'`).

## Low Level API

A low-level non-stream based API is available. It has only two methods.

```js
var createTracker = require('last-line-stream/tracker');
var tracker = createTracker();

// append some text.
tracker.update(someString);

// Find the complete last line of all the text appended.
tracker.lastLine();
```

## License

MIT © [James Talmage](http://github.com/jamestalmage)