input-option.js
This file
Path
lib/stdio/input-option.js
54 lines · 1.3 KiB · JavaScript
Last changed by
Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 1–12why, one step back1import {isReadableStream} from 'is-stream';2import {isUint8Array} from '../utils/uint-array.js';3import {isUrl, isFilePathString} from './type.js';45// Append the `stdin` option with the `input` and `inputFile` options6export const handleInputOptions = ({input, inputFile}, fdNumber) => fdNumber === 07 ? [8 ...handleInputOption(input),9 ...handleInputFileOption(inputFile),10 ]11 : [];12Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
lines 13–19why, one step back13const handleInputOption = input => input === undefined14 ? []15 : [{16 type: getInputType(input),17 value: input,18 optionName: 'input',19 }];100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 20–36why, one step back2021const getInputType = input => {22 if (isReadableStream(input, {checkOpen: false})) {23 return 'nodeStream';24 }2526 if (typeof input === 'string') {27 return 'string';28 }2930 if (isUint8Array(input)) {31 return 'uint8Array';32 }3334 throw new Error('The `input` option must be a string, a Uint8Array or a Node.js Readable stream.');35};36Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
lines 37–42why, one step back37const handleInputFileOption = inputFile => inputFile === undefined38 ? []39 : [{40 ...getInputFileType(inputFile),41 optionName: 'inputFile',42 }];100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 43–54why, one step back4344const getInputFileType = inputFile => {45 if (isUrl(inputFile)) {46 return {type: 'fileUrl', value: inputFile};47 }4849 if (isFilePathString(inputFile)) {50 return {type: 'filePath', value: {file: inputFile}};51 }5253 throw new Error('The `inputFile` option must be a file path string or a file URL.');54};