@knyt/luthier
Version:
A library for building standardized, type-safe native web components with full SSR and hydration support.
21 lines (20 loc) • 616 B
JavaScript
function getConstructor(obj) {
const constructor = Object.getPrototypeOf(obj).constructor;
if (constructor == null) {
return new Error("Constructor not found.");
}
return constructor;
}
/**
* @internal scope: package
*/
export function getConstructorStaticMember(obj, propertyName) {
const constructor = getConstructor(obj);
if (constructor instanceof Error) {
return constructor;
}
if (!Object.hasOwn(constructor, propertyName)) {
return new Error(`Property ${String(propertyName)} not found on constructor.`);
}
return constructor[propertyName];
}