File tree 9 files changed +31
-38
lines changed
9 files changed +31
-38
lines changed Original file line number Diff line number Diff line change 12
12
node-version :
13
13
- 14
14
14
- 12
15
- - 10
16
15
steps :
17
16
- uses : actions/checkout@v2
18
- - uses : actions/setup-node@v1
17
+ - uses : actions/setup-node@v2
19
18
with :
20
19
node-version : ${{ matrix.node-version }}
21
20
- run : npm install
Original file line number Diff line number Diff line change 1
- /// <reference types="node"/>
2
-
3
1
declare const getStdin : {
4
2
/**
5
3
Get [`stdin`](https://nodejs.org/api/process.html#process_process_stdin) as a `string`.
@@ -9,12 +7,10 @@ declare const getStdin: {
9
7
@example
10
8
```
11
9
// example.ts
12
- import getStdin = require( 'get-stdin') ;
10
+ import getStdin from 'get-stdin';
13
11
14
- (async () => {
15
- console.log(await getStdin());
16
- //=> 'unicorns'
17
- })
12
+ console.log(await getStdin());
13
+ //=> 'unicorns'
18
14
19
15
// $ echo unicorns | ts-node example.ts
20
16
// unicorns
@@ -30,4 +26,4 @@ declare const getStdin: {
30
26
buffer ( ) : Promise < Buffer > ;
31
27
} ;
32
28
33
- export = getStdin ;
29
+ export default getStdin ;
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
1
const { stdin} = process ;
3
2
4
- module . exports = async ( ) => {
3
+ export default async function getStdin ( ) {
5
4
let result = '' ;
6
5
7
6
if ( stdin . isTTY ) {
@@ -15,9 +14,9 @@ module.exports = async () => {
15
14
}
16
15
17
16
return result ;
18
- } ;
17
+ }
19
18
20
- module . exports . buffer = async ( ) => {
19
+ getStdin . buffer = async ( ) => {
21
20
const result = [ ] ;
22
21
let length = 0 ;
23
22
Original file line number Diff line number Diff line change 1
1
import { expectType } from 'tsd' ;
2
- import getStdin = require ( '.' ) ;
2
+ import getStdin from './index.js' ;
3
3
4
4
expectType < Promise < string > > ( getStdin ( ) ) ;
5
5
expectType < Promise < Buffer > > ( getStdin . buffer ( ) ) ;
Original file line number Diff line number Diff line change 10
10
"email" : " sindresorhus@gmail.com" ,
11
11
"url" : " https://sindresorhus.com"
12
12
},
13
+ "type" : " module" ,
14
+ "exports" : " ./index.js" ,
13
15
"engines" : {
14
- "node" : " >=10 "
16
+ "node" : " >=12 "
15
17
},
16
18
"scripts" : {
17
19
"test" : " xo && ava test.js test-buffer.js && echo unicorns | node test-real.js && tsd"
31
33
" read"
32
34
],
33
35
"devDependencies" : {
34
- "@types/node" : " ^13.13.5 " ,
35
- "ava" : " ^2.4 .0" ,
36
- "delay" : " ^4.2 .0" ,
37
- "tsd" : " ^0.11 .0" ,
38
- "xo" : " ^0.24.0 "
36
+ "@types/node" : " ^14.14.41 " ,
37
+ "ava" : " ^3.15 .0" ,
38
+ "delay" : " ^5.0 .0" ,
39
+ "tsd" : " ^0.14 .0" ,
40
+ "xo" : " ^0.38.2 "
39
41
}
40
42
}
Original file line number Diff line number Diff line change @@ -12,12 +12,10 @@ $ npm install get-stdin
12
12
13
13
``` js
14
14
// example.js
15
- const getStdin = require ( ' get-stdin' ) ;
15
+ import getStdin from ' get-stdin' ;
16
16
17
- (async () => {
18
- console .log (await getStdin ());
19
- // => 'unicorns'
20
- })();
17
+ console .log (await getStdin ());
18
+ // => 'unicorns'
21
19
```
22
20
23
21
```
Original file line number Diff line number Diff line change 1
- import { serial as test } from 'ava' ;
1
+ import test from 'ava' ;
2
2
import delay from 'delay' ;
3
- import getStdin from '.' ;
3
+ import getStdin from './index.js ' ;
4
4
5
- test ( 'get stdin' , async t => {
5
+ test . serial ( 'get stdin' , async t => {
6
6
process . stdin . isTTY = false ;
7
7
8
8
const promise = getStdin . buffer ( ) ;
9
9
process . stdin . push ( Buffer . from ( 'uni' ) ) ;
10
- process . stdin . push ( Buffer . from ( 'corns' ) ) ;
10
+ process . stdin . push ( Buffer . from ( 'corns' ) ) ; // eslint-disable-line unicorn/no-array-push-push
11
11
await delay ( 1 ) ;
12
12
process . stdin . emit ( 'end' ) ;
13
13
@@ -16,7 +16,7 @@ test('get stdin', async t => {
16
16
t . is ( data . toString ( ) , 'unicorns' ) ;
17
17
} ) ;
18
18
19
- test ( 'get empty buffer when no stdin' , async t => {
19
+ test . serial ( 'get empty buffer when no stdin' , async t => {
20
20
process . stdin . isTTY = true ;
21
21
t . true ( ( await getStdin . buffer ( ) ) . equals ( Buffer . from ( '' ) ) ) ;
22
22
} ) ;
Original file line number Diff line number Diff line change 1
- 'use strict' ;
2
- const getStdin = require ( '.' ) ;
1
+ import getStdin from './index.js' ;
3
2
4
3
( async ( ) => {
5
4
const stdin = await getStdin ( ) ;
Original file line number Diff line number Diff line change 1
- import { serial as test } from 'ava' ;
1
+ import test from 'ava' ;
2
2
import delay from 'delay' ;
3
- import getStdin from '.' ;
3
+ import getStdin from './index.js ' ;
4
4
5
- test ( 'get stdin' , async t => {
5
+ test . serial ( 'get stdin' , async t => {
6
6
process . stdin . isTTY = false ;
7
7
const promise = getStdin ( ) ;
8
8
9
9
process . stdin . push ( 'uni' ) ;
10
- process . stdin . push ( 'corns' ) ;
10
+ process . stdin . push ( 'corns' ) ; // eslint-disable-line unicorn/no-array-push-push
11
11
await delay ( 1 ) ;
12
12
process . stdin . emit ( 'end' ) ;
13
13
14
14
t . is ( ( await promise ) . trim ( ) , 'unicorns' ) ;
15
15
} ) ;
16
16
17
- test ( 'get empty string when no stdin' , async t => {
17
+ test . serial ( 'get empty string when no stdin' , async t => {
18
18
process . stdin . isTTY = true ;
19
19
t . is ( await getStdin ( ) , '' ) ;
20
20
} ) ;
You can’t perform that action at this time.
0 commit comments