UNPKG

metarize

Version:

A lightweight, ESM-compatible TypeScript metadata library for creating and inspecting decorators with zero dependencies

54 lines 1.6 kB
/** * Simplified debug utility that provides basic namespace and conditional output functionality */ /** * Get enabled namespaces from environment variables */ function getEnabledNamespaces() { if (typeof process !== 'undefined' && process.env && process.env.DEBUG) { return process.env.DEBUG.split(',').map(ns => ns.trim()); } return []; } // We'll check the environment variables each time to support testing function getNamespaces() { return getEnabledNamespaces(); } /** * Check if a namespace is enabled * @param namespace Namespace */ function isNamespaceEnabled(namespace) { const namespaces = getNamespaces(); if (namespaces.length === 0) return false; return namespaces.some((ns) => ns === '*' || ns === namespace || (ns.endsWith('*') && namespace.startsWith(ns.slice(0, -1))) || namespace.startsWith(ns + ':')); } /** * Create a debugger instance * @param namespace Namespace */ export function createDebug(namespace) { const enabled = isNamespaceEnabled(namespace); const debugFn = function (formatter, ...args) { if (!debugFn.enabled) return; const time = new Date().toISOString(); if (typeof formatter === 'string') { console.log(`${time} ${namespace} ${formatter}`, ...args); } else { console.log(`${time} ${namespace}`, formatter, ...args); } }; debugFn.enabled = enabled; return debugFn; } /** * Default export for createDebug function */ export default createDebug; //# sourceMappingURL=debug.js.map