#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?im)^(\/\*\*(?:(?:\S|\s)(?!\*\/))*?(?:\S|\s)?\*\/\s*)?((?:(?:const|var|let).*{.*})?[^}\n]*(?:\(.*\).*{))"
Local $sString = "/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
"" & @CRLF & _
"const a = {" & @CRLF & _
" apples() {" & @CRLF & _
"" & @CRLF & _
" }," & @CRLF & _
" apples2 : function() {" & @CRLF & _
" }," & @CRLF & _
" apples3 : () => {" & @CRLF & _
" }" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"function(){}" & @CRLF & _
"" & @CRLF & _
"function() {}" & @CRLF & _
"" & @CRLF & _
"function() { }" & @CRLF & _
"" & @CRLF & _
"function () { }" & @CRLF & _
"function (arg, asdf) { }" & @CRLF & _
"function (arg, asdf):Typings { }" & @CRLF & _
"function (arg, asdf):something<Else> { }" & @CRLF & _
"" & @CRLF & _
"function () { }" & @CRLF & _
"const x = function () { }" & @CRLF & _
"const { x } = function () { }" & @CRLF & _
"" & @CRLF & _
"const { x: asdf } = function () { }" & @CRLF & _
"" & @CRLF & _
"const filterFn = () => {}" & @CRLF & _
"" & @CRLF & _
"// won't grab" & @CRLF & _
"const filterFn = apples.filter(() => {});" & @CRLF & _
"// won't grab" & @CRLF & _
"const filterFn = apples.filter(function(){});" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"class Bla {" & @CRLF & _
" constructor() {" & @CRLF & _
" }" & @CRLF & _
" someMethod1() {" & @CRLF & _
" }" & @CRLF & _
" someMethod2() => {" & @CRLF & _
" }" & @CRLF & _
" get someMethod3() {" & @CRLF & _
" }" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
"HoverBoard.prototype.getFormatValueIfExists = function (prop, defaultValue) {" & @CRLF & _
" try {" & @CRLF & _
" return typeof this.config.formats[this.name][prop] !== 'undefined' ? this.config.formats[self.name][prop] : defaultValue;" & @CRLF & _
" } catch (e) {" & @CRLF & _
" return defaultValue;" & @CRLF & _
" }" & @CRLF & _
"};" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
"const getFormatValueIfExists = function (prop, defaultValue) {" & @CRLF & _
" try {" & @CRLF & _
" return typeof this.config.formats[this.name][prop] !== 'undefined' ? this.config.formats[self.name][prop] : defaultValue;" & @CRLF & _
" } catch (e) {" & @CRLF & _
" return defaultValue;" & @CRLF & _
" }" & @CRLF & _
"};" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
" var getFormatValueIfExists = (prop, defaultValue) => {" & @CRLF & _
" try {" & @CRLF & _
" return typeof this.config.formats[this.name][prop] !== 'undefined' ? this.config.formats[self.name][prop] : defaultValue;" & @CRLF & _
" } catch (e) {" & @CRLF & _
" return defaultValue;" & @CRLF & _
" }" & @CRLF & _
"};" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
"window.x = (prop, defaultValue) => {" & @CRLF & _
" try {" & @CRLF & _
" return typeof this.config.formats[this.name][prop] !== 'undefined' ? this.config.formats[self.name][prop] : defaultValue;" & @CRLF & _
" } catch (e) {" & @CRLF & _
" return defaultValue;" & @CRLF & _
" }" & @CRLF & _
"};" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
"something.else.x = (prop, defaultValue) => {" & @CRLF & _
" try {" & @CRLF & _
" return typeof this.config.formats[this.name][prop] !== 'undefined' ? this.config.formats[self.name][prop] : defaultValue;" & @CRLF & _
" } catch (e) {" & @CRLF & _
" return defaultValue;" & @CRLF & _
" }" & @CRLF & _
"};" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
"var x = null;" & @CRLF & _
"x = (prop, defaultValue) => {" & @CRLF & _
" try {" & @CRLF & _
" return typeof this.config.formats[this.name][prop] !== 'undefined' ? this.config.formats[self.name][prop] : defaultValue;" & @CRLF & _
" } catch (e) {" & @CRLF & _
" return defaultValue;" & @CRLF & _
" }" & @CRLF & _
"};" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
"function getFormatValueIfExists(prop, defaultValue) {" & @CRLF & _
" try {" & @CRLF & _
" return typeof this.config.formats[this.name][prop] !== 'undefined' ? this.config.formats[self.name][prop] : defaultValue;" & @CRLF & _
" } catch (e) {" & @CRLF & _
" return defaultValue;" & @CRLF & _
" }" & @CRLF & _
"};" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
"function (prop, defaultValue) {" & @CRLF & _
" try {" & @CRLF & _
" return typeof this.config.formats[this.name][prop] !== 'undefined' ? this.config.formats[self.name][prop] : defaultValue;" & @CRLF & _
" } catch (e) {" & @CRLF & _
" return defaultValue;" & @CRLF & _
" }" & @CRLF & _
"};" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
"(prop, defaultValue) => {" & @CRLF & _
" try {" & @CRLF & _
" return typeof this.config.formats[this.name][prop] !== 'undefined' ? this.config.formats[self.name][prop] : defaultValue;" & @CRLF & _
" } catch (e) {" & @CRLF & _
" return defaultValue;" & @CRLF & _
" }" & @CRLF & _
"};" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
"((prop, defaultValue) => {" & @CRLF & _
" try {" & @CRLF & _
" return typeof this.config.formats[this.name][prop] !== 'undefined' ? this.config.formats[self.name][prop] : defaultValue;" & @CRLF & _
" } catch (e) {" & @CRLF & _
" return defaultValue;" & @CRLF & _
" }" & @CRLF & _
"}());" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @function" & @CRLF & _
" * @description simple method that tries to retrieve a config value from the format" & @CRLF & _
" * if it exists, else it will return the second argument as the default value." & @CRLF & _
" * @param {string} prop - the prop name to retrieve" & @CRLF & _
" * @param {any} defaultValue - the value to use if we can't extract from the format" & @CRLF & _
" * @returns {any} - the default value or extracted format value" & @CRLF & _
" */" & @CRLF & _
"((prop, defaultValue) => {" & @CRLF & _
" try {" & @CRLF & _
" return typeof this.config.formats[this.name][prop] !== 'undefined' ? this.config.formats[self.name][prop] : defaultValue;" & @CRLF & _
" } catch (e) {" & @CRLF & _
" return defaultValue;" & @CRLF & _
" }" & @CRLF & _
"} (window) );" & @CRLF & _
"" & @CRLF & _
""
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH)
Local $aFullArray[0]
For $i = 0 To UBound($aArray) -1
_ArrayConcatenate($aFullArray, $aArray[$i])
Next
$aArray = $aFullArray
; Present the entire match result
_ArrayDisplay($aArray, "Result")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm