JSPM

  • Created
  • Published
  • Downloads 270548
  • Score
    100M100P100Q170063F
  • License

Parse a given function or string (fn.toString()) to object with `name`, `params`, `parameters`, `args`, `arguments` and `body` properties.

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

npm mit license build status coverage status deps status

Parse a given function or string (fn.toString()) to object with name, params, parameters, args, arguments and body properties.

Install

npm i --save parse-function
npm test

API

For more use-cases see the tests

parseFunction

Parse a given function or string (fn.toString()) to object with name, params, parameters, args, arguments and body properties.

  • [fn] {Function|String}
  • return {Object}
    • name {String} function name or 'anonymous'
    • params {String} function arguments names or ''
    • parameters {String} function arguments names or ''
    • args {Array} function arguments names or []
    • arguments {Array} function arguments names or []
    • body {String} function body as string or ''

Example:

var parseFunction = require('parse-function');

var fixture = 'function testing(val, re, beta) { return true; }';
var actual = parseFunction(fixture);
//=> actual = {
//  name: 'testing',
//  params: 'val, re, beta',
//  parameters: 'val, re, beta',
//  args: ['val', 're', 'beta'],
//  arguments: ['val', 're', 'beta'],
//  body: ' return true; '
//};

var unnamed = function() {};
var res = parseFunction(unnamed);
//=> res = {
//  name: 'anonymous',
//  params: '',
//  parameters: '',
//  args: [],
//  arguments: [],
//  body: ''
//};

Author

Charlike Mike Reagent

License MIT license

Copyright (c) 2014-2015 Charlike Mike Reagent, contributors.
Released under the MIT license.


Powered and automated by kdf, February 9, 2015