Skip to content

Instantly share code, notes, and snippets.

@lavoiesl
Last active November 23, 2020 16:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lavoiesl/5880516 to your computer and use it in GitHub Desktop.
Save lavoiesl/5880516 to your computer and use it in GitHub Desktop.
Extract a function's comment, useful to have multiline string
/*!
* Extract a function's comment, useful to have multiline string
* @link https://gist.github.com/lavoiesl/5880516
*
* Don't forget to use /*! to avoid the comment being removed in minification
*/
// Example:
// var myString = extractFuncCommentString(function(){/*!
// <p>
// foo bar
// </p>
// */});
function extractFuncCommentString(func) {
var matches = func.toString().match(/function\s*\(\)\s*\{\s*\/\*\!?\s*([\s\S]+?)\s*\*\/\s*\}/);
if (!matches) return false;
return matches[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment