Repository URL to install this package:
|
Version:
1.2.8 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getName = exports.getClassName = exports.getDisplayName = exports.toComponentName = toComponentName;
exports.default = void 0;
var _exotic = require("../exotic");
// else if (component.identifier) {
// // @todo or @@identifier
// return component.identifier
// }
function toReactInstanceName(component) {
// react instance
let type = component;
let name = toComponentName(component.type); // console.warn('______________')
// console.log({ component, name })
// console.warn('______________')
// ' ^ ' + type.displayName
// while (type._owner) {
// type = type._owner
// recursion yay!
name += ' ^ ' + toComponentName(type._owner); // }
// console.debug('______________')
// console.log({ component, name })
// return toComponentName(component.type)
return name;
} // eslint-disable-next-line
function toComponentName(component, fallback = 'no-name') {
if ((0, _exotic.isNil)(component)) {
// @@nil
return '';
} else if (!(0, _exotic.isObj)(component)) {
return component;
} else if (!Object.isExtensible(component) && (0, _exotic.isObj)(component.type)) {
return toReactInstanceName(component);
} else if ((0, _exotic.isArray)(component)) {
return component.map(toComponentName).join('-');
} else if ((0, _exotic.isString)(component.displayName)) {
return component.displayName;
} else if (component.constructor.name === 'Function' || component.constructor.name === 'Object') {
return component.name || fallback;
} else {
return component.constructor.name || fallback;
}
}
var _default = toComponentName;
exports.default = _default;