rename-function
Advanced tools
Comparing version 1.0.0 to 1.0.1
## 1.0.1 - 2016-04-14 | ||
- Release v1.0.1 / npm@v1.0.1 | ||
- update description and docs | ||
- allow passing context as third argument or as bind/call/apply-ing `renameFunction` | ||
## 1.0.0 - 2016-04-14 | ||
@@ -4,0 +9,0 @@ - Release v1.0.0 / npm@v1.0.0 |
@@ -31,2 +31,3 @@ /*! | ||
* @param {String} `name` | ||
* @param {Object} `ctx` | ||
* @return {Function} | ||
@@ -36,3 +37,3 @@ * @api public | ||
module.exports = function renameFunction (fn, name) { | ||
module.exports = function renameFunction (fn, name, ctx) { | ||
if (typeof fn !== 'function') { | ||
@@ -45,4 +46,4 @@ throw new TypeError('rename-function: expect `fn` be function') | ||
name = utils.namify(name) | ||
var str = format('return function %s(){return fn.apply(this,arguments)}', name) | ||
var func = (new Function('fn', str))(fn) // eslint-disable-line no-new-func | ||
var str = format('return function %s() { return fn.apply(ctx || this, arguments) }', name) | ||
var func = (new Function('fn', 'ctx', str))(fn, ctx || this) // eslint-disable-line no-new-func | ||
@@ -49,0 +50,0 @@ utils.defineProperty(func, 'toString', function toString () { |
{ | ||
"name": "rename-function", | ||
"version": "1.0.0", | ||
"description": "Rename a given function. Tries to be cross-platform and guaranteed. Useful when you want to preserve name of bound function.", | ||
"version": "1.0.1", | ||
"description": "Rename a given function. Tries to be cross-platform and guaranteed. Useful when you want to preserve name of bound function. In bonus, allows passing context to the renamed function.", | ||
"repository": "tunnckoCore/rename-function", | ||
@@ -6,0 +6,0 @@ "author": "Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)", |
# [rename-function][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] | ||
> Rename a given function. Tries to be cross-platform and guaranteed. Useful when you want to preserve name of bound function. | ||
> Rename a given function. Tries to be cross-platform and guaranteed. Useful when you want to preserve name of bound function. In bonus, allows passing context to the renamed function. | ||
@@ -19,3 +19,3 @@ [![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url] | ||
### [renameFunction](index.js#L35) | ||
### [renameFunction](index.js#L36) | ||
> Rename given `fn` with `name`. If given `name` is same as old, then the `fn` is just returned earlier, nothing more is done. | ||
@@ -27,2 +27,3 @@ | ||
* `name` **{String}** | ||
* `ctx` **{Object}** | ||
* `returns` **{Function}** | ||
@@ -29,0 +30,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
10972
77
105