input.js
This file
Path
lib/stdio/input.js
50 lines · 1.3 KiB · JavaScript
Last changed by
Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
History of this fileTake it
Validate `input` option's type (#668)ehmickybefore adoption65742c6
line 1why, one step back1import {isReadableStream} from 'is-stream';Split files (#837)ehmickybefore adoption672c2d7
line 2why, one step back2import {isUint8Array} from '../utils.js';Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
line 3why, one step back3import {isUrl, isFilePathString} from './type.js';Refactor `stdio` options (#623)ehmickybefore adoption2d76897
line 4why, one step back4Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
lines 5–9why, one step back5// Append the `stdin` option with the `input` and `inputFile` options6export const handleInputOptions = ({input, inputFile}) => [7 handleInputOption(input),8 handleInputFileOption(inputFile),9].filter(Boolean);Refactor `stdio` options (#623)ehmickybefore adoption2d76897
line 10why, one step back10Validate `input` option's type (#668)ehmickybefore adoption65742c6
line 11why, one step back11const handleInputOption = input => input === undefined ? undefined : {Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
line 12why, one step back12 type: getInputType(input),Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
lines 13–14why, one step back13 value: input,14 optionName: 'input',Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 15why, one step back15 fdNumber: 0,Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 16–17why, one step back16};17Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
line 18why, one step back18const getInputType = input => {Upgrade `is-stream` to `4.0.1` (#835)ehmickybefore adoption9cd62aa
line 19why, one step back19 if (isReadableStream(input, {checkOpen: false})) {Validate `input` option's type (#668)ehmickybefore adoption65742c6
lines 20–26why, one step back20 return 'nodeStream';21 }2223 if (typeof input === 'string') {24 return 'string';25 }26Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4
line 27why, one step back27 if (isUint8Array(input)) {Validate `input` option's type (#668)ehmickybefore adoption65742c6
lines 28–34why, one step back28 return 'uint8Array';29 }3031 throw new Error('The `input` option must be a string, a Uint8Array or a Node.js Readable stream.');32};3334const handleInputFileOption = inputFile => inputFile === undefined ? undefined : {Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
line 35why, one step back35 ...getInputFileType(inputFile),Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
line 36why, one step back36 optionName: 'inputFile',Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 37why, one step back37 fdNumber: 0,Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
lines 38–49why, one step back38};3940const getInputFileType = inputFile => {41 if (isUrl(inputFile)) {42 return {type: 'fileUrl', value: inputFile};43 }4445 if (isFilePathString(inputFile)) {46 return {type: 'filePath', value: {file: inputFile}};47 }4849 throw new Error('The `inputFile` option must be a file path string or a file URL.');Refactor `stdio` options (#623)ehmickybefore adoption2d76897
line 50why, one step back50};