notistack-mod
Version:
Notistack with ability to modify active snackbars.
64 lines (52 loc) • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _reactIs = require('react-is');
// https://github.com/JamesMGreene/Function.name/blob/58b314d4a983110c3682f1228f845d39ccca1817/Function.name.js#L3
var fnNameMatchRegex = /^\s*function(?:\s|\s*\/\*.*\*\/\s*)+([^(\s/]*)\s*/;
var getFunctionName = function getFunctionName(fn) {
var match = ('' + fn).match(fnNameMatchRegex);
var name = match && match[1];
return name || '';
};
/**
* @param {function} Component
* @param {string} fallback
* @returns {string | undefined}
*/
var getFunctionComponentName = function getFunctionComponentName(Component) {
var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
return Component.displayName || Component.name || getFunctionName(Component) || fallback;
};
var getWrappedName = function getWrappedName(outerType, innerType, wrapperName) {
var functionName = getFunctionComponentName(innerType);
return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
};
/**
* https://github.com/facebook/react/blob/769b1f270e1251d9dbdce0fcbd9e92e502d059b8/packages/shared/getComponentName.js
*
* @param {React.ReactType} Component
* @returns {string | undefined}
*/
exports.default = function (Component) {
if (Component == null) {
return undefined;
}
if (typeof Component === 'string') {
return Component;
}
if (typeof Component === 'function') {
return getFunctionComponentName(Component, 'Component');
}
if ((typeof Component === 'undefined' ? 'undefined' : _typeof(Component)) === 'object') {
switch (Component.$$typeof) {
case _reactIs.ForwardRef:
return getWrappedName(Component, Component.render, 'ForwardRef');
default:
return undefined;
}
}
return undefined;
};