Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-function-params

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-function-params - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

src/decode.js

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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc