@@ -70,20 +70,34 @@ Output formatters collection.
70
70
const p = $` echo 'foo\n bar'`
71
71
72
72
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')
75
75
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'}
77
84
```
78
85
79
86
## ` [Symbol.asyncIterator] `
80
87
81
- Returns an async iterator of the stdout process.
88
+ Returns an async iterator for the process stdout .
82
89
83
90
``` js
84
91
const p = $` echo "Line1\n Line2\n Line3"`
85
92
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)
87
101
}
88
102
```
89
103
0 commit comments