UNPKG

nve

Version:

Run any command on specific Node.js versions

33 lines (18 loc) 487 B
import{env,stdout}from"node:process"; import{WriteStream}from"node:tty"; const{ prototype:{getColorDepth} }=WriteStream; export const getColorOptions=()=>{ if(!isInteractiveOutput()){ return{} } const colorDepth=getColorDepth(); if(colorDepth===1){ return{} } const forceColor=COLOR_DEPTH_TO_FORCE[colorDepth]; return{env:{FORCE_COLOR:forceColor}} }; const isInteractiveOutput=()=>stdout.isTTY||env.TEST_TTY==="true"; const COLOR_DEPTH_TO_FORCE={1:"0",4:"1",8:"2",24:"3"};