function-regex
Function regex. Regular expression for matching function parts. Expose match groups for function name, arguments and function body.
Last updated 12 years ago by tunnckocore .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install function-regex 
SYNC missed versions from official npm registry.

npm mit license build status coverage status deps status

Function regex. Regular expression for matching function parts. Expose match groups for function name, arguments and function body.

Install

npm install function-regex
npm test

Usage

For more use-cases see the tests

var functionRegex = require('function-regex');

var fixture = function testing(args, opts, dest, cb) {
  return cb ? {
    opts: [1,2,3]
  } : true;
};

fixture.toString().match(functionRegex());
//=> [1] = 'testing'
//=> [2] = 'args, opts, dest, cb'
//=> [3] = '\n    return cb ? {\n      opts: [1,2,3],\n      args: args\n    } : true;\n  '


'function(val, re) { return true; }'.match(functionRegex());
//=> [1] = ''
//=> [2] = 'val, re'
//=> [3] = ' return true; '

Matching groups

  • [0] full function ('function(val, re) { return true; }')
  • [1] function name ('testing')
  • [2] function arguments ('args, opts, dest, cb')
  • [3] function body (' return true; ')

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 27, 2015

Current Tags

  • 1.0.2                                ...           latest (12 years ago)

4 Versions

  • 1.0.2                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
  • 0.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 14
Today 1
This Week 1
This Month 5
Last Day 0
Last Week 1
Last Month 4
Dependencies (0)
None
Dev Dependencies (5)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE