Last active
February 12, 2024 17:18
-
-
Save westc/efa315de762da96b98e2 to your computer and use it in GitHub Desktop.
getComments(fn, opt_trim) returns an array of all the comments in the specified function.
This file contains hidden or 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
(function(RGX_COMMENT, RGX_TRIM) { | |
getComments = function (fn, opt_trim) { | |
var comments = []; | |
(fn + '').replace(RGX_COMMENT, function(m, a, b, c) { | |
if (!c) { | |
m = a == undefined ? b : a; | |
comments.push(opt_trim ? m.replace(RGX_TRIM, '') : m); | |
} | |
}); | |
return comments; | |
}; | |
})(/\/\*([\s\S]*?)\*\/|(?:<\!--|\/\/)([^\r\n]*)|(["'])(?:[^\\\3]+|\\[\s\S])+\3/g, /^[\s\xA0]+|[\s\xA0]+$/g); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The regular expression includes the part for match strings to avoid pulling what looks like a comment out of a string.