Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
The mimic-fn package is a utility that allows you to copy the properties of a function onto another function. This includes the function's name, length (the number of arguments it expects), and custom properties. It is useful when you want to wrap a function without losing its original properties, which can be important for debugging, introspection, and certain function-based APIs that rely on these properties.
Copying function properties
This feature allows you to copy all properties from the original function to the wrapper function, including the function name and custom properties.
const mimicFn = require('mimic-fn');
function original() {}
original.customProp = 'hello';
function wrapper() {
return original();
}
console.log(wrapper.name); // 'wrapper'
console.log(wrapper.customProp); // undefined
mimicFn(wrapper, original);
console.log(wrapper.name); // 'original'
console.log(wrapper.customProp); // 'hello'
The rename-function package allows you to change the name of a function, which is one aspect of what mimic-fn does. However, it does not handle copying other properties or the function's length.
Make a function mimic another one
Useful when you wrap a function in another function and like to preserve the original name and other properties.
$ npm install --save mimic-fn
const mimicFn = require('mimic-fn');
function foo() {}
foo.unicorn = '🦄';
function wrapper() {
return foo() {};
}
console.log(wrapper.name);
//=> 'wrapper'
mimicFn(wrapper, foo);
console.log(wrapper.name);
//=> 'foo'
console.log(wrapper.unicorn);
//=> '🦄'
It will copy over the properties name
, length
, displayName
, and any custom properties you may have set.
Type: Function
Mimicking function.
Type: Function
Function to mimic.
MIT © Sindre Sorhus
FAQs
Make a function mimic another one
The npm package mimic-fn receives a total of 29,472,472 weekly downloads. As such, mimic-fn popularity was classified as popular.
We found that mimic-fn 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.