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 🙏

© 2026 – Pkg Stats / Ryan Hefner

proxy-object-method

v0.1.2

Published

prefix or rear proxy for object method

Readme

proxy-object-method

rear or prefix proxy util for object method

features

  • cheap way to add prefix/rear logic for any method in object
  • register logic by chain
  • execute prefix/rear logic in concurrence way
  • custom define when to execute prefix/rear logic
  • all execute by promise

usage

  • basic usage
const ProxyObjMethod = require('proxy-object-method');
const target = {
  main (...args) {
    console.log(`main args: ${args.slice(0, -1)} ret: ${JSON.stringify(args[args.length - 1])}`)
    return true;
  }
}

const newTarget = new ProxyObjMethod(target)
 .prefix('main', function a (...args) {
   console.log(`prefix-a args: ${args.slice(0, -1)} ret: ${JSON.stringify(args[args.length - 1])}`); 
   return 'prefix1';
 })          
 .rear('main', function b (...args) {
   console.log(`rear-b args: ${args.slice(0, -1)} ret: ${JSON.stringify(args[args.length - 1])}`); 
   return 'rear1';
 })
  .end();                                                       // return proxy object

 newTarget
   .main(1, 2)
   .then(
     result => console.log('function result: ', result),
     err    => console.error('test failed and error:', err)
   );

/*
output: 

prefix-a args: 1,2 ret: {}
main args: 1,2 ret: {"a":"prefix1"}
rear-b args: 1,2 ret: {"a":"prefix1","main":true}
function result:  true
*/
  • concurrence execute
const target = {
  main (...args) {
    console.log(`main args: ${args.slice(0, -1)} ret: ${JSON.stringify(args[args.length - 1])}`)
    return true;
  }
}

// a1 and a2 will be concurrently executed 
const newTarget = new ProxyObjMethod(target)
 .prefix('main', [
   function a1 (...args) {
     console.log(`prefix-a1 args: ${args.slice(0, -1)} ret: ${JSON.stringify(args[args.length - 1])}`); 
     return 'prefix2';
   },
   function a2 (...args) {
     console.log(`prefix-a2 args: ${args.slice(0, -1)} ret: ${JSON.stringify(args[args.length - 1])}`); 
     return 'prefix3';
   }
 ])
 .end();


 newTarget
   .main(1, 2)
   .then(
     result => console.log('function result: ', result),
     err    => console.error('test failed and error:', err)
   );
/*
output:

prefix-a1 args: 1,2 ret: {}
prefix-a2 args: 1,2 ret: {}
main args: 1,2 ret: {"a1":"prefix2","a2":"prefix3"}
function result:  true
*/
  • custom execution condition
const target = {
  executable: false,
  main (...args) {
    console.log(`main args: ${args.slice(0, -1)} ret: ${JSON.stringify(args[args.length - 1])}`)
    return true;
  }
}

// a1 and a2 will be concurrently executed 
const newTarget = new ProxyObjMethod(target)
 .prefix('main',
   function a (...args) {
     console.log(`prefix-a args: ${args.slice(0, -1)} ret: ${JSON.stringify(args[args.length - 1])}`); 
     return 'prefix2';
   }
 , (target) => target.executable)
 .end();

// case1:
 newTarget
   .main(1, 2)
   .then(
     result => console.log('function result: ', result),
     err    => console.error('test failed and error:', err)
   );
/*
output: 

main args: 1,2 ret: {}
function result:  true
*/

// case2: 
newTarget.executable = true;
newTarget
 .main(1, 2)
 .then(
   result => console.log('function result: ', result),
   err    => console.error('test failed and error:', err)
 );
/*
output:

prefix-a args: 1,2 ret: {}
main args: 1,2 ret: {"a":"prefix2"}
function result:  true
*/

more explanation

Proxy-object-method use the name of function to store result and will ignore the result without name.

API

proxyObjMethod.prefix(methodName, prefixFuncs, [conditionFn])

Add one or multi prefix function.

Prefix-function will be executed with method's arguments and other front prefix-function's result map. The result map of prefix-function will look like: { [prefixFuncName]: prefixFuncResult }

if there are multi prefix-function, then they will be concurrently executed.

proxyObjMethod.rear(methodName, rearFuncs, [conditionFn])

Add one or multi rear function.

The rear-function works almost as same as prefix-function.

proxyObjMethod.end()

Return the proxy object. The object is single for proxyObjMethod