JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q33125F
  • License MIT

Wrap javascript functions according to configurable rules.

Package Exports

  • concurix-wrap

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (concurix-wrap) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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