![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
A dynamic proxy for javascript. Provide a light weight proxy class generator with multiple interception.
###About The purpose of Benalu is provide a simple way to do a simple AOP in javascript. Benalu also useful for IOC container library that hasn't support for interception like Inversify 1.x
###Features
Can proxy a Function prototype or an object.
Can proxy method & property
Can add multiple interceptions
###Installation
npm install benalu
###How To Use It
Using benalu is very simple. You start building your proxy by using Benalu
builder
//declare the class
function MyObject(){}
MyObject.prototype.getNumber = function(){
return 700;
}
//create instance
var myObject = new MyObject();
//make a proxy
var proxy = Benalu.fromInstance(myObject)
.addInterception(function(i) {
//filter the invocation
if(i.methodName == "getNumber"){
//call the real method
i.proceed();
//override the return value
i.returnValue = 300;
}
})
.build();
var numResult = proxy.getNumber();
//numResult become 300 vs 700
###Interception & Invocation
Interception in Benalu simply a callback function with single parameter of Invocation
.
Invocation consist of 3 important members:
methodName
name of current invoked method. Usefull when you only want to intercept
specific method of the class
parameters
arguments passed to the invoked method. Usefull when you want to get
information of the arguments passed to the method.
proceed()
method to proceed current invocation. This method will invoke the
method of the real object.
returnValue
return value of the current invoked method. this member filled
automatically after the proceed()
method called. You can override the return value
of current invocation by suplying a value to the returnValue
member
###Interception Priority Interception can be applied more than one in a proxy. The last inserted interceptor having the most priority. If the last interceptor change the return value of Invocation then all previous override will be ignored.
FAQs
A dynamic proxy for javascript
We found that benalu 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.