Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
debug. perf. derf?
Simple wrappers for debugging function performance.
debug
module// DEBUG=sync:* node script.js
import * as derf from 'derf';
const fn = derf.sync('sync:fn', function(a, b) {
// slow operation
return value;
});
// DEBUG=async:* node script.js
import * as derf from 'derf';
const fn1 = derf.callback('async:fn1', function(foo, bar, cb) {
// slow operation
callback(null, value);
});
const fn2 = derf.promise('async:fn2', function(foo, bar) {
// slow operation
return Promise.resolve(value);
});
// DEBUG=middleware:* node script.js
import * as derf from 'derf';
const fn1 = derf.middleware('middleware:fn1', function(req, res, next) {
// slow operation
res.send('foo');
});
const fn2 = derf.middleware('middleware:fn2', function(req, res, next) {
// slow operation
next();
});
const fn3 = derf.middleware('middleware:fn3', function(err, req, res, next) {
// slow operation
request('/something').pipe(res);
});
Every function wrapper takes in the following arguments:
namespace
- Required. A string to pass to debug
or a debug function.fn
- Required. A function to wrap.printer
- Optional. A function to customize what is logged.derf.sync(namespace, fn, [printer])
Wraps a synchronous function.
derf.callback(namespace, fn, [printer])
Wraps a node-style async function. derf will intercept the last function passed in. Meaning it can work with the following types of argument orders.
const fn1 = derf.callback('namespace1', function(a, b, callback) { });
const fn2 = derf.callback('namespace1', function(a, callback, b) { });
const fn1 = derf.callback('namespace1', function(callback, a, b) { });
derf.promise(namespace, fn, [printer])
Wraps a function that returns a promise.
derf.middleware(namespace, fn, [printer])
Wraps express middleware, route handlers, and error handlers.
You can pass in a function as the last argument of each derf wrapper to customize what is logged. The function must return a string and is passed the following arguments:
debug
- function. the debug instance.time
- number. the time in nanoseconds array. the function to to run.args
- array. the arguments the function was called with.retArgs
- array. the error/value the function was resolved with.For example, a simple printer could look like this:
function simplePrinter(debug, time, callArgs, retArgs) {
const [err, res] = retArgs; // not available for middleware
if (err) {
debug('failed in %s nanoseconds', time);
} else {
debug('finished in %s nanoseconds', time);
}
}
TODO
FAQs
A javascript performance debugger.
The npm package derf receives a total of 583 weekly downloads. As such, derf popularity was classified as not popular.
We found that derf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.