Last active
November 23, 2020 16:20
-
-
Save lavoiesl/5880516 to your computer and use it in GitHub Desktop.
Extract a function's comment, useful to have multiline string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* 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