New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dynamic-function

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamic-function

Easily create functions with dynamic name and length.

1.1.0
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

node-dynamic-function

Easily create functions with dynamic name and length. This is useful for wrapping functions without f'ing up their name and length.

Build Status Coverage Status Known Vulnerabilities dependencies Status Downloads

Install

npm install --save dynamic-function

Usage

const dynamicFunction = require('dynamic-function');

function originalFunction(originalArg1, originalArg2) {
    /* ... */
}

const wrappedFunction = dynamicFunction(originalFunction, {
  name: 'wrapped_' + originalFunction.name,
  length: originalFunction.length,
});

console.log(wrappedFunction.name);   // logs 'wrapped_originalFunction'
console.log(wrappedFunction.length); // logs 2

console.log(wrappedFunction.toString());

// function wrapped_originalFunction(originalArg1, originalArg2) {
//   /* ... */
// }

API

dynamicFunction ( func [, options] ) func : function options : object (optional) options.bind : object (default: null) options.name : string (default: '') options.length : number (default: 0)

Performance

Some environments (eg. NodeJS < 4.x.x) don't support renaming functions with Object.defineProperty. In this case there is a fallback to eval.

eval a relatively slow JavaScript feature. Avoid (over)using this in situations where high performance is required.

At start-up (for Server applications) / low load situations using this should pose no problem.

Keywords

dynamic

FAQs

Package last updated on 21 Oct 2016

Did you know?

Socket

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.

Install

Related posts