get-function-params
Advanced tools
Comparing version 2.0.1 to 2.0.2
46
index.js
@@ -1,39 +0,9 @@ | ||
var cache = [] | ||
var patterns = require('./src/patterns') | ||
var encode = require('./src/encode') | ||
var decode = require('./src/decode') | ||
var prePatterns = [ | ||
/'.*?'/, | ||
/".*?"/, | ||
/`.*?`/, | ||
/\[.*?\]/, | ||
/{.*?}/, | ||
/=>\s*?\(.*?\)/, | ||
] | ||
module.exports = function (fn) { | ||
var cache = [] | ||
var postPatterns = [ | ||
/\(.*?\)/, | ||
] | ||
var delim = function (id) { return [':~:', id, ':~:'].join('') } | ||
var encode = function (string, patterns) { | ||
patterns.forEach(function (pattern) { | ||
while (pattern.test(string)) { | ||
var match = pattern.exec(string)[0] | ||
string = string.replace(match, delim(cache.push(match))) | ||
} | ||
}) | ||
return string | ||
} | ||
var decode = function (string) { | ||
var pattern = /:~:(\d+?):~:/ | ||
while (pattern.test(string)) { | ||
var id = pattern.exec(string)[1] | ||
string = string.replace(delim(id), cache[id-1]) | ||
} | ||
return eval('('+string+')') | ||
} | ||
module.exports = function (fn) { | ||
var params = encode(fn.toString().replace(/\/\*.*?\*\//g, ''), prePatterns) | ||
var params = encode(cache, fn.toString().replace(/\/\*.*?\*\//g, ''), patterns.prePatterns) | ||
.match(/(?:function\s*\((.*)\)|\((.*)\))/) | ||
@@ -43,3 +13,3 @@ | ||
return encode(params, postPatterns) | ||
return encode(cache, params, patterns.postPatterns) | ||
.split(',') | ||
@@ -52,5 +22,5 @@ .filter(function (i) { return i }) // filter empty results | ||
} | ||
if (data[1]) obj.default = decode(data.slice(1).join('=')) | ||
if (data[1]) obj.default = decode(cache, data.slice(1).join('=')) | ||
return obj | ||
}) | ||
} |
{ | ||
"name": "get-function-params", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Get list of function params, including default values (if any)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
3430
8
64
1