input.js
This file
Path
lib/stdio/input.js
38 lines · 974 bytes · JavaScript
Last changed by
Validate `input` option's type (#668)ehmickybefore adoption65742c6
History of this fileTake it
Validate `input` option's type (#668)ehmickybefore adoption65742c6
lines 1–2why, one step back1import {Buffer} from 'node:buffer';2import {isReadableStream} from 'is-stream';Refactor `stdio` options (#623)ehmickybefore adoption2d76897
line 3why, one step back3Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
lines 4–8why, one step back4// Append the `stdin` option with the `input` and `inputFile` options5export const handleInputOptions = ({input, inputFile}) => [6 handleInputOption(input),7 handleInputFileOption(inputFile),8].filter(Boolean);Refactor `stdio` options (#623)ehmickybefore adoption2d76897
line 9why, one step back9Validate `input` option's type (#668)ehmickybefore adoption65742c6
lines 10–11why, one step back10const handleInputOption = input => input === undefined ? undefined : {11 type: getType(input),Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
lines 12–14why, one step back12 value: input,13 optionName: 'input',14 index: 0,Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 15–16why, one step back15};16Validate `input` option's type (#668)ehmickybefore adoption65742c6
lines 17–33why, one step back17const getType = input => {18 if (isReadableStream(input)) {19 return 'nodeStream';20 }2122 if (typeof input === 'string') {23 return 'string';24 }2526 if (Object.prototype.toString.call(input) === '[object Uint8Array]' && !Buffer.isBuffer(input)) {27 return 'uint8Array';28 }2930 throw new Error('The `input` option must be a string, a Uint8Array or a Node.js Readable stream.');31};3233const handleInputFileOption = inputFile => inputFile === undefined ? undefined : {Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
lines 34–37why, one step back34 type: 'filePath',35 value: inputFile,36 optionName: 'inputFile',37 index: 0,Refactor `stdio` options (#623)ehmickybefore adoption2d76897
line 38why, one step back38};