Skip to content

Instantly share code, notes, and snippets.

@awkward-ninja
Created November 23, 2017 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awkward-ninja/d996f2714d2233335a6ff22be547518b to your computer and use it in GitHub Desktop.
Save awkward-ninja/d996f2714d2233335a6ff22be547518b to your computer and use it in GitHub Desktop.
Angular-style parameter name extraction (in ES6)
const
PARAMS_RE = /^[^(]*\(([^)]*)\)/m,
COMMENT_RE = /((\/\/.*$)|(\/\*.*?\*\/))/mg,
SPACE_RE = /\s*/mg
const params = String( pred )
.match( PARAMS_RE )[ 1 ]
.replace( COMMENT_RE, '' )
.replace( SPACE_RE, '' )
.split( ',' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment