JSPM

  • Created
  • Published
  • Downloads 165691
  • Score
    100M100P100Q155440F
  • License

Parse a given function or string (fn.toString()) to object with `name`, `args` 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 deps status

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

Install

npm install parse-function
npm test

API

For more use-cases see the tests

parseFunction

Parse given function or string to object with properties name, args, arguments and body

  • [fn] {Function|String}
  • return {Object}
    • name function name or anonymous
    • args function arguments names as array (['val', 're', 'beta']) or ''
    • arguments function arguments as string (val, re, beta) or ''
    • body 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',
//  args: ['val', 're', 'beta'],
//  arguments: 'val, re, beta',
//  body: ' return true; '
//};

var unnamed = function() {};
var res = parseFunction(unnamed);
//=> res = {
//  name: 'anonymous',
//  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, January 26, 2015