Skip to content
Myr

input.js

This file

Path

lib/stdio/input.js

36 lines · 1.2 KiB · JavaScript

Last changed by

Refactor `stdio` option logic (#639)ehmickybefore adoptiond6b4553

History of this file

Take it

Refactor `stdio` options (#623)ehmickybefore adoption2d76897

lines 1–3why, one step back
1import {isStream as isNodeStream} from 'is-stream';
23// Override the `stdin` option with the `input` option

Refactor `stdio` option logic (#639)ehmickybefore adoptiond6b4553

lines 4–5why, one step back
4export const handleInputOption = (stdioStream, input) => {
5 if (input === undefined || stdioStream.index !== 0) {

Refactor `stdio` options (#623)ehmickybefore adoption2d76897

lines 6–15why, one step back
6 return stdioStream;
7 }89 const optionName = 'input';10 validateInputOption(stdioStream.value, optionName);11 const type = isNodeStream(input) ? 'nodeStream' : 'stringOrBuffer';12 return {...stdioStream, value: input, type, optionName};13};1415// Override the `stdin` option with the `inputFile` option

Refactor `stdio` option logic (#639)ehmickybefore adoptiond6b4553

lines 16–17why, one step back
16export const handleInputFileOption = (stdioStream, inputFile, input) => {
17 if (inputFile === undefined || stdioStream.index !== 0) {

Refactor `stdio` options (#623)ehmickybefore adoption2d76897

lines 18–36why, one step back
18 return stdioStream;
19 }2021 if (input !== undefined) {22 throw new TypeError('The `input` and `inputFile` options cannot be both set.');23 }2425 const optionName = 'inputFile';26 validateInputOption(stdioStream.value, optionName);27 return {...stdioStream, value: inputFile, type: 'filePath', optionName};28};2930const validateInputOption = (value, optionName) => {31 if (!CAN_USE_INPUT.has(value)) {32 throw new TypeError(`The \`${optionName}\` and \`stdin\` options cannot be both set.`);33 }34};3536const CAN_USE_INPUT = new Set([undefined, null, 'overlapped', 'pipe']);