element-vir
Version:
Heroic. Reactive. Declarative. Type safe. Web components without compromise.
51 lines (50 loc) • 1.4 kB
JavaScript
import { AssertionError, check } from '@augment-vir/assert';
import { getObjectTypedKeys, wrapInTry } from '@augment-vir/common';
const expectedStaticProperties = getObjectTypedKeys({
assign: '',
assignedInputs: '',
cssVars: '',
elementOptions: '',
events: '',
hostClasses: '',
init: '',
InputsType: '',
render: '',
slotNames: '',
StateType: '',
styles: '',
tagName: '',
UpdateStateType: '',
});
/**
* Asserts that the given input is a declarative element definition.
*
* @category Util
* @see
* - {@link isDeclarativeElementDefinition}
*/
export function assertDeclarativeElementDefinition(input, failMessage) {
if (!check.isFunction(input)) {
throw new AssertionError('Input is not a declarative element constructor', failMessage);
}
expectedStaticProperties.forEach((expectedProperty) => {
if (!check.hasKey(input, expectedProperty)) {
throw new AssertionError(`missing prop '${expectedProperty}'`, failMessage);
}
});
}
/**
* Checks that the given input is a declarative element definition.
*
* @category Util
* @see
* - {@link assertDeclarativeElementDefinition}
*/
export function isDeclarativeElementDefinition(input) {
return wrapInTry(() => {
assertDeclarativeElementDefinition(input);
return true;
}, {
fallbackValue: false,
});
}