Skip to content

Commit 4dda4d4

Browse files
committed
docs: describe .lines(delimiter) API
1 parent 12c8c60 commit 4dda4d4

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

docs/process-output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface ProcessOutput extends Error {
3030
text(encoding: Encoding = 'utf8'): string
3131

3232
// Output lines splitted by newline
33-
lines(): string[]
33+
lines(delimiter?: string | RegExp): string[]
3434

3535
// combined stdout and stderr
3636
toString(): string

docs/process-promise.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,34 @@ Output formatters collection.
7070
const p = $`echo 'foo\nbar'`
7171

7272
await p.text() // foo\n\bar\n
73-
await p.text('hex') // 666f6f0a0861720a
74-
await p.buffer() // Buffer.from('foo\n\bar\n')
73+
await p.text('hex') // 666f6f0a0861720a
74+
await p.buffer() // Buffer.from('foo\n\bar\n')
7575
await p.lines() // ['foo', 'bar']
76-
await $`echo '{"foo": "bar"}'`.json() // {foo: 'bar'}
76+
77+
// You can specify a custom lines delimiter if necessary:
78+
await $`touch foo bar baz; find ./ -type f -print0`
79+
.lines('\0') // ['./bar', './baz', './foo']
80+
81+
// If the output is a valid JSON, parse it in place:
82+
await $`echo '{"foo": "bar"}'`
83+
.json() // {foo: 'bar'}
7784
```
7885

7986
## `[Symbol.asyncIterator]`
8087

81-
Returns an async iterator of the stdout process.
88+
Returns an async iterator for the process stdout.
8289

8390
```js
8491
const p = $`echo "Line1\nLine2\nLine3"`
8592
for await (const line of p) {
86-
console.log()
93+
console.log(line)
94+
}
95+
96+
// Custom delimiter can be specified:
97+
for await (const line of $({
98+
delimiter: '\0'
99+
})`touch foo bar baz; find ./ -type f -print0`) {
100+
console.log(line)
87101
}
88102
```
89103

0 commit comments

Comments
 (0)