.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / strip-indent / node_modules / get-stdin / index.js
1 'use strict';
2
3 module.exports = function (cb) {
4         var stdin = process.stdin;
5         var ret = '';
6
7         if (stdin.isTTY) {
8                 setImmediate(cb, '');
9                 return;
10         }
11
12         stdin.setEncoding('utf8');
13
14         stdin.on('readable', function () {
15                 var chunk;
16
17                 while (chunk = stdin.read()) {
18                         ret += chunk;
19                 }
20         });
21
22         stdin.on('end', function () {
23                 cb(ret);
24         });
25 };
26
27 module.exports.buffer = function (cb) {
28         var stdin = process.stdin;
29         var ret = [];
30         var len = 0;
31
32         if (stdin.isTTY) {
33                 setImmediate(cb, new Buffer(''));
34                 return;
35         }
36
37         stdin.on('readable', function () {
38                 var chunk;
39
40                 while (chunk = stdin.read()) {
41                         ret.push(chunk);
42                         len += chunk.length;
43                 }
44         });
45
46         stdin.on('end', function () {
47                 cb(Buffer.concat(ret, len));
48         });
49 };