Skip to content
Myr

input.js

This file

Path

lib/stdio/input.js

50 lines · 1.2 KiB · JavaScript

Last changed by

Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13

History of this file

Take it

Validate `input` option's type (#668)ehmickybefore adoption65742c6

line 1why, one step back
1import {isReadableStream} from 'is-stream';

Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13

line 2why, one step back
2import {isUrl, isFilePathString} from './type.js';

Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4

line 3why, one step back
3import {isUint8Array} from './utils.js';

Refactor `stdio` options (#623)ehmickybefore adoption2d76897

line 4why, one step back
4

Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25

lines 5–9why, one step back
5// Append the `stdin` option with the `input` and `inputFile` options
6export const handleInputOptions = ({input, inputFile}) => [7 handleInputOption(input),8 handleInputFileOption(inputFile),9].filter(Boolean);

Refactor `stdio` options (#623)ehmickybefore adoption2d76897

line 10why, one step back
10

Validate `input` option's type (#668)ehmickybefore adoption65742c6

line 11why, one step back
11const handleInputOption = input => input === undefined ? undefined : {

Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13

line 12why, one step back
12 type: getInputType(input),

Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25

lines 13–15why, one step back
13 value: input,
14 optionName: 'input',15 index: 0,

Refactor `stdio` options (#623)ehmickybefore adoption2d76897

lines 16–17why, one step back
16};
17

Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13

line 18why, one step back
18const getInputType = input => {

Validate `input` option's type (#668)ehmickybefore adoption65742c6

lines 19–26why, one step back
19 if (isReadableStream(input)) {
20 return 'nodeStream';21 }2223 if (typeof input === 'string') {24 return 'string';25 }26

Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4

line 27why, one step back
27 if (isUint8Array(input)) {

Validate `input` option's type (#668)ehmickybefore adoption65742c6

lines 28–34why, one step back
28 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 back
35 ...getInputFileType(inputFile),

Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25

lines 36–37why, one step back
36 optionName: 'inputFile',
37 index: 0,

Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13

lines 38–49why, one step back
38};
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 back
50};