Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 8, add TypeScript definition (#27)
- Loading branch information
1 parent
83c5c9f
commit 7ddb55c
Showing
10 changed files
with
85 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '10' | ||
- '8' | ||
- '6' | ||
- '4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/// <reference types="node"/> | ||
|
||
declare const getStdin: { | ||
/** | ||
Get [`stdin`](https://nodejs.org/api/process.html#process_process_stdin) as a `string`. | ||
@returns A promise that is resolved when the `end` event fires on the `stdin` stream, indicating that there is no more data to be read. In a TTY context, an empty `string` is returned. | ||
@example | ||
``` | ||
// example.ts | ||
import getStdin = require('get-stdin'); | ||
(async () => { | ||
console.log(await getStdin()); | ||
//=> 'unicorns' | ||
}) | ||
// $ echo unicorns | ts-node example.ts | ||
// unicorns | ||
``` | ||
*/ | ||
(): Promise<string>; | ||
|
||
/** | ||
Get [`stdin`](https://nodejs.org/api/process.html#process_process_stdin) as a `Buffer`. | ||
@returns A promise that is resolved when the `end` event fires on the `stdin` stream, indicating that there is no more data to be read. In a TTY context, an empty `Buffer` is returned. | ||
*/ | ||
buffer(): Promise<Buffer>; | ||
}; | ||
|
||
export = getStdin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {expectType} from 'tsd'; | ||
import getStdin = require('.'); | ||
|
||
expectType<Promise<string>>(getStdin()); | ||
expectType<Promise<Buffer>>(getStdin.buffer()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
import test from 'ava'; | ||
import m from '.'; | ||
import {serial as test} from 'ava'; | ||
import delay from 'delay'; | ||
import getStdin from '.'; | ||
|
||
test.serial('get stdin', async t => { | ||
t.plan(2); | ||
test('get stdin', async t => { | ||
process.stdin.isTTY = false; | ||
|
||
const promise = m.buffer(); | ||
const promise = getStdin.buffer(); | ||
process.stdin.push(Buffer.from('uni')); | ||
process.stdin.push(Buffer.from('corns')); | ||
await delay(1); | ||
process.stdin.emit('end'); | ||
|
||
const data = await promise; | ||
t.true(data.equals(Buffer.from('unicorns'))); | ||
t.is(data.toString(), 'unicorns'); | ||
}); | ||
|
||
test.serial('get empty buffer when no stdin', async t => { | ||
test('get empty buffer when no stdin', async t => { | ||
process.stdin.isTTY = true; | ||
t.true((await m.buffer()).equals(Buffer.from(''))); | ||
t.true((await getStdin.buffer()).equals(Buffer.from(''))); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
const m = require('.'); | ||
const getStdin = require('.'); | ||
|
||
m().then(data => { | ||
getStdin().then(data => { | ||
process.exit(data ? 0 : 1); // eslint-disable-line unicorn/no-process-exit | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import test from 'ava'; | ||
import m from '.'; | ||
import {serial as test} from 'ava'; | ||
import delay from 'delay'; | ||
import getStdin from '.'; | ||
|
||
test.serial('get stdin', async t => { | ||
t.plan(1); | ||
test('get stdin', async t => { | ||
process.stdin.isTTY = false; | ||
const promise = m(); | ||
const promise = getStdin(); | ||
|
||
process.stdin.push('uni'); | ||
process.stdin.push('corns'); | ||
await delay(1); | ||
process.stdin.emit('end'); | ||
|
||
t.is((await promise).trim(), 'unicorns'); | ||
}); | ||
|
||
test.serial('get empty string when no stdin', async t => { | ||
test('get empty string when no stdin', async t => { | ||
process.stdin.isTTY = true; | ||
t.is(await m(), ''); | ||
t.is(await getStdin(), ''); | ||
}); |