UNPKG

nano-spawn

Version:

Tiny process execution for humans — a better child_process

13 lines (10 loc) 400 B
import process from 'node:process'; import {stripVTControlCharacters} from 'node:util'; export const getContext = raw => ({ start: process.hrtime.bigint(), command: raw.map(part => getCommandPart(stripVTControlCharacters(part))).join(' '), state: {stdout: '', stderr: '', output: ''}, }); const getCommandPart = part => /[^\w./-]/.test(part) ? `'${part.replaceAll('\'', '\'\\\'\'')}'` : part;