UNPKG

knip

Version:

Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects

29 lines (28 loc) 1.33 kB
import util, { parseArgs } from 'node:util'; import st from './colors.js'; const { values } = parseArgs({ strict: false, options: { debug: { type: 'boolean' } } }); const IS_DEBUG_ENABLED = values.debug ?? false; const IS_COLORS = !process.env.NO_COLOR; const noop = () => { }; const inspectOptions = { maxArrayLength: null, depth: null, colors: IS_COLORS }; export const inspect = (obj) => console.log(util.inspect(obj, inspectOptions)); const ctx = (text) => typeof text === 'string' ? st.yellow(`[${text}]`) : `${st.yellow(`[${text[0]}]`)} ${st.cyan(text[1])}`; const logArray = (collection) => { console.log(util.inspect(collection.sort(), inspectOptions)); }; export const debugLog = IS_DEBUG_ENABLED ? (context, message) => console.log(`${ctx(context)} ${message}`) : noop; export const debugLogObject = IS_DEBUG_ENABLED ? (context, name, obj) => { console.log(`${ctx(context)} ${name}`); console.log(util.inspect(typeof obj === 'function' ? obj() : obj, inspectOptions)); } : noop; export const debugLogArray = IS_DEBUG_ENABLED ? (context, message, elements) => { const collection = Array.from(typeof elements === 'function' ? elements() : elements); console.debug(`${ctx(context)} ${message} (${collection.length})`); logArray(collection); } : noop;