Comparing version 1.0.0 to 2.0.0
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) |
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
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
3036
4
35
3
15