Package Exports
- parse-function
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parse-function) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
parse-function

Parse a function, arrow function or string to object with
name,args,paramsandbodyproperties.
Please read the CHANGELOG!
Pro Tips (What version to use?)
There's no breaking changes between versions, the only version that have partial breaking change is v2.1.x, so don't use it.
- use
v2.0.x- if you don't need support forarrow functionsandes6 default params. - use
v2.2.x- if you just want basic support fores6 featureslikeES6 Arrow Functions(faster thanv2.3.x) - use
v2.3.x- if you want full support ofes6 arrow functionsandes6 default params(this usesacorn)
Install
npm i parse-function --saveUsage
For more use-cases see the tests
const parseFunction = require('parse-function')parseFunction
Parse function, arrow function or string to object.
[val]{Function|ArrowFunction|String} function or string to parsereturns{Object} withname,args,paramsandbodypropertiesname{String} name of the function oranonymousbody{String} body of the function or''params{String} arguments names as string (as is) or empty string''parameters{String} hidden property, alias ofparamsargs{Array} arguments names as array, or empty array[]arguments{Array} hidden property, alias ofargsvalue{String} hidden property, string representation of the givenvalorig{Function|ArrowFunction|String} hidden property, original givenvalvalid{Boolean} hidden property,truewhenvalis function or string,falseotherwiseinvalid{Boolean} hidden property, opposite ofopts.validdefaults{Object} hidden property, empty object or ES6 default params
Example
const parseFunction = require('parse-function')
const fixture = 'function testing (a, b, callback) { callback(null, a + b) }'
const obj = parseFunction(fixture)
// => {
// name: 'testing',
// body: ' callback(null, a + b) ',
// params: 'a, b, callback',
// args: ['a', 'b', 'callback']
// }
const withoutName = function (x, y) {}
const res = parseFunction(withoutName)
// => {
// name: 'anonymous',
// body: '',
// params: 'x, y',
// args: ['x', 'y']
// }Related
- function-regex: Function regex. Regular expression for matching function parts. Expose match groups for function name, arguments and function body.
- gulp-di: Dependency injection framework for the Gulp streaming build system
- is-empty-function: Check that given string, function or arrow function have empty body, using
parse-function. - is-installed: Checks that given package is installed on the system - globally or locally.
- is-missing: Check that given
nameoruser/repoexists in npm registry or in github as user repository.
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.