Created
October 16, 2022 14:08
-
-
Save heartforit/1bda829c1b12bb2dcdecd02fd8ecc071 to your computer and use it in GitHub Desktop.
Check for arrow function / lambda in javascript
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
function isLambda(func){ | |
if(typeof func !== "function") throw new Error("invalid function was provided") | |
let firstLine = func.toString() | |
.split("\n")['0'] | |
.replace(/\n|\r|\s/ig, "") | |
return (!firstLine.includes("function") && (firstLine.includes(")=>{") || firstLine.includes("){"))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment