Skip to content
Myr

utils.js

This file

Path

lib/utils.js

34 lines · 1.5 KiB · JavaScript

Last changed by

`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562

History of this file

Take it

Split files (#837)ehmickybefore adoption672c2d7

line 1why, one step back
1import {Buffer} from 'node:buffer';

`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562

line 2why, one step back
2import {ChildProcess} from 'node:child_process';

Split files (#837)ehmickybefore adoption672c2d7

lines 3–28why, one step back
3import {addAbortListener} from 'node:events';
4import process from 'node:process';56export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);78export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);9export const isBinary = value => isUint8Array(value) || Buffer.isBuffer(value);1011const textDecoder = new TextDecoder();12export const binaryToString = uint8ArrayOrBuffer => textDecoder.decode(uint8ArrayOrBuffer);1314export const isStandardStream = stream => STANDARD_STREAMS.includes(stream);15export const STANDARD_STREAMS = [process.stdin, process.stdout, process.stderr];16export const STANDARD_STREAMS_ALIASES = ['stdin', 'stdout', 'stderr'];1718export const incrementMaxListeners = (eventEmitter, maxListenersIncrement, signal) => {19 const maxListeners = eventEmitter.getMaxListeners();20 if (maxListeners === 0 || maxListeners === Number.POSITIVE_INFINITY) {21 return;22 }2324 eventEmitter.setMaxListeners(maxListeners + maxListenersIncrement);25 addAbortListener(signal, () => {26 eventEmitter.setMaxListeners(eventEmitter.getMaxListeners() - maxListenersIncrement);27 });28};

`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562

lines 29–34why, one step back
29
30export const isExecaChildProcess = value => isChildProcess(value)31 && typeof value.then === 'function'32 && typeof value.pipe === 'function';3334export const isChildProcess = value => value instanceof ChildProcess;