npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

concurix-wrap

v0.6.0

Published

Wrap javascript functions according to configurable rules.

Downloads

9

Readme

concurix-wrap

This is a utility library used by concurix-monitor. We suggest you check out that library as it will automatically apply this wrapper with logic for integration with the Concurix service.

NPM

david-dm david-dm

Build Status

Javascript wrappers for inserting before and after calls around a function, while preserving as much identity of the wrapped function as possible.

Unlike simple function wrappers, the returned proxy tries to mimic the wrapped function as closely as possible (including properties and name)

To get the most out of this module, you can optionally expose V8's debug as a symbol this module will look for:

node --expose-debug-as=v8debug app.js
var wrap = require("concurix-wrap");

// A silly prime number finder
function findPrimes(n) {
  var primes = [2], j, isPrime, i = 3
  while (primes.length < n) {
    isPrime = true
    for (j = 0; j < primes.length; j++) {
      if (i % primes[j] === 0) {
        isPrime = false
        break;
      }
    }
    if (isPrime) primes.push(i);
    i+=2;
  }
  return primes;
}

findPrimes = wrap(findPrimes)
  .before(function () {
    console.log("Starting `findPrimes()` at %s", new Date());
  })
  .after(function () {
    console.log("Finished `findPrimes()` at %s", new Date());
  })
  .getProxy();

var result = findPrimes(100000);
console.log(result[result.length - 1]);

/*
Starting `findPrimes()` at Tue Nov 19 2013 12:25:31 GMT-0800 (PST)
Finished `findPrimes()` at Tue Nov 19 2013 12:25:59 GMT-0800 (PST)
1299709
*/

API

var wrapped = wrap(fn)

Wrap a function with a proxy that allows you to trigger behavior before or after execution.

wrapped.getProxy()

Retreive the proxy function that will perform the original task with your added hooks.

wrapped.before(fn)

Execute fn before the wrapped function begins.

wrapped.after(fn)

Execute fn after the wrapped function completes. This does not follow asynchronous continuations.

wrapped.orgFun

Retreive the original function from the wrapper, unmodified.

LICENSE

MIT