JSPM

  • Created
  • Published
  • Downloads 273651
  • Score
    100M100P100Q158927F
  • License MIT

Parse a function, arrow function or string to object with name, args, params 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

parse-function npmjs.com The MIT License

Parse a function, arrow function or string to object with name, args, params and body properties.

code climate standard code style travis build status coverage status dependency status

Please read the CHANGELOG to see more info and the diffs between v2.0.1 and v2.1.0. There's no breaking changes.

Install

npm i parse-function --save

Usage

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 parse
  • returns {Object} with name, args, params and body properties
    • name {String} name of the function or anonymous
    • body {String} body of the function or ''
    • params {String} arguments names as string (as is) or empty string ''
    • parameters {String} hidden property, alias of params
    • args {Array} arguments names as array, or empty array []
    • arguments {Array} hidden property, alias of args
    • value {String} hidden property, string representation of the given val
    • orig {Function|ArrowFunction|String} hidden property, original given val
    • valid {Boolean} hidden property, true when val is function or string, false otherwise
    • invalid {Boolean} hidden property, opposite of opts.valid

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']
// }
  • 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 name or user/repo exists 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.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckocore.tk keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github