(stdioItems, fdNumber, optionName)
| 11 | // When `stdio[fdNumber]` is a single value, this guess is fairly straightforward. |
| 12 | // However, when it is an array instead, we also need to make sure the different values are not incompatible with each other. |
| 13 | export const getStreamDirection = (stdioItems, fdNumber, optionName) => { |
| 14 | const directions = stdioItems.map(stdioItem => getStdioItemDirection(stdioItem, fdNumber)); |
| 15 | |
| 16 | if (directions.includes('input') && directions.includes('output')) { |
| 17 | throw new TypeError(`The \`${optionName}\` option must not be an array of both readable and writable values.`); |
| 18 | } |
| 19 | |
| 20 | return directions.find(Boolean) ?? DEFAULT_DIRECTION; |
| 21 | }; |
| 22 | |
| 23 | // `direction` is set when the user explicitly requests it, e.g. `{value: 'pipe', input: true}`. |
| 24 | // It takes precedence over guessing, but not over the fixed direction of `stdin`/`stdout`/`stderr`. |
no test coverage detected