@material-ui/core
Version:
React components that implement Google's Material Design.
23 lines (19 loc) • 716 B
JavaScript
// Fork of recompose/getDisplayName with added IE11 support
// Simplified polyfill for IE11 support
// https://github.com/JamesMGreene/Function.name/blob/58b314d4a983110c3682f1228f845d39ccca1817/Function.name.js#L3
const fnNameMatchRegex = /^\s*function(?:\s|\s*\/\*.*\*\/\s*)+([^(\s/]*)\s*/;
export function getFunctionName(fn) {
const match = `${fn}`.match(fnNameMatchRegex);
const name = match && match[1];
return name || '';
}
function getDisplayName(Component) {
if (typeof Component === 'string') {
return Component;
}
if (!Component) {
return undefined;
}
return Component.displayName || Component.name || getFunctionName(Component) || 'Component';
}
export default getDisplayName;