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

fn-args

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fn-args - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

license

15

index.js
'use strict';
module.exports = function (fn) {
module.exports = fn => {
if (typeof fn !== 'function') {

@@ -11,12 +11,11 @@ throw new TypeError('Expected a function');

// from https://github.com/jrburke/requirejs
var reComments = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
const reComments = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
var reFnArgs = /^function\s*[^(]*\(([^)]+)\)/;
// the first part matches parens-less arrow functions
// the second part matches the rest
const reFnArgs = /^(?:async)?([^=()]+)=|\(([^)]+)\)/;
var match = reFnArgs.exec(fn.toString().replace(reComments, ''));
const match = reFnArgs.exec(fn.toString().replace(reComments, ''));
return match ? match[1].split(',').map(function (el) {
return el.trim();
}) : [];
return match ? (match[1] || match[2]).split(',').map(x => x.trim()) : [];
};
{
"name": "fn-args",
"version": "1.0.0",
"description": "Get the arguments of a function",
"version": "2.0.0",
"description": "Get the arguments of a function, arrow function, generator function, async function",
"license": "MIT",

@@ -10,9 +10,9 @@ "repository": "sindresorhus/fn-args",

"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "mocha"
"test": "xo && mocha --harmony"
},

@@ -23,12 +23,25 @@ "files": [

"keywords": [
"function",
"arguments",
"fn",
"function",
"func",
"args",
"arguments",
"tostring",
"extract"
"extract",
"parse",
"generator",
"async",
"arrow"
],
"devDependencies": {
"mocha": "*"
"mocha": "*",
"semver": "^5.3.0",
"xo": "*"
},
"xo": {
"esnext": true,
"ignores": [
"test*.js"
]
}
}
# fn-args [![Build Status](https://travis-ci.org/sindresorhus/fn-args.svg?branch=master)](https://travis-ci.org/sindresorhus/fn-args)
> Get the arguments of a function
> Get the arguments of a function, arrow function, generator function, async function

@@ -8,3 +8,3 @@

```sh
```
$ npm install --save fn-args

@@ -17,6 +17,15 @@ ```

```js
var fn = function (foo, bar) {};
const fnArgs = require('fn-args');
fnArgs(fn);
fnArgs(function (foo, bar) {});
//=> ['foo', 'bar']
fnArgs((foo, bar) => {});
//=> ['foo', 'bar']
fnArgs(function * (foo, bar) {});
//=> ['foo', 'bar']
fnArgs(async function (foo, bar) {});
//=> ['foo', 'bar']
```

@@ -27,2 +36,2 @@

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)
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