Current Dev State

This commit is contained in:
Tim Lorsbach
2025-06-23 20:13:54 +02:00
parent b4f9bb277d
commit ded50edaa2
22617 changed files with 4345095 additions and 174 deletions

View File

@ -0,0 +1,18 @@
module.exports = function debugFactory(_debugApi, _options) {
var wrapLazyEval = require('./lazy-eval');
var formatArgs = require('./formatArgs');
var options = _options || {
formatArgs: true
};
var debugApi = _debugApi ? _debugApi : require('debug');
debugApi = wrapLazyEval(debugApi);
debugApi = formatArgs({
debugApi: debugApi,
options: options
});
return debugApi;
}

View File

@ -0,0 +1,24 @@
module.exports = function formatArgs(args) {
var debugApi = args.debugApi;
var options = args.options;
if(options.formatArgs == true){
/*
fixing it so we don't get redundant timestamps on prod
https://github.com/visionmedia/debug/issues/161
*/
debugApi.formatArgs = function() {
if (this.useColors)
arguments[0] = ' \u001b[9' + this.color + 'm' + this.namespace + ' ' + '\u001b[0m' + arguments[0];
else
arguments[0] = ' ' + this.namespace + ' ' + arguments[0];
return arguments;
}
}
else if ( typeof options.formatArgs === 'function'){
debugApi.formatArgs = options.formatArgs;
}
return debugApi;
}

View File

@ -0,0 +1,50 @@
var objectAssign = require('object-assign');
var memoize = require('memoizee');
function _resolveOutput(func, bindThis) {
var wrapped = function() {
var i = arguments.length;
var args = [];
while (i--) args[i] = arguments[i];
// lazy function eval to keep output memory pressure down, if not used
if (typeof args[0] === 'function') {
args[0] = args[0]();
}
return func.apply(bindThis, args);
};
objectAssign(wrapped, func);
return wrapped;
};
function wrapEval(_debug) {
var debugOrig = _debug;
var noop = function(){};
function debug(namespace) {
var instance = debugOrig(namespace);
// if we're not enabled then don't attempt to log anything
// if a debug namespace wraps its debug in a closure then it never allocates anything but the function itself
if (!instance.enabled){
objectAssign(noop, instance);
instance = noop;
}
else {
instance = _resolveOutput(instance);
}
return instance;
}
var debugMemoized = memoize(debug);
objectAssign(debugMemoized, debugOrig);
return debugMemoized;
}
module.exports = wrapEval;

View File

@ -0,0 +1,34 @@
function spawnFactory(_namespace, _debugFabFactory) {
var memoize = require('memoizee');
var namespace = _namespace || '';
var debugFabFactory = _debugFabFactory;
if(!debugFabFactory){
debugFabFactory = require('./debugFabFactory')();
}
function Debugger(_base, _ns){
var base = _base || '';
var ns = _ns || '';
var newNs = ns ? [base, ns].join(':') : base;
var debug = debugFabFactory(newNs);
this.debug = debug;
this.debug.spawn = this.spawn;
}
Debugger.prototype.spawn = function(ns) {
var dbg = new Debugger(this.namespace, ns);
return dbg.debug;
};
Debugger.prototype.spawn = memoize(Debugger.prototype.spawn);
var rootDebug = (new Debugger(namespace)).debug;
return rootDebug;
};
module.exports = spawnFactory;