Browse Source

Initial commit

Sven Slootweg 4 years ago
parent
commit
6f81270dd1
7 changed files with 100 additions and 1 deletions
  1. 2 1
      .gitignore
  2. 1 0
      .npmignore
  3. 29 0
      README.md
  4. 18 0
      gulpfile.js
  5. 3 0
      index.js
  6. 29 0
      package.json
  7. 18 0
      src/index.js

+ 2 - 1
.gitignore

@ -2,4 +2,5 @@
2 2
# https://help.github.com/articles/ignoring-files
3 3
# Example .gitignore files: https://github.com/github/gitignore
4 4
/bower_components/
5
/node_modules/
5
/node_modules/
6
/lib/

+ 1 - 0
.npmignore

@ -0,0 +1 @@
1
/node_modules/

+ 29 - 0
README.md

@ -0,0 +1,29 @@
1
# stream-to-logger
2
3
TODO
4
5
## License
6
7
[WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), whichever you prefer. A donation and/or attribution are appreciated, but not required.
8
9
## Donate
10
11
My income consists largely of donations for my projects. If this module is useful to you, consider [making a donation](http://cryto.net/~joepie91/donate.html)!
12
13
You can donate using Bitcoin, PayPal, Flattr, cash-in-mail, SEPA transfers, and pretty much anything else.
14
15
## Contributing
16
17
Pull requests welcome. Please make sure your modifications are in line with the overall code style, and ensure that you're editing the files in `src/`, not those in `lib/`.
18
19
Build tool of choice is `gulp`; simply run `gulp` while developing, and it will watch for changes.
20
21
Be aware that by making a pull request, you agree to release your modifications under the licenses stated above.
22
23
## Usage
24
25
TODO
26
27
## API
28
29
TODO

+ 18 - 0
gulpfile.js

@ -0,0 +1,18 @@
1
var gulp = require("gulp");
2
var presetES2015 = require("@joepie91/gulp-preset-es2015");
3
4
var source = ["src/**/*.js"]
5
6
gulp.task('babel', function() {
7
	return gulp.src(source)
8
		.pipe(presetES2015({
9
			basePath: __dirname
10
		}))
11
		.pipe(gulp.dest("lib/"));
12
});
13
14
gulp.task("watch", function () {
15
	gulp.watch(source, ["babel"]);
16
});
17
18
gulp.task("default", ["babel", "watch"]);

+ 3 - 0
index.js

@ -0,0 +1,3 @@
1
'use strict';
2
3
module.exports = require("./lib");

+ 29 - 0
package.json

@ -0,0 +1,29 @@
1
{
2
  "name": "stream-to-logger",
3
  "version": "0.0.1",
4
  "description": "Calls a logger function for each line in a stream",
5
  "main": "index.js",
6
  "scripts": {
7
    "test": "echo \"Error: no test specified\" && exit 1"
8
  },
9
  "repository": {
10
    "type": "git",
11
    "url": "http://git.cryto.net/joepie91/node-stream-to-logger.git"
12
  },
13
  "keywords": [
14
    "stream",
15
    "logging"
16
  ],
17
  "author": "Sven Slootweg",
18
  "license": "WTFPL",
19
  "dependencies": {
20
    "split": "^1.0.0",
21
    "stream-combiner2": "^1.1.1",
22
    "through2-sink": "^1.0.0"
23
  },
24
  "devDependencies": {
25
    "@joepie91/gulp-preset-es2015": "^1.0.1",
26
    "babel-preset-es2015": "^6.6.0",
27
    "gulp": "^3.9.1"
28
  }
29
}

+ 18 - 0
src/index.js

@ -0,0 +1,18 @@
1
'use strict';
2
3
const split = require("split");
4
const streamCombiner = require("stream-combiner2");
5
const sink = require("through2-sink");
6
7
module.exports = function logStream(logger) {
8
	return streamCombiner([
9
		split(),
10
		sink((chunk) => {
11
			let line = chunk.toString();
12
13
			if (line.trim() !== "") {
14
				logger(line);
15
			}
16
		})
17
	]);
18
}