element-vir
Version:
Heroic. Reactive. Declarative. Type safe. Web components without compromise.
28 lines (27 loc) • 867 B
JavaScript
import { check } from '@augment-vir/assert';
/**
* Checks if the input is an instance of a DeclarativeElement, the super class of all custom
* elements defined with element-vir.
*
* @category Util
*/
export function isDeclarativeElement(input) {
const markerProperties = [
'instanceInputs',
'instanceState',
'definition',
];
return check.hasKeys(input, markerProperties);
}
/**
* Checks if the input is an instance of a DeclarativeElement, the super class of all custom
* elements defined with element-vir.
*
* @category Util
*/
export function assertIsDeclarativeElement(input) {
if (!isDeclarativeElement(input)) {
console.error('this is not a declarative element:', input);
throw new Error(`${String(check.hasKey(input, 'tagName') ? input.tagName : input)} is not a declarative element.`);
}
}