function-name.js 465 B

12345678910111213
  1. "use strict";
  2. module.exports = function functionName(func) {
  3. return (
  4. func.displayName ||
  5. func.name ||
  6. // Use function decomposition as a last resort to get function
  7. // name. Does not rely on function decomposition to work - if it
  8. // doesn't debugging will be slightly less informative
  9. // (i.e. toString will say 'spy' rather than 'myFunc').
  10. (String(func).match(/function ([^\s(]+)/) || [])[1]
  11. );
  12. };