Skip to content
Myr

utils.js

This file

Path

lib/utils.js

29 lines · 1.2 KiB · JavaScript

Last changed by

Stricter values for the `encoding` option (#928)ehmickybefore adoption477bbc4

History of this file

Take it

Stricter values for the `encoding` option (#928)ehmickybefore adoption477bbc4

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–4why, one step back
3import {addAbortListener} from 'node:events';
4import process from 'node:process';

Stricter values for the `encoding` option (#928)ehmickybefore adoption477bbc4

lines 5–11why, one step back
5
6export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);78export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);910const textDecoder = new TextDecoder();11export const uint8ArrayToString = uint8Array => textDecoder.decode(uint8Array);

Split files (#837)ehmickybefore adoption672c2d7

lines 12–27why, one step back
12
13export const isStandardStream = stream => STANDARD_STREAMS.includes(stream);14export const STANDARD_STREAMS = [process.stdin, process.stdout, process.stderr];15export const STANDARD_STREAMS_ALIASES = ['stdin', 'stdout', 'stderr'];1617export const incrementMaxListeners = (eventEmitter, maxListenersIncrement, signal) => {18 const maxListeners = eventEmitter.getMaxListeners();19 if (maxListeners === 0 || maxListeners === Number.POSITIVE_INFINITY) {20 return;21 }2223 eventEmitter.setMaxListeners(maxListeners + maxListenersIncrement);24 addAbortListener(signal, () => {25 eventEmitter.setMaxListeners(eventEmitter.getMaxListeners() - maxListenersIncrement);26 });27};

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

line 28why, one step back
28

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 29why, one step back
29export const isSubprocess = value => value instanceof ChildProcess;