@vitruvius-labs/ts-predicate
Version:
TypeScript predicates library
16 lines (15 loc) • 448 B
JavaScript
function getName(value) {
if (typeof value === "function") {
return value.name;
}
if (typeof value === "object" && value !== null) {
// eslint-disable-next-line @ts/no-unsafe-assignment -- Prototype is loosely typed
const PROTO = Object.getPrototypeOf(value);
if (PROTO === null) {
return "";
}
return PROTO.constructor.name;
}
return undefined;
}
export { getName };