Skip to content
Myr

stdio.js

This file

Path

lib/stdio.js

41 lines · 879 bytes · JavaScript

Last changed by

Replace `null` by `undefined` (#193)ehmickybefore adoptiondca1504

History of this file

Take it

Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a

lines 1–7why, one step back
1'use strict';
2const alias = ['stdin', 'stdout', 'stderr'];34const hasAlias = opts => alias.some(x => Boolean(opts[x]));56module.exports = opts => {7 if (!opts) {

Replace `null` by `undefined` (#193)ehmickybefore adoptiondca1504

line 8why, one step back
8 return;

Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a

lines 9–28why, one step back
9 }
1011 if (opts.stdio && hasAlias(opts)) {12 throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${alias.map(x => `\`${x}\``).join(', ')}`);13 }1415 if (typeof opts.stdio === 'string') {16 return opts.stdio;17 }1819 const stdio = opts.stdio || [];2021 if (!Array.isArray(stdio)) {22 throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);23 }2425 const result = [];26 const len = Math.max(stdio.length, alias.length);2728 for (let i = 0; i < len; i++) {

Replace `null` by `undefined` (#193)ehmickybefore adoptiondca1504

line 29why, one step back
29 let value;

Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a

lines 30–41why, one step back
30
31 if (stdio[i] !== undefined) {32 value = stdio[i];33 } else if (opts[alias[i]] !== undefined) {34 value = opts[alias[i]];35 }3637 result[i] = value;38 }3940 return result;41};