source: frontend/node_modules/@sinonjs/commons/lib/function-name.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 818 bytes
RevLine 
[9af201e]1"use strict";
2
3/**
4 * Returns a display name for a function
5 *
6 * @param {Function} func
7 * @returns {string}
8 */
9module.exports = function functionName(func) {
10 if (!func) {
11 return "";
12 }
13
14 try {
15 return (
16 func.displayName ||
17 func.name ||
18 // Use function decomposition as a last resort to get function
19 // name. Does not rely on function decomposition to work - if it
20 // doesn't debugging will be slightly less informative
21 // (i.e. toString will say 'spy' rather than 'myFunc').
22 (String(func).match(/function ([^\s(]+)/) || [])[1]
23 );
24 } catch (e) {
25 // Stringify may fail and we might get an exception, as a last-last
26 // resort fall back to empty string.
27 return "";
28 }
29};
Note: See TracBrowser for help on using the repository browser.