[Pkg-javascript-commits] [node-get-stdin] 01/02: Imported Upstream version 4.0.1

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Fri Mar 20 23:21:09 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository node-get-stdin.

commit eaaa53d9b3d9a268e5e73c843c8970e43375e7e8
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Fri Mar 20 23:56:23 2015 +0100

    Imported Upstream version 4.0.1
---
 .editorconfig  | 15 +++++++++++++++
 .gitattributes |  1 +
 .gitignore     |  1 +
 .jshintrc      | 13 +++++++++++++
 .travis.yml    |  3 +++
 index.js       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 license        | 21 +++++++++++++++++++++
 package.json   | 35 +++++++++++++++++++++++++++++++++++
 readme.md      | 44 ++++++++++++++++++++++++++++++++++++++++++++
 test-buffer.js | 27 +++++++++++++++++++++++++++
 test-real.js   |  6 ++++++
 test.js        | 24 ++++++++++++++++++++++++
 12 files changed, 239 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..86c8f59
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[package.json]
+indent_style = space
+indent_size = 2
+
+[*.md]
+trim_trailing_whitespace = false
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..176a458
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..804f8af
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,13 @@
+{
+	"node": true,
+	"esnext": true,
+	"bitwise": true,
+	"camelcase": true,
+	"curly": true,
+	"immed": true,
+	"newcap": true,
+	"noarg": true,
+	"undef": true,
+	"unused": "vars",
+	"strict": true
+}
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..244b7e8
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,3 @@
+language: node_js
+node_js:
+  - '0.10'
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..0f1aeb3
--- /dev/null
+++ b/index.js
@@ -0,0 +1,49 @@
+'use strict';
+
+module.exports = function (cb) {
+	var stdin = process.stdin;
+	var ret = '';
+
+	if (stdin.isTTY) {
+		setImmediate(cb, '');
+		return;
+	}
+
+	stdin.setEncoding('utf8');
+
+	stdin.on('readable', function () {
+		var chunk;
+
+		while (chunk = stdin.read()) {
+			ret += chunk;
+		}
+	});
+
+	stdin.on('end', function () {
+		cb(ret);
+	});
+};
+
+module.exports.buffer = function (cb) {
+	var stdin = process.stdin;
+	var ret = [];
+	var len = 0;
+
+	if (stdin.isTTY) {
+		setImmediate(cb, new Buffer(''));
+		return;
+	}
+
+	stdin.on('readable', function () {
+		var chunk;
+
+		while (chunk = stdin.read()) {
+			ret.push(chunk);
+			len += chunk.length;
+		}
+	});
+
+	stdin.on('end', function () {
+		cb(Buffer.concat(ret, len));
+	});
+};
diff --git a/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)
+
+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/package.json b/package.json
new file mode 100644
index 0000000..9a3e42a
--- /dev/null
+++ b/package.json
@@ -0,0 +1,35 @@
+{
+  "name": "get-stdin",
+  "version": "4.0.1",
+  "description": "Easier stdin",
+  "license": "MIT",
+  "repository": "sindresorhus/get-stdin",
+  "author": {
+    "name": "Sindre Sorhus",
+    "email": "sindresorhus at gmail.com",
+    "url": "http://sindresorhus.com"
+  },
+  "engines": {
+    "node": ">=0.10.0"
+  },
+  "scripts": {
+    "test": "node test.js && node test-buffer.js && echo unicorns | node test-real.js"
+  },
+  "files": [
+    "index.js"
+  ],
+  "keywords": [
+    "std",
+    "stdin",
+    "stdio",
+    "concat",
+    "buffer",
+    "stream",
+    "process",
+    "stream"
+  ],
+  "devDependencies": {
+    "ava": "0.0.4",
+    "buffer-equal": "0.0.1"
+  }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..bc1d32a
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,44 @@
+# get-stdin [![Build Status](https://travis-ci.org/sindresorhus/get-stdin.svg?branch=master)](https://travis-ci.org/sindresorhus/get-stdin)
+
+> Easier stdin
+
+
+## Install
+
+```sh
+$ npm install --save get-stdin
+```
+
+
+## Usage
+
+```js
+// example.js
+var stdin = require('get-stdin');
+
+stdin(function (data) {
+	console.log(data);
+	//=> unicorns
+});
+```
+
+```sh
+$ echo unicorns | node example.js
+unicorns
+```
+
+
+## API
+
+### stdin(callback)
+
+Get `stdin` as a string.
+
+### stdin.buffer(callback)
+
+Get `stdin` as a buffer.
+
+
+## License
+
+MIT © [Sindre Sorhus](http://sindresorhus.com)
diff --git a/test-buffer.js b/test-buffer.js
new file mode 100644
index 0000000..799e907
--- /dev/null
+++ b/test-buffer.js
@@ -0,0 +1,27 @@
+'use strict';
+var test = require('ava');
+var bufferEqual = require('buffer-equal');
+var stdin = require('./');
+
+test('get stdin as a buffer', function (t) {
+	t.plan(2);
+	process.stdin.isTTY = false;
+
+	stdin.buffer(function (data) {
+		t.assert(bufferEqual(data, new Buffer('unicorns')));
+		t.assert(data.toString().trim() === 'unicorns');
+	});
+
+	process.stdin.push(new Buffer('unicorns'));
+	process.stdin.emit('end');
+});
+
+test('get empty buffer when no stdin', function (t) {
+	t.plan(1);
+	process.stdin.isTTY = true;
+
+	stdin.buffer(function (data) {
+		t.assert(bufferEqual(data, new Buffer('')));
+	});
+});
+
diff --git a/test-real.js b/test-real.js
new file mode 100644
index 0000000..c6b63d3
--- /dev/null
+++ b/test-real.js
@@ -0,0 +1,6 @@
+'use strict';
+var stdin = require('./');
+
+stdin(function (data) {
+	process.exit(data ? 0 : 1);
+});
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..b2734f7
--- /dev/null
+++ b/test.js
@@ -0,0 +1,24 @@
+'use strict';
+var test = require('ava');
+var stdin = require('./');
+
+test('get stdin', function (t) {
+	t.plan(1);
+	process.stdin.isTTY = false;
+
+	stdin(function (data) {
+		t.assert(data.trim() === 'unicorns');
+	});
+
+	process.stdin.push('unicorns');
+	process.stdin.emit('end');
+});
+
+test('get empty string when no stdin', function (t) {
+	t.plan(1);
+	process.stdin.isTTY = true;
+
+	stdin(function (data) {
+		t.assert(data === '');
+	});
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-get-stdin.git



More information about the Pkg-javascript-commits mailing list