MCPcopy Create free account
hub / github.com/sindresorhus/execa / getStreamDirection

Function getStreamDirection

lib/stdio/direction.js:13–21  ·  view source on GitHub ↗
(stdioItems, fdNumber, optionName)

Source from the content-addressed store, hash-verified

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.
13export 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`.

Callers 1

getFileDescriptorFunction · 0.90

Calls 1

getStdioItemDirectionFunction · 0.85

Tested by

no test coverage detected