aboutsummaryrefslogtreecommitdiff
path: root/node_modules/last-line-stream
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/last-line-stream')
-rw-r--r--node_modules/last-line-stream/index.js24
-rw-r--r--node_modules/last-line-stream/license21
-rw-r--r--node_modules/last-line-stream/package.json44
-rw-r--r--node_modules/last-line-stream/readme.md71
-rw-r--r--node_modules/last-line-stream/tracker.js26
5 files changed, 186 insertions, 0 deletions
diff --git a/node_modules/last-line-stream/index.js b/node_modules/last-line-stream/index.js
new file mode 100644
index 000000000..2ecc37adf
--- /dev/null
+++ b/node_modules/last-line-stream/index.js
@@ -0,0 +1,24 @@
+'use strict';
+var through2 = require('through2');
+var StringDecoder = require('string_decoder').StringDecoder;
+var createTracker = require('./tracker');
+
+module.exports = function (pipeDestination) {
+ var decoder = new StringDecoder();
+ var tracker = createTracker();
+
+ var stream = through2(function (chunk, enc, cb) {
+ tracker.update(decoder.write(chunk));
+ cb(null, chunk);
+ });
+
+ Object.defineProperty(stream, 'lastLine', {
+ get: tracker.lastLine
+ });
+
+ if (pipeDestination) {
+ stream.pipe(pipeDestination);
+ }
+
+ return stream;
+};
diff --git a/node_modules/last-line-stream/license b/node_modules/last-line-stream/license
new file mode 100644
index 000000000..ad5d021ed
--- /dev/null
+++ b/node_modules/last-line-stream/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) James Talmage <james@talmage.io> (github.com/jamestalmage)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/node_modules/last-line-stream/package.json b/node_modules/last-line-stream/package.json
new file mode 100644
index 000000000..a33e93b8d
--- /dev/null
+++ b/node_modules/last-line-stream/package.json
@@ -0,0 +1,44 @@
+{
+ "name": "last-line-stream",
+ "version": "1.0.0",
+ "description": "A PassThrough stream that keeps track of last line written",
+ "license": "MIT",
+ "repository": "jamestalmage/last-line-stream",
+ "author": {
+ "name": "James Talmage",
+ "email": "james@talmage.io",
+ "url": "github.com/jamestalmage"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "xo && nyc --reporter=lcov --reporter=text --cache ava"
+ },
+ "files": [
+ "index.js",
+ "tracker.js"
+ ],
+ "keywords": [
+ "stream",
+ "streams",
+ "line",
+ "lines",
+ "newline",
+ "spy",
+ "last",
+ "passthrough",
+ "pass-through",
+ "pass",
+ "through"
+ ],
+ "dependencies": {
+ "through2": "^2.0.0"
+ },
+ "devDependencies": {
+ "ava": "^0.9.1",
+ "coveralls": "^2.11.6",
+ "nyc": "^5.3.0",
+ "xo": "^0.12.1"
+ }
+}
diff --git a/node_modules/last-line-stream/readme.md b/node_modules/last-line-stream/readme.md
new file mode 100644
index 000000000..de6922adc
--- /dev/null
+++ b/node_modules/last-line-stream/readme.md
@@ -0,0 +1,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)
diff --git a/node_modules/last-line-stream/tracker.js b/node_modules/last-line-stream/tracker.js
new file mode 100644
index 000000000..61728e376
--- /dev/null
+++ b/node_modules/last-line-stream/tracker.js
@@ -0,0 +1,26 @@
+'use strict';
+
+module.exports = function () {
+ var lastLine = [''];
+
+ function update(str) {
+ var idx = str.lastIndexOf('\n');
+ if (idx === -1) {
+ lastLine.push(str);
+ } else {
+ lastLine = [str.substring(idx + 1)];
+ }
+ }
+
+ function getLastLine() {
+ if (lastLine.length > 1) {
+ lastLine = [lastLine.join('')];
+ }
+ return lastLine[0];
+ }
+
+ return {
+ update: update,
+ lastLine: getLastLine
+ };
+};